CMS 3D CMS Logo

L1TMuonGlobalParamsOnlineProd.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <fstream>
3 #include <strstream>
4 
13 #include "OnlineDBqueryHelper.h"
14 
15 class L1TMuonGlobalParamsOnlineProd : public L1ConfigOnlineProdBaseExt<L1TMuonGlobalParamsO2ORcd,L1TMuonGlobalParams> {
16 private:
17 public:
18  virtual std::shared_ptr<L1TMuonGlobalParams> newObject(const std::string& objectKey, const L1TMuonGlobalParamsO2ORcd &record) override ;
19 
22 };
23 
25 
26 std::shared_ptr<L1TMuonGlobalParams> L1TMuonGlobalParamsOnlineProd::newObject(const std::string& objectKey, const L1TMuonGlobalParamsO2ORcd &record) {
27  using namespace edm::es;
28 
29  const L1TMuonGlobalParamsRcd& baseRcd = record.template getRecord< L1TMuonGlobalParamsRcd >() ;
31  baseRcd.get( baseSettings ) ;
32 
33  if( objectKey.empty() ){
34  edm::LogError( "L1-O2O: L1TMuonGlobalParamsOnlineProd" ) << "Key is empty";
35  throw std::runtime_error("Empty objectKey");
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  edm::LogInfo( "L1-O2O: L1TMuonGlobalParamsOnlineProd" ) << "Producing L1TMuonGlobalParams with TSC key =" << tscKey << " and RS key = " << rsKey ;
42 
43  std::string algo_key, hw_key;
44  std::string hw_payload;
45  std::map<std::string,std::string> rs_payloads, algo_payloads;
46  try {
47  std::map<std::string,std::string> keys =
48  l1t::OnlineDBqueryHelper::fetch( {"ALGO","HW"},
49  "UGMT_KEYS",
50  tscKey,
52  );
53  algo_key = keys["ALGO"];
54  hw_key = keys["HW"];
55 
56  hw_payload = l1t::OnlineDBqueryHelper::fetch( {"CONF"},
57  "UGMT_CLOBS",
58  hw_key,
60  ) ["CONF"];
61 
62  std::map<std::string,std::string> rsKeys =
63  l1t::OnlineDBqueryHelper::fetch( {"MP7","MP7_MONI","AMC13_MONI"},
64  "UGMT_RS_KEYS",
65  rsKey,
67  );
68 
69  std::map<std::string,std::string> algoKeys =
70  l1t::OnlineDBqueryHelper::fetch( {"MP7","LUTS"},
71  "UGMT_ALGO_KEYS",
72  algo_key,
74  );
75 
76  for(auto &key : rsKeys)
77  rs_payloads[ key.second ] =
79  "UGMT_CLOBS",
80  key.second,
82  ) ["CONF"];
83 
84  for(auto &key : algoKeys)
85  algo_payloads[ key.second ] =
87  "UGMT_CLOBS",
88  key.second,
90  ) ["CONF"];
91  } catch ( std::runtime_error &e ) {
92  edm::LogError( "L1-O2O: L1TMuonGlobalParamsOnlineProd" ) << e.what();
93  throw std::runtime_error("Broken key");
94  }
95 
96 
97  // for debugging dump the configs to local files
98  {
99  std::ofstream output(std::string("/tmp/").append(hw_key.substr(0,hw_key.find("/"))).append(".xml"));
100  output << hw_payload;
101  output.close();
102  }
103  for(auto &conf : rs_payloads){
104  std::ofstream output(std::string("/tmp/").append(conf.first.substr(0,conf.first.find("/"))).append(".xml"));
105  output<<conf.second;
106  output.close();
107  }
108  for(auto &conf : algo_payloads){
109  std::ofstream output(std::string("/tmp/").append(conf.first.substr(0,conf.first.find("/"))).append(".xml"));
110  output<<conf.second;
111  output.close();
112  }
113 
114  // finally, push all payloads to the XML parser and construct the TrigSystem objects with each of those
115  l1t::XmlConfigParser xmlRdr;
116  l1t::TriggerSystem trgSys;
117 
118  // HW settings should always go first
119  xmlRdr.readDOMFromString( hw_payload );
120  xmlRdr.readRootElement ( trgSys );
121 
122  // now let's parse ALGO and then RS settings
123  for(auto &conf : algo_payloads){
124  xmlRdr.readDOMFromString( conf.second );
125  xmlRdr.readRootElement ( trgSys );
126  }
127  for(auto &conf : rs_payloads){
128  xmlRdr.readDOMFromString( conf.second );
129  xmlRdr.readRootElement ( trgSys );
130  }
131  trgSys.setConfigured();
132 
133  L1TMuonGlobalParamsHelper m_params_helper( *(baseSettings.product()) );
134  m_params_helper.loadFromOnline(trgSys);
135 
136  std::shared_ptr< L1TMuonGlobalParams > retval = std::make_shared< L1TMuonGlobalParams >( cast_to_L1TMuonGlobalParams(m_params_helper) );
137 
138  return retval ;
139 }
140 
141 //define this as a plug-in
const L1TMuonGlobalParams & cast_to_L1TMuonGlobalParams(const L1TMuonGlobalParams_PUBLIC &x)
void setConfigured(bool state=true) noexcept
Definition: TriggerSystem.h:73
virtual std::shared_ptr< L1TMuonGlobalParams > newObject(const std::string &objectKey, const L1TMuonGlobalParamsO2ORcd &record) override
JetCorrectorParameters::Record record
Definition: classes.h:7
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 loadFromOnline(l1t::TriggerSystem &trgSys, const std::string &processorId="")
void get(HolderT &iHolder) const
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
void readRootElement(TriggerSystem &aTriggerSystem, const std::string &sysId="")
L1TMuonGlobalParamsOnlineProd(const edm::ParameterSet &)