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 
27 void TriggerSystem::addProcessor (const char *processor, const char *role, const char *crate, const char *slot) {
28  // every processor must have a single defined role
29  auto p2r = procToRole.find(processor);
30  if( p2r != procToRole.end() && p2r->second != role )
31  throw std::runtime_error("Processor: '" + string(processor) + "' already exists but with different role: '" + 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(const char *id, const char *procOrRole, const char *type, const char *value, const char *delim) {
55  // some tables forget to specify delimeter and we get an empty string here
56  // force the "," default delimeter
57  if( strlen(delim) == 0 ) delim = ",";
58 
59  // first try to locate a processor with name matching the procOrRole argument
60  auto processor = procParameters.find(procOrRole);
61  if( processor != procParameters.end() ){
62  // processor found -> apply settings to this processor
63  auto setting = processor->second.find(id);
64  if( setting != processor->second.end() ){
65  // setting with this id already exists -> always take the latest value
66  // if( logs )
67  // *logs << "Warning: overriding already existing " << id
68  // << " = (" << setting->second.getType() << ") " << setting->second.getValue()
69  // << " with new value (" << type << ") " << value << endl;
70  setting->second = Parameter(id,procOrRole,type,value,delim);
71  } else
72  processor->second.insert(
73  make_pair(string(id), Parameter(id,procOrRole,type,value,delim))
74  );
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(
97  make_pair(string(id), Parameter(id,procOrRole,type,value,delim))
98  );
99  } else {
100  map<string,Parameter> tmp;
101  tmp.insert( make_pair(id, Parameter(id,procOrRole,type,value)) );
102  procParameters.insert( make_pair(proc, std::move(tmp)) );
103  // construct with brace-initialization, although better looking, cannot use move constructor:
104  //procParameters.insert(
105  // make_pair(proc, map<string,Parameter>( {{id,Parameter(id,procOrRole,type,value)}} ) )
106  //);
107  }
108  }
109  } else
110  throw runtime_error("Processor or Role '" + string(procOrRole) + "' was not found");
111 }
112 
113 void TriggerSystem::addTable(const char *id, const char *procOrRole, const char *columns, const char *types, const vector<string>& rows, const char *delim) {
114  // some tables forget to specify delimeter and we get an empty string here
115  // force the "," default delimeter
116  if( strlen(delim) == 0 ) delim = ",";
117 
118  // first try to locate a processor with name matching the procOrRole argument
119  auto processor = procParameters.find(procOrRole);
120  if( processor != procParameters.end() ){
121  // processor found -> apply settings to this processor
122  auto setting = processor->second.find(id);
123  if( setting != processor->second.end() )
124  // setting with this id already exists -> always take latest value
125  setting->second = Parameter(id,procOrRole,types,columns,rows,delim);
126  else
127  processor->second.insert(
128  make_pair(string(id), Parameter(id,procOrRole,types,columns,rows,delim))
129  );
130  // let's run a consistency check
131  auto p2r = procToRole.find(procOrRole);
132  if( p2r == procToRole.end() )
133  if( logs )
134  *logs << "Warning: TriggerSystem object doesn't yet assign "
135  << " a role to the processor " << procOrRole << endl;
136  return;
137  }
138 
139  // if we've got here, the procOrRole argument must have meaning of role,
140  // throw exception otherwise
141  auto role = roleForProcs.find(procOrRole);
142  if( role != roleForProcs.end() ){
143  // apply setting on all of the processors for this role
144  for(auto &proc : role->second){
145  auto processor = procParameters.find( proc );
146  if( processor != procParameters.end() ){
147  // processor found -> apply settings to this processor
148  // unless the setting with such id already exists
149  auto setting = processor->second.find(id);
150  if( setting == processor->second.end() )
151  processor->second.insert(
152  make_pair(string(id), Parameter(id,procOrRole,types,columns,rows,delim))
153  );
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 
181  // first try to locate a processor with name matching the procOrRoleOrDaq argument
182  auto processor = procMasks.find(procOrRoleOrDaq);
183  if( processor != procMasks.end() ){
184  // processor found -> apply settings to this processor
185  auto mask = processor->second.find(id);
186  if( mask != processor->second.end() ){
187  // setting with this id already exists -> always take the latest value
188  //if( logs)
189  // *logs << "Warning: overriding already existing " << id
190  // << " = (" << setting->second.getType() << ") " << setting->second.getValue()
191  // << " with new value (" << type << ") " << value << endl;
192  mask->second = Mask(id, procOrRoleOrDaq);
193  } else
194  processor->second.insert(
195  make_pair(string(id), Mask(id, procOrRoleOrDaq))
196  );
197  // let's run a consistency check
198  auto p2r = procToRole.find(procOrRoleOrDaq);
199  if( p2r == procToRole.end() )
200  if( logs )
201  *logs << "Warning: TriggerSystem object doesn't yet assign "
202  << " a role to the processor " << procOrRoleOrDaq << endl;
203  return;
204  }
205 
206  // if we've got here, the procOrRoleOrDaq argument may have meaning of role
207  auto role = roleForProcs.find(procOrRoleOrDaq);
208  if( role != roleForProcs.end() ){
209  // apply setting on all of the processors for this role
210  for(auto &proc : role->second){
211  auto processor = procMasks.find( proc );
212  if( processor != procMasks.end() ){
213  // processor found -> apply settings to this processor
214  // unless the setting with such id already exists
215  auto mask = processor->second.find(id);
216  if( mask == processor->second.end() )
217  processor->second.insert(
218  make_pair(string(id), Mask(id, procOrRoleOrDaq))
219  );
220  } else {
221  // here, copy constructor creates no overhead over the move constructor, whould that be defined
222  procMasks.insert(
223  make_pair(proc, map<string,Mask>( {{id,Mask(id, procOrRoleOrDaq)}} ) )
224  );
225  }
226  }
227  return;
228  }
229 
230  // if we've got here, the procOrRoleOrDaq argument the only choise left is daqttc configuration
231  // that, in turn, can again be a daqttc processor or daqttc role
232  // in either case, for daq we do not have any independent configuration apart from the mask status
233  // and the slot location of the processor that is masked (sitting, of course, in the same crate)
234  auto d2c = daqttcToCrate.find(procOrRoleOrDaq);
235  if( d2c != daqttcToCrate.end() ){
236  // now, as we know crate of this daqttc, look for the crate's processors that match the id name
237  size_t idLen = strlen(id);
238  string slot = id + (idLen>2 ? idLen - 2 : 0); // last two digits of the port comptise the slot #
239  auto processors = crateForProcs.find(d2c->second);
240  if( processors != crateForProcs.end() ){
241  for(auto &proc : processors->second)
242  if( procToSlot[proc] == slot )
243  procEnabled[proc] = false;
244  } else
245  if( logs )
246  *logs << "Warning: no processors in daqttc crate for "
247  << procOrRoleOrDaq << " ... do nothing" << endl;
248  return;
249  }
250 
251  // so, finally, this is daqttc role
252  auto r2d = roleForDaqttcs.find(procOrRoleOrDaq);
253  if( r2d != roleForDaqttcs.end() ){
254  for(auto &daq : r2d->second){
255  auto processors = crateForProcs.find(daq);
256  if( processors != crateForProcs.end() ){
257  for(auto &proc : processors->second)
258  procEnabled[proc] = false;
259  } else
260  if( logs )
261  *logs << "Warning: no processors in daqttc crate " << d2c->second
262  << " for " << procOrRoleOrDaq << " ... do nothing" << endl;
263  return;
264  }
265  }
266 
267  // if we ever reach here, we've ran out of options
268  throw runtime_error ("Processor/DAQ or Role '" + string(procOrRoleOrDaq) + "' was not found in the map for masking");
269 }
270 
271 const map<string, Mask>& TriggerSystem::getMasks(const char *p) const {
272  if( !isConfigured )
273  throw std::runtime_error("TriggerSystem is not configured yet. First call the configureSystem method");
274 
275  auto processor = procMasks.find(p);
276  if( processor == procMasks.end() )
277  throw std::runtime_error("Processor '" + string(p) + "' was not found in the configuration");
278 
279  return processor->second;
280 }
281 
282 bool TriggerSystem::isMasked(const char *p, const char *id) const {
283  const std::map<std::string, Mask>& m = getMasks(p);
284 
285  auto mask = m.find(id);
286  if( mask == m.end() ) return false;
287 
288  return true;
289 }
290 
291 void TriggerSystem::disableProcOrRoleOrDaq(const char *procOrRoleOrDaq) {
292  // follow the standard search steps to identify if the argument is processor or role or daqttc processor/role
293 
294  // the argument is simply a processor's name
295  auto processor = procEnabled.find(procOrRoleOrDaq);
296  if( processor != procEnabled.end() ){
297  processor->second = false;
298  return;
299  }
300 
301  // role
302  auto role = roleForProcs.find(procOrRoleOrDaq);
303  if( role != roleForProcs.end() ){
304  // apply setting on all of the processors for this role
305  for(auto &proc : role->second)
306  // by design procEnabled must have every single processor for every role
307  procEnabled[proc] = false;
308  return;
309  }
310 
311  // the whole daq of a crate is disables -> disable all of the processors in the crate
312  auto d2c = daqttcToCrate.find(procOrRoleOrDaq);
313  if( d2c != daqttcToCrate.end() ){
314  auto processors = crateForProcs.find(d2c->second);
315  if( processors != crateForProcs.end() ){
316  for(auto &proc : processors->second)
317  // by design procEnabled must have every single processor for every crate
318  procEnabled[proc] = false;
319  } else
320  if( logs )
321  *logs << "Warning: no processors in daqttc crate for "
322  << procOrRoleOrDaq << " ... do nothing" << endl;
323  return;
324  }
325 
326  // so, finally, this is daqttc role
327  auto r2d = roleForDaqttcs.find(procOrRoleOrDaq);
328  if( r2d != roleForDaqttcs.end() ){
329  for(auto &daq : r2d->second){
330  auto d2c = daqttcToCrate.find(daq);
331  if( d2c != daqttcToCrate.end() ){
332  auto processors = crateForProcs.find(d2c->second);
333  if( processors != crateForProcs.end() ){
334  for(auto &proc : processors->second)
335  procEnabled[proc] = false;
336  } else
337  if( logs )
338  *logs << "Warning: no processors in daqttc crate " << d2c->second
339  << " for " << procOrRoleOrDaq << " ... do nothing" << endl;
340  } else
341  if( logs )
342  *logs << "Warning: daqttc " << daq << " has no crate "
343  << " ... do nothing" << endl;
344  return;
345  }
346  }
347 
348  // if we ever reach here, we've ran out of options
349  throw runtime_error("Processor/DAQ or Role '" + string(procOrRoleOrDaq) + "' was not found");
350 }
351 
352 bool TriggerSystem::isProcEnabled(const char *p) const {
353  if( !isConfigured )
354  throw std::runtime_error("TriggerSystem is not configured yet. First call the configureSystem method");
355 
356  auto processor = procEnabled.find(p);
357  if( processor == procEnabled.end() )
358  throw runtime_error("Processor '" + string(p) + "' not found");
359 
360  return processor->second;
361 }
362 
363 } // end of l1t namespace
364 
def getParameters(parameters)
Definition: cfg-viewer.py:440
type
Definition: HCALResponse.h:21
void readDOMFromFile(const std::string &fName, xercesc::DOMDocument *&doc)
TrainProcessor *const proc
Definition: MVATrainer.cc:101
delete x;
Definition: CaloConfig.h:22
void buildGlobalDoc(const std::string &key, const std::string &topPath="")
Definition: value.py:1
bool insert(Storage &iStorage, ItemType *iItem, const IdTag &iIdTag)
Definition: HCMethods.h:49
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
void readRootElement(TriggerSystem &aTriggerSystem, const std::string &sysId="")
void readContexts(const std::string &key, const std::string &sysId, TriggerSystem &aTriggerSystem)
def move(src, dest)
Definition: eostools.py:511
Definition: Mask.h:10