delphi-edm4hep
DELPHI SDST/FDST -> EDM4hep converter
Loading...
Searching...
No Matches
delphi_sdst_pass.cpp
Go to the documentation of this file.
1// delphi_sdst_pass — Pass-1 binary.
2//
3// Reads a Delphi shortDST directly via PHDST and writes an intermediate
4// edm4hep file containing the sDST_* collections.
5//
6// Usage: delphi_sdst_pass <input.sdst> <output.edm4hep.root> [-n MAX]
7// delphi_sdst_pass -N|--nickname <nickname> <output.edm4hep.root> [-n MAX]
8// delphi_sdst_pass -P|--pdl <pdlinput> <output.edm4hep.root> [-n MAX]
9
11#include "delphi_edm4hep/CollectionWriter.h" // EventContext
33
34#include <charconv>
35#include <cstdlib>
36#include <cstring>
37#include <filesystem>
38#include <iostream>
39#include <string>
40#include <vector>
41
43namespace dom = delphi_edm4hep;
44
45// PHDST user-hook overrides. These MUST live in the binary TU (not in
46// libdelphi_edm4hep.a), because libphdstxx.a / libskelanaxx.a ship default
47// stubs and a double-archive-definition would error at link time.
48// We forward into the harness which dispatches to the configured hooks.
49extern "C" {
50 void user00_() noexcept { harness::on_user00(); }
51 void user01_(int* need) noexcept { harness::on_user01(need); }
52 void user02_() noexcept { harness::on_user02(); }
53 void user99_() noexcept { harness::on_user99(); }
54}
55
56static void usage(const char* argv0) {
57 std::cerr
58 << "usage: " << argv0
59 << " <input.sdst> <output.edm4hep.root> [-n MAX_EVENTS]\n"
60 << " " << argv0
61 << " -N|--nickname <nickname> <output.edm4hep.root> [-n MAX_EVENTS]\n"
62 << " " << argv0
63 << " -P|--pdl <pdlinput> <output.edm4hep.root> [-n MAX_EVENTS]\n";
64}
65
66// Parse a strictly-positive integer for -n; error + usage + exit(1) on
67// non-numeric input, <= 0, or overflow. (std::atoi silently returned 0 on
68// "-n abc"/"-n 0", which max_events<=0 then treated as "unlimited".)
69static int parseMaxEvents(const char* s, const char* argv0) {
70 int v = 0;
71 const char* end = s + std::strlen(s);
72 const auto res = std::from_chars(s, end, v);
73 if (res.ec != std::errc{} || res.ptr != end || v <= 0) {
74 std::cerr << "error: -n expects a positive integer, got '" << s << "'\n";
75 usage(argv0);
76 std::exit(1);
77 }
78 return v;
79}
80
81int main(int argc, char** argv) {
82 if (argc < 2) { usage(argv[0]); return 1; }
83
85 std::vector<std::string> positional;
86 bool have_input_mode = false;
87
88 for (int i = 1; i < argc; ++i) {
89 const std::string arg = argv[i];
90 if ((arg == "-N" || arg == "--nickname") && i + 1 < argc) {
91 if (have_input_mode) {
92 std::cerr << "error: only one of <input.sdst>, -N/--nickname,"
93 " -P/--pdl may be given\n";
94 usage(argv[0]);
95 return 1;
96 }
98 cfg.input_nickname = argv[++i];
99 have_input_mode = true;
100 } else if ((arg == "-P" || arg == "--pdl") && i + 1 < argc) {
101 if (have_input_mode) {
102 std::cerr << "error: only one of <input.sdst>, -N/--nickname,"
103 " -P/--pdl may be given\n";
104 usage(argv[0]);
105 return 1;
106 }
108 cfg.input = argv[++i];
109 have_input_mode = true;
110 } else if (arg == "-n" && i + 1 < argc) {
111 cfg.max_events = parseMaxEvents(argv[++i], argv[0]);
112 } else if (!arg.empty() && arg[0] == '-') {
113 std::cerr << "unknown option: " << arg << "\n";
114 usage(argv[0]);
115 return 1;
116 } else {
117 positional.push_back(arg);
118 }
119 }
120
121 if (have_input_mode) {
122 if (positional.size() != 1) { usage(argv[0]); return 1; }
123 cfg.output = positional[0];
124 } else {
125 if (positional.size() != 2) { usage(argv[0]); return 1; }
126 cfg.input = positional[0];
127 cfg.output = positional[1];
128 }
129
130 // Per-event dispatch: Event scalars first, then Truth gen-particles
131 // (since RecoToMC links need them), then Tracking (which Vertex /
132 // V0 / PhotonConv depend on), then the RecoToMC link emission, then
133 // Vertex. Writers run under Pass::Sdst; the prefix on each
134 // collection follows its bank.
135 cfg.on_event = [](podio::Frame& frame, int /*run*/, int /*evt*/) {
138
139 // All writers (CollectionWriter base + ctx-mediated I/O).
140 // Pipeline ordering: scalars first, then truth-gen, then tracks (so
141 // ctx.tracking is set), then everything downstream that needs it.
144 // TrackElements runs before Tracking so the mother tracks can link to
145 // the track elements while they are still mutable.
155 // sDST-only PA extras: PHOT/ODHI ParticleID, SSTC STIC showers.
159 // §3.3 deferred PSC commons: VD hits + VECP-indexed PID extras.
162
163 // PA modules that are on the (X)shortDST as well as the fullDST. Each is
164 // empty when its module is absent, which depends on the processing rather
165 // than on the era -- see the availability table in the README.
170 // B-tagging. After Tracking (needs ctx.tracking to resolve AABTAG's
171 // PA addresses onto emitted Particles).
173 };
174
175 return harness::run(cfg);
176}
void emit() override
Definition Tof.cpp:32
static int parseMaxEvents(const char *s, const char *argv0)
int main(int argc, char **argv)
void user02_() noexcept
void user99_() noexcept
void user01_(int *need) noexcept
void user00_() noexcept
static void usage(const char *argv0)
void on_user99() noexcept
void on_user02() noexcept
int run(const Config &cfg)
void on_user01(int *need) noexcept
void on_user00() noexcept
std::filesystem::path output
std::filesystem::path input