test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1TMuonGlobalParamsOnlineProd.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <fstream>
3 #include <strstream>
4 
12 
13 class L1TMuonGlobalParamsOnlineProd : public L1ConfigOnlineProdBaseExt<L1TMuonGlobalParamsO2ORcd,L1TMuonGlobalParams> {
14 private:
15 public:
16  virtual boost::shared_ptr<L1TMuonGlobalParams> newObject(const std::string& objectKey, const L1TMuonGlobalParamsO2ORcd &record) override ;
17 
20 };
21 
23 
24 boost::shared_ptr<L1TMuonGlobalParams> L1TMuonGlobalParamsOnlineProd::newObject(const std::string& objectKey, const L1TMuonGlobalParamsO2ORcd &record) {
25  using namespace edm::es;
26 
27  const L1TMuonGlobalParamsRcd& baseRcd = record.template getRecord< L1TMuonGlobalParamsRcd >() ;
29  baseRcd.get( baseSettings ) ;
30 
31  if( objectKey.empty() ){
32  edm::LogError( "L1-O2O: L1TMuonGlobalParamsOnlineProd" ) << "Key is empty";
33  throw std::runtime_error("Empty objectKey");
35  }
36 
37  std::string tscKey = objectKey.substr(0, objectKey.find(":") );
38  std::string rsKey = objectKey.substr( objectKey.find(":")+1, std::string::npos );
39 
40  std::string stage2Schema = "CMS_TRG_L1_CONF" ;
41  edm::LogInfo( "L1-O2O: L1TMuonGlobalParamsOnlineProd" ) << "Producing L1TMuonGlobalParams with TSC key =" << tscKey << " and RS key = " << rsKey ;
42 
43  // ALGO and HW
44  std::vector< std::string > queryStrings ;
45  queryStrings.push_back( "ALGO" ) ;
46  queryStrings.push_back( "HW" ) ;
47 
48  std::string algo_key, hw_key;
49 
50  // select ALGO,HW from CMS_TRG_L1_CONF.UGMT_KEYS where ID = tscKey ;
51  l1t::OMDSReader::QueryResults queryResult =
52  m_omdsReader.basicQuery( queryStrings,
53  stage2Schema,
54  "UGMT_KEYS",
55  "UGMT_KEYS.ID",
57  ) ;
58 
59  if( queryResult.queryFailed() || queryResult.numberRows() != 1 ){
60  edm::LogError( "L1-O2O: L1TMuonGlobalParamsOnlineProd" ) << "Cannot get UGMT_KEYS.{ALGO,HW} for ID = " << tscKey ;
61  throw std::runtime_error("Broken key");
63  }
64 
65  if( !queryResult.fillVariable( "ALGO", algo_key) ) algo_key = "";
66  if( !queryResult.fillVariable( "HW", hw_key ) ) hw_key = "";
67 
68  // RS
69  queryStrings.clear();
70  queryStrings.push_back( "MP7" );
71  queryStrings.push_back( "MP7_MONI" );
72  queryStrings.push_back( "AMC13_MONI");
73 
74  std::string rs_mp7_key, rs_mp7moni_key, rs_amc13moni_key;
75 
76  // select MP7, MP&_MONI, AMC13_MONI from CMS_TRG_L1_CONF.UGMT_RS_KEYS where ID = rsKey ;
77  queryResult =
78  m_omdsReader.basicQuery( queryStrings,
79  stage2Schema,
80  "UGMT_RS_KEYS",
81  "UGMT_RS_KEYS.ID",
83  ) ;
84 
85  if( queryResult.queryFailed() || queryResult.numberRows() != 1 ){
86  edm::LogError( "L1-O2O: L1TMuonGlobalParamsOnlineProd" ) << "Cannot get UGMT_RS_KEYS.{MP7,MP7_MONI,AMC13_MONI} for ID = " << rsKey ;
87  throw std::runtime_error("Broken key");
89  }
90 
91  if( !queryResult.fillVariable( "MP7", rs_mp7_key ) ) rs_mp7_key = "";
92  if( !queryResult.fillVariable( "MP7_MONI", rs_mp7moni_key ) ) rs_mp7moni_key = "";
93  if( !queryResult.fillVariable( "AMC13_MONI", rs_amc13moni_key) ) rs_amc13moni_key = "";
94 
95 
96  std::string algo_mp7_key, algo_luts_key;
97 
98  queryStrings.clear();
99  queryStrings.push_back( "MP7" );
100  queryStrings.push_back( "LUTS" );
101 
102  // query ALGO configuration
103  queryResult =
104  m_omdsReader.basicQuery( queryStrings,
105  stage2Schema,
106  "UGMT_ALGO_KEYS",
107  "UGMT_ALGO_KEYS.ID",
108  m_omdsReader.singleAttribute(algo_key)
109  ) ;
110 
111  if( queryResult.queryFailed() || queryResult.numberRows() != 1 ){
112  edm::LogError( "L1-O2O: L1TMuonGlobalParamsOnlineProd" ) << "Cannot get UGMT_ALGO.{MP7,LUTS} for ID = " << algo_key;
113  throw std::runtime_error("Broken key");
115  }
116 
117  if( !queryResult.fillVariable( "MP7", algo_mp7_key ) ) algo_mp7_key = "";
118  if( !queryResult.fillVariable( "LUTS", algo_luts_key ) ) algo_luts_key = "";
119  // remember ALGO configuration
120 
121  // At this point we have four keys: one ALGO key, one HW key, and two RS keys; now query the payloads for these keys
122  // Now querry the actual payloads
123  enum {kALGO=0, kRS, kHW, NUM_TYPES};
124  std::map<std::string,std::string> payloads[NUM_TYPES]; // associates key -> XML payload for a given type of payloads
125  std::string xmlPayload;
126 
127  queryStrings.clear();
128  queryStrings.push_back( "CONF" );
129 
130  // query ALGO configurations
131  queryResult =
132  m_omdsReader.basicQuery( queryStrings,
133  stage2Schema,
134  "UGMT_ALGO",
135  "UGMT_ALGO.ID",
136  m_omdsReader.singleAttribute(algo_mp7_key)
137  ) ;
138 
139  if( queryResult.queryFailed() || queryResult.numberRows() != 1 ){
140  edm::LogError( "L1-O2O: L1TMuonGlobalParamsOnlineProd" ) << "Cannot get UGMT_ALGO.CONF for ID = " << algo_mp7_key;
141  throw std::runtime_error("Broken key");
143  }
144 
145  if( !queryResult.fillVariable( "CONF", xmlPayload ) ) xmlPayload = "";
146  // remember MP7 ALGO configuration
147  payloads[kALGO][algo_mp7_key] = xmlPayload;
148 
149  queryResult =
150  m_omdsReader.basicQuery( queryStrings,
151  stage2Schema,
152  "UGMT_ALGO",
153  "UGMT_ALGO.ID",
154  m_omdsReader.singleAttribute(algo_luts_key)
155  ) ;
156 
157  if( queryResult.queryFailed() || queryResult.numberRows() != 1 ){
158  edm::LogError( "L1-O2O: L1TMuonGlobalParamsOnlineProd" ) << "Cannot get UGMT_ALGO.CONF for ID = " << algo_luts_key;
159  throw std::runtime_error("Broken key");
161  }
162 
163  if( !queryResult.fillVariable( "CONF", xmlPayload ) ) xmlPayload = "";
164  // remember ALGO configuration
165  payloads[kALGO][algo_luts_key] = xmlPayload;
166 
167 
168  // query HW configuration
169  queryResult =
170  m_omdsReader.basicQuery( queryStrings,
171  stage2Schema,
172  "UGMT_HW",
173  "UGMT_HW.ID",
175  ) ;
176 
177  if( queryResult.queryFailed() || queryResult.numberRows() != 1 ){
178  edm::LogError( "L1-O2O: L1TMuonGlobalParamsOnlineProd" ) << "Cannot get UGMT_HW.CONF for ID = " << hw_key;
179  throw std::runtime_error("Broken key");
181  }
182 
183  if( !queryResult.fillVariable( "CONF", xmlPayload ) ) xmlPayload = "";
184  // remember HW configuration
185  payloads[kHW][hw_key] = xmlPayload;
186 
187  // query MP7 and AMC13 RS configuration
188  queryResult =
189  m_omdsReader.basicQuery( queryStrings,
190  stage2Schema,
191  "UGMT_RS",
192  "UGMT_RS.ID",
193  m_omdsReader.singleAttribute(rs_mp7_key)
194  ) ;
195 
196  if( queryResult.queryFailed() || queryResult.numberRows() != 1 ){
197  edm::LogError( "L1-O2O: L1TMuonGlobalParamsOnlineProd" ) << "Cannot get UGMT_RS.CONF for ID = " << rs_mp7_key;
198  throw std::runtime_error("Broken key");
199 //? return boost::shared_ptr< L1TMuonGlobalParams >( new L1TMuonGlobalParams( *(baseSettings.product()) ) ) ;
200  }
201 
202  if( !queryResult.fillVariable( "CONF", xmlPayload ) ) xmlPayload = "";
203  // remember MP7 RS configuration
204  payloads[kRS][rs_mp7_key] = xmlPayload;
205 
206  queryResult =
207  m_omdsReader.basicQuery( queryStrings,
208  stage2Schema,
209  "UGMT_RS",
210  "UGMT_RS.ID",
211  m_omdsReader.singleAttribute(rs_mp7moni_key)
212  ) ;
213 
214  if( queryResult.queryFailed() || queryResult.numberRows() != 1 ){
215  edm::LogError( "L1-O2O: L1TMuonGlobalParamsOnlineProd" ) << "Cannot get UGMT_RS.CONF for ID = " << rs_mp7moni_key;
216  throw std::runtime_error("Broken key");
218  }
219 
220  if( !queryResult.fillVariable( "CONF", xmlPayload ) ) xmlPayload = "";
221  // remember MP7 RS configuration
222  payloads[kRS][rs_mp7moni_key] = xmlPayload;
223 
224  // query AMC13 RS configuration
225  queryResult =
226  m_omdsReader.basicQuery( queryStrings,
227  stage2Schema,
228  "UGMT_RS",
229  "UGMT_RS.ID",
230  m_omdsReader.singleAttribute(rs_amc13moni_key)
231  ) ;
232 
233  if( queryResult.queryFailed() || queryResult.numberRows() != 1 ){
234  edm::LogError( "L1-O2O: L1TMuonBarrelParamsOnlineProd" ) << "Cannot get UGMT_RS.CONF for ID = " << rs_amc13moni_key;
235  throw std::runtime_error("Broken key");
237  }
238 
239  if( !queryResult.fillVariable( "CONF", xmlPayload ) ) xmlPayload = "";
240  // remember AMC13 RS configuration
241  payloads[kRS][rs_amc13moni_key] = xmlPayload;
242 
243 
244  // for debugging dump the configs to local files
245  for(auto &conf : payloads[kHW]){
246  std::ofstream output(std::string("/tmp/").append(conf.first.substr(0,conf.first.find("/"))).append(".xml"));
247  output<<conf.second;
248  output.close();
249  }
250  for(auto &conf : payloads[kALGO]){
251  std::ofstream output(std::string("/tmp/").append(conf.first.substr(0,conf.first.find("/"))).append(".xml"));
252  output<<conf.second;
253  output.close();
254  }
255  for(auto &conf : payloads[kRS]){
256  std::ofstream output(std::string("/tmp/").append(conf.first.substr(0,conf.first.find("/"))).append(".xml"));
257  output<<conf.second;
258  output.close();
259  }
260 
261  // finally, push all payloads to the XML parser and construct the TrigSystem objects with each of those
262  l1t::XmlConfigReader xmlRdr;
263  l1t::TrigSystem trgSys;
264  // HW settings should always go first
265  for(auto &conf : payloads[ kHW ]){
266  xmlRdr.readDOMFromString( conf.second );
267  xmlRdr.readRootElement ( trgSys );
268  }
269  // now let's parse ALGO and then RS settings
270  for(auto &conf : payloads[ kALGO ]){
271  xmlRdr.readDOMFromString( conf.second );
272  xmlRdr.readRootElement ( trgSys );
273  }
274  for(auto &conf : payloads[ kRS ]){
275  xmlRdr.readDOMFromString( conf.second );
276  xmlRdr.readRootElement ( trgSys );
277  }
278  trgSys.setConfigured();
279 
280  L1TMuonGlobalParamsHelper m_params_helper( *(baseSettings.product()) );
281  m_params_helper.loadFromOnline(trgSys);
282 
283  return boost::shared_ptr< L1TMuonGlobalParams >( new L1TMuonGlobalParams( cast_to_L1TMuonGlobalParams(m_params_helper) ) ) ;
284 }
285 
286 //define this as a plug-in
const L1TMuonGlobalParams & cast_to_L1TMuonGlobalParams(const L1TMuonGlobalParams_PUBLIC &x)
const QueryResults singleAttribute(const T &data) const
Definition: OMDSReader.h:296
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 ...
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 setConfigured(const bool state=true)
Definition: TrigSystem.h:39
void loadFromOnline(l1t::TrigSystem &trgSys, const std::string &processorId="")
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
L1TMuonGlobalParamsOnlineProd(const edm::ParameterSet &)
virtual boost::shared_ptr< L1TMuonGlobalParams > newObject(const std::string &objectKey, const L1TMuonGlobalParamsO2ORcd &record) override