CMS 3D CMS Logo

L1TMuonBarrelParamsOnlineProd.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <fstream>
3 
11 #include "OnlineDBqueryHelper.h"
12 
13 #include "xercesc/util/PlatformUtils.hpp"
14 using namespace XERCES_CPP_NAMESPACE;
15 
16 class L1TMuonBarrelParamsOnlineProd : public L1ConfigOnlineProdBaseExt<L1TMuonBarrelParamsO2ORcd,L1TMuonBarrelParams> {
17 private:
19 public:
20  std::shared_ptr<L1TMuonBarrelParams> newObject(const std::string& objectKey, const L1TMuonBarrelParamsO2ORcd& record) override ;
21 
24 };
25 
27  transactionSafe = iConfig.getParameter<bool>("transactionSafe");
28 }
29 
30 std::shared_ptr<L1TMuonBarrelParams> L1TMuonBarrelParamsOnlineProd::newObject(const std::string& objectKey, const L1TMuonBarrelParamsO2ORcd& record) {
31  using namespace edm::es;
32 
33  const L1TMuonBarrelParamsRcd& baseRcd = record.template getRecord< L1TMuonBarrelParamsRcd >() ;
35  baseRcd.get( baseSettings ) ;
36 
37  if (objectKey.empty()) {
38  edm::LogError( "L1-O2O: L1TMuonBarrelParamsOnlineProd" ) << "Key is empty, returning empty L1TMuonBarrelParams";
39  if( transactionSafe )
40  throw std::runtime_error("SummaryForFunctionManager: BMTF | Faulty | Empty objectKey");
41  else {
42  edm::LogError( "L1-O2O: L1TMuonBarrelParamsOnlineProd" ) << "returning unmodified prototype of L1TMuonBarrelParams";
43  return std::make_shared< L1TMuonBarrelParams >( *(baseSettings.product()) ) ;
44  }
45  }
46 
47  std::string tscKey = objectKey.substr(0, objectKey.find(":") );
48  std::string rsKey = objectKey.substr( objectKey.find(":")+1, std::string::npos );
49 
50 
51  edm::LogInfo( "L1-O2O: L1TMuonBarrelParamsOnlineProd" ) << "Producing L1TMuonBarrelParams with TSC key = " << tscKey << " and RS key = " << rsKey ;
52 
53  std::string algo_key, hw_key;
54  std::string mp7_key, amc13_key;
55  std::string hw_payload, algo_payload, mp7_payload, amc13_payload;
56  try {
57  std::map<std::string,std::string> keys =
58  l1t::OnlineDBqueryHelper::fetch( {"ALGO","HW"},
59  "BMTF_KEYS",
60  tscKey,
62  );
63  algo_key = keys["ALGO"];
64  hw_key = keys["HW"];
65 
66  hw_payload =
68  "BMTF_CLOBS",
69  hw_key,
71  ) ["CONF"];
72 
73  algo_payload =
75  "BMTF_CLOBS",
76  algo_key,
78  ) ["CONF"];
79 
80  std::map<std::string,std::string> rsKeys =
81  l1t::OnlineDBqueryHelper::fetch( {"MP7","AMC13"},
82  "BMTF_RS_KEYS",
83  rsKey,
85  );
86  mp7_key = rsKeys["MP7"];
87  amc13_key = rsKeys["AMC13"];
88 
89  mp7_payload =
91  "BMTF_CLOBS",
92  mp7_key,
94  ) ["CONF"];
95  amc13_payload =
97  "BMTF_CLOBS",
98  amc13_key,
100  ) ["CONF"];
101 
102  } catch ( std::runtime_error &e ) {
103  edm::LogError( "L1-O2O: L1TMuonBarrelParamsOnlineProd" ) << e.what();
104  if( transactionSafe )
105  throw std::runtime_error(std::string("SummaryForFunctionManager: BMTF | Faulty | ") + e.what());
106  else {
107  edm::LogError( "L1-O2O: L1TMuonBarrelParamsOnlineProd" ) << "returning unmodified prototype of L1TMuonBarrelParams";
108  return std::make_shared< L1TMuonBarrelParams >( *(baseSettings.product()) ) ;
109  }
110  }
111 
112 
113  // for debugging dump the configs to local files
114  {
115  std::ofstream output(std::string("/tmp/").append(hw_key.substr(0,hw_key.find("/"))).append(".xml"));
116  output << hw_payload;
117  output.close();
118  }
119  {
120  std::ofstream output(std::string("/tmp/").append(algo_key.substr(0,algo_key.find("/"))).append(".xml"));
121  output << algo_payload;
122  output.close();
123  }
124  {
125  std::ofstream output(std::string("/tmp/").append(mp7_key.substr(0,mp7_key.find("/"))).append(".xml"));
126  output << mp7_payload;
127  output.close();
128  }
129  {
130  std::ofstream output(std::string("/tmp/").append(amc13_key.substr(0,amc13_key.find("/"))).append(".xml"));
131  output << amc13_payload;
132  output.close();
133  }
134 
135  // finally, push all payloads to the XML parser and construct the TrigSystem objects with each of those
136  l1t::XmlConfigParser xmlRdr;
137  l1t::TriggerSystem parsedXMLs;
138  try {
139  // HW settings should always go first
140  xmlRdr.readDOMFromString( hw_payload );
141  xmlRdr.readRootElement ( parsedXMLs );
142 
143  // now let's parse ALGO settings
144  xmlRdr.readDOMFromString( algo_payload );
145  xmlRdr.readRootElement ( parsedXMLs );
146 
147  // remaining RS settings
148  xmlRdr.readDOMFromString( mp7_payload );
149  xmlRdr.readRootElement ( parsedXMLs );
150 
151  xmlRdr.readDOMFromString( amc13_payload );
152  xmlRdr.readRootElement ( parsedXMLs );
153  parsedXMLs.setConfigured();
154 
155  } catch ( std::runtime_error &e ) {
156  edm::LogError( "L1-O2O: L1TMuonBarrelParamsOnlineProd" ) << e.what();
157  if( transactionSafe )
158  throw std::runtime_error(std::string("SummaryForFunctionManager: BMTF | Faulty | ") + e.what());
159  else {
160  edm::LogError( "L1-O2O: L1TMuonBarrelParamsOnlineProd" ) << "returning unmodified prototype of L1TMuonBarrelParams";
161  return std::make_shared< L1TMuonBarrelParams >( *(baseSettings.product()) ) ;
162  }
163  }
164 
165  L1TMuonBarrelParamsHelper m_params_helper( *(baseSettings.product()) );
166  try {
167  m_params_helper.configFromDB( parsedXMLs );
168  } catch ( std::runtime_error &e ) {
169  edm::LogError( "L1-O2O: L1TMuonBarrelParamsOnlineProd" ) << e.what();
170  if( transactionSafe )
171  throw std::runtime_error(std::string("SummaryForFunctionManager: BMTF | Faulty | ") + e.what());
172  else {
173  edm::LogError( "L1-O2O: L1TMuonBarrelParamsOnlineProd" ) << "returning unmodified prototype of L1TMuonBarrelParams";
174  return std::make_shared< L1TMuonBarrelParams >( *(baseSettings.product()) ) ;
175  }
176  }
177 
178  std::shared_ptr< L1TMuonBarrelParams > retval = std::make_shared< L1TMuonBarrelParams>( m_params_helper );
179 
180  edm::LogInfo( "L1-O2O: L1TCaloParamsOnlineProd" ) << "SummaryForFunctionManager: BMTF | OK | All looks good";
181  return retval;
182 }
183 
184 //define this as a plug-in
T getParameter(std::string const &) const
void setConfigured(bool state=true) noexcept
Definition: TriggerSystem.h:73
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)
std::shared_ptr< L1TMuonBarrelParams > newObject(const std::string &objectKey, const L1TMuonBarrelParamsO2ORcd &record) override
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
void readRootElement(TriggerSystem &aTriggerSystem, const std::string &sysId="")
void configFromDB(l1t::TriggerSystem &trgSys)
bool get(HolderT &iHolder) const
L1TMuonBarrelParamsOnlineProd(const edm::ParameterSet &)