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