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