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