CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
L1TGlobalPrescalesVetosOnlineProd Class Reference
Inheritance diagram for L1TGlobalPrescalesVetosOnlineProd:
L1ConfigOnlineProdBaseExt< L1TGlobalPrescalesVetosO2ORcd, L1TGlobalPrescalesVetos > edm::ESProducer edm::ESProxyFactoryProducer edm::eventsetup::DataProxyProvider

Public Member Functions

 L1TGlobalPrescalesVetosOnlineProd (const edm::ParameterSet &)
 
std::shared_ptr< L1TGlobalPrescalesVetosnewObject (const std::string &objectKey, const L1TGlobalPrescalesVetosO2ORcd &record) override
 
 ~L1TGlobalPrescalesVetosOnlineProd (void) override
 
- Public Member Functions inherited from L1ConfigOnlineProdBaseExt< L1TGlobalPrescalesVetosO2ORcd, L1TGlobalPrescalesVetos >
 L1ConfigOnlineProdBaseExt (const edm::ParameterSet &)
 
std::shared_ptr< L1TGlobalPrescalesVetosproduce (const L1TGlobalPrescalesVetosO2ORcd &iRecord)
 
 ~L1ConfigOnlineProdBaseExt () override
 
- Public Member Functions inherited from edm::ESProducer
 ESProducer ()
 
 ~ESProducer ()(false) override
 
- Public Member Functions inherited from edm::ESProxyFactoryProducer
 ESProxyFactoryProducer ()
 
void newInterval (const eventsetup::EventSetupRecordKey &iRecordType, const ValidityInterval &iInterval) override
 overrides DataProxyProvider method More...
 
 ~ESProxyFactoryProducer () noexcept(false) override
 
- Public Member Functions inherited from edm::eventsetup::DataProxyProvider
 DataProxyProvider ()
 
const ComponentDescriptiondescription () const
 
bool isUsingRecord (const EventSetupRecordKey &) const
 
const KeyedProxieskeyedProxies (const EventSetupRecordKey &iRecordKey) const
 
void resetProxies (const EventSetupRecordKey &iRecordType)
 
void resetProxiesIfTransient (const EventSetupRecordKey &iRecordType)
 
void setAppendToDataLabel (const edm::ParameterSet &)
 
void setDescription (const ComponentDescription &iDescription)
 
std::set< EventSetupRecordKeyusingRecords () const
 
virtual ~DataProxyProvider () noexcept(false)
 

Private Attributes

bool transactionSafe
 

Additional Inherited Members

- Public Types inherited from edm::eventsetup::DataProxyProvider
typedef std::vector< std::pair< DataKey, edm::propagate_const< std::shared_ptr< DataProxy > > > > KeyedProxies
 
typedef std::vector< EventSetupRecordKeyKeys
 
typedef std::map< EventSetupRecordKey, KeyedProxiesRecordProxies
 
- Static Public Member Functions inherited from edm::eventsetup::DataProxyProvider
static void prevalidate (ConfigurationDescriptions &)
 
- Protected Member Functions inherited from L1ConfigOnlineProdBaseExt< L1TGlobalPrescalesVetosO2ORcd, L1TGlobalPrescalesVetos >
bool getObjectKey (const L1TGlobalPrescalesVetosO2ORcd &record, std::shared_ptr< L1TGlobalPrescalesVetos > data, std::string &objectKey)
 
- Protected Member Functions inherited from edm::ESProducer
 ESProducer (const ESProducer &)=delete
 
ESProducer const & operator= (const ESProducer &)=delete
 
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 TArg >
ESConsumesCollector setWhatProduced (T *iThis, TReturn(T::*iMethod)(const TRecord &), const TArg &iDec, const es::Label &iLabel={})
 
- Protected Member Functions inherited from edm::ESProxyFactoryProducer
template<class TFactory >
void registerFactory (std::unique_ptr< TFactory > iFactory, const std::string &iLabel=std::string())
 
virtual void registerFactoryWithKey (const eventsetup::EventSetupRecordKey &iRecord, std::unique_ptr< eventsetup::ProxyFactoryBase > iFactory, const std::string &iLabel=std::string())
 
void registerProxies (const eventsetup::EventSetupRecordKey &iRecord, KeyedProxies &aProxyList) override
 override DataProxyProvider method More...
 
- Protected Member Functions inherited from edm::eventsetup::DataProxyProvider
void eraseAll (const EventSetupRecordKey &iRecordKey)
 deletes all the Proxies in aStream More...
 
void invalidateProxies (const EventSetupRecordKey &iRecordKey)
 
template<class T >
void usingRecord ()
 
void usingRecordWithKey (const EventSetupRecordKey &)
 
- Protected Attributes inherited from L1ConfigOnlineProdBaseExt< L1TGlobalPrescalesVetosO2ORcd, L1TGlobalPrescalesVetos >
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 ( const edm::ParameterSet iConfig)
L1TGlobalPrescalesVetosOnlineProd::~L1TGlobalPrescalesVetosOnlineProd ( void  )
inlineoverride

Definition at line 35 of file L1TGlobalPrescalesVetosOnlineProd.cc.

35 {}

Member Function Documentation

std::shared_ptr< L1TGlobalPrescalesVetos > L1TGlobalPrescalesVetosOnlineProd::newObject ( const std::string &  objectKey,
const L1TGlobalPrescalesVetosO2ORcd record 
)
overridevirtual

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

Implements L1ConfigOnlineProdBaseExt< L1TGlobalPrescalesVetosO2ORcd, L1TGlobalPrescalesVetos >.

Definition at line 42 of file L1TGlobalPrescalesVetosOnlineProd.cc.

References a, l1t::TriggerSystem::addProcessor(), patPFMETCorrections_cff::algo, HIPAlignmentAlgorithm_cfi::algoName, hltMVAJetPuId_cff::algos, mps_setup::append, b, l1t::OMDSReader::basicQuery(), cuy::col, DEFINE_FWK_EVENTSETUP_MODULE, SoftLeptonByDistance_cfi::distance, MillePedeFileConverter_cfg::e, l1t::OnlineDBqueryHelper::fetch(), l1t::OMDSReader::QueryResults::fillVariable(), plotBeamSpotDB::first, l1t::TriggerSystem::getParameters(), l1t::PrescalesVetosHelper::getWriteInstance(), mps_fire::i, createfilelist::int, plotBeamSpotDB::last, L1ConfigOnlineProdBaseExt< L1TGlobalPrescalesVetosO2ORcd, L1TGlobalPrescalesVetos >::m_omdsReader, RecoTauDiscriminantConfiguration::mask, l1t::OMDSReader::QueryResults::numberRows(), jets_cff::payload, l1t::OMDSReader::QueryResults::queryFailed(), diffTwoXMLs::r1, diffTwoXMLs::r2, diffTwoXMLs::ranges, l1t::XmlConfigParser::readDOMFromString(), l1t::XmlConfigParser::readRootElement(), alignCSCRings::s, indexGen::s2, l1t::PrescalesVetosHelper::setBxMaskDefault(), l1t::TriggerSystem::setConfigured(), l1t::PrescalesVetosHelper::setPrescaleFactorTable(), l1t::PrescalesVetosHelper::setTriggerAlgoBxMask(), l1t::PrescalesVetosHelper::setTriggerMaskVeto(), l1t::OMDSReader::singleAttribute(), AlCaHLTBitMon_QueryRunRegistry::string, transactionSafe, and TriggerAnalyzer::veto.

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

Member Data Documentation

bool L1TGlobalPrescalesVetosOnlineProd::transactionSafe
private