CMS 3D CMS Logo

TriggerSystem.cc
Go to the documentation of this file.
3 
4 using namespace std;
5 
6 namespace l1t {
7 
8  void TriggerSystem::configureSystemFromFiles(const char *hwCfgFile, const char *topCfgFile, const char *key) {
9  // read hw description xml
10  // this will set the sysId
11  {
12  XmlConfigParser xmlRdr;
13  xmlRdr.readDOMFromFile(hwCfgFile);
14  xmlRdr.readRootElement(*this);
15  }
16  // read configuration xml files
17  {
18  XmlConfigParser xmlRdr;
19  xmlRdr.readDOMFromFile(topCfgFile);
20  xmlRdr.buildGlobalDoc(key, topCfgFile);
21  xmlRdr.readContexts(key, sysId, *this);
22  }
23  isConfigured = true;
24  }
25 
26  void TriggerSystem::addProcessor(const char *processor, const char *role, const char *crate, const char *slot) {
27  // every processor must have a single defined role
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: '" +
31  p2r->second + "'");
32  else {
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);
40  }
41  }
42 
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);
47  else {
48  daqttcToRole[daq] = role;
49  daqttcToCrate[daq] = crate;
50  roleForDaqttcs[role].insert(daq);
51  }
52  }
53 
54  void TriggerSystem::addParameter(
55  const char *id, const char *procOrRole, const char *type, const char *value, const char *delim) {
56  // some tables forget to specify delimeter and we get an empty string here
57  // force the "," default delimeter
58  if (strlen(delim) == 0)
59  delim = ",";
60 
61  // first try to locate a processor with name matching the procOrRole argument
62  auto processor = procParameters.find(procOrRole);
63  if (processor != procParameters.end()) {
64  // processor found -> apply settings to this processor
65  auto setting = processor->second.find(id);
66  if (setting != processor->second.end()) {
67  // setting with this id already exists -> always take the latest value
68  // if( logs )
69  // *logs << "Warning: overriding already existing " << id
70  // << " = (" << setting->second.getType() << ") " << setting->second.getValue()
71  // << " with new value (" << type << ") " << value << endl;
72  setting->second = Parameter(id, procOrRole, type, value, delim);
73  } else
74  processor->second.insert(make_pair(string(id), Parameter(id, procOrRole, type, value, delim)));
75  // let's run a consistency check
76  auto p2r = procToRole.find(procOrRole);
77  if (p2r == procToRole.end())
78  if (logs)
79  *logs << "Warning: TriggerSystem object doesn't yet assign "
80  << " a role to the processor " << procOrRole << endl;
81  return;
82  }
83 
84  // if we've got here, the procOrRole argument must have meaning of role,
85  // throw exception otherwise
86  auto role = roleForProcs.find(procOrRole);
87  if (role != roleForProcs.end()) {
88  // apply setting on all of the processors for this role
89  for (auto &proc : role->second) {
90  auto processor = procParameters.find(proc);
91  if (processor != procParameters.end()) {
92  // processor found -> apply settings to this processor
93  // unless the setting with such id already exists
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)));
97  } else {
98  map<string, Parameter> tmp;
99  tmp.insert(make_pair(id, Parameter(id, procOrRole, type, value)));
100  procParameters.insert(make_pair(proc, std::move(tmp)));
101  // construct with brace-initialization, although better looking, cannot use move constructor:
102  //procParameters.insert(
103  // make_pair(proc, map<string,Parameter>( {{id,Parameter(id,procOrRole,type,value)}} ) )
104  //);
105  }
106  }
107  } else
108  throw runtime_error("Processor or Role '" + string(procOrRole) + "' was not found");
109  }
110 
111  void TriggerSystem::addTable(const char *id,
112  const char *procOrRole,
113  const char *columns,
114  const char *types,
115  const vector<string> &rows,
116  const char *delim) {
117  // some tables forget to specify delimeter and we get an empty string here
118  // force the "," default delimeter
119  if (strlen(delim) == 0)
120  delim = ",";
121 
122  // first try to locate a processor with name matching the procOrRole argument
123  auto processor = procParameters.find(procOrRole);
124  if (processor != procParameters.end()) {
125  // processor found -> apply settings to this processor
126  auto setting = processor->second.find(id);
127  if (setting != processor->second.end())
128  // setting with this id already exists -> always take latest value
129  setting->second = Parameter(id, procOrRole, types, columns, rows, delim);
130  else
131  processor->second.insert(make_pair(string(id), Parameter(id, procOrRole, types, columns, rows, delim)));
132  // let's run a consistency check
133  auto p2r = procToRole.find(procOrRole);
134  if (p2r == procToRole.end())
135  if (logs)
136  *logs << "Warning: TriggerSystem object doesn't yet assign "
137  << " a role to the processor " << procOrRole << endl;
138  return;
139  }
140 
141  // if we've got here, the procOrRole argument must have meaning of role,
142  // throw exception otherwise
143  auto role = roleForProcs.find(procOrRole);
144  if (role != roleForProcs.end()) {
145  // apply setting on all of the processors for this role
146  for (auto &proc : role->second) {
147  auto processor = procParameters.find(proc);
148  if (processor != procParameters.end()) {
149  // processor found -> apply settings to this processor
150  // unless the setting with such id already exists
151  auto setting = processor->second.find(id);
152  if (setting == processor->second.end())
153  processor->second.insert(make_pair(string(id), Parameter(id, procOrRole, types, columns, rows, delim)));
154  } else {
155  map<string, Parameter> tmp;
156  tmp.insert(make_pair(id, Parameter(id, procOrRole, types, columns, rows, delim)));
157  procParameters.insert(make_pair(proc, std::move(tmp)));
158  // construct with brace-initialization, although better looking, cannot use move constructor:
159  //procParameters.insert(
160  // make_pair(proc, map<string,Parameter>( {{id,Parameter(id,procOrRole,types,columns,rows,delim)}} ) )
161  //);
162  }
163  }
164  } else
165  throw runtime_error("Processor or Role '" + string(procOrRole) + "' was not found");
166  }
167 
168  const map<string, Parameter> &TriggerSystem::getParameters(const char *p) const {
169  if (!isConfigured)
170  throw runtime_error("TriggerSystem is not configured yet. First call the configureSystem method");
171 
172  auto processor = procParameters.find(p);
173  if (processor == procParameters.end())
174  throw runtime_error("Processor '" + string(p) + "' was not found in the configuration");
175 
176  return processor->second;
177  }
178 
179  void TriggerSystem::addMask(const char *id, const char *procOrRoleOrDaq) {
180  // first try to locate a processor with name matching the procOrRoleOrDaq argument
181  auto processor = procMasks.find(procOrRoleOrDaq);
182  if (processor != procMasks.end()) {
183  // processor found -> apply settings to this processor
184  auto mask = processor->second.find(id);
185  if (mask != processor->second.end()) {
186  // setting with this id already exists -> always take the latest value
187  //if( logs)
188  // *logs << "Warning: overriding already existing " << id
189  // << " = (" << setting->second.getType() << ") " << setting->second.getValue()
190  // << " with new value (" << type << ") " << value << endl;
191  mask->second = Mask(id, procOrRoleOrDaq);
192  } else
193  processor->second.insert(make_pair(string(id), Mask(id, procOrRoleOrDaq)));
194  // let's run a consistency check
195  auto p2r = procToRole.find(procOrRoleOrDaq);
196  if (p2r == procToRole.end())
197  if (logs)
198  *logs << "Warning: TriggerSystem object doesn't yet assign "
199  << " a role to the processor " << procOrRoleOrDaq << endl;
200  return;
201  }
202 
203  // if we've got here, the procOrRoleOrDaq argument may have meaning of role
204  auto role = roleForProcs.find(procOrRoleOrDaq);
205  if (role != roleForProcs.end()) {
206  // apply setting on all of the processors for this role
207  for (auto &proc : role->second) {
208  auto processor = procMasks.find(proc);
209  if (processor != procMasks.end()) {
210  // processor found -> apply settings to this processor
211  // unless the setting with such id already exists
212  auto mask = processor->second.find(id);
213  if (mask == processor->second.end())
214  processor->second.insert(make_pair(string(id), Mask(id, procOrRoleOrDaq)));
215  } else {
216  // here, copy constructor creates no overhead over the move constructor, whould that be defined
217  procMasks.insert(make_pair(proc, map<string, Mask>({{id, Mask(id, procOrRoleOrDaq)}})));
218  }
219  }
220  return;
221  }
222 
223  // if we've got here, the procOrRoleOrDaq argument the only choise left is daqttc configuration
224  // that, in turn, can again be a daqttc processor or daqttc role
225  // in either case, for daq we do not have any independent configuration apart from the mask status
226  // and the slot location of the processor that is masked (sitting, of course, in the same crate)
227  auto d2c = daqttcToCrate.find(procOrRoleOrDaq);
228  if (d2c != daqttcToCrate.end()) {
229  // now, as we know crate of this daqttc, look for the crate's processors that match the id name
230  size_t idLen = strlen(id);
231  string slot = id + (idLen > 2 ? idLen - 2 : 0); // last two digits of the port comptise the slot #
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;
237  } else if (logs)
238  *logs << "Warning: no processors in daqttc crate for " << procOrRoleOrDaq << " ... do nothing" << endl;
239  return;
240  }
241 
242  // so, finally, this is daqttc role
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;
250  } else if (logs)
251  *logs << "Warning: no processors in daqttc crate " << d2c->second << " for " << procOrRoleOrDaq
252  << " ... do nothing" << endl;
253  return;
254  }
255  }
256 
257  // if we ever reach here, we've ran out of options
258  throw runtime_error("Processor/DAQ or Role '" + string(procOrRoleOrDaq) + "' was not found in the map for masking");
259  }
260 
261  const map<string, Mask> &TriggerSystem::getMasks(const char *p) const {
262  if (!isConfigured)
263  throw std::runtime_error("TriggerSystem is not configured yet. First call the configureSystem method");
264 
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");
268 
269  return processor->second;
270  }
271 
272  bool TriggerSystem::isMasked(const char *p, const char *id) const {
273  const std::map<std::string, Mask> &m = getMasks(p);
274 
275  auto mask = m.find(id);
276  if (mask == m.end())
277  return false;
278 
279  return true;
280  }
281 
282  void TriggerSystem::disableProcOrRoleOrDaq(const char *procOrRoleOrDaq) {
283  // follow the standard search steps to identify if the argument is processor or role or daqttc processor/role
284 
285  // the argument is simply a processor's name
286  auto processor = procEnabled.find(procOrRoleOrDaq);
287  if (processor != procEnabled.end()) {
288  processor->second = false;
289  return;
290  }
291 
292  // role
293  auto role = roleForProcs.find(procOrRoleOrDaq);
294  if (role != roleForProcs.end()) {
295  // apply setting on all of the processors for this role
296  for (auto &proc : role->second)
297  // by design procEnabled must have every single processor for every role
298  procEnabled[proc] = false;
299  return;
300  }
301 
302  // the whole daq of a crate is disables -> disable all of the processors in the crate
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)
308  // by design procEnabled must have every single processor for every crate
309  procEnabled[proc] = false;
310  } else if (logs)
311  *logs << "Warning: no processors in daqttc crate for " << procOrRoleOrDaq << " ... do nothing" << endl;
312  return;
313  }
314 
315  // so, finally, this is daqttc role
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;
325  } else if (logs)
326  *logs << "Warning: no processors in daqttc crate " << d2c->second << " for " << procOrRoleOrDaq
327  << " ... do nothing" << endl;
328  } else if (logs)
329  *logs << "Warning: daqttc " << daq << " has no crate "
330  << " ... do nothing" << endl;
331  return;
332  }
333  }
334 
335  // if we ever reach here, we've ran out of options
336  throw runtime_error("Processor/DAQ or Role '" + string(procOrRoleOrDaq) + "' was not found");
337  }
338 
339  bool TriggerSystem::isProcEnabled(const char *p) const {
340  if (!isConfigured)
341  throw std::runtime_error("TriggerSystem is not configured yet. First call the configureSystem method");
342 
343  auto processor = procEnabled.find(p);
344  if (processor == procEnabled.end())
345  throw runtime_error("Processor '" + string(p) + "' not found");
346 
347  return processor->second;
348  }
349 
350 } // namespace l1t
l1t::XmlConfigParser::readRootElement
void readRootElement(TriggerSystem &aTriggerSystem, const std::string &sysId="")
Definition: XmlConfigParser.cc:189
createJobs.tmp
tmp
align.sh
Definition: createJobs.py:716
l1t::Mask
Definition: Mask.h:10
XmlConfigParser.h
l1t::XmlConfigParser::readContexts
void readContexts(const std::string &key, const std::string &sysId, TriggerSystem &aTriggerSystem)
Definition: XmlConfigParser.cc:502
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:78
l1t::Parameter
Definition: Parameter.h:21
l1t::XmlConfigParser
Definition: XmlConfigParser.h:23
ValidateTausOnZEEFastSim_cff.proc
proc
Definition: ValidateTausOnZEEFastSim_cff.py:6
AlCaHLTBitMon_ParallelJobs.p
def p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
l1t::XmlConfigParser::readDOMFromFile
void readDOMFromFile(const std::string &fName, xercesc::DOMDocument *&doc)
l1t
delete x;
Definition: CaloConfig.h:22
type
type
Definition: SiPixelVCal_PayloadInspector.cc:39
value
Definition: value.py:1
types
types
Definition: AlignPCLThresholds_PayloadInspector.cc:30
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
mps_check.columns
columns
Definition: mps_check.py:244
TriggerSystem.h
l1t::XmlConfigParser::buildGlobalDoc
void buildGlobalDoc(const std::string &key, const std::string &topPath="")
Definition: XmlConfigParser.cc:533
postprocess-scan-build.rows
rows
Definition: postprocess-scan-build.py:23
crabWrapper.key
key
Definition: crabWrapper.py:19