delphi-edm4hep
DELPHI SDST/FDST -> EDM4hep converter
Loading...
Searching...
No Matches
PhdstHarness.h
Go to the documentation of this file.
1// PhdstHarness.h
2//
3// Thin wrapper around the PHDST event loop (user00 / user01 / user02 /
4// user99 Fortran callbacks). Owns the per-job podio writer and per-event
5// Frame builder. Single-instance because PHDST is globally stateful —
6// one PHDST per process.
7//
8// The binary's user00_/01_/02_/99_ Fortran overrides forward into the
9// `on_user00/01/02/99` entry points exposed here. We can't put those
10// overrides in the library itself because libphdstxx.a / libskelanaxx.a
11// ship default-stub implementations and a static-archive double-supply
12// of the same symbol breaks linking.
13//
14
15#pragma once
16
17
18#include <podio/Frame.h>
19#include <podio/ROOTReader.h>
20#include <podio/ROOTWriter.h>
21
22#include <filesystem>
23#include <functional>
24#include <string>
25#include <vector>
26
28
29// Per-event hook. Called once per kept event from user02_, AFTER PSBEG
30// has populated the SKELANA commons. The hook fills `frame` from
31// whichever domain modules it needs.
32using EventHook = std::function<void(podio::Frame& frame, int run, int evt)>;
33
34// Per-job init hook (after PSINI + IFL flags + writer open) and per-job
35// teardown hook (before writer.finish()). Both optional.
36using InitHook = std::function<void()>;
37using FinalizeHook = std::function<void()>;
38
39// How `run()` builds PDLINPUT (PHDST's cwd input directive file):
40// File — `input` is a Delphi .sdst/.fadana/.al file; writes a
41// "FILE = <abs path>" directive.
42// Nickname — `input_nickname` is a DELPHI dataset nickname (e.g.
43// "short94_c2" or "short94_c2/c1-10"); writes a
44// "FAT = <nickname>" directive so PHDST's own dataset
45// lookup resolves it.
46// Pdl — `input` is a pre-built PDL file (e.g. from `fatfind`);
47// copied verbatim to PDLINPUT.
48enum class InputMode { File, Nickname, Pdl };
49
50struct Config {
51 std::filesystem::path input; // File: Delphi .sdst/.fadana/.al; Pdl: path to the PDL file to copy
52 std::string input_nickname; // Nickname: the DELPHI dataset nickname
54 std::filesystem::path output; // edm4hep output (podio writes)
55 std::filesystem::path input_edm4hep; // pass-2 only: intermediate to copy through; empty for pass 1
56 // pass-2 only: ADDITIONAL intermediates whose (run,evt) indices are
57 // unioned with input_edm4hep. A long run's official short-DST events
58 // are spread across several .al tape files; each maps to its own
59 // intermediate, and a single raw segment of that run can match events
60 // in any of them. Without the union, segments whose events live in a
61 // non-indexed tape match nothing and produce a 0-event (metadata-only)
62 // file. (run,evt) is globally unique, so the union has no real
63 // collisions; first-occurrence wins.
64 std::vector<std::filesystem::path> input_edm4hep_extra;
65 int max_events = -1; // -1 = unlimited
66
70};
71
72// Run the PHDST event loop with `cfg`. Writes a PDLINPUT in cwd per
73// cfg.input_mode (see InputMode above), drives phdst_(), and blocks until
74// done. File mode points PDLINPUT at a short cwd-local symlink rather than
75// the real path, because the legacy fixed-format parser truncates long ones.
76// Returns 0 only when at least one event was written.
77int run(const Config& cfg);
78
79// User-callback forwarders. The binary's extern "C" user*_ overrides
80// invoke these. They consult the static config + state set by `run`.
81// Every forwarder is noexcept. Throwing init, event, finalize, or writer code
82// is converted into a controlled job failure before control returns through
83// an extern "C" userNN_ callback into PHDST/Fortran.
84void on_user00() noexcept;
85void on_user01(int* need) noexcept;
86void on_user02() noexcept;
87void on_user99() noexcept;
88
89// Accessor for the pass-1 intermediate frame (when cfg.input_edm4hep is
90// non-empty). Returns nullptr otherwise or before user02 has loaded the
91// matching frame. Valid for the duration of the current event hook.
92const podio::Frame* currentSdstFrame();
93
94} // namespace delphi_edm4hep::harness
void on_user99() noexcept
void on_user02() noexcept
int run(const Config &cfg)
std::function< void()> InitHook
const podio::Frame * currentSdstFrame()
std::function< void()> FinalizeHook
void on_user01(int *need) noexcept
std::function< void(podio::Frame &frame, int run, int evt)> EventHook
void on_user00() noexcept
std::vector< std::filesystem::path > input_edm4hep_extra
std::filesystem::path input_edm4hep
std::filesystem::path output
std::filesystem::path input