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:
18 public:
19  std::shared_ptr<L1TMuonGlobalParams> newObject(const std::string& objectKey, const L1TMuonGlobalParamsO2ORcd &record) override ;
20 
23 };
24 
26  transactionSafe = iConfig.getParameter<bool>("transactionSafe");
27 }
28 
29 std::shared_ptr<L1TMuonGlobalParams> L1TMuonGlobalParamsOnlineProd::newObject(const std::string& objectKey, const L1TMuonGlobalParamsO2ORcd &record) {
30  using namespace edm::es;
31 
32  const L1TMuonGlobalParamsRcd& baseRcd = record.template getRecord< L1TMuonGlobalParamsRcd >() ;
34  baseRcd.get( baseSettings ) ;
35 
36  if( objectKey.empty() ){
37  edm::LogError( "L1-O2O: L1TMuonGlobalParamsOnlineProd" ) << "Key is empty";
38  if( transactionSafe )
39  throw std::runtime_error("SummaryForFunctionManager: uGMT | Faulty | Empty objectKey");
40  else {
41  edm::LogError( "L1-O2O: L1TMuonGlobalParams" ) << "returning unmodified prototype of L1TMuonGlobalParams";
42  return std::make_shared< L1TMuonGlobalParams>( *(baseSettings.product()) ) ;
43  }
44  }
45 
46  std::string tscKey = objectKey.substr(0, objectKey.find(":") );
47  std::string rsKey = objectKey.substr( objectKey.find(":")+1, std::string::npos );
48 
49  edm::LogInfo( "L1-O2O: L1TMuonGlobalParamsOnlineProd" ) << "Producing L1TMuonGlobalParams with TSC key =" << tscKey << " and RS key = " << rsKey ;
50 
51  std::string algo_key, hw_key;
52  std::string hw_payload;
53  std::map<std::string,std::string> rs_payloads, algo_payloads;
54  try {
55  std::map<std::string,std::string> keys =
56  l1t::OnlineDBqueryHelper::fetch( {"ALGO","HW"},
57  "UGMT_KEYS",
58  tscKey,
60  );
61  algo_key = keys["ALGO"];
62  hw_key = keys["HW"];
63 
64  hw_payload = l1t::OnlineDBqueryHelper::fetch( {"CONF"},
65  "UGMT_CLOBS",
66  hw_key,
68  ) ["CONF"];
69 
70  std::map<std::string,std::string> rsKeys =
71  l1t::OnlineDBqueryHelper::fetch( {"MP7","MP7_MONI","AMC13_MONI"},
72  "UGMT_RS_KEYS",
73  rsKey,
75  );
76 
77  std::map<std::string,std::string> algoKeys =
78  l1t::OnlineDBqueryHelper::fetch( {"MP7","LUTS"},
79  "UGMT_ALGO_KEYS",
80  algo_key,
82  );
83 
84  for(auto &key : rsKeys)
85  rs_payloads[ key.second ] =
87  "UGMT_CLOBS",
88  key.second,
90  ) ["CONF"];
91 
92  for(auto &key : algoKeys)
93  algo_payloads[ key.second ] =
95  "UGMT_CLOBS",
96  key.second,
98  ) ["CONF"];
99  } catch ( std::runtime_error &e ) {
100  edm::LogError( "L1-O2O: L1TMuonGlobalParamsOnlineProd" ) << e.what();
101  if( transactionSafe )
102  throw std::runtime_error("SummaryForFunctionManager: uGMT | Faulty | Broken key");
103  else {
104  edm::LogError( "L1-O2O: L1TMuonGlobalParamsOnlineProd" ) << "returning unmodified prototype of L1TMuonGlobalParams";
105  return std::make_shared< L1TMuonGlobalParams >( *(baseSettings.product()) ) ;
106  }
107  }
108 
109  // for debugging dump the configs to local files
110  {
111  std::ofstream output(std::string("/tmp/").append(hw_key.substr(0,hw_key.find("/"))).append(".xml"));
112  output << hw_payload;
113  output.close();
114  }
115  for(auto &conf : rs_payloads){
116  std::ofstream output(std::string("/tmp/").append(conf.first.substr(0,conf.first.find("/"))).append(".xml"));
117  output<<conf.second;
118  output.close();
119  }
120  for(auto &conf : algo_payloads){
121  std::ofstream output(std::string("/tmp/").append(conf.first.substr(0,conf.first.find("/"))).append(".xml"));
122  output<<conf.second;
123  output.close();
124  }
125 
126  // finally, push all payloads to the XML parser and construct the TrigSystem objects with each of those
127  l1t::XmlConfigParser xmlRdr;
128  l1t::TriggerSystem trgSys;
129 
130  try {
131  // HW settings should always go first
132  xmlRdr.readDOMFromString( hw_payload );
133  xmlRdr.readRootElement ( trgSys );
134 
135  // now let's parse ALGO and then RS settings
136  for(auto &conf : algo_payloads){
137  xmlRdr.readDOMFromString( conf.second );
138  xmlRdr.readRootElement ( trgSys );
139  }
140  for(auto &conf : rs_payloads){
141  xmlRdr.readDOMFromString( conf.second );
142  xmlRdr.readRootElement ( trgSys );
143  }
144  trgSys.setConfigured();
145  } catch ( std::runtime_error &e ) {
146  edm::LogError( "L1-O2O: L1TMuonGlobalParamsOnlineProd" ) << e.what();
147  if( transactionSafe )
148  throw std::runtime_error("SummaryForFunctionManager: uGMT | Faulty | Cannot parse XMLs");
149  else {
150  edm::LogError( "L1-O2O: L1TMuonGlobalParamsOnlineProd" ) << "returning unmodified prototype of L1TMuonGlobalParams";
151  return std::make_shared< L1TMuonGlobalParams >( *(baseSettings.product()) ) ;
152  }
153  }
154 
155  L1TMuonGlobalParamsHelper m_params_helper( *(baseSettings.product()) );
156  try {
157  m_params_helper.loadFromOnline(trgSys);
158  } catch ( std::runtime_error &e ) {
159  edm::LogError( "L1-O2O: L1TMuonGlobalParamsOnlineProd" ) << e.what();
160  if( transactionSafe )
161  throw std::runtime_error("SummaryForFunctionManager: uGMT | Faulty | Cannot run helper");
162  else {
163  edm::LogError( "L1-O2O: L1TMuonGlobalParamsOnlineProd" ) << "returning unmodified prototype of L1TMuonGlobalParams";
164  return std::make_shared< L1TMuonGlobalParams >( *(baseSettings.product()) ) ;
165  }
166  }
167 
168  std::shared_ptr< L1TMuonGlobalParams > retval = std::make_shared< L1TMuonGlobalParams >( cast_to_L1TMuonGlobalParams(m_params_helper) );
169 
170  edm::LogInfo( "L1-O2O: L1TMuonGlobalParamsOnlineProd" ) << "SummaryForFunctionManager: uGMT | OK | All looks good";
171  return retval ;
172 }
173 
174 //define this as a plug-in
const L1TMuonGlobalParams & cast_to_L1TMuonGlobalParams(const L1TMuonGlobalParams_PUBLIC &x)
T getParameter(std::string const &) const
void setConfigured(bool state=true) noexcept
Definition: TriggerSystem.h:73
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="")
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
void readRootElement(TriggerSystem &aTriggerSystem, const std::string &sysId="")
L1TMuonGlobalParamsOnlineProd(const edm::ParameterSet &)
bool get(HolderT &iHolder) const