CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1TGlobalUtil.cc
Go to the documentation of this file.
1 // L1TGlobalUtil
2 //
3 // author: Brian Winer Ohio State
4 //
5 
7 
8 #include <iostream>
9 #include <fstream>
10 
13 
21 
22 
25 
26 
27 // constructor
29  // initialize cached IDs
30  m_l1GtMenuCacheID = 0ULL;
31  m_filledPrescales = false;
32  edm::FileInPath f1("L1Trigger/L1TGlobal/data/Luminosity/startup/prescale_L1TGlobal.csv");
34  m_numberPhysTriggers = 512; //need to get this out of the EventSetup
35  m_PreScaleColumn = 1;
36 
37 }
38 
40  edm::FileInPath f1("L1Trigger/L1TGlobal/data/Luminosity/startup/" + filename);
41  m_preScaleFileName = f1.fullPath();
42  m_PreScaleColumn = psColumn;
43 }
44 
45 // destructor
47 }
48 
50  edm::EDGetToken gtAlgToken) {
51 
52  // typically, the L1T menu (may change only between Runs)
53  retrieveL1Run(evSetup);
54  // typically the L1T prescales and index of specific prescale set used (may change only between LumiBlocks)
55  retrieveL1LumiBlock(evSetup);
56  // typically the event by event accept/reject info (changes between Events)
57  retrieveL1Event(iEvent,evSetup,gtAlgToken);
58 
59 }
60 
62 
63  // get / update the trigger menu from the EventSetup
64  // local cache & check on cacheIdentifier
65  unsigned long long l1GtMenuCacheID = evSetup.get<L1TUtmTriggerMenuRcd>().cacheIdentifier();
66 
67  if (m_l1GtMenuCacheID != l1GtMenuCacheID) {
68 
70  evSetup.get< L1TUtmTriggerMenuRcd>().get(l1GtMenu) ;
71  m_l1GtMenu = l1GtMenu.product();
72 
73  //std::cout << "Attempting to fill the map " << std::endl;
74  m_algorithmMap = &(m_l1GtMenu->getAlgorithmMap());
75 
76  //reset vectors since we have new menu
77  resetDecisionVectors();
78 
79  m_l1GtMenuCacheID = l1GtMenuCacheID;
80  }
81 }
82 
84 
85  // Fill the mask and prescales (dummy for now)
86  if(!m_filledPrescales) {
87 
88  // clear and dimension
89  resetPrescaleVectors();
90  resetMaskVectors();
91 
92  //Load the full prescale set for use
93  loadPrescalesAndMasks();
94 
95  // Set Prescale factors to initial (This is somewhat stupid...should fix up)
96  m_prescaleFactorsAlgoTrig = &m_initialPrescaleFactorsAlgoTrig;
97  m_triggerMaskAlgoTrig = &m_initialTriggerMaskAlgoTrig;
98  m_triggerMaskVetoAlgoTrig = &m_initialTriggerMaskVetoAlgoTrig;
99 
100 
101  //Pick which set we are using
102  if(m_PreScaleColumn > m_prescaleFactorsAlgoTrig->size() || m_PreScaleColumn < 1) {
103  LogTrace("l1t|Global")
104  << "\nNo Prescale Set: " << m_PreScaleColumn
105  << "\nMax Prescale Set value : " << m_prescaleFactorsAlgoTrig->size()
106  << "\nSetting prescale column to 1"
107  << std::endl;
108  m_PreScaleColumn = 1;
109  }
110  LogDebug("l1t|Global") << "Grabing prescale column "<< m_PreScaleColumn << endl;
111  const std::vector<int>& prescaleSet = (*m_prescaleFactorsAlgoTrig)[m_PreScaleColumn-1];
112 
113  for (std::map<std::string, L1TUtmAlgorithm>::const_iterator itAlgo = m_algorithmMap->begin(); itAlgo != m_algorithmMap->end(); itAlgo++) {
114 
115  // Get the algorithm name
116  std::string algName = itAlgo->first;
117  int algBit = (itAlgo->second).getIndex(); //algoBitNumber();
118 
119  (m_prescales[algBit]).first = algName;
120  (m_prescales[algBit]).second = prescaleSet[algBit];
121 
122  (m_masks[algBit]).first = algName;
123  (m_masks[algBit]).second = (*m_triggerMaskAlgoTrig)[algBit];
124 
125  (m_vetoMasks[algBit]).first = algName;
126  (m_vetoMasks[algBit]).second = (*m_triggerMaskVetoAlgoTrig)[algBit];
127  }
128 
129  m_filledPrescales = true;
130  }
131 }
132 
134  edm::EDGetToken gtAlgToken) {
135 
136 // Get the Global Trigger Output Algorithm block
137  iEvent.getByToken(gtAlgToken,m_uGtAlgBlk);
138  m_finalOR = false;
139 
140  //Make sure we have a valid AlgBlk
141  if(m_uGtAlgBlk.isValid()) {
142  // get the GlabalAlgBlk (Stupid find better way) of BX=0
143  std::vector<GlobalAlgBlk>::const_iterator algBlk = m_uGtAlgBlk->begin(0);
144  if (algBlk != m_uGtAlgBlk->end(0)){
145  // Grab the final OR from the AlgBlk,
146  m_finalOR = algBlk->getFinalOR();
147 
148  // Make a map of the trigger name and whether it passed various stages (initial,prescale,final)
149  // Note: might be able to improve performance by not full remaking map with names each time
150  for (std::map<std::string, L1TUtmAlgorithm>::const_iterator itAlgo = m_algorithmMap->begin(); itAlgo != m_algorithmMap->end(); itAlgo++) {
151 
152  // Get the algorithm name
153  std::string algName = itAlgo->first;
154  int algBit = (itAlgo->second).getIndex(); //algoBitNumber();
155 
156  bool decisionInitial = algBlk->getAlgoDecisionInitial(algBit);
157  (m_decisionsInitial[algBit]).first = algName;
158  (m_decisionsInitial[algBit]).second = decisionInitial;
159 
160  bool decisionPrescaled = algBlk->getAlgoDecisionInterm(algBit);
161  (m_decisionsPrescaled[algBit]).first = algName;
162  (m_decisionsPrescaled[algBit]).second = decisionPrescaled;
163 
164  bool decisionFinal = algBlk->getAlgoDecisionFinal(algBit);
165  (m_decisionsFinal[algBit]).first = algName;
166  (m_decisionsFinal[algBit]).second = decisionFinal;
167  }
168  } else {
169  //cout << "Error empty AlgBlk recovered.\n";
170  }
171  } else {
172  //cout<< "Error no valid uGT Algorithm Data with Token provided " << endl;
173  }
174 }
175 
177 
178  std::ifstream inputPrescaleFile;
179  inputPrescaleFile.open(m_preScaleFileName);
180 
181  std::vector<std::vector<int> > vec;
182  std::vector<std::vector<int> > prescale_vec;
183 
184  std::vector<unsigned int> temp_triggerMask;
185  std::vector<unsigned int> temp_triggerVetoMask;
186 
187  if( inputPrescaleFile ){
188  std::string prefix1("#");
189  std::string prefix2("-1");
190 
191  std::string line;
192 
193  bool first = true;
194 
195  while( getline(inputPrescaleFile,line) ){
196 
197  if( !line.compare(0, prefix1.size(), prefix1) ) continue;
198  //if( !line.compare(0, prefix2.size(), prefix2) ) continue;
199 
200  istringstream split(line);
201  int value;
202  int col = 0;
203  char sep;
204 
205  while( split >> value ){
206  if( first ){
207  // Each new value read on line 1 should create a new inner vector
208  vec.push_back(std::vector<int>());
209  }
210 
211  vec[col].push_back(value);
212  ++col;
213 
214  // read past the separator
215  split>>sep;
216  }
217 
218  // Finished reading line 1 and creating as many inner
219  // vectors as required
220  first = false;
221  }
222 
223 
224  int NumPrescaleSets = 0;
225 
226  int maskColumn = -1;
227  int maskVetoColumn = -1;
228  for( int iCol=0; iCol<int(vec.size()); iCol++ ){
229  if( vec[iCol].size() > 0 ){
230  int firstRow = vec[iCol][0];
231 
232  if( firstRow > 0 ) NumPrescaleSets++;
233  else if( firstRow==-2 ) maskColumn = iCol;
234  else if( firstRow==-3 ) maskVetoColumn = iCol;
235  }
236  }
237 
238  // Fill default values for mask and veto mask
239  for( unsigned int iBit = 0; iBit < m_numberPhysTriggers; ++iBit ){
240  unsigned int inputDefaultMask = 1;
241  unsigned int inputDefaultVetoMask = 0;
242  temp_triggerMask.push_back(inputDefaultMask);
243  temp_triggerVetoMask.push_back(inputDefaultVetoMask);
244  }
245 
246 // cout << " Mask Column " << maskColumn << " VetoColumn " << maskVetoColumn << endl;
247 
248  // Fill non-trivial mask and veto mask
249  if( maskColumn>=0 || maskVetoColumn>=0 ){
250  for( int iBit=1; iBit<int(vec[0].size()); iBit++ ){
251  unsigned int algoBit = vec[0][iBit];
252  // algoBit must be less than the number of triggers
253  if( algoBit < m_numberPhysTriggers ){
254  if( maskColumn>=0 ){
255  unsigned int triggerMask = vec[maskColumn][iBit];
256  temp_triggerMask[algoBit] = triggerMask;
257 // cout << "Settting Mask for bit " << algoBit << " to " << triggerMask << endl;
258  }
259  if( maskVetoColumn>=0 ){
260  unsigned int triggerVetoMask = vec[maskVetoColumn][iBit];
261  temp_triggerVetoMask[algoBit] = triggerVetoMask;
262  }
263  }
264  }
265  }
266 
267 
268  if( NumPrescaleSets > 0 ){
269  // Fill default prescale set
270  for( int iSet=0; iSet<NumPrescaleSets; iSet++ ){
271  prescale_vec.push_back(std::vector<int>());
272  for( unsigned int iBit = 0; iBit < m_numberPhysTriggers; ++iBit ){
273  int inputDefaultPrescale = 1;
274  prescale_vec[iSet].push_back(inputDefaultPrescale);
275  }
276  }
277 
278  // Fill non-trivial prescale set
279  for( int iBit=1; iBit<int(vec[0].size()); iBit++ ){
280  unsigned int algoBit = vec[0][iBit];
281  // algoBit must be less than the number of triggers
282  if( algoBit < m_numberPhysTriggers ){
283  for( int iSet=0; iSet<int(vec.size()); iSet++ ){
284  int useSet = -1;
285  if( vec[iSet].size() > 0 ){
286  useSet = vec[iSet][0];
287  }
288  useSet -= 1;
289 
290  if( useSet<0 ) continue;
291 
292  int prescale = vec[iSet][iBit];
293  prescale_vec[useSet][algoBit] = prescale;
294  }
295  }
296  else{
297  LogTrace("l1t|Global")
298  << "\nPrescale file has algo bit: " << algoBit
299  << "\nThis is larger than the number of triggers: " << m_numberPhysTriggers
300  << "\nSomething is wrong. Ignoring."
301  << std::endl;
302  }
303  }
304  }
305 
306  }
307  else {
308  LogTrace("l1t|Global")
309  << "\nCould not find file: " << m_preScaleFileName
310  << "\nFilling the prescale vectors with prescale 1"
311  << "\nSetting prescale set to 1"
312  << std::endl;
313 
314  m_PreScaleColumn = 1;
315 
316  for( int col=0; col < 1; col++ ){
317  prescale_vec.push_back(std::vector<int>());
318  for( unsigned int iBit = 0; iBit < m_numberPhysTriggers; ++iBit ){
319  int inputDefaultPrescale = 1;
320  prescale_vec[col].push_back(inputDefaultPrescale);
321  }
322  }
323  }
324 
325  inputPrescaleFile.close();
326 
327  m_initialPrescaleFactorsAlgoTrig = prescale_vec;
328  m_initialTriggerMaskAlgoTrig = temp_triggerMask;
329  m_initialTriggerMaskVetoAlgoTrig = temp_triggerVetoMask;
330 
331 }
332 
334 
335  // Reset all the vector contents with null information
336  m_decisionsInitial.clear();
337  m_decisionsInitial.resize(m_numberPhysTriggers);
338  m_decisionsPrescaled.clear();
339  m_decisionsPrescaled.resize(m_numberPhysTriggers);
340  m_decisionsFinal.clear();
341  m_decisionsFinal.resize(m_numberPhysTriggers);
342 
343 
344  for(unsigned int algBit = 0; algBit< m_numberPhysTriggers; algBit++) {
345 
346  (m_decisionsInitial[algBit]).first = "NULL";
347  (m_decisionsInitial[algBit]).second = false;
348 
349  (m_decisionsPrescaled[algBit]).first = "NULL";
350  (m_decisionsPrescaled[algBit]).second = false;
351 
352  (m_decisionsFinal[algBit]).first = "NULL";
353  (m_decisionsFinal[algBit]).second = false;
354 
355  }
356 
357 
358 }
359 
361 
362  // Reset all the vector contents with null information
363  m_prescales.clear();
364  m_prescales.resize(m_numberPhysTriggers);
365 
366  for(unsigned int algBit = 0; algBit< m_numberPhysTriggers; algBit++) {
367 
368  (m_prescales[algBit]).first = "NULL";
369  (m_prescales[algBit]).second = 1;
370 
371  }
372 
373 }
374 
376 
377  // Reset all the vector contents with null information
378  m_masks.clear();
379  m_masks.resize(m_numberPhysTriggers);
380  m_vetoMasks.clear();
381  m_vetoMasks.resize(m_numberPhysTriggers);
382 
383  for(unsigned int algBit = 0; algBit< m_numberPhysTriggers; algBit++) {
384 
385  (m_masks[algBit]).first = "NULL";
386  (m_masks[algBit]).second = true;
387 
388  (m_vetoMasks[algBit]).first = "NULL";
389  (m_vetoMasks[algBit]).second = false;
390 
391  }
392 
393 }
394 
395 const bool l1t::L1TGlobalUtil::getAlgBitFromName(const std::string& algName, int& bit) const {
396 
397  std::map<std::string, L1TUtmAlgorithm>::const_iterator itAlgo = m_algorithmMap->find(algName);
398  if(itAlgo != m_algorithmMap->end()) {
399  bit = (itAlgo->second).getIndex(); //algoBitNumber();
400  return true;
401  }
402 
403  return false; //did not find anything by that name
404 }
405 
406 const bool l1t::L1TGlobalUtil::getAlgNameFromBit(int& bit, std::string& algName) const {
407 
408  // since we are just looking up the name, doesn't matter which vector we get it from
409  if((m_decisionsInitial[bit]).first != "NULL") {
410  algName = (m_decisionsInitial[bit]).first;
411  return true;
412  }
413  return false; //No name associated with this bit
414 
415 }
416 
417 const bool l1t::L1TGlobalUtil::getInitialDecisionByBit(int& bit, bool& decision) const {
418 
419  /*
420  for(std::vector<GlobalAlgBlk>::const_iterator algBlk = m_uGtAlgBlk->begin(0); algBlk != m_uGtAlgBlk->end(0); ++algBlk) {
421  decision = algBlk->getAlgoDecisionFinal(bit);
422  }
423  */
424  // Need some check that this is a valid bit
425  if((m_decisionsInitial[bit]).first != "NULL") {
426  decision = (m_decisionsInitial[bit]).second;
427  return true;
428  }
429 
430  return false; //couldn't get the information requested.
431 }
432 const bool l1t::L1TGlobalUtil::getPrescaledDecisionByBit(int& bit, bool& decision) const {
433 
434  // Need some check that this is a valid bit
435  if((m_decisionsPrescaled[bit]).first != "NULL") {
436  decision = (m_decisionsPrescaled[bit]).second;
437  return true;
438  }
439 
440  return false; //couldn't get the information requested.
441 }
442 const bool l1t::L1TGlobalUtil::getFinalDecisionByBit(int& bit, bool& decision) const {
443 
444  // Need some check that this is a valid bit
445  if((m_decisionsFinal[bit]).first != "NULL") {
446  decision = (m_decisionsFinal[bit]).second;
447  return true;
448  }
449 
450  return false; //couldn't get the information requested.
451 }
452 const bool l1t::L1TGlobalUtil::getPrescaleByBit(int& bit, int& prescale) const {
453 
454  // Need some check that this is a valid bit
455  if((m_prescales[bit]).first != "NULL") {
456  prescale = (m_prescales[bit]).second;
457  return true;
458  }
459 
460  return false; //couldn't get the information requested.
461 }
462 const bool l1t::L1TGlobalUtil::getMaskByBit(int& bit, bool& mask) const {
463 
464  // Need some check that this is a valid bit
465  if((m_masks[bit]).first != "NULL") {
466  mask = (m_masks[bit]).second;
467  return true;
468  }
469 
470  return false; //couldn't get the information requested.
471 }
472 
473 const bool l1t::L1TGlobalUtil::getVetoMaskByBit(int& bit, bool& veto) const {
474 
475  // Need some check that this is a valid bit
476  if((m_vetoMasks[bit]).first != "NULL") {
477  veto = (m_vetoMasks[bit]).second;
478  return true;
479  }
480 
481  return false; //couldn't get the information requested.
482 }
483 
484 const bool l1t::L1TGlobalUtil::getInitialDecisionByName(const std::string& algName, bool& decision) const {
485 
486  int bit = -1;
487  if(getAlgBitFromName(algName,bit)) {
488  decision = (m_decisionsInitial[bit]).second;
489  return true;
490  }
491 
492  return false; //trigger name was not the menu.
493 }
494 
495 const bool l1t::L1TGlobalUtil::getPrescaledDecisionByName(const std::string& algName, bool& decision) const {
496 
497  int bit = -1;
498  if(getAlgBitFromName(algName,bit)) {
499  decision = (m_decisionsPrescaled[bit]).second;
500  return true;
501  }
502 
503  return false; //trigger name was not the menu.
504 }
505 
506 const bool l1t::L1TGlobalUtil::getFinalDecisionByName(const std::string& algName, bool& decision) const {
507 
508  int bit = -1;
509  if(getAlgBitFromName(algName,bit)) {
510  decision = (m_decisionsFinal[bit]).second;
511  return true;
512  }
513 
514  return false; //trigger name was not the menu.
515 }
516 const bool l1t::L1TGlobalUtil::getPrescaleByName(const std::string& algName, int& prescale) const {
517 
518  int bit = -1;
519  if(getAlgBitFromName(algName,bit)) {
520  prescale = (m_prescales[bit]).second;
521  return true;
522  }
523 
524  return false; //trigger name was not the menu.
525 }
526 const bool l1t::L1TGlobalUtil::getMaskByName(const std::string& algName, bool& mask) const {
527 
528  int bit = -1;
529  if(getAlgBitFromName(algName,bit)) {
530  mask = (m_masks[bit]).second;
531  return true;
532  }
533 
534  return false; //trigger name was not the menu.
535 }
536 const bool l1t::L1TGlobalUtil::getVetoMaskByName(const std::string& algName, bool& veto) const {
537 
538  int bit = -1;
539  if(getAlgBitFromName(algName,bit)) {
540  veto = (m_vetoMasks[bit]).second;
541  return true;
542  }
543 
544  return false; //trigger name was not the menu.
545 }
#define LogDebug(id)
const bool getInitialDecisionByBit(int &bit, bool &decision) const
std::string m_preScaleFileName
const bool getAlgBitFromName(const std::string &AlgName, int &bit) const
void retrieveL1Event(const edm::Event &iEvent, const edm::EventSetup &evSetup, edm::EDGetToken gtAlgToken)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
const bool getPrescaleByBit(int &bit, int &prescale) const
unsigned int m_PreScaleColumn
void retrieveL1LumiBlock(const edm::EventSetup &evSetup)
const bool getInitialDecisionByName(const std::string &algName, bool &decision) const
void retrieveL1(const edm::Event &iEvent, const edm::EventSetup &evSetup, edm::EDGetToken gtAlgToken)
initialize the class (mainly reserve)
void resetDecisionVectors()
clear decision vectors on a menu change
const bool getMaskByName(const std::string &algName, bool &mask) const
U second(std::pair< T, U > const &p)
int iEvent
Definition: GenABIO.cc:230
const bool getFinalDecisionByName(const std::string &algName, bool &decision) const
void OverridePrescalesAndMasks(std::string filename, unsigned int psColumn=1)
#define LogTrace(id)
const bool getAlgNameFromBit(int &bit, std::string &AlgName) const
const bool getVetoMaskByBit(int &bit, bool &veto) const
unsigned long long m_l1GtMenuCacheID
const bool getMaskByBit(int &bit, bool &mask) const
const T & get() const
Definition: EventSetup.h:56
T const * product() const
Definition: ESHandle.h:86
const bool getVetoMaskByName(const std::string &algName, bool &veto) const
const bool getFinalDecisionByBit(int &bit, bool &decision) const
tuple filename
Definition: lut2db_cfg.py:20
const bool getPrescaleByName(const std::string &algName, int &prescale) const
const bool getPrescaledDecisionByName(const std::string &algName, bool &decision) const
std::string fullPath() const
Definition: FileInPath.cc:184
int col
Definition: cuy.py:1008
double split
Definition: MVATrainer.cc:139
void retrieveL1Run(const edm::EventSetup &evSetup)
tuple size
Write out results.
const bool getPrescaledDecisionByBit(int &bit, bool &decision) const
unsigned int m_numberPhysTriggers