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::unique_ptr<const L1TMuonBarrelParams> newObject(const std::string& objectKey, const L1TMuonBarrelParamsO2ORcd& record) override ;
21 
24 };
25 
27  transactionSafe = iConfig.getParameter<bool>("transactionSafe");
28 }
29 
30 std::unique_ptr<const L1TMuonBarrelParams> L1TMuonBarrelParamsOnlineProd::newObject(const std::string& objectKey, const L1TMuonBarrelParamsO2ORcd& record) {
31 
32  const L1TMuonBarrelParamsRcd& baseRcd = record.template getRecord< L1TMuonBarrelParamsRcd >() ;
34  baseRcd.get( baseSettings ) ;
35 
36  if (objectKey.empty()) {
37  edm::LogError( "L1-O2O: L1TMuonBarrelParamsOnlineProd" ) << "Key is empty, returning empty L1TMuonBarrelParams";
38  if( transactionSafe )
39  throw std::runtime_error("SummaryForFunctionManager: BMTF | Faulty | Empty objectKey");
40  else {
41  edm::LogError( "L1-O2O: L1TMuonBarrelParamsOnlineProd" ) << "returning unmodified prototype of L1TMuonBarrelParams";
42  return std::make_unique< const L1TMuonBarrelParams >( *(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 
50  edm::LogInfo( "L1-O2O: L1TMuonBarrelParamsOnlineProd" ) << "Producing L1TMuonBarrelParams with TSC key = " << tscKey << " and RS key = " << rsKey ;
51 
52  std::string algo_key, hw_key;
53  std::string mp7_key, amc13_key;
54  std::string hw_payload, algo_payload, mp7_payload, amc13_payload;
55  try {
56  std::map<std::string,std::string> keys =
57  l1t::OnlineDBqueryHelper::fetch( {"ALGO","HW"},
58  "BMTF_KEYS",
59  tscKey,
61  );
62  algo_key = keys["ALGO"];
63  hw_key = keys["HW"];
64 
65  hw_payload =
67  "BMTF_CLOBS",
68  hw_key,
70  ) ["CONF"];
71 
72  algo_payload =
74  "BMTF_CLOBS",
75  algo_key,
77  ) ["CONF"];
78 
79  std::map<std::string,std::string> rsKeys =
80  l1t::OnlineDBqueryHelper::fetch( {"MP7","AMC13"},
81  "BMTF_RS_KEYS",
82  rsKey,
84  );
85  mp7_key = rsKeys["MP7"];
86  amc13_key = rsKeys["AMC13"];
87 
88  mp7_payload =
90  "BMTF_CLOBS",
91  mp7_key,
93  ) ["CONF"];
94  amc13_payload =
96  "BMTF_CLOBS",
97  amc13_key,
99  ) ["CONF"];
100 
101  } catch ( std::runtime_error &e ) {
102  edm::LogError( "L1-O2O: L1TMuonBarrelParamsOnlineProd" ) << e.what();
103  if( transactionSafe )
104  throw std::runtime_error(std::string("SummaryForFunctionManager: BMTF | Faulty | ") + e.what());
105  else {
106  edm::LogError( "L1-O2O: L1TMuonBarrelParamsOnlineProd" ) << "returning unmodified prototype of L1TMuonBarrelParams";
107  return std::make_unique< const L1TMuonBarrelParams >( *(baseSettings.product()) ) ;
108  }
109  }
110 
111 
112  // for debugging dump the configs to local files
113  {
114  std::ofstream output(std::string("/tmp/").append(hw_key.substr(0,hw_key.find("/"))).append(".xml"));
115  output << hw_payload;
116  output.close();
117  }
118  {
119  std::ofstream output(std::string("/tmp/").append(algo_key.substr(0,algo_key.find("/"))).append(".xml"));
120  output << algo_payload;
121  output.close();
122  }
123  {
124  std::ofstream output(std::string("/tmp/").append(mp7_key.substr(0,mp7_key.find("/"))).append(".xml"));
125  output << mp7_payload;
126  output.close();
127  }
128  {
129  std::ofstream output(std::string("/tmp/").append(amc13_key.substr(0,amc13_key.find("/"))).append(".xml"));
130  output << amc13_payload;
131  output.close();
132  }
133 
134  // finally, push all payloads to the XML parser and construct the TrigSystem objects with each of those
135  l1t::XmlConfigParser xmlRdr;
136  l1t::TriggerSystem parsedXMLs;
137  try {
138  // HW settings should always go first
139  xmlRdr.readDOMFromString( hw_payload );
140  xmlRdr.readRootElement ( parsedXMLs );
141 
142  // now let's parse ALGO settings
143  xmlRdr.readDOMFromString( algo_payload );
144  xmlRdr.readRootElement ( parsedXMLs );
145 
146  // remaining RS settings
147  xmlRdr.readDOMFromString( mp7_payload );
148  xmlRdr.readRootElement ( parsedXMLs );
149 
150  xmlRdr.readDOMFromString( amc13_payload );
151  xmlRdr.readRootElement ( parsedXMLs );
152  parsedXMLs.setConfigured();
153 
154  } catch ( std::runtime_error &e ) {
155  edm::LogError( "L1-O2O: L1TMuonBarrelParamsOnlineProd" ) << e.what();
156  if( transactionSafe )
157  throw std::runtime_error(std::string("SummaryForFunctionManager: BMTF | Faulty | ") + e.what());
158  else {
159  edm::LogError( "L1-O2O: L1TMuonBarrelParamsOnlineProd" ) << "returning unmodified prototype of L1TMuonBarrelParams";
160  return std::make_unique< const L1TMuonBarrelParams >( *(baseSettings.product()) ) ;
161  }
162  }
163 
164  L1TMuonBarrelParamsHelper m_params_helper( *(baseSettings.product()) );
165  try {
166  m_params_helper.configFromDB( parsedXMLs );
167  } catch ( std::runtime_error &e ) {
168  edm::LogError( "L1-O2O: L1TMuonBarrelParamsOnlineProd" ) << e.what();
169  if( transactionSafe )
170  throw std::runtime_error(std::string("SummaryForFunctionManager: BMTF | Faulty | ") + e.what());
171  else {
172  edm::LogError( "L1-O2O: L1TMuonBarrelParamsOnlineProd" ) << "returning unmodified prototype of L1TMuonBarrelParams";
173  return std::make_unique< const L1TMuonBarrelParams >( *(baseSettings.product()) ) ;
174  }
175  }
176 
177  auto retval = std::make_unique< const L1TMuonBarrelParams>( m_params_helper );
178 
179  edm::LogInfo( "L1-O2O: L1TCaloParamsOnlineProd" ) << "SummaryForFunctionManager: BMTF | OK | All looks good";
180  return retval;
181 }
182 
183 //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
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)
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
void readRootElement(TriggerSystem &aTriggerSystem, const std::string &sysId="")
std::unique_ptr< const L1TMuonBarrelParams > newObject(const std::string &objectKey, const L1TMuonBarrelParamsO2ORcd &record) override
void configFromDB(l1t::TriggerSystem &trgSys)
L1TMuonBarrelParamsOnlineProd(const edm::ParameterSet &)