test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1TMuonBarrelParamsOnlineProd.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <fstream>
3 
10 
11 #include "xercesc/util/PlatformUtils.hpp"
12 using namespace XERCES_CPP_NAMESPACE;
13 
14 class L1TMuonBarrelParamsOnlineProd : public L1ConfigOnlineProdBaseExt<L1TMuonBarrelParamsO2ORcd,L1TMuonBarrelParams> {
15 private:
16 public:
17  virtual boost::shared_ptr<L1TMuonBarrelParams> newObject(const std::string& objectKey, const L1TMuonBarrelParamsO2ORcd& record) override ;
18 
21 };
22 
24 
25 boost::shared_ptr<L1TMuonBarrelParams> L1TMuonBarrelParamsOnlineProd::newObject(const std::string& objectKey, const L1TMuonBarrelParamsO2ORcd& record) {
26  using namespace edm::es;
27 
28  const L1TMuonBarrelParamsRcd& baseRcd = record.template getRecord< L1TMuonBarrelParamsRcd >() ;
30  baseRcd.get( baseSettings ) ;
31 
32 
33  if (objectKey.empty()) {
34  edm::LogInfo( "L1-O2O: L1TMuonBarrelParamsOnlineProd" ) << "Key is empty, returning empty L1TMuonBarrelParams";
35  return boost::shared_ptr< L1TMuonBarrelParams > ( new L1TMuonBarrelParams( *(baseSettings.product()) ) );
36  }
37 
38  std::string tscKey = objectKey.substr(0, objectKey.find(":") );
39  std::string rsKey = objectKey.substr( objectKey.find(":")+1, std::string::npos );
40 
41 
42  std::string stage2Schema = "CMS_TRG_L1_CONF" ;
43  edm::LogInfo( "L1-O2O: L1TMuonBarrelParamsOnlineProd" ) << "Producing L1TMuonBarrelParams with TSC key =" << tscKey << " and RS key = " << rsKey ;
44 
45  // first, find keys for the algo and RS tables
46 
47  // ALGO and HW
48  std::vector< std::string > queryStrings ;
49  queryStrings.push_back( "ALGO" ) ;
50  queryStrings.push_back( "HW" ) ;
51 
52  std::string algo_key, hw_key;
53 
54  // select ALGO,HW from CMS_TRG_L1_CONF.BMTF_KEYS where ID = tscKey ;
55  l1t::OMDSReader::QueryResults queryResult =
56  m_omdsReader.basicQuery( queryStrings,
57  stage2Schema,
58  "BMTF_KEYS",
59  "BMTF_KEYS.ID",
61  ) ;
62 
63  if( queryResult.queryFailed() || queryResult.numberRows() != 1 ){
64  edm::LogError( "L1-O2O" ) << "Cannot get BMTF_KEYS.{ALGO,HW}" ;
65  return boost::shared_ptr< L1TMuonBarrelParams > ( new L1TMuonBarrelParams( *(baseSettings.product()) ) );
66  }
67 
68  if( !queryResult.fillVariable( "ALGO", algo_key) ) algo_key = "";
69  if( !queryResult.fillVariable( "HW", hw_key ) ) hw_key = "";
70 
71 
72  // RS
73  queryStrings.clear() ;
74  queryStrings.push_back( "MP7" ) ;
75  queryStrings.push_back( "DAQTTC" ) ;
76 
77  std::string rs_mp7_key, rs_amc13_key;
78 
79  // select RS from CMS_TRG_L1_CONF.BMTF_RS_KEYS where ID = rsKey ;
80  queryResult =
81  m_omdsReader.basicQuery( queryStrings,
82  stage2Schema,
83  "BMTF_RS_KEYS",
84  "BMTF_RS_KEYS.ID",
86  ) ;
87 
88  if( queryResult.queryFailed() || queryResult.numberRows() != 1 ){
89  edm::LogError( "L1-O2O" ) << "Cannot get BMTF_RS_KEYS.{MP7,DAQTTC}" ;
90  return boost::shared_ptr< L1TMuonBarrelParams > ( new L1TMuonBarrelParams( *(baseSettings.product()) ) );
91  }
92 
93  if( !queryResult.fillVariable( "MP7", rs_mp7_key ) ) rs_mp7_key = "";
94  if( !queryResult.fillVariable( "DAQTTC", rs_amc13_key) ) rs_amc13_key = "";
95 
96 
97  // At this point we have four keys: one ALGO key, one HW key, and two RS keys; now query the payloads for these keys
98  // Now querry the actual payloads
99  enum {kALGO=0, kRS, kHW, NUM_TYPES};
100  std::map<std::string,std::string> payloads[NUM_TYPES]; // associates key -> XML payload for a given type of payloads
101  std::string xmlPayload;
102 
103  queryStrings.clear();
104  queryStrings.push_back( "CONF" );
105 
106  // query ALGO configuration
107  queryResult =
108  m_omdsReader.basicQuery( queryStrings,
109  stage2Schema,
110  "BMTF_ALGO",
111  "BMTF_ALGO.ID",
112  m_omdsReader.singleAttribute(algo_key)
113  ) ;
114 
115  if( queryResult.queryFailed() || queryResult.numberRows() != 1 ){
116  edm::LogError( "L1-O2O: L1TMuonBarrelParamsOnlineProd" ) << "Cannot get BMTF_ALGO.CONF for ID="<<algo_key;
117  return boost::shared_ptr< L1TMuonBarrelParams >( new L1TMuonBarrelParams( *(baseSettings.product()) ) ) ;
118  }
119 
120  if( !queryResult.fillVariable( "CONF", xmlPayload ) ) xmlPayload = "";
121  // remember ALGO configuration
122  payloads[kALGO][algo_key] = xmlPayload;
123 
124  // query HW configuration
125  queryResult =
126  m_omdsReader.basicQuery( queryStrings,
127  stage2Schema,
128  "BMTF_HW",
129  "BMTF_HW.ID",
131  ) ;
132 
133  if( queryResult.queryFailed() || queryResult.numberRows() != 1 ){
134  edm::LogError( "L1-O2O: L1TMuonBarrelParamsOnlineProd" ) << "Cannot get BMTF_HW.CONF for ID="<<hw_key;
135  return boost::shared_ptr< L1TMuonBarrelParams >( new L1TMuonBarrelParams( *(baseSettings.product()) ) ) ;
136  }
137 
138  if( !queryResult.fillVariable( "CONF", xmlPayload ) ) xmlPayload = "";
139  // remember HW configuration
140  payloads[kHW][hw_key] = xmlPayload;
141 
142  // query MP7 RS configuration
143  queryResult =
144  m_omdsReader.basicQuery( queryStrings,
145  stage2Schema,
146  "BMTF_RS",
147  "BMTF_RS.ID",
148  m_omdsReader.singleAttribute(rs_mp7_key)
149  ) ;
150 
151  if( queryResult.queryFailed() || queryResult.numberRows() != 1 ){
152  edm::LogError( "L1-O2O: L1TMuonBarrelParamsOnlineProd" ) << "Cannot get BMTF_RS.CONF for ID="<<rs_mp7_key;
153  return boost::shared_ptr< L1TMuonBarrelParams >( new L1TMuonBarrelParams( *(baseSettings.product()) ) ) ;
154  }
155 
156  if( !queryResult.fillVariable( "CONF", xmlPayload ) ) xmlPayload = "";
157  // remember MP7 RS configuration
158  payloads[kRS][rs_mp7_key] = xmlPayload;
159 
160  // query AMC13 RS configuration
161  queryResult =
162  m_omdsReader.basicQuery( queryStrings,
163  stage2Schema,
164  "BMTF_RS",
165  "BMTF_RS.ID",
166  m_omdsReader.singleAttribute(rs_amc13_key)
167  ) ;
168 
169  if( queryResult.queryFailed() || queryResult.numberRows() != 1 ){
170  edm::LogError( "L1-O2O: L1TMuonBarrelParamsOnlineProd" ) << "Cannot get BMTF_RS.CONF for ID="<<rs_amc13_key;
171  return boost::shared_ptr< L1TMuonBarrelParams >( new L1TMuonBarrelParams( *(baseSettings.product()) ) ) ;
172  }
173 
174  if( !queryResult.fillVariable( "CONF", xmlPayload ) ) xmlPayload = "";
175  // remember AMC13 RS configuration
176  payloads[kRS][rs_amc13_key] = xmlPayload;
177 
178 // for debugging dump the configs to local files
179 for(auto &conf : payloads[kHW]){
180  std::ofstream output(std::string("/tmp/").append(conf.first.substr(0,conf.first.find("/"))).append(".xml"));
181  output<<conf.second;
182  output.close();
183 }
184 for(auto &conf : payloads[kALGO]){
185  std::ofstream output(std::string("/tmp/").append(conf.first.substr(0,conf.first.find("/"))).append(".xml"));
186  output<<conf.second;
187  output.close();
188 }
189 for(auto &conf : payloads[kRS]){
190  std::ofstream output(std::string("/tmp/").append(conf.first.substr(0,conf.first.find("/"))).append(".xml"));
191  output<<conf.second;
192  output.close();
193 }
194 
195  // finally, push all payloads to the XML parser and construct the TrigSystem objects with each of those
196  l1t::XmlConfigReader xmlRdr;
197  l1t::TrigSystem parsedXMLs;
198 // parsedXMLs.addProcRole("processors", "procMP7");
199  // HW settings should always go first
200  for(auto &conf : payloads[ kHW ]){
201  xmlRdr.readDOMFromString( conf.second );
202  xmlRdr.readRootElement ( parsedXMLs );
203  }
204  // now let's parse ALGO and then RS settings
205  for(auto &conf : payloads[ kALGO ]){
206  xmlRdr.readDOMFromString( conf.second );
207  xmlRdr.readRootElement ( parsedXMLs );
208  }
209  for(auto &conf : payloads[ kRS ]){
210  xmlRdr.readDOMFromString( conf.second );
211  xmlRdr.readRootElement ( parsedXMLs );
212  }
213  parsedXMLs.setConfigured();
214 
215  // for debugging also dump the configs to local files
216  for(size_t type=0; type<NUM_TYPES; type++)
217  for(auto &conf : payloads[ type ]){
218  std::ofstream output(std::string("/tmp/").append(conf.first.substr(0,conf.first.find("/"))).append(".xml"));
219  output<<conf.second;
220  output.close();
221  }
222 
223  L1TMuonBarrelParamsHelper m_params_helper(*(baseSettings.product()) );
224  m_params_helper.configFromDB(parsedXMLs);
225  boost::shared_ptr< L1TMuonBarrelParams > retval( new L1TMuonBarrelParams(m_params_helper) ) ;
226 
227  return retval;
228 
229 }
230 
231 //define this as a plug-in
type
Definition: HCALResponse.h:21
void configFromDB(l1t::TrigSystem &trgSys)
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 ...
virtual boost::shared_ptr< L1TMuonBarrelParams > newObject(const std::string &objectKey, const L1TMuonBarrelParamsO2ORcd &record) override
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
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
L1TMuonBarrelParamsOnlineProd(const edm::ParameterSet &)