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