CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
L1TGlobalPrescalesVetosOnlineProd Class Reference
Inheritance diagram for L1TGlobalPrescalesVetosOnlineProd:
L1ConfigOnlineProdBaseExt< L1TGlobalPrescalesVetosFractO2ORcd, L1TGlobalPrescalesVetosFract > edm::ESProducer edm::ESProductResolverFactoryProducer edm::eventsetup::ESProductResolverProvider

Public Member Functions

 L1TGlobalPrescalesVetosOnlineProd (const edm::ParameterSet &)
 
std::unique_ptr< const L1TGlobalPrescalesVetosFractnewObject (const std::string &objectKey, const L1TGlobalPrescalesVetosFractO2ORcd &record) override
 
 ~L1TGlobalPrescalesVetosOnlineProd (void) override
 
- Public Member Functions inherited from L1ConfigOnlineProdBaseExt< L1TGlobalPrescalesVetosFractO2ORcd, L1TGlobalPrescalesVetosFract >
 L1ConfigOnlineProdBaseExt (const edm::ParameterSet &)
 
std::unique_ptr< const L1TGlobalPrescalesVetosFractproduce (const L1TGlobalPrescalesVetosFractO2ORcd &iRecord)
 
 ~L1ConfigOnlineProdBaseExt () override
 
- Public Member Functions inherited from edm::ESProducer
 ESProducer ()
 
 ESProducer (const ESProducer &)=delete
 
 ESProducer (ESProducer &&)=delete
 
ESResolverIndex const * getTokenIndices (unsigned int iIndex) const
 
ESRecordIndex const * getTokenRecordIndices (unsigned int iIndex) const
 
bool hasMayConsumes () const noexcept
 
size_t numberOfTokenIndices (unsigned int iIndex) const
 
ESProduceroperator= (const ESProducer &)=delete
 
ESProduceroperator= (ESProducer &&)=delete
 
SerialTaskQueueChainqueue ()
 
template<typename Record >
std::optional< std::vector< ESResolverIndex > > updateFromMayConsumes (unsigned int iIndex, const Record &iRecord) const
 
void updateLookup (eventsetup::ESRecordsToProductResolverIndices const &) final
 
 ~ESProducer () noexcept(false) override
 
- Public Member Functions inherited from edm::ESProductResolverFactoryProducer
 ESProductResolverFactoryProducer ()
 
 ESProductResolverFactoryProducer (const ESProductResolverFactoryProducer &)=delete
 
const ESProductResolverFactoryProduceroperator= (const ESProductResolverFactoryProducer &)=delete
 
 ~ESProductResolverFactoryProducer () noexcept(false) override
 
- Public Member Functions inherited from edm::eventsetup::ESProductResolverProvider
void createKeyedResolvers (EventSetupRecordKey const &key, unsigned int nConcurrentIOVs)
 
const ComponentDescriptiondescription () const
 
 ESProductResolverProvider ()
 
 ESProductResolverProvider (const ESProductResolverProvider &)=delete
 
void fillRecordsNotAllowingConcurrentIOVs (std::set< EventSetupRecordKey > &recordsNotAllowingConcurrentIOVs) const
 
virtual void initConcurrentIOVs (EventSetupRecordKey const &key, unsigned int nConcurrentIOVs)
 
bool isUsingRecord (const EventSetupRecordKey &key) const
 
KeyedResolverskeyedResolvers (const EventSetupRecordKey &iRecordKey, unsigned int iovIndex=0)
 
const ESProductResolverProvideroperator= (const ESProductResolverProvider &)=delete
 
void setAppendToDataLabel (const edm::ParameterSet &)
 
void setDescription (const ComponentDescription &iDescription)
 
std::set< EventSetupRecordKeyusingRecords () const
 
virtual ~ESProductResolverProvider () noexcept(false)
 

Private Attributes

bool transactionSafe
 

Additional Inherited Members

- Static Public Member Functions inherited from edm::eventsetup::ESProductResolverProvider
static void prevalidate (ConfigurationDescriptions &)
 
- Protected Types inherited from edm::ESProductResolverFactoryProducer
using EventSetupRecordKey = eventsetup::EventSetupRecordKey
 
- Protected Types inherited from edm::eventsetup::ESProductResolverProvider
using KeyedResolversVector = std::vector< std::pair< DataKey, std::shared_ptr< ESProductResolver > >>
 
- Protected Member Functions inherited from L1ConfigOnlineProdBaseExt< L1TGlobalPrescalesVetosFractO2ORcd, L1TGlobalPrescalesVetosFract >
bool getObjectKey (const L1TGlobalPrescalesVetosFractO2ORcd &record, std::string &objectKey)
 
edm::ESConsumesCollectorT< L1TGlobalPrescalesVetosFractO2ORcdwrappedSetWhatProduced (const edm::ParameterSet &)
 
- Protected Member Functions inherited from edm::ESProducer
ESConsumesInfoconsumesInfoPushBackNew ()
 
unsigned int consumesInfoSize () const
 
template<typename CallbackT , typename TList , typename TRecord >
void registerProducts (std::shared_ptr< std::pair< unsigned int, std::shared_ptr< CallbackT >>> iCallback, const TList *, const TRecord *iRecord, const es::Label &iLabel)
 
template<typename CallbackT , typename TRecord >
void registerProducts (std::shared_ptr< std::pair< unsigned int, std::shared_ptr< CallbackT >>>, const eventsetup::produce::Null *, const TRecord *, const es::Label &)
 
template<typename T >
auto setWhatProduced (T *iThis, const es::Label &iLabel={})
 
template<typename T >
auto setWhatProduced (T *iThis, const char *iLabel)
 
template<typename T >
auto setWhatProduced (T *iThis, const std::string &iLabel)
 
template<typename T , typename TDecorator >
auto setWhatProduced (T *iThis, const TDecorator &iDec, const es::Label &iLabel={})
 
template<typename T , typename TReturn , typename TRecord >
auto setWhatProduced (T *iThis, TReturn(T::*iMethod)(const TRecord &), const es::Label &iLabel={})
 
template<typename T , typename TReturn , typename TRecord , typename TDecorator >
auto setWhatProduced (T *iThis, TReturn(T ::*iMethod)(const TRecord &), const TDecorator &iDec, const es::Label &iLabel={})
 
template<typename TFunc >
auto setWhatProduced (TFunc &&func, const es::Label &iLabel={})
 
template<typename TReturn , typename TRecord , typename TFunc , typename TDecorator >
ESConsumesCollectorT< TRecord > setWhatProduced (TFunc &&func, TDecorator &&iDec, const es::Label &iLabel={})
 
void usesResources (std::vector< std::string > const &)
 
- Protected Member Functions inherited from edm::ESProductResolverFactoryProducer
template<class TFactory >
void registerFactory (std::unique_ptr< TFactory > iFactory, const std::string &iLabel=std::string())
 
virtual void registerFactoryWithKey (const EventSetupRecordKey &iRecord, std::unique_ptr< eventsetup::ESProductResolverFactoryBase > iFactory, const std::string &iLabel=std::string())
 
KeyedResolversVector registerResolvers (const EventSetupRecordKey &, unsigned int iovIndex) override
 
- Protected Member Functions inherited from edm::eventsetup::ESProductResolverProvider
template<class T >
void usingRecord ()
 
void usingRecordWithKey (const EventSetupRecordKey &key)
 
- Protected Attributes inherited from L1ConfigOnlineProdBaseExt< L1TGlobalPrescalesVetosFractO2ORcd, L1TGlobalPrescalesVetosFract >
bool m_copyFromCondDB
 
cond::persistency::Session m_dbSession
 
bool m_forceGeneration
 
l1t::OMDSReader m_omdsReader
 

Detailed Description

Definition at line 28 of file L1TGlobalPrescalesVetosOnlineProd.cc.

Constructor & Destructor Documentation

◆ L1TGlobalPrescalesVetosOnlineProd()

L1TGlobalPrescalesVetosOnlineProd::L1TGlobalPrescalesVetosOnlineProd ( const edm::ParameterSet iConfig)

◆ ~L1TGlobalPrescalesVetosOnlineProd()

L1TGlobalPrescalesVetosOnlineProd::~L1TGlobalPrescalesVetosOnlineProd ( void  )
inlineoverride

Definition at line 38 of file L1TGlobalPrescalesVetosOnlineProd.cc.

38 {}

Member Function Documentation

◆ newObject()

std::unique_ptr< const L1TGlobalPrescalesVetosFract > L1TGlobalPrescalesVetosOnlineProd::newObject ( const std::string &  objectKey,
const L1TGlobalPrescalesVetosFractO2ORcd record 
)
overridevirtual

std::vector< std::string > queryColumns;

Implements L1ConfigOnlineProdBaseExt< L1TGlobalPrescalesVetosFractO2ORcd, L1TGlobalPrescalesVetosFract >.

Definition at line 47 of file L1TGlobalPrescalesVetosOnlineProd.cc.

References a, l1t::TriggerSystem::addProcessor(), MillePedeAlignmentAlgorithm_cfi::algoName, Puppi_cff::algos, mps_setup::append, b, l1t::OMDSReader::basicQuery(), nano_mu_digi_cff::bx, cuy::col, HLT_2024v14_cff::distance, MillePedeFileConverter_cfg::e, l1t::OnlineDBqueryHelper::fetch(), l1t::OMDSReader::QueryResults::fillVariable(), dqmdumpme::first, l1t::TriggerSystem::getParameters(), l1t::PrescalesVetosFractHelper::getWriteInstance(), mps_fire::i, createfilelist::int, B2GTnPMonitor_cfi::item, PrescalesVetosFract_cff::L1TGlobalPrescalesVetosFract, dqmdumpme::last, L1ConfigOnlineProdBaseExt< L1TGlobalPrescalesVetosFractO2ORcd, L1TGlobalPrescalesVetosFract >::m_omdsReader, ALPAKA_ACCELERATOR_NAMESPACE::pixelClustering::pixelStatus::mask, l1t::OMDSReader::QueryResults::numberRows(), L1TriggerKeyDummy_cfi::objectKey, skim900GeV_StreamA_MinBiasPD_cfg::output1, skim900GeV_StreamA_MinBiasPD_cfg::output2, skim900GeV_StreamA_MinBiasPD_cfg::output3, jetsAK4_Puppi_cff::payload, setupCalibrationTree_cff::prescale, hltrates_dqm_sourceclient-live_cfg::prescales, l1t::OMDSReader::QueryResults::queryFailed(), diffTwoXMLs::r1, diffTwoXMLs::r2, isotrackApplyRegressor::range, diffTwoXMLs::ranges, l1t::XmlConfigParser::readDOMFromString(), l1t::XmlConfigParser::readRootElement(), alignCSCRings::s, l1t::PrescalesVetosFractHelper::setBxMaskDefault(), l1t::TriggerSystem::setConfigured(), l1t::PrescalesVetosFractHelper::setPrescaleFactorTable(), l1t::PrescalesVetosFractHelper::setTriggerAlgoBxMask(), l1t::PrescalesVetosFractHelper::setTriggerMaskVeto(), l1t::OMDSReader::singleAttribute(), AlCaHLTBitMon_QueryRunRegistry::string, transactionSafe, and relval_cleanedupgrade::veto.

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

Member Data Documentation

◆ transactionSafe

bool L1TGlobalPrescalesVetosOnlineProd::transactionSafe
private