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:
18 public:
19  virtual std::shared_ptr<L1TMuonBarrelParams> newObject(const std::string& objectKey, const L1TMuonBarrelParamsO2ORcd& record) override ;
20 
23 };
24 
26 
27 std::shared_ptr<L1TMuonBarrelParams> L1TMuonBarrelParamsOnlineProd::newObject(const std::string& objectKey, const L1TMuonBarrelParamsO2ORcd& record) {
28  using namespace edm::es;
29 
30  const L1TMuonBarrelParamsRcd& baseRcd = record.template getRecord< L1TMuonBarrelParamsRcd >() ;
32  baseRcd.get( baseSettings ) ;
33 
34 
35  if (objectKey.empty()) {
36  edm::LogError( "L1-O2O: L1TMuonBarrelParamsOnlineProd" ) << "Key is empty, returning empty L1TMuonBarrelParams";
37  throw std::runtime_error("Empty objectKey");
38  }
39 
40  std::string tscKey = objectKey.substr(0, objectKey.find(":") );
41  std::string rsKey = objectKey.substr( objectKey.find(":")+1, std::string::npos );
42 
43 
44  edm::LogInfo( "L1-O2O: L1TMuonBarrelParamsOnlineProd" ) << "Producing L1TMuonBarrelParams with TSC key = " << tscKey << " and RS key = " << rsKey ;
45 
46  std::string algo_key, hw_key;
47  std::string mp7_key, amc13_key;
48  std::string hw_payload, algo_payload, mp7_payload, amc13_payload;
49  try {
50  std::map<std::string,std::string> keys =
51  l1t::OnlineDBqueryHelper::fetch( {"ALGO","HW"},
52  "BMTF_KEYS",
53  tscKey,
55  );
56  algo_key = keys["ALGO"];
57  hw_key = keys["HW"];
58 
59  hw_payload =
61  "BMTF_CLOBS",
62  hw_key,
64  ) ["CONF"];
65 
66  algo_payload =
68  "BMTF_CLOBS",
69  algo_key,
71  ) ["CONF"];
72 
73  std::map<std::string,std::string> rsKeys =
74  l1t::OnlineDBqueryHelper::fetch( {"MP7","AMC13"},
75  "BMTF_RS_KEYS",
76  rsKey,
78  );
79  mp7_key = rsKeys["MP7"];
80  amc13_key = rsKeys["AMC13"];
81 
82  mp7_payload =
84  "BMTF_CLOBS",
85  mp7_key,
87  ) ["CONF"];
88  amc13_payload =
90  "BMTF_CLOBS",
91  amc13_key,
93  ) ["CONF"];
94 
95  } catch ( std::runtime_error &e ) {
96  edm::LogError( "L1-O2O: L1TMuonBarrelParamsOnlineProd" ) << e.what();
97  throw std::runtime_error("Broken key");
98  }
99 
100 
101  // for debugging dump the configs to local files
102  {
103  std::ofstream output(std::string("/tmp/").append(hw_key.substr(0,hw_key.find("/"))).append(".xml"));
104  output << hw_payload;
105  output.close();
106  }
107  {
108  std::ofstream output(std::string("/tmp/").append(algo_key.substr(0,algo_key.find("/"))).append(".xml"));
109  output << algo_payload;
110  output.close();
111  }
112  {
113  std::ofstream output(std::string("/tmp/").append(mp7_key.substr(0,mp7_key.find("/"))).append(".xml"));
114  output << mp7_payload;
115  output.close();
116  }
117  {
118  std::ofstream output(std::string("/tmp/").append(amc13_key.substr(0,amc13_key.find("/"))).append(".xml"));
119  output << amc13_payload;
120  output.close();
121  }
122 
123  // finally, push all payloads to the XML parser and construct the TrigSystem objects with each of those
124  l1t::XmlConfigParser xmlRdr;
125  l1t::TriggerSystem parsedXMLs;
126 
127  // HW settings should always go first
128  xmlRdr.readDOMFromString( hw_payload );
129  xmlRdr.readRootElement ( parsedXMLs );
130 
131  // now let's parse ALGO settings
132  xmlRdr.readDOMFromString( algo_payload );
133  xmlRdr.readRootElement ( parsedXMLs );
134 
135  // remaining RS settings
136  xmlRdr.readDOMFromString( mp7_payload );
137  xmlRdr.readRootElement ( parsedXMLs );
138 
139  xmlRdr.readDOMFromString( amc13_payload );
140  xmlRdr.readRootElement ( parsedXMLs );
141  parsedXMLs.setConfigured();
142 
143  L1TMuonBarrelParamsHelper m_params_helper( *(baseSettings.product()) );
144  m_params_helper.configFromDB( parsedXMLs );
145  std::shared_ptr< L1TMuonBarrelParams > retval = std::make_shared< L1TMuonBarrelParams>( m_params_helper );
146 
147  return retval;
148 }
149 
150 //define this as a plug-in
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)
void get(HolderT &iHolder) const
virtual 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)
L1TMuonBarrelParamsOnlineProd(const edm::ParameterSet &)