8 void TriggerSystem::configureSystemFromFiles(
const char *hwCfgFile,
const char *topCfgFile,
const char *
key) {
26 void TriggerSystem::addProcessor(
const char *processor,
const char *role,
const char *crate,
const char *slot) {
28 auto p2r = procToRole.find(processor);
29 if (p2r != procToRole.end() && p2r->second != role)
30 throw std::runtime_error(
"Processor: '" +
string(processor) +
"' already exists but with different role: '" +
33 procEnabled[processor] =
true;
34 procToRole[processor] = role;
35 procToSlot[processor] = slot;
36 procParameters.insert(make_pair(
string(processor), std::map<std::string, Parameter>()));
37 procMasks.insert(make_pair(
string(processor), std::map<std::string, Mask>()));
38 roleForProcs[role].insert(processor);
39 crateForProcs[crate].insert(processor);
43 void TriggerSystem::addDaq(
const char *daq,
const char *role,
const char *crate) {
44 auto d2r = daqttcToRole.find(daq);
45 if (d2r != daqttcToRole.end() && d2r->second != role)
46 throw runtime_error(
"DAQttc: '" +
string(daq) +
"' already exists but with different role: " + d2r->second);
48 daqttcToRole[daq] = role;
49 daqttcToCrate[daq] = crate;
50 roleForDaqttcs[role].insert(daq);
54 void TriggerSystem::addParameter(
55 const char *
id,
const char *procOrRole,
const char *
type,
const char *
value,
const char *delim) {
58 if (strlen(delim) == 0)
62 auto processor = procParameters.find(procOrRole);
63 if (processor != procParameters.end()) {
65 auto setting = processor->second.find(
id);
66 if (setting != processor->second.end()) {
74 processor->second.insert(make_pair(
string(
id),
Parameter(
id, procOrRole,
type,
value, delim)));
76 auto p2r = procToRole.find(procOrRole);
77 if (p2r == procToRole.end())
79 *logs <<
"Warning: TriggerSystem object doesn't yet assign "
80 <<
" a role to the processor " << procOrRole << endl;
86 auto role = roleForProcs.find(procOrRole);
87 if (role != roleForProcs.end()) {
89 for (
auto &
proc : role->second) {
90 auto processor = procParameters.find(
proc);
91 if (processor != procParameters.end()) {
94 auto setting = processor->second.find(
id);
95 if (setting == processor->second.end())
96 processor->second.insert(make_pair(
string(
id),
Parameter(
id, procOrRole,
type,
value, delim)));
98 map<string, Parameter>
tmp;
108 throw runtime_error(
"Processor or Role '" +
string(procOrRole) +
"' was not found");
111 void TriggerSystem::addTable(
const char *
id,
112 const char *procOrRole,
115 const vector<string> &
rows,
119 if (strlen(delim) == 0)
123 auto processor = procParameters.find(procOrRole);
124 if (processor != procParameters.end()) {
126 auto setting = processor->second.find(
id);
127 if (setting != processor->second.end())
133 auto p2r = procToRole.find(procOrRole);
134 if (p2r == procToRole.end())
136 *logs <<
"Warning: TriggerSystem object doesn't yet assign "
137 <<
" a role to the processor " << procOrRole << endl;
143 auto role = roleForProcs.find(procOrRole);
144 if (role != roleForProcs.end()) {
146 for (
auto &
proc : role->second) {
147 auto processor = procParameters.find(
proc);
148 if (processor != procParameters.end()) {
151 auto setting = processor->second.find(
id);
152 if (setting == processor->second.end())
155 map<string, Parameter>
tmp;
165 throw runtime_error(
"Processor or Role '" +
string(procOrRole) +
"' was not found");
168 const map<string, Parameter> &TriggerSystem::getParameters(
const char *
p)
const {
170 throw runtime_error(
"TriggerSystem is not configured yet. First call the configureSystem method");
172 auto processor = procParameters.find(
p);
173 if (processor == procParameters.end())
174 throw runtime_error(
"Processor '" +
string(
p) +
"' was not found in the configuration");
176 return processor->second;
179 void TriggerSystem::addMask(
const char *
id,
const char *procOrRoleOrDaq) {
181 auto processor = procMasks.find(procOrRoleOrDaq);
182 if (processor != procMasks.end()) {
184 auto mask = processor->second.find(
id);
185 if (mask != processor->second.end()) {
191 mask->second =
Mask(
id, procOrRoleOrDaq);
193 processor->second.insert(make_pair(
string(
id),
Mask(
id, procOrRoleOrDaq)));
195 auto p2r = procToRole.find(procOrRoleOrDaq);
196 if (p2r == procToRole.end())
198 *logs <<
"Warning: TriggerSystem object doesn't yet assign "
199 <<
" a role to the processor " << procOrRoleOrDaq << endl;
204 auto role = roleForProcs.find(procOrRoleOrDaq);
205 if (role != roleForProcs.end()) {
207 for (
auto &
proc : role->second) {
208 auto processor = procMasks.find(
proc);
209 if (processor != procMasks.end()) {
212 auto mask = processor->second.find(
id);
213 if (mask == processor->second.end())
214 processor->second.insert(make_pair(
string(
id),
Mask(
id, procOrRoleOrDaq)));
217 procMasks.insert(make_pair(
proc, map<string, Mask>({{
id,
Mask(
id, procOrRoleOrDaq)}})));
227 auto d2c = daqttcToCrate.find(procOrRoleOrDaq);
228 if (d2c != daqttcToCrate.end()) {
230 size_t idLen = strlen(
id);
231 string slot =
id + (idLen > 2 ? idLen - 2 : 0);
232 auto processors = crateForProcs.find(d2c->second);
233 if (processors != crateForProcs.end()) {
234 for (
auto &
proc : processors->second)
235 if (procToSlot[
proc] == slot)
236 procEnabled[
proc] =
false;
238 *logs <<
"Warning: no processors in daqttc crate for " << procOrRoleOrDaq <<
" ... do nothing" << endl;
243 auto r2d = roleForDaqttcs.find(procOrRoleOrDaq);
244 if (r2d != roleForDaqttcs.end()) {
245 for (
auto &daq : r2d->second) {
246 auto processors = crateForProcs.find(daq);
247 if (processors != crateForProcs.end()) {
248 for (
auto &
proc : processors->second)
249 procEnabled[
proc] =
false;
251 *logs <<
"Warning: no processors in daqttc crate " << d2c->second <<
" for " << procOrRoleOrDaq
252 <<
" ... do nothing" << endl;
258 throw runtime_error(
"Processor/DAQ or Role '" +
string(procOrRoleOrDaq) +
"' was not found in the map for masking");
261 const map<string, Mask> &TriggerSystem::getMasks(
const char *
p)
const {
263 throw std::runtime_error(
"TriggerSystem is not configured yet. First call the configureSystem method");
265 auto processor = procMasks.find(
p);
266 if (processor == procMasks.end())
267 throw std::runtime_error(
"Processor '" +
string(
p) +
"' was not found in the configuration");
269 return processor->second;
272 bool TriggerSystem::isMasked(
const char *
p,
const char *
id)
const {
273 const std::map<std::string, Mask> &
m = getMasks(
p);
275 auto mask =
m.find(
id);
282 void TriggerSystem::disableProcOrRoleOrDaq(
const char *procOrRoleOrDaq) {
286 auto processor = procEnabled.find(procOrRoleOrDaq);
287 if (processor != procEnabled.end()) {
288 processor->second =
false;
293 auto role = roleForProcs.find(procOrRoleOrDaq);
294 if (role != roleForProcs.end()) {
296 for (
auto &
proc : role->second)
298 procEnabled[
proc] =
false;
303 auto d2c = daqttcToCrate.find(procOrRoleOrDaq);
304 if (d2c != daqttcToCrate.end()) {
305 auto processors = crateForProcs.find(d2c->second);
306 if (processors != crateForProcs.end()) {
307 for (
auto &
proc : processors->second)
309 procEnabled[
proc] =
false;
311 *logs <<
"Warning: no processors in daqttc crate for " << procOrRoleOrDaq <<
" ... do nothing" << endl;
316 auto r2d = roleForDaqttcs.find(procOrRoleOrDaq);
317 if (r2d != roleForDaqttcs.end()) {
318 for (
auto &daq : r2d->second) {
319 auto d2c = daqttcToCrate.find(daq);
320 if (d2c != daqttcToCrate.end()) {
321 auto processors = crateForProcs.find(d2c->second);
322 if (processors != crateForProcs.end()) {
323 for (
auto &
proc : processors->second)
324 procEnabled[
proc] =
false;
326 *logs <<
"Warning: no processors in daqttc crate " << d2c->second <<
" for " << procOrRoleOrDaq
327 <<
" ... do nothing" << endl;
329 *logs <<
"Warning: daqttc " << daq <<
" has no crate "
330 <<
" ... do nothing" << endl;
336 throw runtime_error(
"Processor/DAQ or Role '" +
string(procOrRoleOrDaq) +
"' was not found");
339 bool TriggerSystem::isProcEnabled(
const char *
p)
const {
341 throw std::runtime_error(
"TriggerSystem is not configured yet. First call the configureSystem method");
343 auto processor = procEnabled.find(
p);
344 if (processor == procEnabled.end())
345 throw runtime_error(
"Processor '" +
string(
p) +
"' not found");
347 return processor->second;