File indexing completed on 2024-04-06 12:20:28
0001 #include "L1Trigger/L1TCommon/interface/TriggerSystem.h"
0002 #include "L1Trigger/L1TCommon/interface/XmlConfigParser.h"
0003
0004 using namespace std;
0005
0006 namespace l1t {
0007
0008 void TriggerSystem::configureSystemFromFiles(const char *hwCfgFile, const char *topCfgFile, const char *key) {
0009
0010
0011 {
0012 XmlConfigParser xmlRdr;
0013 xmlRdr.readDOMFromFile(hwCfgFile);
0014 xmlRdr.readRootElement(*this);
0015 }
0016
0017 {
0018 XmlConfigParser xmlRdr;
0019 xmlRdr.readDOMFromFile(topCfgFile);
0020 xmlRdr.buildGlobalDoc(key, topCfgFile);
0021 xmlRdr.readContexts(key, sysId, *this);
0022 }
0023 isConfigured = true;
0024 }
0025
0026 void TriggerSystem::addProcessor(const char *processor, const char *role, const char *crate, const char *slot) {
0027
0028 auto p2r = procToRole.find(processor);
0029 if (p2r != procToRole.end() && p2r->second != role)
0030 throw std::runtime_error("Processor: '" + string(processor) + "' already exists but with different role: '" +
0031 p2r->second + "'");
0032 else {
0033 procEnabled[processor] = true;
0034 procToRole[processor] = role;
0035 procToSlot[processor] = slot;
0036 procParameters.insert(make_pair(string(processor), std::map<std::string, Parameter>()));
0037 procMasks.insert(make_pair(string(processor), std::map<std::string, Mask>()));
0038 roleForProcs[role].insert(processor);
0039 crateForProcs[crate].insert(processor);
0040 }
0041 }
0042
0043 void TriggerSystem::addDaq(const char *daq, const char *role, const char *crate) {
0044 auto d2r = daqttcToRole.find(daq);
0045 if (d2r != daqttcToRole.end() && d2r->second != role)
0046 throw runtime_error("DAQttc: '" + string(daq) + "' already exists but with different role: " + d2r->second);
0047 else {
0048 daqttcToRole[daq] = role;
0049 daqttcToCrate[daq] = crate;
0050 roleForDaqttcs[role].insert(daq);
0051 }
0052 }
0053
0054 void TriggerSystem::addParameter(
0055 const char *id, const char *procOrRole, const char *type, const char *value, const char *delim) {
0056
0057
0058 if (strlen(delim) == 0)
0059 delim = ",";
0060
0061
0062 auto processor = procParameters.find(procOrRole);
0063 if (processor != procParameters.end()) {
0064
0065 auto setting = processor->second.find(id);
0066 if (setting != processor->second.end()) {
0067
0068
0069
0070
0071
0072 setting->second = Parameter(id, procOrRole, type, value, delim);
0073 } else
0074 processor->second.insert(make_pair(string(id), Parameter(id, procOrRole, type, value, delim)));
0075
0076 auto p2r = procToRole.find(procOrRole);
0077 if (p2r == procToRole.end())
0078 if (logs)
0079 *logs << "Warning: TriggerSystem object doesn't yet assign "
0080 << " a role to the processor " << procOrRole << endl;
0081 return;
0082 }
0083
0084
0085
0086 auto role = roleForProcs.find(procOrRole);
0087 if (role != roleForProcs.end()) {
0088
0089 for (auto &proc : role->second) {
0090 auto processor = procParameters.find(proc);
0091 if (processor != procParameters.end()) {
0092
0093
0094 auto setting = processor->second.find(id);
0095 if (setting == processor->second.end())
0096 processor->second.insert(make_pair(string(id), Parameter(id, procOrRole, type, value, delim)));
0097 } else {
0098 map<string, Parameter> tmp;
0099 tmp.insert(make_pair(id, Parameter(id, procOrRole, type, value)));
0100 procParameters.insert(make_pair(proc, std::move(tmp)));
0101
0102
0103
0104
0105 }
0106 }
0107 } else
0108 throw runtime_error("Processor or Role '" + string(procOrRole) + "' was not found");
0109 }
0110
0111 void TriggerSystem::addTable(const char *id,
0112 const char *procOrRole,
0113 const char *columns,
0114 const char *types,
0115 const vector<string> &rows,
0116 const char *delim) {
0117
0118
0119 if (strlen(delim) == 0)
0120 delim = ",";
0121
0122
0123 auto processor = procParameters.find(procOrRole);
0124 if (processor != procParameters.end()) {
0125
0126 auto setting = processor->second.find(id);
0127 if (setting != processor->second.end())
0128
0129 setting->second = Parameter(id, procOrRole, types, columns, rows, delim);
0130 else
0131 processor->second.insert(make_pair(string(id), Parameter(id, procOrRole, types, columns, rows, delim)));
0132
0133 auto p2r = procToRole.find(procOrRole);
0134 if (p2r == procToRole.end())
0135 if (logs)
0136 *logs << "Warning: TriggerSystem object doesn't yet assign "
0137 << " a role to the processor " << procOrRole << endl;
0138 return;
0139 }
0140
0141
0142
0143 auto role = roleForProcs.find(procOrRole);
0144 if (role != roleForProcs.end()) {
0145
0146 for (auto &proc : role->second) {
0147 auto processor = procParameters.find(proc);
0148 if (processor != procParameters.end()) {
0149
0150
0151 auto setting = processor->second.find(id);
0152 if (setting == processor->second.end())
0153 processor->second.insert(make_pair(string(id), Parameter(id, procOrRole, types, columns, rows, delim)));
0154 } else {
0155 map<string, Parameter> tmp;
0156 tmp.insert(make_pair(id, Parameter(id, procOrRole, types, columns, rows, delim)));
0157 procParameters.insert(make_pair(proc, std::move(tmp)));
0158
0159
0160
0161
0162 }
0163 }
0164 } else
0165 throw runtime_error("Processor or Role '" + string(procOrRole) + "' was not found");
0166 }
0167
0168 const map<string, Parameter> &TriggerSystem::getParameters(const char *p) const {
0169 if (!isConfigured)
0170 throw runtime_error("TriggerSystem is not configured yet. First call the configureSystem method");
0171
0172 auto processor = procParameters.find(p);
0173 if (processor == procParameters.end())
0174 throw runtime_error("Processor '" + string(p) + "' was not found in the configuration");
0175
0176 return processor->second;
0177 }
0178
0179 void TriggerSystem::addMask(const char *id, const char *procOrRoleOrDaq) {
0180
0181 auto processor = procMasks.find(procOrRoleOrDaq);
0182 if (processor != procMasks.end()) {
0183
0184 auto mask = processor->second.find(id);
0185 if (mask != processor->second.end()) {
0186
0187
0188
0189
0190
0191 mask->second = Mask(id, procOrRoleOrDaq);
0192 } else
0193 processor->second.insert(make_pair(string(id), Mask(id, procOrRoleOrDaq)));
0194
0195 auto p2r = procToRole.find(procOrRoleOrDaq);
0196 if (p2r == procToRole.end())
0197 if (logs)
0198 *logs << "Warning: TriggerSystem object doesn't yet assign "
0199 << " a role to the processor " << procOrRoleOrDaq << endl;
0200 return;
0201 }
0202
0203
0204 auto role = roleForProcs.find(procOrRoleOrDaq);
0205 if (role != roleForProcs.end()) {
0206
0207 for (auto &proc : role->second) {
0208 auto processor = procMasks.find(proc);
0209 if (processor != procMasks.end()) {
0210
0211
0212 auto mask = processor->second.find(id);
0213 if (mask == processor->second.end())
0214 processor->second.insert(make_pair(string(id), Mask(id, procOrRoleOrDaq)));
0215 } else {
0216
0217 procMasks.insert(make_pair(proc, map<string, Mask>({{id, Mask(id, procOrRoleOrDaq)}})));
0218 }
0219 }
0220 return;
0221 }
0222
0223
0224
0225
0226
0227 auto d2c = daqttcToCrate.find(procOrRoleOrDaq);
0228 if (d2c != daqttcToCrate.end()) {
0229
0230 size_t idLen = strlen(id);
0231 string slot = id + (idLen > 2 ? idLen - 2 : 0);
0232 auto processors = crateForProcs.find(d2c->second);
0233 if (processors != crateForProcs.end()) {
0234 for (auto &proc : processors->second)
0235 if (procToSlot[proc] == slot)
0236 procEnabled[proc] = false;
0237 } else if (logs)
0238 *logs << "Warning: no processors in daqttc crate for " << procOrRoleOrDaq << " ... do nothing" << endl;
0239 return;
0240 }
0241
0242
0243 auto r2d = roleForDaqttcs.find(procOrRoleOrDaq);
0244 if (r2d != roleForDaqttcs.end()) {
0245 for (auto &daq : r2d->second) {
0246 auto processors = crateForProcs.find(daq);
0247 if (processors != crateForProcs.end()) {
0248 for (auto &proc : processors->second)
0249 procEnabled[proc] = false;
0250 } else if (logs)
0251 *logs << "Warning: no processors in daqttc crate " << d2c->second << " for " << procOrRoleOrDaq
0252 << " ... do nothing" << endl;
0253 return;
0254 }
0255 }
0256
0257
0258 throw runtime_error("Processor/DAQ or Role '" + string(procOrRoleOrDaq) + "' was not found in the map for masking");
0259 }
0260
0261 const map<string, Mask> &TriggerSystem::getMasks(const char *p) const {
0262 if (!isConfigured)
0263 throw std::runtime_error("TriggerSystem is not configured yet. First call the configureSystem method");
0264
0265 auto processor = procMasks.find(p);
0266 if (processor == procMasks.end())
0267 throw std::runtime_error("Processor '" + string(p) + "' was not found in the configuration");
0268
0269 return processor->second;
0270 }
0271
0272 bool TriggerSystem::isMasked(const char *p, const char *id) const {
0273 const std::map<std::string, Mask> &m = getMasks(p);
0274
0275 auto mask = m.find(id);
0276 if (mask == m.end())
0277 return false;
0278
0279 return true;
0280 }
0281
0282 void TriggerSystem::disableProcOrRoleOrDaq(const char *procOrRoleOrDaq) {
0283
0284
0285
0286 auto processor = procEnabled.find(procOrRoleOrDaq);
0287 if (processor != procEnabled.end()) {
0288 processor->second = false;
0289 return;
0290 }
0291
0292
0293 auto role = roleForProcs.find(procOrRoleOrDaq);
0294 if (role != roleForProcs.end()) {
0295
0296 for (auto &proc : role->second)
0297
0298 procEnabled[proc] = false;
0299 return;
0300 }
0301
0302
0303 auto d2c = daqttcToCrate.find(procOrRoleOrDaq);
0304 if (d2c != daqttcToCrate.end()) {
0305 auto processors = crateForProcs.find(d2c->second);
0306 if (processors != crateForProcs.end()) {
0307 for (auto &proc : processors->second)
0308
0309 procEnabled[proc] = false;
0310 } else if (logs)
0311 *logs << "Warning: no processors in daqttc crate for " << procOrRoleOrDaq << " ... do nothing" << endl;
0312 return;
0313 }
0314
0315
0316 auto r2d = roleForDaqttcs.find(procOrRoleOrDaq);
0317 if (r2d != roleForDaqttcs.end()) {
0318 for (auto &daq : r2d->second) {
0319 auto d2c = daqttcToCrate.find(daq);
0320 if (d2c != daqttcToCrate.end()) {
0321 auto processors = crateForProcs.find(d2c->second);
0322 if (processors != crateForProcs.end()) {
0323 for (auto &proc : processors->second)
0324 procEnabled[proc] = false;
0325 } else if (logs)
0326 *logs << "Warning: no processors in daqttc crate " << d2c->second << " for " << procOrRoleOrDaq
0327 << " ... do nothing" << endl;
0328 } else if (logs)
0329 *logs << "Warning: daqttc " << daq << " has no crate "
0330 << " ... do nothing" << endl;
0331 return;
0332 }
0333 }
0334
0335
0336 throw runtime_error("Processor/DAQ or Role '" + string(procOrRoleOrDaq) + "' was not found");
0337 }
0338
0339 bool TriggerSystem::isProcEnabled(const char *p) const {
0340 if (!isConfigured)
0341 throw std::runtime_error("TriggerSystem is not configured yet. First call the configureSystem method");
0342
0343 auto processor = procEnabled.find(p);
0344 if (processor == procEnabled.end())
0345 throw runtime_error("Processor '" + string(p) + "' not found");
0346
0347 return processor->second;
0348 }
0349
0350 }