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 &)
 
virtual std::shared_ptr< L1TGlobalPrescalesVetosnewObject (const std::string &objectKey, const L1TGlobalPrescalesVetosO2ORcd &record) override
 
 ~L1TGlobalPrescalesVetosOnlineProd (void)
 
- Public Member Functions inherited from L1ConfigOnlineProdBaseExt< L1TGlobalPrescalesVetosO2ORcd, L1TGlobalPrescalesVetos >
 L1ConfigOnlineProdBaseExt (const edm::ParameterSet &)
 
std::shared_ptr< L1TGlobalPrescalesVetosproduce (const L1TGlobalPrescalesVetosO2ORcd &iRecord)
 
 ~L1ConfigOnlineProdBaseExt ()
 
- 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

int xmlModel
 

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
template<typename T >
void setWhatProduced (T *iThis, const es::Label &iLabel=es::Label())
 
template<typename T >
void setWhatProduced (T *iThis, const char *iLabel)
 
template<typename T >
void setWhatProduced (T *iThis, const std::string &iLabel)
 
template<typename T , typename TDecorator >
void setWhatProduced (T *iThis, const TDecorator &iDec, const es::Label &iLabel=es::Label())
 
template<typename T , typename TReturn , typename TRecord >
void setWhatProduced (T *iThis, TReturn(T::*iMethod)(const TRecord &), const es::Label &iLabel=es::Label())
 
template<typename T , typename TReturn , typename TRecord , typename TArg >
void setWhatProduced (T *iThis, TReturn(T::*iMethod)(const TRecord &), const TArg &iDec, const es::Label &iLabel=es::Label())
 
- 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  )
inline

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

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, TriggerAnalyzer::veto, and xmlModel.

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

Member Data Documentation

int L1TGlobalPrescalesVetosOnlineProd::xmlModel
private