CMS 3D CMS Logo

L1TGlobalPrescalesVetosOnlineProd.cc
Go to the documentation of this file.
1 #include <strings.h> // strcasecmp
2 #include <iostream>
3 #include <fstream>
4 #include <stdexcept>
5 #include <unordered_map>
6 #include <utility>
7 
8 #include "tmEventSetup/tmEventSetup.hh"
9 #include "tmEventSetup/esTriggerMenu.hh"
10 #include "tmEventSetup/esAlgorithm.hh"
11 #include "tmEventSetup/esCondition.hh"
12 #include "tmEventSetup/esObject.hh"
13 #include "tmEventSetup/esCut.hh"
14 #include "tmEventSetup/esScale.hh"
15 #include "tmGrammar/Algorithm.hh"
16 
18 
26 #include "OnlineDBqueryHelper.h"
27 
29  : public L1ConfigOnlineProdBaseExt<L1TGlobalPrescalesVetosO2ORcd, L1TGlobalPrescalesVetos> {
30 private:
32 
33 public:
34  std::unique_ptr<const L1TGlobalPrescalesVetos> newObject(const std::string &objectKey,
35  const L1TGlobalPrescalesVetosO2ORcd &record) override;
36 
39 };
40 
43  wrappedSetWhatProduced(iConfig);
44  transactionSafe = iConfig.getParameter<bool>("transactionSafe");
45 }
46 
47 std::unique_ptr<const L1TGlobalPrescalesVetos> L1TGlobalPrescalesVetosOnlineProd::newObject(
48  const std::string &objectKey, const L1TGlobalPrescalesVetosO2ORcd &record) {
49  edm::LogInfo("L1-O2O: L1TGlobalPrescalesVetosOnlineProd")
50  << "Producing L1TGlobalPrescalesVetos with TSC:RS key = " << objectKey;
51 
52  if (objectKey.empty()) {
53  if (transactionSafe)
54  throw std::runtime_error("SummaryForFunctionManager: uGTrs | Faulty | Empty objectKey");
55  else {
56  edm::LogError("L1-O2O: L1TGlobalPrescalesVetosOnlineProd") << "returning empty L1TGlobalPrescalesVetos object";
57  return std::make_unique<const L1TGlobalPrescalesVetos>();
58  }
59  }
60 
61  unsigned int m_numberPhysTriggers = 512;
62 
63  // dictionary that maps algorithm name to it's index
64  std::unordered_map<std::string, int, std::hash<std::string>> algoName2bit;
65 
66  std::string uGTtscKey = objectKey.substr(0, objectKey.find(":"));
67  std::string uGTrsKey = objectKey.substr(objectKey.find(":") + 1, std::string::npos);
68 
69  std::string stage2Schema = "CMS_TRG_L1_CONF";
70 
71  std::string l1_menu_key;
72  std::vector<std::string> queryStrings;
73  queryStrings.push_back("L1_MENU");
74 
75  // select L1_MENU from CMS_TRG_L1_CONF.UGT_KEYS where ID = objectKey ;
77  queryStrings, stage2Schema, "UGT_KEYS", "UGT_KEYS.ID", m_omdsReader.singleAttribute(uGTtscKey));
78 
79  if (queryResult.queryFailed() || queryResult.numberRows() != 1) {
80  edm::LogError("L1-O2O") << "Cannot get UGT_KEYS.L1_MENU for ID = " << uGTtscKey << " ";
81  if (transactionSafe)
82  throw std::runtime_error("SummaryForFunctionManager: uGTrs | Faulty | Broken key");
83  else {
84  edm::LogError("L1-O2O: L1TGlobalPrescalesVetosOnlineProd") << "returning empty L1TGlobalPrescalesVetos object";
85  return std::make_unique<const L1TGlobalPrescalesVetos>();
86  }
87  }
88 
89  if (!queryResult.fillVariable("L1_MENU", l1_menu_key))
90  l1_menu_key = "";
91 
92  edm::LogInfo("L1-O2O: L1TGlobalPrescalesVetosOnlineProd") << "Producing L1TUtmTriggerMenu with key =" << l1_menu_key;
93 
94  if (uGTtscKey.empty()) {
95  edm::LogError("L1-O2O: L1TGlobalPrescalesVetosOnlineProd") << "TSC key is empty, returning";
96  if (transactionSafe)
97  throw std::runtime_error("SummaryForFunctionManager: uGTrs | Faulty | Empty objectKey");
98  else {
99  edm::LogError("L1-O2O: L1TGlobalPrescalesVetosOnlineProd") << "returning empty L1TGlobalPrescalesVetos object";
100  return std::make_unique<const L1TGlobalPrescalesVetos>();
101  }
102  }
103 
104  std::vector<std::string> queryColumns;
105  queryColumns.push_back("CONF");
106 
107  queryResult = m_omdsReader.basicQuery(
108  queryColumns, stage2Schema, "UGT_L1_MENU", "UGT_L1_MENU.ID", m_omdsReader.singleAttribute(l1_menu_key));
109 
110  if (queryResult.queryFailed() || queryResult.numberRows() != 1) {
111  edm::LogError("L1-O2O: L1TGlobalPrescalesVetosOnlineProd")
112  << "Cannot get UGT_L1_MENU.CONF for ID = " << l1_menu_key;
113  if (transactionSafe)
114  throw std::runtime_error("SummaryForFunctionManager: uGTrs | Faulty | Broken key");
115  else {
116  edm::LogError("L1-O2O: L1TGlobalPrescalesVetosOnlineProd") << "returning empty L1TGlobalPrescalesVetos object";
117  return std::make_unique<const L1TGlobalPrescalesVetos>();
118  }
119  }
120 
121  std::string l1Menu;
122  queryResult.fillVariable("CONF", l1Menu);
124  std::istringstream iss(l1Menu);
125 
126  std::shared_ptr<L1TUtmTriggerMenu> pMenu(
127  const_cast<L1TUtmTriggerMenu *>(reinterpret_cast<const L1TUtmTriggerMenu *>(tmeventsetup::getTriggerMenu(iss))));
128 
129  for (auto algo : pMenu->getAlgorithmMap())
130  algoName2bit[algo.first] = algo.second.getIndex();
131 
133  queryColumns.clear();
134  queryColumns.push_back("ALGOBX_MASK");
135  queryColumns.push_back("ALGO_FINOR_MASK");
136  queryColumns.push_back("ALGO_FINOR_VETO");
137  queryColumns.push_back("ALGO_PRESCALE");
138 
139  std::string prescale_key, bxmask_key, mask_key, vetomask_key;
140  std::string xmlPayload_prescale, xmlPayload_mask_algobx, xmlPayload_mask_finor, xmlPayload_mask_veto;
141  try {
142  std::map<std::string, std::string> subKeys =
143  l1t::OnlineDBqueryHelper::fetch(queryColumns, "UGT_RS_KEYS", uGTrsKey, m_omdsReader);
144  prescale_key = subKeys["ALGO_PRESCALE"];
145  bxmask_key = subKeys["ALGOBX_MASK"];
146  mask_key = subKeys["ALGO_FINOR_MASK"];
147  vetomask_key = subKeys["ALGO_FINOR_VETO"];
148  xmlPayload_prescale = l1t::OnlineDBqueryHelper::fetch({"CONF"}, "UGT_RS_CLOBS", prescale_key, m_omdsReader)["CONF"];
149  xmlPayload_mask_algobx =
150  l1t::OnlineDBqueryHelper::fetch({"CONF"}, "UGT_RS_CLOBS", bxmask_key, m_omdsReader)["CONF"];
151  xmlPayload_mask_finor = l1t::OnlineDBqueryHelper::fetch({"CONF"}, "UGT_RS_CLOBS", mask_key, m_omdsReader)["CONF"];
152  xmlPayload_mask_veto =
153  l1t::OnlineDBqueryHelper::fetch({"CONF"}, "UGT_RS_CLOBS", vetomask_key, m_omdsReader)["CONF"];
154  } catch (std::runtime_error &e) {
155  edm::LogError("L1-O2O: L1TGlobalPrescalesVetosOnlineProd") << e.what();
156  if (transactionSafe)
157  throw std::runtime_error(std::string("SummaryForFunctionManager: uGTrs | Faulty | ") + e.what());
158  else {
159  edm::LogError("L1-O2O: L1TGlobalPrescalesVetosOnlineProd") << "returning empty L1TGlobalPrescalesVetos object";
160  return std::make_unique<const L1TGlobalPrescalesVetos>();
161  }
162  }
163 
164  // for debugging purposes dump the payloads to /tmp
165  std::ofstream output1(std::string("/tmp/").append(prescale_key.substr(0, prescale_key.find("/"))).append(".xml"));
166  output1 << xmlPayload_prescale;
167  output1.close();
168  std::ofstream output2(std::string("/tmp/").append(mask_key.substr(0, mask_key.find("/"))).append(".xml"));
169  output2 << xmlPayload_mask_finor;
170  output2.close();
171  std::ofstream output3(std::string("/tmp/").append(bxmask_key.substr(0, bxmask_key.find("/"))).append(".xml"));
172  output3 << xmlPayload_mask_algobx;
173  output3.close();
174  std::ofstream output4(std::string("/tmp/").append(vetomask_key.substr(0, vetomask_key.find("/"))).append(".xml"));
175  output4 << xmlPayload_mask_veto;
176  output4.close();
177 
179 
180  std::vector<std::vector<int>> prescales;
181  std::vector<unsigned int> triggerMasks;
182  std::vector<int> triggerVetoMasks;
183  std::map<int, std::vector<int>> triggerAlgoBxMaskAlgoTrig;
184 
185  // Prescales
186  try {
187  l1t::XmlConfigParser xmlReader_prescale;
188  l1t::TriggerSystem ts_prescale;
189  ts_prescale.addProcessor("uGtProcessor", "uGtProcessor", "-1", "-1");
190 
191  // run the parser
192  xmlReader_prescale.readDOMFromString(xmlPayload_prescale); // initialize it
193  xmlReader_prescale.readRootElement(ts_prescale, "uGT"); // extract all of the relevant context
194  ts_prescale.setConfigured();
195 
196  const std::map<std::string, l1t::Parameter> &settings_prescale = ts_prescale.getParameters("uGtProcessor");
197  std::map<std::string, unsigned int> prescaleColumns = settings_prescale.at("prescales").getColumnIndices();
198 
199  unsigned int numColumns_prescale = prescaleColumns.size();
200  int nPrescaleSets = numColumns_prescale - 1;
201  std::vector<std::string> algoNames =
202  settings_prescale.at("prescales").getTableColumn<std::string>("algo/prescale-index");
203 
204  if (nPrescaleSets > 0) {
205  // Fill default prescale set
206  for (int iSet = 0; iSet < nPrescaleSets; iSet++) {
207  prescales.push_back(std::vector<int>());
208  for (unsigned int iBit = 0; iBit < m_numberPhysTriggers; ++iBit) {
209  int inputDefaultPrescale = 0; // only prescales that are set in the block below are used
210  prescales[iSet].push_back(inputDefaultPrescale);
211  }
212  }
213 
214  for (auto &col : prescaleColumns) {
215  if (col.second < 1)
216  continue; // we don't care for the algorithms' indicies in 0th column
217  int iSet = col.second - 1;
218  std::vector<unsigned int> prescalesForSet =
219  settings_prescale.at("prescales").getTableColumn<unsigned int>(col.first.c_str());
220  for (unsigned int row = 0; row < prescalesForSet.size(); row++) {
221  unsigned int prescale = prescalesForSet[row];
222  std::string algoName = algoNames[row];
223  unsigned int algoBit = algoName2bit[algoName];
224  prescales[iSet][algoBit] = prescale;
225  }
226  }
227  }
228  } catch (std::runtime_error &e) {
229  if (transactionSafe)
230  throw std::runtime_error(std::string("SummaryForFunctionManager: uGTrs | Faulty | ") + e.what());
231  else {
232  edm::LogError("L1-O2O: L1TGlobalPrescalesVetosOnlineProd") << "returning empty L1TGlobalPrescalesVetos object";
233  return std::make_unique<const L1TGlobalPrescalesVetos>();
234  }
235  }
236 
238 
239  // finor mask
240  try {
241  l1t::XmlConfigParser xmlReader_mask_finor;
242  l1t::TriggerSystem ts_mask_finor;
243  ts_mask_finor.addProcessor("uGtProcessor", "uGtProcessor", "-1", "-1");
244 
245  // run the parser
246  xmlReader_mask_finor.readDOMFromString(xmlPayload_mask_finor); // initialize it
247  xmlReader_mask_finor.readRootElement(ts_mask_finor, "uGT"); // extract all of the relevant context
248  ts_mask_finor.setConfigured();
249 
250  const std::map<std::string, l1t::Parameter> &settings_mask_finor = ts_mask_finor.getParameters("uGtProcessor");
251 
252  std::vector<std::string> algo_mask_finor = settings_mask_finor.at("finorMask").getTableColumn<std::string>("algo");
253  std::vector<unsigned int> mask_mask_finor =
254  settings_mask_finor.at("finorMask").getTableColumn<unsigned int>("mask");
255 
256  // mask (default=1 - unmask)
257  unsigned int default_finor_mask = 1;
258  auto default_finor_row = std::find_if(algo_mask_finor.cbegin(), algo_mask_finor.cend(), [](const std::string &s) {
259  // simpler than overweight std::tolower(s[], std::locale()) POSIX solution (thx to BA):
260  return strcasecmp("all", s.c_str()) == 0;
261  });
262  if (default_finor_row == algo_mask_finor.cend()) {
263  edm::LogError("L1-O2O: L1TGlobalPrescalesVetosOnlineProd")
264  << "\nWarning: No default found in FinOR mask xml, use 1 (unmasked) as default" << std::endl;
265  } else {
266  default_finor_mask = mask_mask_finor[std::distance(algo_mask_finor.cbegin(), default_finor_row)];
267  }
268 
269  for (unsigned int iAlg = 0; iAlg < m_numberPhysTriggers; iAlg++)
270  triggerMasks.push_back(default_finor_mask);
271 
272  for (unsigned int row = 0; row < algo_mask_finor.size(); row++) {
273  std::string algoName = algo_mask_finor[row];
274  if (strcasecmp("all", algoName.c_str()) == 0)
275  continue;
276  unsigned int algoBit = algoName2bit[algoName];
277  unsigned int mask = mask_mask_finor[row];
278  if (algoBit < m_numberPhysTriggers)
279  triggerMasks[algoBit] = mask;
280  }
281  } catch (std::runtime_error &e) {
282  if (transactionSafe)
283  throw std::runtime_error(std::string("SummaryForFunctionManager: uGTrs | Faulty | ") + e.what());
284  else {
285  edm::LogError("L1-O2O: L1TGlobalPrescalesVetosOnlineProd") << "returning empty L1TGlobalPrescalesVetos object";
286  return std::make_unique<const L1TGlobalPrescalesVetos>();
287  }
288  }
289 
291 
292  // veto mask
293  try {
294  l1t::XmlConfigParser xmlReader_mask_veto;
295  l1t::TriggerSystem ts_mask_veto;
296  ts_mask_veto.addProcessor("uGtProcessor", "uGtProcessor", "-1", "-1");
297 
298  // run the parser
299  xmlReader_mask_veto.readDOMFromString(xmlPayload_mask_veto); // initialize it
300  xmlReader_mask_veto.readRootElement(ts_mask_veto, "uGT"); // extract all of the relevant context
301  ts_mask_veto.setConfigured();
302 
303  const std::map<std::string, l1t::Parameter> &settings_mask_veto = ts_mask_veto.getParameters("uGtProcessor");
304  std::vector<std::string> algo_mask_veto = settings_mask_veto.at("vetoMask").getTableColumn<std::string>("algo");
305  std::vector<unsigned int> veto_mask_veto = settings_mask_veto.at("vetoMask").getTableColumn<unsigned int>("veto");
306 
307  // veto mask (default=0 - no veto)
308  unsigned int default_veto_mask = 1;
309  auto default_veto_row = std::find_if(algo_mask_veto.cbegin(), algo_mask_veto.cend(), [](const std::string &s) {
310  // simpler than overweight std::tolower(s[], std::locale()) POSIX solution (thx to BA):
311  return strcasecmp("all", s.c_str()) == 0;
312  });
313  if (default_veto_row == algo_mask_veto.cend()) {
314  edm::LogError("L1-O2O: L1TGlobalPrescalesVetosOnlineProd")
315  << "\nWarning: No default found in Veto mask xml, use 0 (unvetoed) as default" << std::endl;
316  } else {
317  default_veto_mask = veto_mask_veto[std::distance(algo_mask_veto.cbegin(), default_veto_row)];
318  }
319 
320  for (unsigned int iAlg = 0; iAlg < m_numberPhysTriggers; iAlg++)
321  triggerVetoMasks.push_back(default_veto_mask);
322 
323  for (unsigned int row = 0; row < algo_mask_veto.size(); row++) {
324  std::string algoName = algo_mask_veto[row];
325  if (strcasecmp("all", algoName.c_str()) == 0)
326  continue;
327  unsigned int algoBit = algoName2bit[algoName];
328  unsigned int veto = veto_mask_veto[row];
329  if (algoBit < m_numberPhysTriggers)
330  triggerVetoMasks[algoBit] = int(veto);
331  }
332  } catch (std::runtime_error &e) {
333  if (transactionSafe)
334  throw std::runtime_error(std::string("SummaryForFunctionManager: uGTrs | Faulty | ") + e.what());
335  else {
336  edm::LogError("L1-O2O: L1TGlobalPrescalesVetosOnlineProd") << "returning empty L1TGlobalPrescalesVetos object";
337  return std::make_unique<const L1TGlobalPrescalesVetos>();
338  }
339  }
340 
342 
343  // Algo bx mask
344  unsigned int m_bx_mask_default = 1;
345 
346  std::vector<std::string> bx_algo_name;
347  std::vector<std::string> bx_range;
348  std::vector<unsigned int> bx_mask;
349 
350  try {
351  l1t::XmlConfigParser xmlReader_mask_algobx;
352  l1t::TriggerSystem ts_mask_algobx;
353  ts_mask_algobx.addProcessor("uGtProcessor", "uGtProcessor", "-1", "-1");
354 
355  // run the parser
356  xmlReader_mask_algobx.readDOMFromString(xmlPayload_mask_algobx); // initialize it
357  xmlReader_mask_algobx.readRootElement(ts_mask_algobx, "uGT"); // extract all of the relevant context
358  ts_mask_algobx.setConfigured();
359 
360  const std::map<std::string, l1t::Parameter> &settings_mask_algobx = ts_mask_algobx.getParameters("uGtProcessor");
361  bx_algo_name = settings_mask_algobx.at("algorithmBxMask").getTableColumn<std::string>("algo");
362  bx_range = settings_mask_algobx.at("algorithmBxMask").getTableColumn<std::string>("range");
363  bx_mask = settings_mask_algobx.at("algorithmBxMask").getTableColumn<unsigned int>("mask");
364  } catch (std::runtime_error &e) {
365  if (transactionSafe)
366  throw std::runtime_error(std::string("SummaryForFunctionManager: uGTrs | Faulty | ") + e.what());
367  else {
368  edm::LogError("L1-O2O: L1TGlobalPrescalesVetosOnlineProd") << "returning empty L1TGlobalPrescalesVetos object";
369  return std::make_unique<const L1TGlobalPrescalesVetos>();
370  }
371  }
372 
373  int default_bxmask_row = -1;
374  typedef std::pair<unsigned long, unsigned long> Range_t;
375  // auto comp = [] (Range_t a, Range_t b){ return a.first < b.first; };
376  struct RangeComp_t {
377  bool operator()(const Range_t &a, const Range_t &b) const { return a.first < b.first; }
378  };
379  std::map<std::string, std::set<Range_t, RangeComp_t>> non_default_bx_ranges;
380 
381  for (unsigned int row = 0; row < bx_algo_name.size(); row++) {
382  const std::string &s1 = bx_algo_name[row];
383  const std::string &s2 = bx_range[row];
384  // find "all" broadcast keywords
385  bool broadcastAlgo = false;
386  bool broadcastRange = false;
387  if (strcasecmp("all", s1.c_str()) == 0)
388  broadcastAlgo = true;
389  if (strcasecmp("all", s2.c_str()) == 0)
390  broadcastRange = true;
391  // ALL-ALL-default:
392  if (broadcastAlgo && broadcastRange) {
393  if (row != 0) {
394  edm::LogError("L1-O2O: L1TGlobalPrescalesVetosOnlineProd")
395  << "\nWarning: ALL-ALL row is not the first one, ignore it assuming 1 (unmasked) as the default"
396  << std::endl;
397  continue;
398  }
399  if (default_bxmask_row >= 0) {
400  edm::LogError("L1-O2O: L1TGlobalPrescalesVetosOnlineProd")
401  << "\nWarning: multiple ALL-ALL rows found, using the first" << std::endl;
402  continue;
403  }
404  default_bxmask_row = row;
405  m_bx_mask_default = bx_mask[row];
406  continue;
407  }
408  // interpret the range
409  unsigned long first = 0, last = 0;
410  if (broadcastRange) {
411  first = 0;
412  last = 3563;
413  } else {
414  char *dash = nullptr;
415  first = strtoul(s2.data(), &dash, 0);
416  while (*dash != '\0' && *dash != '-')
417  ++dash;
418  last = (*dash != '\0' ? strtoul(++dash, &dash, 0) : first);
419  if (first == 3564)
420  first = 0;
421  if (last == 3564)
422  last = 0;
423  // what could possibly go wrong?
424  if (*dash != '\0') {
425  edm::LogError("L1-O2O: L1TGlobalPrescalesVetosOnlineProd")
426  << "\nWarning: parsing " << s2 << " as [" << first << "," << last << "] range" << std::endl;
427  }
428  if (first > 3563) {
429  edm::LogError("L1-O2O: L1TGlobalPrescalesVetosOnlineProd")
430  << "\nWarning: start of interval is out of range: " << s2 << ", skipping the row" << std::endl;
431  continue;
432  }
433  if (last > 3563) {
434  last = 3563;
435  edm::LogError("L1-O2O: L1TGlobalPrescalesVetosOnlineProd")
436  << "\nWarning: end of interval is out of range: " << s2 << ", force [" << first << "," << last << "] range"
437  << std::endl;
438  }
439  if (first > last) {
440  edm::LogError("L1-O2O: L1TGlobalPrescalesVetosOnlineProd")
441  << "\nWarning: inverse/spillover range " << s2 << ", accounting for circular orbit as [0," << last
442  << "] & [" << first << ",3563]" << std::endl;
443  }
444  }
445  // {algo,ALL}-{range,ALL}-{0,1}:
446  std::vector<std::string> algos;
447  std::vector<std::pair<unsigned long, unsigned long>> orderedRanges;
448  if (first <= last) {
449  if (!broadcastAlgo) {
450  algos.push_back(bx_algo_name[row]);
451  orderedRanges.push_back(std::make_pair(first, last));
452  } else {
453  for (const auto &i : non_default_bx_ranges) {
454  algos.push_back(i.first);
455  orderedRanges.push_back(std::make_pair(first, last));
456  }
457  }
458  } else {
459  if (!broadcastAlgo) {
460  algos.push_back(bx_algo_name[row]);
461  algos.push_back(bx_algo_name[row]);
462  orderedRanges.push_back(std::make_pair(0, last));
463  orderedRanges.push_back(std::make_pair(first, 3563));
464  } else {
465  for (const auto &i : non_default_bx_ranges) {
466  algos.push_back(i.first);
467  algos.push_back(i.first);
468  orderedRanges.push_back(std::make_pair(0, last));
469  orderedRanges.push_back(std::make_pair(first, 3563));
470  }
471  }
472  }
473 
474  for (unsigned int item = 0; item < algos.size(); item++) {
475  const std::string &algoName = algos[item];
476  unsigned int first = orderedRanges[item].first;
477  unsigned int last = orderedRanges[item].second;
478 
479  std::set<Range_t, RangeComp_t> &ranges = non_default_bx_ranges[algoName];
480  // .insert
481  // (
482  // std::pair< std::string, std::set<Range_t,RangeComp_t> >
483  // (
484  // algoName, std::set<Range_t,RangeComp_t>()
485  // )
486  // ).first->second; // I don't care if insert was successfull or if I've got a hold on existing range
487 
488  // current range may or may not overlap with the already present ranges
489  // if end of the predecessor starts before begin of the current range and begin
490  // of the successor starts after end of the current range there is no overlap
491  // and I save this range only if it has mask different from the default
492  // otherwise modify predecessor/successor ranges accordingly
493  std::set<Range_t>::iterator curr = ranges.end(); // inserted range
494  std::set<Range_t>::iterator succ =
495  ranges.lower_bound(std::make_pair(first, last)); // successor starts at current or later
496  std::set<Range_t>::iterator pred = succ;
497  if (pred != ranges.begin())
498  pred--;
499  else
500  pred = ranges.end();
501 
502  if ((pred == ranges.end() || pred->second < first) && (succ == ranges.end() || succ->first > last)) {
503  // no overlap
504  if (m_bx_mask_default != bx_mask[row])
505  curr = ranges.insert(std::make_pair(first, last)).first;
506  // do nothing if this is a default-mask interval
507  } else {
508  // pred/succ iterators are read-only, create intermediate adjusted copies
509  Range_t newPred, newSucc;
510  bool modifiedPred = false, gapInPred = false, modifiedSucc = false, dropSucc = false;
511  // overlap found with predecessor range
512  if (pred != ranges.end() && pred->second >= first && pred->second <= last) {
513  if (m_bx_mask_default != bx_mask[row]) {
514  if (last == pred->second) {
515  // both ranges end in the same place - nothing to do
516  modifiedPred = false;
517  } else {
518  // extend predecessor range
519  newPred.first = pred->first;
520  newPred.second = last;
521  modifiedPred = true;
522  }
523  } else {
524  // shrink predecessor range
525  newPred.first = pred->first;
526  newPred.second = first - 1; // non-negative for the predecessor by design
527  // by design pred->first < first, so the interval above is always valid
528  modifiedPred = true;
529  }
530  }
531  // current range is fully contained in predecessor
532  if (pred != ranges.end() && pred->second > first && pred->second > last) {
533  if (m_bx_mask_default != bx_mask[row]) {
534  // no change to the predecessor range
535  modifiedPred = false;
536  } else {
537  // make a "gap" in predecessor range
538  newPred.first = first;
539  newPred.second = last;
540  gapInPred = true;
541  modifiedPred = true;
542  }
543  }
544  // overlap found with successor range
545  if (succ != ranges.end() && succ->first <= last) {
546  if (m_bx_mask_default != bx_mask[row]) {
547  // extend successor range
548  newSucc.first = first;
549  newSucc.second = succ->second;
550  } else {
551  // shrink successor range
552  newSucc.first = last + 1;
553  newSucc.second = succ->second;
554  if (newSucc.first > 3563 || newSucc.first > newSucc.second)
555  dropSucc = true;
556  }
557  modifiedSucc = true;
558  }
559  // overlap found with both, predecessor and successor, such that I need to merge them
560  if (modifiedPred && modifiedSucc && newPred.second >= newSucc.first) {
561  // make newPred and newSucc identical just in case
562  newPred.second = newSucc.second;
563  newSucc.first = newPred.first;
564  ranges.erase(pred, ++succ);
565  curr = ranges.insert(newPred).first;
566  } else {
567  // merging is not the case, but I still need to propagate the new ranges back to the source
568  if (modifiedPred) {
569  if (!gapInPred) {
570  ranges.erase(pred);
571  curr = ranges.insert(newPred).first;
572  } else {
573  // make a gap by splitting predecessor into two ranges
574  Range_t r1(pred->first, newPred.first - 1); // non-negative for the predecessor by design
575  Range_t r2(newPred.second + 1, pred->second);
576  ranges.erase(pred);
577  ranges.insert(r1);
578  ranges.insert(r2);
579  curr = ranges.end(); // gap cannot cover any additional ranges
580  }
581  }
582  if (modifiedSucc) {
583  ranges.erase(succ);
584  if (!dropSucc)
585  curr = ranges.insert(newSucc).first;
586  }
587  }
588  }
589  // if current range spans over few more ranges after the successor
590  // remove those from the consideration up until the last covered range
591  // that may or may not extend beyond the current range end
592  if (curr != ranges.end()) { // insertion took place
593  std::set<Range_t, RangeComp_t>::iterator last_covered = ranges.upper_bound(std::make_pair(curr->second, 0));
594  if (last_covered != ranges.begin())
595  last_covered--;
596  else
597  last_covered = ranges.end();
598 
599  if (last_covered != ranges.end() && last_covered->first != curr->first) {
600  // ranges is not empty and last_covered is not current itself (i.e. it is different)
601  if (curr->second < last_covered->second) {
602  // the range needs to be extended
603  Range_t newRange(curr->first, last_covered->second);
604  ranges.erase(curr);
605  curr = ranges.insert(newRange).first;
606  }
607  ranges.erase(++curr, last_covered);
608  }
609  }
610  }
611  }
612 
613  if (default_bxmask_row < 0) {
614  edm::LogError("L1-O2O: L1TGlobalPrescalesVetosOnlineProd")
615  << "\nWarning: No default found in BX mask xml, used 1 (unmasked) as default" << std::endl;
616  }
617 
618  for (auto &algo : non_default_bx_ranges) {
619  const std::string &algoName = algo.first;
620  unsigned int algoBit = algoName2bit[algoName];
621  for (auto range : algo.second)
622  for (unsigned int bx = range.first; bx <= range.second; bx++) {
623  triggerAlgoBxMaskAlgoTrig[bx].push_back(algoBit);
624  }
625  }
626 
627  // Set prescales to zero if masked
628  for (unsigned int iSet = 0; iSet < prescales.size(); iSet++) {
629  for (unsigned int iBit = 0; iBit < prescales[iSet].size(); iBit++) {
630  // Add protection in case prescale table larger than trigger mask size
631  if (iBit >= triggerMasks.size()) {
632  edm::LogError("L1-O2O: L1TGlobalPrescalesVetosOnlineProd")
633  << "\nWarning: algoBit in prescale table >= triggerMasks.size() "
634  << "\nWarning: no information on masking bit or not, setting as unmasked " << std::endl;
635  } else {
636  prescales[iSet][iBit] *= triggerMasks[iBit];
637  }
638  }
639  }
640 
642 
644 
645  data_.setBxMaskDefault(m_bx_mask_default);
647  data_.setTriggerMaskVeto(triggerVetoMasks);
648  data_.setTriggerAlgoBxMask(triggerAlgoBxMaskAlgoTrig);
649 
650  auto payload = std::make_unique<const L1TGlobalPrescalesVetos>(*data_.getWriteInstance());
651 
652  edm::LogInfo("L1-O2O: L1TCaloParamsOnlineProd") << "SummaryForFunctionManager: uGTrs | OK | All looks good";
653 
654  return payload;
655 }
656 
657 //define this as a plug-in
l1t::OMDSReader::QueryResults
Definition: OMDSReader.h:49
skim900GeV_StreamA_MinBiasPD_cfg.output3
output3
Definition: skim900GeV_StreamA_MinBiasPD_cfg.py:240
PrescalesVetos_cff.L1TGlobalPrescalesVetos
L1TGlobalPrescalesVetos
Definition: PrescalesVetos_cff.py:14
diffTwoXMLs.ranges
string ranges
Definition: diffTwoXMLs.py:79
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
mps_fire.i
i
Definition: mps_fire.py:355
skim900GeV_StreamA_MinBiasPD_cfg.output1
output1
Definition: skim900GeV_StreamA_MinBiasPD_cfg.py:212
L1ConfigOnlineProdBaseExt< L1TGlobalPrescalesVetosO2ORcd, L1TGlobalPrescalesVetos >::m_omdsReader
l1t::OMDSReader m_omdsReader
Definition: L1ConfigOnlineProdBaseExt.h:47
l1t::OnlineDBqueryHelper::fetch
static std::map< std::string, std::string > fetch(const std::vector< std::string > &queryColumns, const std::string &table, const std::string &key, l1t::OMDSReader &m_omdsReader)
Definition: OnlineDBqueryHelper.cc:3
l1t::XmlConfigParser::readRootElement
void readRootElement(TriggerSystem &aTriggerSystem, const std::string &sysId="")
Definition: XmlConfigParser.cc:189
cuy.col
col
Definition: cuy.py:1010
edm::LogInfo
Definition: MessageLogger.h:254
l1GtPatternGenerator_cfi.bx
bx
Definition: l1GtPatternGenerator_cfi.py:18
l1t::TriggerSystem::addProcessor
void addProcessor(const char *processor, const char *role, const char *crate, const char *slot)
Definition: TriggerSystem.cc:26
GlobalPosition_Frontier_DevDB_cff.record
record
Definition: GlobalPosition_Frontier_DevDB_cff.py:10
HLT_2018_cff.distance
distance
Definition: HLT_2018_cff.py:6417
L1ConfigOnlineProdBaseExt.h
HIPAlignmentAlgorithm_cfi.algoName
algoName
Definition: HIPAlignmentAlgorithm_cfi.py:5
l1t::OMDSReader::singleAttribute
const QueryResults singleAttribute(const T &data) const
Definition: OMDSReader.h:259
indexGen.s2
s2
Definition: indexGen.py:107
dqmdumpme.first
first
Definition: dqmdumpme.py:55
XmlConfigParser.h
l1t::TriggerSystem
Definition: TriggerSystem.h:14
L1TGlobalPrescalesVetosRcd.h
l1t::PrescalesVetosHelper::setPrescaleFactorTable
void setPrescaleFactorTable(std::vector< std::vector< int > > value)
Definition: PrescalesVetosHelper.h:52
cmsdt::algo
algo
Definition: constants.h:164
alignCSCRings.s
s
Definition: alignCSCRings.py:92
dqmdumpme.last
last
Definition: dqmdumpme.py:56
L1ConfigOnlineProdBaseExt
Definition: L1ConfigOnlineProdBaseExt.h:32
jets_cff.algos
algos
Definition: jets_cff.py:644
l1t::OMDSReader::QueryResults::fillVariable
bool fillVariable(const std::string &columnName, T &outputVariable) const
Definition: OMDSReader.h:274
L1TGlobalPrescalesVetos
Definition: L1TGlobalPrescalesVetos.h:13
l1t::PrescalesVetosHelper::setBxMaskDefault
void setBxMaskDefault(int value)
Definition: PrescalesVetosHelper.h:46
PrescalesVetosHelper.h
jets_cff.payload
payload
Definition: jets_cff.py:34
b
double b
Definition: hdecay.h:118
L1TGlobalPrescalesVetosO2ORcd
Definition: L1TGlobalPrescalesVetosO2ORcd.h:13
L1TGlobalPrescalesVetosOnlineProd
Definition: L1TGlobalPrescalesVetosOnlineProd.cc:28
l1t::PrescalesVetosHelper
Definition: PrescalesVetosHelper.h:32
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
L1TGlobalPrescalesVetosO2ORcd.h
l1t::XmlConfigParser
Definition: XmlConfigParser.h:23
L1TUtmTriggerMenu.h
OnlineDBqueryHelper.h
L1TGlobalPrescalesVetosOnlineProd::L1TGlobalPrescalesVetosOnlineProd
L1TGlobalPrescalesVetosOnlineProd(const edm::ParameterSet &)
Definition: L1TGlobalPrescalesVetosOnlineProd.cc:41
l1t::PrescalesVetosHelper::setTriggerAlgoBxMask
void setTriggerAlgoBxMask(std::map< int, std::vector< int > > value)
Definition: PrescalesVetosHelper.h:63
edm::ParameterSet
Definition: ParameterSet.h:36
edm::LogError
Definition: MessageLogger.h:183
a
double a
Definition: hdecay.h:119
hltrates_dqm_sourceclient-live_cfg.prescales
prescales
Definition: hltrates_dqm_sourceclient-live_cfg.py:86
mps_setup.append
append
Definition: mps_setup.py:85
diffTwoXMLs.r2
r2
Definition: diffTwoXMLs.py:73
createfilelist.int
int
Definition: createfilelist.py:10
l1t::OMDSReader::QueryResults::numberRows
int numberRows() const
Definition: OMDSReader.h:60
B2GTnPMonitor_cfi.item
item
Definition: B2GTnPMonitor_cfi.py:147
skim900GeV_StreamA_MinBiasPD_cfg.output2
output2
Definition: skim900GeV_StreamA_MinBiasPD_cfg.py:226
l1t::OMDSReader::basicQuery
const QueryResults basicQuery(const std::vector< std::string > &columnNames, const std::string &schemaName, const std::string &tableName, const std::string &conditionLHS="", const QueryResults conditionRHS=QueryResults(), const std::string &conditionRHSName="")
Definition: OMDSReader.cc:75
prescale
Definition: PrescaleEventFilter.cc:32
L1TGlobalPrescalesVetos.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
l1t::PrescalesVetosHelper::getWriteInstance
L1TGlobalPrescalesVetos * getWriteInstance()
Definition: PrescalesVetosHelper.h:70
l1t::TriggerSystem::getParameters
const std::map< std::string, Parameter > & getParameters(const char *processor) const
Definition: TriggerSystem.cc:168
diffTwoXMLs.r1
r1
Definition: diffTwoXMLs.py:53
DEFINE_FWK_EVENTSETUP_MODULE
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
L1TGlobalPrescalesVetosOnlineProd::~L1TGlobalPrescalesVetosOnlineProd
~L1TGlobalPrescalesVetosOnlineProd(void) override
Definition: L1TGlobalPrescalesVetosOnlineProd.cc:38
l1t::PrescalesVetosHelper::setTriggerMaskVeto
void setTriggerMaskVeto(std::vector< int > value)
Definition: PrescalesVetosHelper.h:57
l1t::OMDSReader::QueryResults::queryFailed
bool queryFailed() const
Definition: OMDSReader.h:59
TriggerSystem.h
L1TGlobalPrescalesVetosOnlineProd::transactionSafe
bool transactionSafe
Definition: L1TGlobalPrescalesVetosOnlineProd.cc:31
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
L1ConfigOnlineProdBaseExt< L1TGlobalPrescalesVetosO2ORcd, L1TGlobalPrescalesVetos >::wrappedSetWhatProduced
edm::ESConsumesCollectorT< L1TGlobalPrescalesVetosO2ORcd > wrappedSetWhatProduced(const edm::ParameterSet &)
Definition: L1ConfigOnlineProdBaseExt.h:93
L1TGlobalPrescalesVetosOnlineProd::newObject
std::unique_ptr< const L1TGlobalPrescalesVetos > newObject(const std::string &objectKey, const L1TGlobalPrescalesVetosO2ORcd &record) override
Definition: L1TGlobalPrescalesVetosOnlineProd.cc:47
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37