CMS 3D CMS Logo

L1TGlobalPrescalesVetosOnlineProd.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <fstream>
3 #include <stdexcept>
4 
12 #include "OnlineDBqueryHelper.h"
13 
14 class L1TGlobalPrescalesVetosOnlineProd : public L1ConfigOnlineProdBaseExt<L1TGlobalPrescalesVetosO2ORcd,L1TGlobalPrescalesVetos> {
15 private:
16 public:
17  virtual std::shared_ptr<L1TGlobalPrescalesVetos> newObject(const std::string& objectKey, const L1TGlobalPrescalesVetosO2ORcd& record) override ;
18 
21 };
22 
24 
25 std::shared_ptr<L1TGlobalPrescalesVetos> L1TGlobalPrescalesVetosOnlineProd::newObject(const std::string& objectKey, const L1TGlobalPrescalesVetosO2ORcd& record) {
26  using namespace edm::es;
27 
28  edm::LogInfo( "L1-O2O: L1TGlobalPrescalesVetosOnlineProd" ) << "Producing L1TGlobalPrescalesVetos with RS key = " << objectKey ;
29 
30  if( objectKey.empty() ){
31  edm::LogError( "L1-O2O: L1TGlobalPrescalesVetosOnlineProd" ) << "Key is empty";
32  throw std::runtime_error("Empty objecKey");
33  }
34 
35  std::vector< std::string > queryColumns ;
36  queryColumns.push_back( "ALGOBX_MASK" ) ;
37  queryColumns.push_back( "ALGO_FINOR_MASK" ) ;
38  queryColumns.push_back( "ALGO_FINOR_VETO" ) ;
39  queryColumns.push_back( "ALGO_PRESCALE" ) ;
40 
41  std::string prescale_key, bxmask_key, mask_key, vetomask_key;
42  std::string xmlPayload_prescale, xmlPayload_mask_algobx, xmlPayload_mask_finor, xmlPayload_mask_veto;
43  try {
44  std::map<std::string,std::string> subKeys = l1t::OnlineDBqueryHelper::fetch( queryColumns, "UGT_RS_KEYS", objectKey, m_omdsReader );
45  prescale_key = subKeys["ALGO_PRESCALE"];
46  bxmask_key = subKeys["ALGOBX_MASK"];
47  mask_key = subKeys["ALGO_FINOR_MASK"];
48  vetomask_key = subKeys["ALGO_FINOR_VETO"];
49  xmlPayload_prescale = l1t::OnlineDBqueryHelper::fetch( {"CONF"}, "UGT_RS_CLOBS", prescale_key, m_omdsReader )["CONF"];
50  xmlPayload_mask_algobx = l1t::OnlineDBqueryHelper::fetch( {"CONF"}, "UGT_RS_CLOBS", bxmask_key, m_omdsReader )["CONF"];
51  xmlPayload_mask_finor = l1t::OnlineDBqueryHelper::fetch( {"CONF"}, "UGT_RS_CLOBS", mask_key, m_omdsReader )["CONF"];
52  xmlPayload_mask_veto = l1t::OnlineDBqueryHelper::fetch( {"CONF"}, "UGT_RS_CLOBS", vetomask_key, m_omdsReader )["CONF"];
53  } catch ( std::runtime_error &e ) {
54  edm::LogError( "L1-O2O: L1TGlobalPrescalesVetosOnlineProd" ) << e.what();
55  throw std::runtime_error("Broken key");
56  }
57 
58 
59  // for debugging purposes dump the payloads to /tmp
60  std::ofstream output1(std::string("/tmp/").append(prescale_key.substr(0,prescale_key.find("/"))).append(".xml"));
61  output1<<xmlPayload_prescale;
62  output1.close();
63  std::ofstream output2(std::string("/tmp/").append(mask_key.substr(0,mask_key.find("/"))).append(".xml"));
64  output2<<xmlPayload_mask_finor;
65  output2.close();
66  std::ofstream output3(std::string("/tmp/").append(bxmask_key.substr(0,bxmask_key.find("/"))).append(".xml"));
67  output3<<xmlPayload_mask_algobx;
68  output3.close();
69  std::ofstream output4(std::string("/tmp/").append(vetomask_key.substr(0,vetomask_key.find("/"))).append(".xml"));
70  output4<<xmlPayload_mask_veto;
71  output4.close();
72 
74 
75  unsigned int m_numberPhysTriggers = 512;
76  unsigned int m_bx_mask_default = 1;
77 
78 
79  std::vector<std::vector<int> > prescales;
80  std::vector<unsigned int> triggerMasks;
81  std::vector<int> triggerVetoMasks;
82  std::map<int, std::vector<int> > triggerAlgoBxMaskAlgoTrig;
83 
84  // Prescales
85  l1t::XmlConfigParser xmlReader_prescale;
86  l1t::TriggerSystem ts_prescale;
87  ts_prescale.addProcessor("uGtProcessor", "uGtProcessor","-1","-1");
88 
89  // run the parser
90  xmlReader_prescale.readDOMFromString( xmlPayload_prescale ); // initialize it
91  xmlReader_prescale.readRootElement( ts_prescale, "uGT" ); // extract all of the relevant context
92  ts_prescale.setConfigured();
93 
94  const std::map<std::string, l1t::Parameter> &settings_prescale = ts_prescale.getParameters("uGtProcessor");
95  std::map<std::string,unsigned int> prescaleColumns = settings_prescale.at("prescales").getColumnIndices();
96 
97  unsigned int numColumns_prescale = prescaleColumns.size();
98 
99  int NumPrescaleSets = numColumns_prescale - 1;
101  std::vector<unsigned int> algoBits = settings_prescale.at("prescales").getTableColumn<unsigned int>("algo/prescale-index");
102  int NumAlgos_prescale = *std::max_element(algoBits.begin(), algoBits.end()) + 1;
103 
104  if( NumPrescaleSets > 0 ){
105  // Fill default prescale set
106  for( int iSet=0; iSet<NumPrescaleSets; iSet++ ){
107  prescales.push_back(std::vector<int>());
108  for( int iBit = 0; iBit < NumAlgos_prescale; ++iBit ){
109  int inputDefaultPrescale = 0; // only prescales that are set in the block below are used
110  prescales[iSet].push_back(inputDefaultPrescale);
111  }
112  }
113 
114  for(auto &col : prescaleColumns){
115  if( col.second<1 ) continue; // we don't care for the algorithms' indicies in 0th column
116  int iSet = col.second - 1;
117  std::vector<unsigned int> prescalesForSet = settings_prescale.at("prescales").getTableColumn<unsigned int>(col.first.c_str());
118  for(unsigned int row=0; row<prescalesForSet.size(); row++){
119  unsigned int prescale = prescalesForSet[row];
120  unsigned int algoBit = algoBits[row];
121  prescales[iSet][algoBit] = prescale;
122  }
123  }
124  }
125 
126 
128 
129  // finor mask
130  // Setting mask to default 1 (unmask)
131  for( unsigned int iAlg=0; iAlg < m_numberPhysTriggers; iAlg++ )
132  triggerMasks.push_back(1);
133 
134  l1t::XmlConfigParser xmlReader_mask_finor;
135  l1t::TriggerSystem ts_mask_finor;
136  ts_mask_finor.addProcessor("uGtProcessor", "uGtProcessor","-1","-1");
137 
138  // run the parser
139  xmlReader_mask_finor.readDOMFromString( xmlPayload_mask_finor ); // initialize it
140  xmlReader_mask_finor.readRootElement( ts_mask_finor, "uGT" ); // extract all of the relevant context
141  ts_mask_finor.setConfigured();
142 
143  const std::map<std::string, l1t::Parameter>& settings_mask_finor = ts_mask_finor.getParameters("uGtProcessor");
144 
145  std::vector<unsigned int> algo_mask_finor = settings_mask_finor.at("finorMask").getTableColumn<unsigned int>("algo");
146  std::vector<unsigned int> mask_mask_finor = settings_mask_finor.at("finorMask").getTableColumn<unsigned int>("mask");
147 
148  for(unsigned int row=0; row<algo_mask_finor.size(); row++){
149  unsigned int algoBit = algo_mask_finor[row];
150  unsigned int mask = mask_mask_finor[row];
151  if( algoBit < m_numberPhysTriggers ) triggerMasks[algoBit] = mask;
152  }
153 
155 
156  // veto mask
157  // Setting veto mask to default 0 (no veto)
158  for( unsigned int iAlg=0; iAlg < m_numberPhysTriggers; iAlg++ )
159  triggerVetoMasks.push_back(0);
160 
161  l1t::XmlConfigParser xmlReader_mask_veto;
162  l1t::TriggerSystem ts_mask_veto;
163  ts_mask_veto.addProcessor("uGtProcessor", "uGtProcessor","-1","-1");
164 
165  // run the parser
166  xmlReader_mask_veto.readDOMFromString( xmlPayload_mask_veto ); // initialize it
167  xmlReader_mask_veto.readRootElement( ts_mask_veto, "uGT" ); // extract all of the relevant context
168  ts_mask_veto.setConfigured();
169 
170  const std::map<std::string, l1t::Parameter>& settings_mask_veto = ts_mask_veto.getParameters("uGtProcessor");
171  std::vector<unsigned int> algo_mask_veto = settings_mask_veto.at("vetoMask").getTableColumn<unsigned int>("algo");
172  std::vector<unsigned int> veto_mask_veto = settings_mask_veto.at("vetoMask").getTableColumn<unsigned int>("veto");
173 
174  for(unsigned int row=0; row<algo_mask_veto.size(); row++){
175  unsigned int algoBit = algo_mask_veto[row];
176  unsigned int veto = veto_mask_veto[row];
177  if( algoBit < m_numberPhysTriggers ) triggerVetoMasks[algoBit] = int(veto);
178  }
179 
181 
182  // Algo bx mask
183  l1t::XmlConfigParser xmlReader_mask_algobx;
184  l1t::TriggerSystem ts_mask_algobx;
185  ts_mask_algobx.addProcessor("uGtProcessor", "uGtProcessor","-1","-1");
186 
187  // run the parser
188  xmlReader_mask_algobx.readDOMFromString( xmlPayload_mask_algobx ); // initialize it
189  xmlReader_mask_algobx.readRootElement( ts_mask_algobx, "uGT" ); // extract all of the relevant context
190  ts_mask_algobx.setConfigured();
191 
192  const std::map<std::string, l1t::Parameter>& settings_mask_algobx = ts_mask_algobx.getParameters("uGtProcessor");
193  std::map<std::string,unsigned int> mask_algobx_columns = settings_mask_algobx.at("algorithmBxMask").getColumnIndices();
194  std::vector<unsigned int> bunches = settings_mask_algobx.at("algorithmBxMask").getTableColumn<unsigned int>("bx/algo");
195 
196  unsigned int numCol_mask_algobx = mask_algobx_columns.size();
197 
198  int NumAlgoBitsInMask = numCol_mask_algobx - 1;
199  for( int iBit=0; iBit<NumAlgoBitsInMask; iBit++ ){
200  std::vector<unsigned int> algo = settings_mask_algobx.at("algorithmBxMask").getTableColumn<unsigned int>(std::to_string(iBit).c_str());
201  for(unsigned int bx=0; bx<bunches.size(); bx++){
202  if( algo[bx]!=m_bx_mask_default ) triggerAlgoBxMaskAlgoTrig[ bunches[bx] ].push_back(iBit);
203  }
204  }
205 
206 
207  // Set prescales to zero if masked
208  for( unsigned int iSet=0; iSet < prescales.size(); iSet++ ){
209  for( unsigned int iBit=0; iBit < prescales[iSet].size(); iBit++ ){
210  // Add protection in case prescale table larger than trigger mask size
211  if( iBit >= triggerMasks.size() ){
212  edm::LogError( "L1-O2O: L1TGlobalPrescalesVetosOnlineProd" )
213  << "\nWarning: algoBit in prescale table >= triggerMasks.size() "
214  << "\nWarning: no information on masking bit or not, setting as unmasked "
215  << std::endl;
216  }
217  else {
218  prescales[iSet][iBit] *= triggerMasks[iBit];
219  }
220  }
221  }
222 
224 
226 
227  data_.setBxMaskDefault ( m_bx_mask_default );
228  data_.setPrescaleFactorTable ( prescales );
229  data_.setTriggerMaskVeto ( triggerVetoMasks );
230  data_.setTriggerAlgoBxMask ( triggerAlgoBxMaskAlgoTrig );
231 
232  using namespace edm::es;
233  std::shared_ptr<L1TGlobalPrescalesVetos> pMenu(data_.getWriteInstance());
234  return pMenu;
235 
236 }
237 
238 //define this as a plug-in
L1TGlobalPrescalesVetosOnlineProd(const edm::ParameterSet &)
void setConfigured(bool state=true) noexcept
Definition: TriggerSystem.h:73
void setPrescaleFactorTable(std::vector< std::vector< int > > value)
JetCorrectorParameters::Record record
Definition: classes.h:7
virtual std::shared_ptr< L1TGlobalPrescalesVetos > newObject(const std::string &objectKey, const L1TGlobalPrescalesVetosO2ORcd &record) override
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)
void setTriggerMaskVeto(std::vector< int > value)
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
const std::map< std::string, Parameter > & getParameters(const char *processor) const
void readRootElement(TriggerSystem &aTriggerSystem, const std::string &sysId="")
col
Definition: cuy.py:1008
void addProcessor(const char *processor, const char *role, const char *crate, const char *slot)
void setTriggerAlgoBxMask(std::map< int, std::vector< int > > value)
L1TGlobalPrescalesVetos * getWriteInstance()