test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1TGlobalPrescalesVetosESProducer.cc
Go to the documentation of this file.
1 
10 
11 // system include files
12 #include <memory>
13 #include <iostream>
14 #include <fstream>
15 #include <unistd.h>
16 #include <stdio.h>
17 #include <stdlib.h>
18 
19 #include "tmEventSetup/tmEventSetup.hh"
20 #include "tmEventSetup/esTriggerMenu.hh"
21 #include "tmEventSetup/esAlgorithm.hh"
22 #include "tmEventSetup/esCondition.hh"
23 #include "tmEventSetup/esObject.hh"
24 #include "tmEventSetup/esCut.hh"
25 #include "tmEventSetup/esScale.hh"
26 #include "tmGrammar/Algorithm.hh"
27 
34 
36 
39 
44 
45 using namespace std;
46 using namespace edm;
47 using namespace l1t;
48 //
49 // class declaration
50 //
51 
53 public:
56 
57  typedef std::shared_ptr<L1TGlobalPrescalesVetos> ReturnType;
58 
59  ReturnType produce(const L1TGlobalPrescalesVetosRcd&);
60 
61 private:
62 
64 
65  unsigned int m_numberPhysTriggers;
68 
69  std::vector<std::vector<int> > m_initialPrescaleFactorsAlgoTrig;
70  std::vector<unsigned int> m_initialTriggerMaskAlgoTrig;
72  std::map<int, std::vector<int> > m_initialTriggerAlgoBxMaskAlgoTrig;
73 };
74 
75 //
76 // constants, enums and typedefs
77 //
78 
79 //
80 // static data member definitions
81 //
82 
83 //
84 // constructors and destructor
85 //
87  data_(new L1TGlobalPrescalesVetos())
88 {
89  //the following line is needed to tell the framework what
90  // data is being produced
91  setWhatProduced(this);
92  //setWhatProduced(this, conf.getParameter<std::string>("label"));
93 
95 
96  // directory in /data/Luminosity for the trigger menu
97  std::string menuDir = conf.getParameter<std::string>("TriggerMenuLuminosity");
98  //std::string menuDir = "startup";
99 
100  m_verbosity = conf.getParameter<int>("Verbosity");
101  m_bx_mask_default = conf.getParameter<int>("AlgoBxMaskDefault");
102 
103  // XML files
104  std::string prescalesFileName = conf.getParameter<std::string>("PrescaleXMLFile");
105  std::string algobxmaskFileName = conf.getParameter<std::string>("AlgoBxMaskXMLFile");
106  std::string finormaskFileName = conf.getParameter<std::string>("FinOrMaskXMLFile");
107  std::string vetomaskFileName = conf.getParameter<std::string>("VetoMaskXMLFile");
108 
109  // Full path
110  edm::FileInPath f1_prescale("L1Trigger/L1TGlobal/data/Luminosity/" + menuDir + "/" + prescalesFileName);
111  std::string m_prescaleFile = f1_prescale.fullPath();
112 
113  edm::FileInPath f1_mask_algobx("L1Trigger/L1TGlobal/data/Luminosity/" + menuDir + "/" + algobxmaskFileName);
114  std::string m_algobxmaskFile = f1_mask_algobx.fullPath();
115 
116  edm::FileInPath f1_mask_finor("L1Trigger/L1TGlobal/data/Luminosity/" + menuDir + "/" + finormaskFileName);
117  std::string m_finormaskFile = f1_mask_finor.fullPath();
118 
119  edm::FileInPath f1_mask_veto("L1Trigger/L1TGlobal/data/Luminosity/" + menuDir + "/" + vetomaskFileName);
120  std::string m_vetomaskFile = f1_mask_veto.fullPath();
121 
122  // XML payloads
123  std::string xmlPayload_prescale;
124  std::string xmlPayload_mask_algobx;
125  std::string xmlPayload_mask_finor;
126  std::string xmlPayload_mask_veto;
127 
128  std::vector<std::vector<int> > prescales;
129  std::vector<unsigned int> triggerMasks;
130  std::vector<int> triggerVetoMasks;
131  std::map<int, std::vector<int> > triggerAlgoBxMaskAlgoTrig;
132 
133  // Prescales
134  std::ifstream input_prescale;
135  input_prescale.open( m_prescaleFile );
136  if( !input_prescale ){
137  LogTrace("L1TGlobalPrescalesVetosESProducer")
138  << "\nCould not find file: " << m_prescaleFile
139  << "\nFilling the prescale vectors with prescale 1"
140  << std::endl;
141 
142  for( int col=0; col < 1; col++ ){
143  prescales.push_back(std::vector<int>());
144  for( unsigned int iBit = 0; iBit < m_numberPhysTriggers; ++iBit ){
145  int inputDefaultPrescale = 1;
146  prescales[col].push_back(inputDefaultPrescale);
147  }
148  }
149  }
150  else {
151  while( !input_prescale.eof() ){
152  string tmp;
153  getline( input_prescale, tmp, '\n' );
154  xmlPayload_prescale.append( tmp );
155  }
156 
157  XmlConfigReader xmlReader_prescale;
158  l1t::TrigSystem ts_prescale;
159  ts_prescale.addProcRole("uGtProcessor", "uGtProcessor");
160 
161  // run the parser
162  xmlReader_prescale.readDOMFromString( xmlPayload_prescale ); // initialize it
163  xmlReader_prescale.readRootElement( ts_prescale, "uGT" ); // extract all of the relevant context
164  ts_prescale.setConfigured();
165 
166  std::map<string, l1t::Setting> settings_prescale = ts_prescale.getSettings("uGtProcessor");
167  std::vector<l1t::TableRow> tRow_prescale = settings_prescale["prescales"].getTableRows();
168 
169  unsigned int numColumns_prescale = 0;
170  if( tRow_prescale.size()>0 ){
171  std::vector<std::string> firstRow_prescale = tRow_prescale[0].getRow();
172  numColumns_prescale = firstRow_prescale.size();
173  }
174 
175  int NumPrescaleSets = numColumns_prescale - 1;
176  int NumAlgos_prescale = tRow_prescale.size();
177 
178  if( NumPrescaleSets > 0 ){
179  // Fill default prescale set
180  for( int iSet=0; iSet<NumPrescaleSets; iSet++ ){
181  prescales.push_back(std::vector<int>());
182  for( int iBit = 0; iBit < NumAlgos_prescale; ++iBit ){
183  int inputDefaultPrescale = 1;
184  prescales[iSet].push_back(inputDefaultPrescale);
185  }
186  }
187 
188  for( auto it=tRow_prescale.begin(); it!=tRow_prescale.end(); it++ ){
189  unsigned int algoBit = it->getRowValue<unsigned int>("algo/prescale-index");
190  for( int iSet=0; iSet<NumPrescaleSets; iSet++ ){
191  int prescale = it->getRowValue<unsigned int>(std::to_string(iSet));
192  prescales[iSet][algoBit] = prescale;
193  }
194  }
195  }
196 
197  }
198  input_prescale.close();
199 
200 
201 
202 
204 
205  // finor mask
206  // Setting mask to default 1 (unmask)
207  for( unsigned int iAlg=0; iAlg < m_numberPhysTriggers; iAlg++ )
208  triggerMasks.push_back(1);
209 
210 
211  std::ifstream input_mask_finor;
212  input_mask_finor.open( m_finormaskFile );
213  if( !input_mask_finor ){
214  LogTrace("L1TGlobalPrescalesVetosESProducer")
215  << "\nCould not find file: " << m_finormaskFile
216  << "\nFilling the finor mask vectors with 1 (unmask)"
217  << std::endl;
218  }
219  else {
220  while( !input_mask_finor.eof() ){
221  string tmp;
222  getline( input_mask_finor, tmp, '\n' );
223  xmlPayload_mask_finor.append( tmp );
224  }
225 
226  XmlConfigReader xmlReader_mask_finor;
227  l1t::TrigSystem ts_mask_finor;
228  ts_mask_finor.addProcRole("uGtProcessor", "uGtProcessor");
229 
230  // run the parser
231  xmlReader_mask_finor.readDOMFromString( xmlPayload_mask_finor ); // initialize it
232  xmlReader_mask_finor.readRootElement( ts_mask_finor, "uGT" ); // extract all of the relevant context
233  ts_mask_finor.setConfigured();
234 
235  std::map<string, l1t::Setting> settings_mask_finor = ts_mask_finor.getSettings("uGtProcessor");
236 
237  std::vector<l1t::TableRow> tRow_mask_finor = settings_mask_finor["finorMask"].getTableRows();
238 
239  for( auto it=tRow_mask_finor.begin(); it!=tRow_mask_finor.end(); it++ ){
240  unsigned int algoBit = it->getRowValue<unsigned int>("algo");
241  unsigned int mask = it->getRowValue<unsigned int>("mask");
242  if( algoBit < m_numberPhysTriggers ) triggerMasks[algoBit] = mask;
243  }
244  }
245  input_mask_finor.close();
246 
247 
249 
250  // veto mask
251  // Setting veto mask to default 0 (no veto)
252  for( unsigned int iAlg=0; iAlg < m_numberPhysTriggers; iAlg++ )
253  triggerVetoMasks.push_back(0);
254 
255  std::ifstream input_mask_veto;
256  input_mask_veto.open( m_vetomaskFile );
257  if( !input_mask_veto ){
258  LogTrace("L1TGlobalPrescalesVetosESProducer")
259  << "\nCould not find file: " << m_vetomaskFile
260  << "\nFilling the veto mask vectors with 1 (unmask)"
261  << std::endl;
262  }
263  else {
264  while( !input_mask_veto.eof() ){
265  string tmp;
266  getline( input_mask_veto, tmp, '\n' );
267  xmlPayload_mask_veto.append( tmp );
268  }
269 
270  XmlConfigReader xmlReader_mask_veto;
271  l1t::TrigSystem ts_mask_veto;
272  ts_mask_veto.addProcRole("uGtProcessor", "uGtProcessor");
273 
274  // run the parser
275  xmlReader_mask_veto.readDOMFromString( xmlPayload_mask_veto ); // initialize it
276  xmlReader_mask_veto.readRootElement( ts_mask_veto, "uGT" ); // extract all of the relevant context
277  ts_mask_veto.setConfigured();
278 
279  std::map<string, l1t::Setting> settings_mask_veto = ts_mask_veto.getSettings("uGtProcessor");
280  std::vector<l1t::TableRow> tRow_mask_veto = settings_mask_veto["vetoMask"].getTableRows();
281 
282  for( auto it=tRow_mask_veto.begin(); it!=tRow_mask_veto.end(); it++ ){
283  unsigned int algoBit = it->getRowValue<unsigned int>("algo");
284  unsigned int veto = it->getRowValue<unsigned int>("veto");
285  if( algoBit < m_numberPhysTriggers ) triggerVetoMasks[algoBit] = int(veto);
286  }
287  }
288  input_mask_veto.close();
289 
291 
292  // Algo bx mask
293  std::ifstream input_mask_algobx;
294  input_mask_algobx.open( m_algobxmaskFile );
295  if( !input_mask_algobx ){
296  LogTrace("L1TGlobalPrescalesVetosESProducer")
297  << "\nCould not find file: " << m_algobxmaskFile
298  << "\nNot filling map"
299  << std::endl;
300  }
301  else {
302  while( !input_mask_algobx.eof() ){
303  string tmp;
304  getline( input_mask_algobx, tmp, '\n' );
305  xmlPayload_mask_algobx.append( tmp );
306  }
307 
308  XmlConfigReader xmlReader_mask_algobx;
309  l1t::TrigSystem ts_mask_algobx;
310  ts_mask_algobx.addProcRole("uGtProcessor", "uGtProcessor");
311 
312  // run the parser
313  xmlReader_mask_algobx.readDOMFromString( xmlPayload_mask_algobx ); // initialize it
314  xmlReader_mask_algobx.readRootElement( ts_mask_algobx, "uGT" ); // extract all of the relevant context
315  ts_mask_algobx.setConfigured();
316 
317  std::map<string, l1t::Setting> settings_mask_algobx = ts_mask_algobx.getSettings("uGtProcessor");
318  std::vector<l1t::TableRow> tRow_mask_algobx = settings_mask_algobx["algorithmBxMask"].getTableRows();
319 
320  unsigned int numCol_mask_algobx = 0;
321  if( tRow_mask_algobx.size()>0 ){
322  std::vector<std::string> firstRow_mask_algobx = tRow_mask_algobx[0].getRow();
323  numCol_mask_algobx = firstRow_mask_algobx.size();
324  }
325 
326  int NumAlgoBitsInMask = numCol_mask_algobx - 1;
327  if( NumAlgoBitsInMask > 0 ){
328  for( auto it=tRow_mask_algobx.begin(); it!=tRow_mask_algobx.end(); it++ ){
329  int bx = it->getRowValue<unsigned int>("bx/algo");
330  std::vector<int> maskedBits;
331  for( int iBit=0; iBit<NumAlgoBitsInMask; iBit++ ){
332  unsigned int maskBit = it->getRowValue<unsigned int>(std::to_string(iBit));
333  if( int(maskBit)!=m_bx_mask_default ) maskedBits.push_back(iBit);
334  }
335  if( maskedBits.size()>0 ) triggerAlgoBxMaskAlgoTrig[bx] = maskedBits;
336  }
337  }
338 
339  }
340  input_mask_algobx.close();
341 
342 
343  // Set prescales to zero if masked
344  for( unsigned int iSet=0; iSet < prescales.size(); iSet++ ){
345  for( unsigned int iBit=0; iBit < prescales[iSet].size(); iBit++ ){
346  // Add protection in case prescale table larger than trigger mask size
347  if( iBit >= triggerMasks.size() ){
348  edm::LogWarning("L1TGlobal")
349  << "\nWarning: algoBit in prescale table >= triggerMasks.size() "
350  << "\nWarning: no information on masking bit or not, setting as unmasked "
351  << std::endl;
352  }
353  else {
354  prescales[iSet][iBit] *= triggerMasks[iBit];
355  }
356  }
357  }
358 
360  m_initialTriggerMaskAlgoTrig = triggerMasks;
361  m_initialTriggerMaskVetoAlgoTrig = triggerVetoMasks;
362  m_initialTriggerAlgoBxMaskAlgoTrig = triggerAlgoBxMaskAlgoTrig;
363 
364 }
365 
366 
368 {
369 
370  // do anything here that needs to be done at desctruction time
371  // (e.g. close files, deallocate resources etc.)
372 
373 }
374 
375 
376 //
377 // member functions
378 //
379 
380 // ------------ method called to produce the data ------------
383 {
384  // configure the helper class parameters via its set funtions, e.g.:
389 
390  if( m_verbosity ){
391  LogDebug("L1TGlobal") << " ====> Prescales table <=== " << std::endl;
392  for( unsigned int ix=0; ix < m_initialPrescaleFactorsAlgoTrig.size(); ix++ ){
393  LogDebug("L1TGlobal") << " Prescale set = " << ix << std::endl;
394  for( unsigned int iy=0; iy < m_initialPrescaleFactorsAlgoTrig[ix].size(); iy++ ){
395  LogDebug("L1TGlobal") << "\t Algo " << iy << ": " << m_initialPrescaleFactorsAlgoTrig[ix][iy] << std::endl;
396  }
397  }
398 
399  LogDebug("L1TGlobal") << " ====> Trigger mask veto <=== " << std::endl;
400  for( unsigned int ix=0; ix < m_initialTriggerMaskVetoAlgoTrig.size(); ix++ ){
401  LogDebug("L1TGlobal") << "\t Algo " << ix << ": " << m_initialTriggerMaskVetoAlgoTrig[ix] << std::endl;
402  }
403 
404  LogDebug("L1TGlobal") << " ====> Algo bx mask <=== " << std::endl;
405  if( m_initialTriggerAlgoBxMaskAlgoTrig.size()==0 ) LogDebug("L1TGlobal") << "\t(empty map)" << std::endl;
406  for( auto& it: m_initialTriggerAlgoBxMaskAlgoTrig ){
407  LogDebug("L1TGlobal") << " bx = " << it.first << " : iAlg =";
408  std::vector<int> masked = it.second;
409  for( unsigned int iAlg=0; iAlg < masked.size(); iAlg++ ){
410  LogDebug("L1TGlobal") << " " << masked[iAlg];
411  }
412  LogDebug("L1TGlobal") << " " << std::endl;
413  }
414  }
415 
416  // write the condition format to the event setup via the helper:
417  using namespace edm::es;
418  std::shared_ptr<L1TGlobalPrescalesVetos> pMenu(data_.getWriteInstance());
419  return pMenu;
420 }
421 
422 //define this as a plug-in
#define LogDebug(id)
T getParameter(std::string const &) const
void setPrescaleFactorTable(std::vector< std::vector< int > > value)
std::vector< std::vector< int > > m_initialPrescaleFactorsAlgoTrig
void readRootElement(TrigSystem &aTrigSystem, const std::string &sysId="")
std::shared_ptr< L1TGlobalPrescalesVetos > ReturnType
L1TGlobalPrescalesVetosESProducer(const edm::ParameterSet &)
void setWhatProduced(T *iThis, const es::Label &iLabel=es::Label())
Definition: ESProducer.h:115
void addProcRole(const std::string &processor, const std::string &role)
Definition: TrigSystem.cc:39
void setConfigured(const bool state=true)
Definition: TrigSystem.h:39
#define LogTrace(id)
void setTriggerMaskVeto(std::vector< int > value)
std::map< std::string, Setting > getSettings(const std::string &processor)
Definition: TrigSystem.cc:179
std::map< int, std::vector< int > > m_initialTriggerAlgoBxMaskAlgoTrig
std::vector< unsigned int > m_initialTriggerMaskAlgoTrig
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
ReturnType produce(const L1TGlobalPrescalesVetosRcd &)
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
void readDOMFromString(const std::string &str, xercesc::DOMDocument *&doc)
std::string fullPath() const
Definition: FileInPath.cc:184
void setTriggerAlgoBxMask(std::map< int, std::vector< int > > value)
int col
Definition: cuy.py:1008
L1TGlobalPrescalesVetos * getWriteInstance()