CMS 3D CMS Logo

L1TGlobalPrescalesVetosESProducer.cc
Go to the documentation of this file.
1 
10 // system include files
11 #include <memory>
12 #include <iostream>
13 #include <fstream>
14 #include <unistd.h>
15 #include <cstdio>
16 #include <cstdlib>
17 
18 #include "tmEventSetup/tmEventSetup.hh"
19 #include "tmEventSetup/esTriggerMenu.hh"
20 #include "tmEventSetup/esAlgorithm.hh"
21 #include "tmEventSetup/esCondition.hh"
22 #include "tmEventSetup/esObject.hh"
23 #include "tmEventSetup/esCut.hh"
24 #include "tmEventSetup/esScale.hh"
25 #include "tmGrammar/Algorithm.hh"
26 
32 
34 
37 
41 
42 using namespace std;
43 using namespace edm;
44 using namespace l1t;
45 //
46 // class declaration
47 //
48 
50 public:
53 
54  using ReturnType = std::unique_ptr<L1TGlobalPrescalesVetos>;
55 
56  ReturnType produce(const L1TGlobalPrescalesVetosRcd&);
57 
58 private:
60 
61  unsigned int m_numberPhysTriggers;
64 
65  std::vector<std::vector<int> > m_initialPrescaleFactorsAlgoTrig;
66  std::vector<unsigned int> m_initialTriggerMaskAlgoTrig;
68  std::map<int, std::vector<int> > m_initialTriggerAlgoBxMaskAlgoTrig;
69 };
70 
71 //
72 // constants, enums and typedefs
73 //
74 
75 //
76 // static data member definitions
77 //
78 
79 //
80 // constructors and destructor
81 //
83  : data_(new L1TGlobalPrescalesVetos()) {
84  //the following line is needed to tell the framework what
85  // data is being produced
86  setWhatProduced(this);
87  //setWhatProduced(this, conf.getParameter<std::string>("label"));
88 
90 
91  // directory in /data/Luminosity for the trigger menu
92  std::string menuDir = conf.getParameter<std::string>("TriggerMenuLuminosity");
93  //std::string menuDir = "startup";
94 
95  m_verbosity = conf.getParameter<int>("Verbosity");
96  m_bx_mask_default = conf.getParameter<int>("AlgoBxMaskDefault");
97 
98  // XML files
99  std::string prescalesFileName = conf.getParameter<std::string>("PrescaleXMLFile");
100  std::string algobxmaskFileName = conf.getParameter<std::string>("AlgoBxMaskXMLFile");
101  std::string finormaskFileName = conf.getParameter<std::string>("FinOrMaskXMLFile");
102  std::string vetomaskFileName = conf.getParameter<std::string>("VetoMaskXMLFile");
103 
104  // Full path
105  edm::FileInPath f1_prescale("L1Trigger/L1TGlobal/data/Luminosity/" + menuDir + "/" + prescalesFileName);
106  std::string m_prescaleFile = f1_prescale.fullPath();
107 
108  edm::FileInPath f1_mask_algobx("L1Trigger/L1TGlobal/data/Luminosity/" + menuDir + "/" + algobxmaskFileName);
109  std::string m_algobxmaskFile = f1_mask_algobx.fullPath();
110 
111  edm::FileInPath f1_mask_finor("L1Trigger/L1TGlobal/data/Luminosity/" + menuDir + "/" + finormaskFileName);
112  std::string m_finormaskFile = f1_mask_finor.fullPath();
113 
114  edm::FileInPath f1_mask_veto("L1Trigger/L1TGlobal/data/Luminosity/" + menuDir + "/" + vetomaskFileName);
115  std::string m_vetomaskFile = f1_mask_veto.fullPath();
116 
117  // XML payloads
118  std::string xmlPayload_prescale;
119  std::string xmlPayload_mask_algobx;
120  std::string xmlPayload_mask_finor;
121  std::string xmlPayload_mask_veto;
122 
123  std::vector<std::vector<int> > prescales;
124  std::vector<unsigned int> triggerMasks;
125  std::vector<int> triggerVetoMasks;
126  std::map<int, std::vector<int> > triggerAlgoBxMaskAlgoTrig;
127 
128  // Prescales
129  std::ifstream input_prescale;
130  input_prescale.open(m_prescaleFile);
131  if (not m_prescaleFile.empty() and not input_prescale) {
132  edm::LogError("L1TGlobalPrescalesVetosESProducer")
133  << "\nCould not find prescale file: " << m_prescaleFile
134  << "\nDeafulting to a single prescale column, with all prescales set to 1 (unprescaled)";
135 
136  const int inputDefaultPrescale = 1;
137  // by default, fill a single prescale column
138  prescales.push_back(std::vector<int>(m_numberPhysTriggers, inputDefaultPrescale));
139  } else {
140  while (!input_prescale.eof()) {
141  string tmp;
142  getline(input_prescale, tmp, '\n');
143  xmlPayload_prescale.append(tmp);
144  }
145 
146  l1t::XmlConfigParser xmlReader_prescale;
147  l1t::TriggerSystem ts_prescale;
148  ts_prescale.addProcessor("uGtProcessor", "uGtProcessor", "-1", "-1");
149 
150  // run the parser
151  xmlReader_prescale.readDOMFromString(xmlPayload_prescale); // initialize it
152  xmlReader_prescale.readRootElement(ts_prescale, "uGT"); // extract all of the relevant context
153  ts_prescale.setConfigured();
154 
155  const std::map<std::string, l1t::Parameter>& settings_prescale = ts_prescale.getParameters("uGtProcessor");
156  std::map<std::string, unsigned int> prescaleColumns = settings_prescale.at("prescales").getColumnIndices();
157 
158  unsigned int numColumns_prescale = prescaleColumns.size();
159 
160  int NumPrescaleSets = numColumns_prescale - 1;
162  std::vector<unsigned int> algoBits =
163  settings_prescale.at("prescales").getTableColumn<unsigned int>("algo/prescale-index");
164  int NumAlgos_prescale = *std::max_element(algoBits.begin(), algoBits.end()) + 1;
165 
166  if (NumPrescaleSets > 0) {
167  // Fill default prescale set
168  for (int iSet = 0; iSet < NumPrescaleSets; iSet++) {
169  prescales.push_back(std::vector<int>());
170  for (int iBit = 0; iBit < NumAlgos_prescale; ++iBit) {
171  int inputDefaultPrescale = 0; // only prescales that are set in the block below are used
172  prescales[iSet].push_back(inputDefaultPrescale);
173  }
174  }
175 
176  for (auto& col : prescaleColumns) {
177  if (col.second < 1)
178  continue; // we don't care for the algorithms' indicies in 0th column
179  int iSet = col.second - 1;
180  std::vector<unsigned int> prescalesForSet =
181  settings_prescale.at("prescales").getTableColumn<unsigned int>(col.first.c_str());
182  for (unsigned int row = 0; row < prescalesForSet.size(); row++) {
183  unsigned int prescale = prescalesForSet[row];
184  unsigned int algoBit = algoBits[row];
185  prescales[iSet][algoBit] = prescale;
186  }
187  }
188  }
189  }
190  input_prescale.close();
191 
193 
194  // finor mask
195  // set all masks to 1 (unmasked) by default
196  triggerMasks.insert(triggerMasks.end(), m_numberPhysTriggers, 1);
197 
198  std::ifstream input_mask_finor;
199  input_mask_finor.open(m_finormaskFile);
200  if (not m_finormaskFile.empty() and not input_mask_finor) {
201  edm::LogError("L1TGlobalPrescalesVetosESProducer")
202  << "\nCould not find finor mask file: " << m_finormaskFile
203  << "\nDeafulting the finor mask for all triggers to 1 (unmasked)";
204  } else {
205  while (!input_mask_finor.eof()) {
206  string tmp;
207  getline(input_mask_finor, tmp, '\n');
208  xmlPayload_mask_finor.append(tmp);
209  }
210 
211  l1t::XmlConfigParser xmlReader_mask_finor;
212  l1t::TriggerSystem ts_mask_finor;
213  ts_mask_finor.addProcessor("uGtProcessor", "uGtProcessor", "-1", "-1");
214 
215  // run the parser
216  xmlReader_mask_finor.readDOMFromString(xmlPayload_mask_finor); // initialize it
217  xmlReader_mask_finor.readRootElement(ts_mask_finor, "uGT"); // extract all of the relevant context
218  ts_mask_finor.setConfigured();
219 
220  const std::map<std::string, l1t::Parameter>& settings_mask_finor = ts_mask_finor.getParameters("uGtProcessor");
221 
222  std::vector<unsigned int> algo_mask_finor =
223  settings_mask_finor.at("finorMask").getTableColumn<unsigned int>("algo");
224  std::vector<unsigned int> mask_mask_finor =
225  settings_mask_finor.at("finorMask").getTableColumn<unsigned int>("mask");
226 
227  for (unsigned int row = 0; row < algo_mask_finor.size(); row++) {
228  unsigned int algoBit = algo_mask_finor[row];
229  unsigned int mask = mask_mask_finor[row];
230  if (algoBit < m_numberPhysTriggers)
231  triggerMasks[algoBit] = mask;
232  }
233  }
234  input_mask_finor.close();
235 
237 
238  // veto mask
239  // Setting veto mask to default 0 (no veto)
240  for (unsigned int iAlg = 0; iAlg < m_numberPhysTriggers; iAlg++)
241  triggerVetoMasks.push_back(0);
242 
243  std::ifstream input_mask_veto;
244  input_mask_veto.open(m_vetomaskFile);
245  if (not m_vetomaskFile.empty() and not input_mask_veto) {
246  edm::LogError("L1TGlobalPrescalesVetosESProducer") << "\nCould not find veto mask file: " << m_vetomaskFile
247  << "\nDeafulting the veto mask for all triggers to 1 (unmasked)";
248  } else {
249  while (!input_mask_veto.eof()) {
250  string tmp;
251  getline(input_mask_veto, tmp, '\n');
252  xmlPayload_mask_veto.append(tmp);
253  }
254 
255  l1t::XmlConfigParser xmlReader_mask_veto;
256  l1t::TriggerSystem ts_mask_veto;
257  ts_mask_veto.addProcessor("uGtProcessor", "uGtProcessor", "-1", "-1");
258 
259  // run the parser
260  xmlReader_mask_veto.readDOMFromString(xmlPayload_mask_veto); // initialize it
261  xmlReader_mask_veto.readRootElement(ts_mask_veto, "uGT"); // extract all of the relevant context
262  ts_mask_veto.setConfigured();
263 
264  const std::map<std::string, l1t::Parameter>& settings_mask_veto = ts_mask_veto.getParameters("uGtProcessor");
265  std::vector<unsigned int> algo_mask_veto = settings_mask_veto.at("vetoMask").getTableColumn<unsigned int>("algo");
266  std::vector<unsigned int> veto_mask_veto = settings_mask_veto.at("vetoMask").getTableColumn<unsigned int>("veto");
267 
268  for (unsigned int row = 0; row < algo_mask_veto.size(); row++) {
269  unsigned int algoBit = algo_mask_veto[row];
270  unsigned int veto = veto_mask_veto[row];
271  if (algoBit < m_numberPhysTriggers)
272  triggerVetoMasks[algoBit] = int(veto);
273  }
274  }
275  input_mask_veto.close();
276 
278 
279  // Algo bx mask
280  std::ifstream input_mask_algobx;
281  input_mask_algobx.open(m_algobxmaskFile);
282  if (not m_algobxmaskFile.empty() and not input_mask_algobx) {
283  edm::LogError("L1TGlobalPrescalesVetosESProducer")
284  << "\nCould not find bx mask file: " << m_algobxmaskFile << "\nNot filling the bx mask map";
285  } else {
286  while (!input_mask_algobx.eof()) {
287  string tmp;
288  getline(input_mask_algobx, tmp, '\n');
289  xmlPayload_mask_algobx.append(tmp);
290  }
291 
292  l1t::XmlConfigParser xmlReader_mask_algobx;
293  l1t::TriggerSystem ts_mask_algobx;
294  ts_mask_algobx.addProcessor("uGtProcessor", "uGtProcessor", "-1", "-1");
295 
296  // run the parser
297  xmlReader_mask_algobx.readDOMFromString(xmlPayload_mask_algobx); // initialize it
298  xmlReader_mask_algobx.readRootElement(ts_mask_algobx, "uGT"); // extract all of the relevant context
299  ts_mask_algobx.setConfigured();
300 
301  const std::map<std::string, l1t::Parameter>& settings_mask_algobx = ts_mask_algobx.getParameters("uGtProcessor");
302  std::map<std::string, unsigned int> mask_algobx_columns =
303  settings_mask_algobx.at("algorithmBxMask").getColumnIndices();
304  std::vector<unsigned int> bunches =
305  settings_mask_algobx.at("algorithmBxMask").getTableColumn<unsigned int>("bx/algo");
306 
307  unsigned int numCol_mask_algobx = mask_algobx_columns.size();
308 
309  int NumAlgoBitsInMask = numCol_mask_algobx - 1;
310  for (int iBit = 0; iBit < NumAlgoBitsInMask; iBit++) {
311  std::vector<unsigned int> algo =
312  settings_mask_algobx.at("algorithmBxMask").getTableColumn<unsigned int>(std::to_string(iBit).c_str());
313  for (unsigned int bx = 0; bx < bunches.size(); bx++) {
314  if (algo[bx] != unsigned(m_bx_mask_default))
315  triggerAlgoBxMaskAlgoTrig[bunches[bx]].push_back(iBit);
316  }
317  }
318  }
319  input_mask_algobx.close();
320 
321  // Set prescales to zero if masked
322  for (auto& prescale : prescales) {
323  for (unsigned int iBit = 0; iBit < prescale.size(); iBit++) {
324  // Add protection in case prescale table larger than trigger mask size
325  if (iBit >= triggerMasks.size()) {
326  edm::LogWarning("L1TGlobal") << "\nWarning: algoBit in prescale table >= triggerMasks.size() "
327  << "\nWarning: no information on masking bit or not, setting as unmasked "
328  << std::endl;
329  } else {
330  prescale[iBit] *= triggerMasks[iBit];
331  }
332  }
333  }
334 
336  m_initialTriggerMaskAlgoTrig = triggerMasks;
337  m_initialTriggerMaskVetoAlgoTrig = triggerVetoMasks;
338  m_initialTriggerAlgoBxMaskAlgoTrig = triggerAlgoBxMaskAlgoTrig;
339 }
340 
342  // do anything here that needs to be done at desctruction time
343  // (e.g. close files, deallocate resources etc.)
344 }
345 
346 //
347 // member functions
348 //
349 
350 // ------------ method called to produce the data ------------
352  const L1TGlobalPrescalesVetosRcd& iRecord) {
353  // configure the helper class parameters via its set funtions, e.g.:
358 
359  if (m_verbosity) {
360  LogDebug("L1TGlobal") << " ====> Prescales table <=== " << std::endl;
361  for (unsigned int ix = 0; ix < m_initialPrescaleFactorsAlgoTrig.size(); ix++) {
362  LogDebug("L1TGlobal") << " Prescale set = " << ix << std::endl;
363  for (unsigned int iy = 0; iy < m_initialPrescaleFactorsAlgoTrig[ix].size(); iy++) {
364  LogDebug("L1TGlobal") << "\t Algo " << iy << ": " << m_initialPrescaleFactorsAlgoTrig[ix][iy] << std::endl;
365  }
366  }
367 
368  LogDebug("L1TGlobal") << " ====> Trigger mask veto <=== " << std::endl;
369  for (unsigned int ix = 0; ix < m_initialTriggerMaskVetoAlgoTrig.size(); ix++) {
370  LogDebug("L1TGlobal") << "\t Algo " << ix << ": " << m_initialTriggerMaskVetoAlgoTrig[ix] << std::endl;
371  }
372 
373  LogDebug("L1TGlobal") << " ====> Algo bx mask <=== " << std::endl;
375  LogDebug("L1TGlobal") << "\t(empty map)" << std::endl;
376  for (auto& it : m_initialTriggerAlgoBxMaskAlgoTrig) {
377  LogDebug("L1TGlobal") << " bx = " << it.first << " : iAlg =";
378  std::vector<int> masked = it.second;
379  for (int& iAlg : masked) {
380  LogDebug("L1TGlobal") << " " << iAlg;
381  }
382  LogDebug("L1TGlobal") << " " << std::endl;
383  }
384  }
385 
386  // Return copy so that we don't give away our owned pointer to framework
387  return std::make_unique<L1TGlobalPrescalesVetos>(*data_.getWriteInstance());
388 }
389 
390 //define this as a plug-in
L1TGlobalPrescalesVetosRcd
Definition: L1TGlobalPrescalesVetosRcd.h:11
L1TGlobalPrescalesVetosESProducer::produce
ReturnType produce(const L1TGlobalPrescalesVetosRcd &)
Definition: L1TGlobalPrescalesVetosESProducer.cc:351
MessageLogger.h
L1TGlobalPrescalesVetosESProducer::m_initialPrescaleFactorsAlgoTrig
std::vector< std::vector< int > > m_initialPrescaleFactorsAlgoTrig
Definition: L1TGlobalPrescalesVetosESProducer.cc:65
edm
HLT enums.
Definition: AlignableModifier.h:19
l1t::XmlConfigParser::readRootElement
void readRootElement(TriggerSystem &aTriggerSystem, const std::string &sysId="")
Definition: XmlConfigParser.cc:189
cuy.col
col
Definition: cuy.py:1010
edm::ESProducer::setWhatProduced
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:163
l1GtPatternGenerator_cfi.bx
bx
Definition: l1GtPatternGenerator_cfi.py:18
L1TGlobalPrescalesVetosESProducer::data_
PrescalesVetosHelper data_
Definition: L1TGlobalPrescalesVetosESProducer.cc:59
l1t::TriggerSystem::addProcessor
void addProcessor(const char *processor, const char *role, const char *crate, const char *slot)
Definition: TriggerSystem.cc:26
ESProducer.h
createJobs.tmp
tmp
align.sh
Definition: createJobs.py:716
L1TGlobalPrescalesVetosESProducer::m_verbosity
int m_verbosity
Definition: L1TGlobalPrescalesVetosESProducer.cc:62
L1TGlobalPrescalesVetosESProducer::L1TGlobalPrescalesVetosESProducer
L1TGlobalPrescalesVetosESProducer(const edm::ParameterSet &)
Definition: L1TGlobalPrescalesVetosESProducer.cc:82
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
L1TGlobalPrescalesVetosESProducer::m_numberPhysTriggers
unsigned int m_numberPhysTriggers
Definition: L1TGlobalPrescalesVetosESProducer.cc:61
XmlConfigParser.h
l1t::TriggerSystem
Definition: TriggerSystem.h:14
FileInPath.h
L1TGlobalPrescalesVetosRcd.h
l1t::PrescalesVetosHelper::setPrescaleFactorTable
void setPrescaleFactorTable(std::vector< std::vector< int > > value)
Definition: PrescalesVetosHelper.h:52
cmsdt::algo
algo
Definition: constants.h:164
edm::FileInPath
Definition: FileInPath.h:64
L1TGlobalPrescalesVetosESProducer
Definition: L1TGlobalPrescalesVetosESProducer.cc:49
L1TGlobalPrescalesVetos
Definition: L1TGlobalPrescalesVetos.h:13
L1TGlobalPrescalesVetosESProducer::m_initialTriggerMaskVetoAlgoTrig
std::vector< int > m_initialTriggerMaskVetoAlgoTrig
Definition: L1TGlobalPrescalesVetosESProducer.cc:67
l1t::PrescalesVetosHelper::setBxMaskDefault
void setBxMaskDefault(int value)
Definition: PrescalesVetosHelper.h:46
PrescalesVetosHelper.h
L1TGlobalPrescalesVetosESProducer::m_bx_mask_default
int m_bx_mask_default
Definition: L1TGlobalPrescalesVetosESProducer.cc:63
l1t::PrescalesVetosHelper
Definition: PrescalesVetosHelper.h:32
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
ESProducts.h
l1t::XmlConfigParser
Definition: XmlConfigParser.h:23
l1t::PrescalesVetosHelper::setTriggerAlgoBxMask
void setTriggerAlgoBxMask(std::map< int, std::vector< int > > value)
Definition: PrescalesVetosHelper.h:63
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:223
edm::ParameterSet
Definition: ParameterSet.h:47
l1t
delete x;
Definition: CaloConfig.h:22
hltrates_dqm_sourceclient-live_cfg.prescales
prescales
Definition: hltrates_dqm_sourceclient-live_cfg.py:90
L1TGlobalPrescalesVetosESProducer::~L1TGlobalPrescalesVetosESProducer
~L1TGlobalPrescalesVetosESProducer() override
Definition: L1TGlobalPrescalesVetosESProducer.cc:341
createfilelist.int
int
Definition: createfilelist.py:10
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
prescale
Definition: PrescaleEventFilter.cc:32
L1TGlobalPrescalesVetos.h
l1t::PrescalesVetosHelper::getWriteInstance
L1TGlobalPrescalesVetos * getWriteInstance()
Definition: PrescalesVetosHelper.h:70
ModuleFactory.h
std
Definition: JetResolutionObject.h:76
l1t::TriggerSystem::getParameters
const std::map< std::string, Parameter > & getParameters(const char *processor) const
Definition: TriggerSystem.cc:168
DEFINE_FWK_EVENTSETUP_MODULE
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
Parameter.h
l1t::PrescalesVetosHelper::setTriggerMaskVeto
void setTriggerMaskVeto(std::vector< int > value)
Definition: PrescalesVetosHelper.h:57
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
TriggerSystem.h
L1TGlobalPrescalesVetosESProducer::m_initialTriggerAlgoBxMaskAlgoTrig
std::map< int, std::vector< int > > m_initialTriggerAlgoBxMaskAlgoTrig
Definition: L1TGlobalPrescalesVetosESProducer.cc:68
edm::ESProducer
Definition: ESProducer.h:104
L1TGlobalPrescalesVetosESProducer::ReturnType
std::unique_ptr< L1TGlobalPrescalesVetos > ReturnType
Definition: L1TGlobalPrescalesVetosESProducer.cc:54
l1t::XmlConfigParser::readDOMFromString
void readDOMFromString(const std::string &str, xercesc::DOMDocument *&doc)
l1t::TriggerSystem::setConfigured
void setConfigured(bool state=true) noexcept
Definition: TriggerSystem.h:74
PbPb_ZMuSkimMuonDPG_cff.veto
veto
Definition: PbPb_ZMuSkimMuonDPG_cff.py:61
edm::FileInPath::fullPath
std::string fullPath() const
Definition: FileInPath.cc:163
L1TGlobalPrescalesVetosESProducer::m_initialTriggerMaskAlgoTrig
std::vector< unsigned int > m_initialTriggerMaskAlgoTrig
Definition: L1TGlobalPrescalesVetosESProducer.cc:66