delphi-edm4hep
DELPHI SDST/FDST -> EDM4hep converter
Loading...
Searching...
No Matches
DstCensus.cpp
Go to the documentation of this file.
2
3#include "phdst/functions.hpp"
4#include "phdst/uxcom.hpp"
5#include "phdst/uxlink.hpp"
6
7#include <algorithm>
8#include <cmath>
9#include <cstring>
10#include <set>
11#include <string_view>
12#include <utility>
13
14namespace ph = phdst;
15
16namespace delphi_edm4hep::census {
17namespace {
18
19// Blocklet label -> mnemonic, from PHDST's own tables: XTRAID (labels 1..21),
20// XTRAID2 (41..43) and the shortDST-family extra modules CHIDXM (22..35).
21// phdstxx.car:16689-16723. Label 0 is the standard module.
22constexpr std::pair<int, std::string_view> kModules[] = {
23 {0,"MAIN"},{1,"CCAL"},{2,"EMCA"},{3,"HCAL"},{4,"MU"},{5,"EL"},{6,"MRIC"},
24 {7,"MTPC"},{8,"TRAC"},{9,"TOF"},{10,"VD"},{11,"TDHA"},{12,"TEID"},
25 {13,"TETP"},{14,"TEOD"},{15,"TEFA"},{16,"TEFB"},{17,"TDID"},{18,"SAT"},
26 {19,"STIC"},{20,"TRAX"},{21,"TERF"},{22,"EMNC"},{23,"HCNC"},{24,"MUID"},
27 {25,"ELID"},{26,"HAID"},{27,"MUFI"},{28,"ELTR"},{29,"ODHI"},{30,"PHOT"},
28 {31,"OTRK"},{32,"NMUS"},{33,"SSTC"},{34,"HCRO"},{35,"HCMU"},
29 {41,"TEST"},{42,"TEVF"},{43,"TERB"},
30};
31
32// PILOT blocklets PHDST knows about (PIBL, phdstxx.car:16600-16660). Four
33// characters, space-padded, as IPHPIC expects.
34constexpr const char* kPilot[] = {
35 "DAS ", "VERS", "IDEN", "DANA", "DANI", "DANF", "DPHA", "DPHY", "DJET",
36 "SAT ", "VSAT", "TRIG", "TRGR", "DETV", "DETI", "DETP", "DETE", "TTAG",
37 "DTAG", "LEP ",
38};
39
40std::set<std::string> g_modules;
41std::set<std::string> g_pilot;
42
43std::string_view mnemonic(int label) {
44 for (const auto& [id, name] : kModules) {
45 if (id == label) return name;
46 }
47 return {};
48}
49
50// Trailing spaces are part of the Fortran name, not of the reported one.
51std::string trimmed(const char* name) {
52 std::string out(name);
53 while (!out.empty() && out.back() == ' ') out.pop_back();
54 return out;
55}
56
57} // namespace
58
60 const int LDTOP = ph::LDTOP;
61 if (LDTOP <= 0) return;
62
63 for (const char* name : kPilot) {
64 if (ph::IPHPIC(name, 1) > 0) g_pilot.insert(trimmed(name));
65 }
66
67 // Read the blocklet labels out of each PA header rather than probing every
68 // mnemonic: IQ(lpa+4) is the blocklet count, the words after it are the
69 // per-blocklet lengths, and blocklet i's data follows them with its label
70 // in the first word.
71 for (int lpv = ph::LQ(LDTOP - 1); lpv > 0; lpv = ph::LQ(lpv)) {
72 for (int lpa = ph::LQ(lpv - 1); lpa > 0; lpa = ph::LQ(lpa)) {
73 const int nblk = ph::IQ(lpa + 4);
74 if (nblk <= 0 || nblk > 64) continue;
75 int offset = lpa + 4 + nblk;
76 for (int i = 1; i <= nblk; ++i) {
77 const int len = ph::IQ(lpa + 4 + i);
78 if (len <= 0) break;
79 const int label = static_cast<int>(std::lround(ph::Q(offset + 1)));
80 if (const auto name = mnemonic(label); !name.empty()) {
81 g_modules.emplace(name);
82 }
83 offset += len;
84 }
85 }
86 }
87}
88
89std::vector<std::string> paModules() {
90 return {g_modules.begin(), g_modules.end()};
91}
92
93std::vector<std::string> pilotBlocklets() {
94 return {g_pilot.begin(), g_pilot.end()};
95}
96
97} // namespace delphi_edm4hep::census
std::vector< std::string > pilotBlocklets()
Definition DstCensus.cpp:93
std::vector< std::string > paModules()
Definition DstCensus.cpp:89
const char * label(Provenance prov)
Definition PaWalk.h:21