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