test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1TGlobalPrescalesVetosOnlineProd.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <fstream>
3 
10 
11 
12 
13 class L1TGlobalPrescalesVetosOnlineProd : public L1ConfigOnlineProdBaseExt<L1TGlobalPrescalesVetosO2ORcd,L1TGlobalPrescalesVetos> {
14 private:
15 public:
16  virtual std::shared_ptr<L1TGlobalPrescalesVetos> newObject(const std::string& objectKey, const L1TGlobalPrescalesVetosO2ORcd& record) override ;
17 
20 };
21 
23 
24 std::shared_ptr<L1TGlobalPrescalesVetos> L1TGlobalPrescalesVetosOnlineProd::newObject(const std::string& objectKey, const L1TGlobalPrescalesVetosO2ORcd& record) {
25  using namespace edm::es;
26 
27  edm::LogInfo( "L1-O2O: L1TGlobalPrescalesVetosOnlineProd" ) << "Producing L1TGlobalPrescalesVetos with RS key =" << objectKey ;
28 
29  if( objectKey.empty() ){
30  edm::LogInfo( "L1-O2O: L1TGlobalPrescalesVetosOnlineProd" ) << "Key is empty";
31  throw std::runtime_error("Empty objecKey");
33  }
34 
35  std::string stage2Schema = "CMS_TRG_L1_CONF" ;
36 
37  std::vector< std::string > queryStrings ;
38  queryStrings.push_back( "MP7" ) ;
39  queryStrings.push_back( "AMC502_EXTCOND" ) ;
40  queryStrings.push_back( "AMC502_FINOR" ) ;
41  queryStrings.push_back( "ALGOBX_MASK" ) ;
42  queryStrings.push_back( "ALGO_FINOR_MASK" ) ;
43  queryStrings.push_back( "ALGO_FINOR_VETO" ) ;
44  queryStrings.push_back( "ALGO_PRESCALE" ) ;
45 
46  std::string prescale_key, bxmask_key, mask_key, vetomask_key;
47 
48  // select MP7, AMC502_EXTCOND, AMC502_FINOR, ALGOBX_MASK, ALGO_FINOR_MASK, ALGO_FINOR_VETO, ALGO_PRESCALE from CMS_TRG_L1_CONF.UGT_RS_KEYS where ID = objectKey ;
49  l1t::OMDSReader::QueryResults queryResult =
50  m_omdsReader.basicQuery( queryStrings,
51  stage2Schema,
52  "UGT_RS_KEYS",
53  "UGT_RS_KEYS.ID",
54  m_omdsReader.singleAttribute(objectKey)
55  ) ;
56 
57  if( queryResult.queryFailed() || queryResult.numberRows() != 1 ){
58  edm::LogError( "L1-O2O" ) << "Cannot get UGT_RS_KEYS.{MP7,AMC502_EXTCOND,AMC502_FINOR,ALGOBX_MASK,ALGO_FINOR_MASK,ALGO_FINOR_VETO,ALGO_PRESCALE} for ID = " << objectKey;
59  throw std::runtime_error("Broken key");
61  }
62 
63  if( !queryResult.fillVariable( "ALGO_PRESCALE", prescale_key) ) prescale_key = "";
64  if( !queryResult.fillVariable( "ALGOBX_MASK", bxmask_key) ) bxmask_key = "";
65  if( !queryResult.fillVariable( "ALGO_FINOR_MASK", mask_key) ) mask_key = "";
66  if( !queryResult.fillVariable( "ALGO_FINOR_VETO", vetomask_key) ) vetomask_key = "";
67 
68  queryStrings.clear();
69  queryStrings.push_back( "CONF" ) ;
70 
71 
72  std::string xmlPayload_prescale, xmlPayload_mask_algobx, xmlPayload_mask_finor, xmlPayload_mask_veto;
73 
74  queryResult =
75  m_omdsReader.basicQuery( queryStrings,
76  stage2Schema,
77  "UGT_RS",
78  "UGT_RS.ID",
79  m_omdsReader.singleAttribute(prescale_key)
80  ) ;
81 
82  if( queryResult.queryFailed() || queryResult.numberRows() != 1 ){
83  edm::LogError( "L1-O2O: L1TGlobalPrescalesVetosOnlineProd" ) << "Cannot get UGT_RS.CONF for prescale_key = "<<prescale_key ;
84  throw std::runtime_error("Broken key");
86  }
87 
88  if( !queryResult.fillVariable( "CONF", xmlPayload_prescale ) ) xmlPayload_prescale = "";
89 
90 
91  queryResult =
92  m_omdsReader.basicQuery( queryStrings,
93  stage2Schema,
94  "UGT_RS",
95  "UGT_RS.ID",
97  ) ;
98 
99  if( queryResult.queryFailed() || queryResult.numberRows() != 1 ){
100  edm::LogError( "L1-O2O: L1TGlobalPrescalesVetosOnlineProd" ) << "Cannot get UGT_RS.CONF for mask_key = "<<mask_key ;
101  throw std::runtime_error("Broken key");
103  }
104 
105  if( !queryResult.fillVariable( "CONF", xmlPayload_mask_finor ) ) xmlPayload_mask_finor = "";
106 
107 
108  queryResult =
109  m_omdsReader.basicQuery( queryStrings,
110  stage2Schema,
111  "UGT_RS",
112  "UGT_RS.ID",
113  m_omdsReader.singleAttribute(bxmask_key)
114  ) ;
115 
116  if( queryResult.queryFailed() || queryResult.numberRows() != 1 ){
117  edm::LogError( "L1-O2O: L1TGlobalPrescalesVetosOnlineProd" ) << "Cannot get UGT_RS.CONF for bxmask_key = "<<bxmask_key ;
118  throw std::runtime_error("Broken key");
120  }
121 
122  if( !queryResult.fillVariable( "CONF", xmlPayload_mask_algobx ) ) xmlPayload_mask_algobx = "";
123 
124 
125  queryResult =
126  m_omdsReader.basicQuery( queryStrings,
127  stage2Schema,
128  "UGT_RS",
129  "UGT_RS.ID",
130  m_omdsReader.singleAttribute(vetomask_key)
131  ) ;
132 
133  if( queryResult.queryFailed() || queryResult.numberRows() != 1 ){
134  edm::LogError( "L1-O2O: L1TGlobalPrescalesVetosOnlineProd" ) << "Cannot get UGT_RS.CONF for vetomask_key = "<<vetomask_key ;
135  throw std::runtime_error("Broken key");
137  }
138 
139  if( !queryResult.fillVariable( "CONF", xmlPayload_mask_veto ) ) xmlPayload_mask_veto = "";
140 
141  // for debugging purposes dump the payloads to /tmp
142  std::ofstream output1(std::string("/tmp/").append(prescale_key.substr(0,prescale_key.find("/"))).append(".xml"));
143  output1<<xmlPayload_prescale;
144  output1.close();
145  std::ofstream output2(std::string("/tmp/").append(mask_key.substr(0,mask_key.find("/"))).append(".xml"));
146  output2<<xmlPayload_mask_finor;
147  output2.close();
148  std::ofstream output3(std::string("/tmp/").append(bxmask_key.substr(0,bxmask_key.find("/"))).append(".xml"));
149  output3<<xmlPayload_mask_algobx;
150  output3.close();
151  std::ofstream output4(std::string("/tmp/").append(vetomask_key.substr(0,vetomask_key.find("/"))).append(".xml"));
152  output4<<xmlPayload_mask_veto;
153  output4.close();
154 
156 
157  unsigned int m_numberPhysTriggers = 512;
158  unsigned int m_bx_mask_default = 1;
159 
160 
161  std::vector<std::vector<int> > prescales;
162  std::vector<unsigned int> triggerMasks;
163  std::vector<int> triggerVetoMasks;
164  std::map<int, std::vector<int> > triggerAlgoBxMaskAlgoTrig;
165 
166  // Prescales
167  l1t::XmlConfigReader xmlReader_prescale;
168  l1t::TrigSystem ts_prescale;
169  ts_prescale.addProcRole("uGtProcessor", "uGtProcessor");
170 
171  // run the parser
172  xmlReader_prescale.readDOMFromString( xmlPayload_prescale ); // initialize it
173  xmlReader_prescale.readRootElement( ts_prescale, "uGT" ); // extract all of the relevant context
174  ts_prescale.setConfigured();
175 
176  std::map<std::string, l1t::Setting> settings_prescale = ts_prescale.getSettings("uGtProcessor");
177  std::vector<l1t::TableRow> tRow_prescale = settings_prescale["prescales"].getTableRows();
178 
179  unsigned int numColumns_prescale = 0;
180  if( tRow_prescale.size()>0 ){
181  std::vector<std::string> firstRow_prescale = tRow_prescale[0].getRow();
182  numColumns_prescale = firstRow_prescale.size();
183  }
184 
185  int NumPrescaleSets = numColumns_prescale - 1;
188  unsigned int NumAlgos_prescale = 0;
189  for( auto it=tRow_prescale.begin(); it!=tRow_prescale.end(); it++ ){
190  unsigned int algoBit = it->getRowValue<unsigned int>("algo/prescale-index");
191  if( NumAlgos_prescale < algoBit+1 ) NumAlgos_prescale = algoBit+1;
192  }
193 
194  if( NumPrescaleSets > 0 ){
195  // Fill default prescale set
196  for( int iSet=0; iSet<NumPrescaleSets; iSet++ ){
197  prescales.push_back(std::vector<int>());
198  for( unsigned int iBit = 0; iBit < NumAlgos_prescale; ++iBit ){
199  int inputDefaultPrescale = 0; // only prescales that are set in the block below are used
200  prescales[iSet].push_back(inputDefaultPrescale);
201  }
202  }
203 
204  for( auto it=tRow_prescale.begin(); it!=tRow_prescale.end(); it++ ){
205  unsigned int algoBit = it->getRowValue<unsigned int>("algo/prescale-index");
206  for( int iSet=0; iSet<NumPrescaleSets; iSet++ ){
207  int prescale = 0;
208  try{
209  prescale = it->getRowValue<unsigned int>(std::to_string(iSet));
210  } catch (std::runtime_error &e){
211  edm::LogError( "L1-O2O: L1TGlobalPrescalesVetosOnlineProd" )
212  << "\nWarning: missing value for algoBit " << algoBit << " (row)"
213  << " in prescale set " << iSet << " (column) of " << prescale_key
214  << " also stored in /tmp/" << prescale_key.substr(0,prescale_key.find("/")).append(".xml")
215  << "\nWarning: no information on algoBit, setting to 0 "
216  << std::endl;
217  }
218  prescales[iSet][algoBit] = prescale;
219  }
220  }
221  }
222 
223 
225 
226  // finor mask
227  // Setting mask to default 1 (unmask)
228  for( unsigned int iAlg=0; iAlg < m_numberPhysTriggers; iAlg++ )
229  triggerMasks.push_back(1);
230 
231  l1t::XmlConfigReader xmlReader_mask_finor;
232  l1t::TrigSystem ts_mask_finor;
233  ts_mask_finor.addProcRole("uGtProcessor", "uGtProcessor");
234 
235  // run the parser
236  xmlReader_mask_finor.readDOMFromString( xmlPayload_mask_finor ); // initialize it
237  xmlReader_mask_finor.readRootElement( ts_mask_finor, "uGT" ); // extract all of the relevant context
238  ts_mask_finor.setConfigured();
239 
240  std::map<std::string, l1t::Setting> settings_mask_finor = ts_mask_finor.getSettings("uGtProcessor");
241  std::vector<l1t::TableRow> tRow_mask_finor = settings_mask_finor["finorMask"].getTableRows();
242 
243  for( auto it=tRow_mask_finor.begin(); it!=tRow_mask_finor.end(); it++ ){
244  unsigned int algoBit = it->getRowValue<unsigned int>("algo");
245  unsigned int mask = it->getRowValue<unsigned int>("mask");
246  if( algoBit < m_numberPhysTriggers ) triggerMasks[algoBit] = mask;
247  }
248 
250 
251  // veto mask
252  // Setting veto mask to default 0 (no veto)
253  for( unsigned int iAlg=0; iAlg < m_numberPhysTriggers; iAlg++ )
254  triggerVetoMasks.push_back(0);
255 
256  l1t::XmlConfigReader xmlReader_mask_veto;
257  l1t::TrigSystem ts_mask_veto;
258  ts_mask_veto.addProcRole("uGtProcessor", "uGtProcessor");
259 
260  // run the parser
261  xmlReader_mask_veto.readDOMFromString( xmlPayload_mask_veto ); // initialize it
262  xmlReader_mask_veto.readRootElement( ts_mask_veto, "uGT" ); // extract all of the relevant context
263  ts_mask_veto.setConfigured();
264 
265  std::map<std::string, l1t::Setting> settings_mask_veto = ts_mask_veto.getSettings("uGtProcessor");
266  std::vector<l1t::TableRow> tRow_mask_veto = settings_mask_veto["vetoMask"].getTableRows();
267 
268  for( auto it=tRow_mask_veto.begin(); it!=tRow_mask_veto.end(); it++ ){
269  unsigned int algoBit = it->getRowValue<unsigned int>("algo");
270  unsigned int veto = it->getRowValue<unsigned int>("veto");
271  if( algoBit < m_numberPhysTriggers ) triggerVetoMasks[algoBit] = int(veto);
272  }
273 
275 
276  // Algo bx mask
277  l1t::XmlConfigReader xmlReader_mask_algobx;
278  l1t::TrigSystem ts_mask_algobx;
279  ts_mask_algobx.addProcRole("uGtProcessor", "uGtProcessor");
280 
281  // run the parser
282  xmlReader_mask_algobx.readDOMFromString( xmlPayload_mask_algobx ); // initialize it
283  xmlReader_mask_algobx.readRootElement( ts_mask_algobx, "uGT" ); // extract all of the relevant context
284  ts_mask_algobx.setConfigured();
285 
286  std::map<std::string, l1t::Setting> settings_mask_algobx = ts_mask_algobx.getSettings("uGtProcessor");
287  std::vector<l1t::TableRow> tRow_mask_algobx = settings_mask_algobx["algorithmBxMask"].getTableRows();
288 
289  unsigned int numCol_mask_algobx = 0;
290  if( tRow_mask_algobx.size()>0 ){
291  std::vector<std::string> firstRow_mask_algobx = tRow_mask_algobx[0].getRow();
292  numCol_mask_algobx = firstRow_mask_algobx.size();
293  }
294 
295  int NumAlgoBitsInMask = numCol_mask_algobx - 1;
296  if( NumAlgoBitsInMask > 0 ){
297  for( auto it=tRow_mask_algobx.begin(); it!=tRow_mask_algobx.end(); it++ ){
298  int bx = it->getRowValue<unsigned int>("bx/algo");
299  std::vector<int> maskedBits;
300  for( int iBit=0; iBit<NumAlgoBitsInMask; iBit++ ){
301  unsigned int maskBit = it->getRowValue<unsigned int>(std::to_string(iBit));
302  if( maskBit!=m_bx_mask_default ) maskedBits.push_back(iBit);
303  }
304  if( maskedBits.size()>0 ) triggerAlgoBxMaskAlgoTrig[bx] = maskedBits;
305  }
306  }
307 
308 
309  // Set prescales to zero if masked
310  for( unsigned int iSet=0; iSet < prescales.size(); iSet++ ){
311  for( unsigned int iBit=0; iBit < prescales[iSet].size(); iBit++ ){
312  // Add protection in case prescale table larger than trigger mask size
313  if( iBit >= triggerMasks.size() ){
314  edm::LogError( "L1-O2O: L1TGlobalPrescalesVetosOnlineProd" )
315  << "\nWarning: algoBit in prescale table >= triggerMasks.size() "
316  << "\nWarning: no information on masking bit or not, setting as unmasked "
317  << std::endl;
318  }
319  else {
320  prescales[iSet][iBit] *= triggerMasks[iBit];
321  }
322  }
323  }
324 
326 
328 
329  data_.setBxMaskDefault ( m_bx_mask_default );
331  data_.setTriggerMaskVeto ( triggerVetoMasks );
332  data_.setTriggerAlgoBxMask ( triggerAlgoBxMaskAlgoTrig );
333 
334  using namespace edm::es;
335  std::shared_ptr<L1TGlobalPrescalesVetos> pMenu(data_.getWriteInstance());
336  return pMenu;
337 
338 }
339 
340 //define this as a plug-in
L1TGlobalPrescalesVetosOnlineProd(const edm::ParameterSet &)
void setPrescaleFactorTable(std::vector< std::vector< int > > value)
const QueryResults singleAttribute(const T &data) const
Definition: OMDSReader.h:295
JetCorrectorParameters::Record record
Definition: classes.h:7
boost::dynamic_bitset append(const boost::dynamic_bitset<> &bs1, const boost::dynamic_bitset<> &bs2)
this method takes two bitsets bs1 and bs2 and returns result of bs2 appended to the end of bs1 ...
virtual std::shared_ptr< L1TGlobalPrescalesVetos > newObject(const std::string &objectKey, const L1TGlobalPrescalesVetosO2ORcd &record) override
void addProcRole(const std::string &processor, const std::string &role)
Definition: TrigSystem.cc:39
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
void setTriggerMaskVeto(std::vector< int > value)
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
void setTriggerAlgoBxMask(std::map< int, std::vector< int > > value)
L1TGlobalPrescalesVetos * getWriteInstance()