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