-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathgen_trigger_record.cxx
218 lines (194 loc) · 5.13 KB
/
gen_trigger_record.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#include <cassert>
#include <cstdio>
#include <string>
static void Usage() {
printf("gen_trigger_record <output.hxx>\n");
}
static constexpr int kNStreamsPerUnit = 40;
static constexpr int kNUnits = 150;
static constexpr int kNTriggers = 10;
static constexpr int kNHWSignalsInterfaces = 10;
static constexpr int kNTRBuilders = 10;
int main(int argc, char **argv)
{
if (argc < 2 || std::string(argv[1]) == "-h") {
Usage();
return 0;
}
FILE *f = fopen(argv[1], "w+");
assert(f);
fprintf(f,
"#ifndef TriggerRecord_H\n"
"#define TriggerRecord_H\n"
"\n"
"// THIS FILE IS GENERATED!\n"
"\n"
"#include <Rtypes.h>\n"
"\n"
"#include <cstddef>\n"
"#include <cstdint>\n"
"#include <string>\n"
"#include <vector>\n"
"\n"
"class TriggerRecord {\n"
"public:\n"
" static constexpr int kNStreamsPerUnit = %d;\n"
" static constexpr int kNUnits = %d;\n"
" static constexpr int kNTriggers = %d;\n"
" static constexpr int kNHWSignalsInterfaces = %d;\n"
" static constexpr int kNTRBuilders = %d;\n"
"\n"
" enum class EDataType {\n"
" kWIBEth,\n"
" kDAPHNEStream,\n"
" kTriggerRecordHeader,\n"
" kTriggerCandidate,\n"
" kTriggerActivity,\n"
" kTriggerPrimitive,\n"
" kHardwareSignal\n"
" };\n"
"\n"
" struct Stream {\n"
" EDataType fDataType;\n"
" std::vector<std::byte> fData;\n"
" };\n"
"\n"
" struct DetectorUnit {\n",
kNStreamsPerUnit, kNUnits, kNTriggers, kNHWSignalsInterfaces, kNTRBuilders);
for (unsigned i = 0; i < kNStreamsPerUnit; ++i) {
fprintf(f,
" Stream fStream%03d;\n",
i);
};
fprintf(f,
" };\n"
"\n"
" struct Detectors {\n"
);
for (unsigned i = 0; i < kNUnits; ++i) {
fprintf(f,
" DetectorUnit fUnit%03d;\n",
i);
};
fprintf(f,
" };\n"
"\n"
" struct HWSignalsInterfaces {\n"
);
for (unsigned i = 0; i < kNHWSignalsInterfaces; ++i) {
fprintf(f,
" Stream fHWSignalStream%03d;\n",
i);
};
fprintf(f,
" };\n"
"\n"
" struct Triggers {\n"
);
for (unsigned i = 0; i < kNTriggers; ++i) {
fprintf(f,
" Stream fTriggerStream%03d;\n",
i);
};
fprintf(f,
" };\n"
" struct TRBuilders {\n"
);
for (unsigned i = 0; i < kNTRBuilders; ++i) {
fprintf(f,
" Stream fTRBuilderStream%03d;\n",
i);
};
fprintf(f,
" };\n"
"\n"
" std::uint64_t fTRID;\n"
" std::uint64_t fSliceID;\n"
" std::string fFragmentTypeSourceIdMap;\n"
" std::string fRecordHeaderSourceId;\n"
" std::string fSourceIdPathMap;\n"
" std::string fSubdetectorSourceIdMap;\n"
"\n"
" Detectors fDetectors;\n"
" HWSignalsInterfaces fHWInterfaces;\n"
" Triggers fTriggers;\n"
" TRBuilders fTRBuilders;\n"
"\n"
" Stream *GetReadoutStream(int detId, int streamId)\n"
" {\n"
" static bool kIsInitialized = false;\n"
" static size_t kStreamOffsets[%d][%d];\n"
" if (!kIsInitialized) {\n",
kNUnits, kNStreamsPerUnit);
for (unsigned i = 0; i < kNUnits; i++) {
for (unsigned j = 0; j < kNStreamsPerUnit; j++) {
fprintf(f,
" kStreamOffsets[%d][%d] = offsetof(TriggerRecord, fDetectors.fUnit%03d.fStream%03d);\n",
i, j, i, j);
}
}
fprintf(f,
" kIsInitialized = true;\n"
" }\n"
" return reinterpret_cast<Stream *>(reinterpret_cast<unsigned char *>(this) + kStreamOffsets[detId][streamId]);\n"
" }\n"
"\n"
" Stream *GetHWSignalsInterfaceStream(int id)\n"
" {\n"
" static bool kIsInitialized = false;\n"
" static size_t kStreamOffsets[%d];\n"
" if (!kIsInitialized) {\n",
kNHWSignalsInterfaces);
for (unsigned i = 0; i < kNHWSignalsInterfaces; i++) {
fprintf(f,
" kStreamOffsets[%d] = offsetof(TriggerRecord, fHWInterfaces.fHWSignalStream%03d);\n",
i, i);
}
fprintf(f,
" kIsInitialized = true;\n"
" }\n"
" return reinterpret_cast<Stream *>(reinterpret_cast<unsigned char *>(this) + kStreamOffsets[id]);\n"
" }\n"
"\n"
" Stream *GetTRBuilderStream(int id)\n"
" {\n"
" static bool kIsInitialized = false;\n"
" static size_t kStreamOffsets[%d];\n"
" if (!kIsInitialized) {\n",
kNTRBuilders);
for (unsigned i = 0; i < kNTRBuilders; i++) {
fprintf(f,
" kStreamOffsets[%d] = offsetof(TriggerRecord, fTRBuilders.fTRBuilderStream%03d);\n",
i, i);
}
fprintf(f,
" kIsInitialized = true;\n"
" }\n"
" return reinterpret_cast<Stream *>(reinterpret_cast<unsigned char *>(this) + kStreamOffsets[id]);\n"
" }\n"
"\n"
" Stream *GetTriggerStream(int id)\n"
" {\n"
" static bool kIsInitialized = false;\n"
" static size_t kStreamOffsets[%d];\n"
" if (!kIsInitialized) {\n",
kNTriggers);
for (unsigned i = 0; i < kNTriggers; i++) {
fprintf(f,
" kStreamOffsets[%d] = offsetof(TriggerRecord, fTriggers.fTriggerStream%03d);\n",
i, i);
}
fprintf(f,
" kIsInitialized = true;\n"
" }\n"
" return reinterpret_cast<Stream *>(reinterpret_cast<unsigned char *>(this) + kStreamOffsets[id]);\n"
" }\n"
"\n"
" ClassDefNV(TriggerRecord, 1)\n"
"};\n"
"\n"
"#endif // TriggerRecord_H\n"
);
fclose(f);
return 0;
}