CMS 3D CMS Logo

L1TMuonEndCapParamsOnlineProd.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <fstream>
3 #include <ctime>
4 #include <string>
5 #include <map>
6 
14 #include "OnlineDBqueryHelper.h"
15 
16 class L1TMuonEndCapParamsOnlineProd : public L1ConfigOnlineProdBaseExt<L1TMuonEndCapParamsO2ORcd,L1TMuonEndCapParams> {
17 private:
18 public:
19  std::shared_ptr<L1TMuonEndCapParams> newObject(const std::string& objectKey, const L1TMuonEndCapParamsO2ORcd& record) override ;
20 
23 };
24 
26 
27 std::shared_ptr<L1TMuonEndCapParams> L1TMuonEndCapParamsOnlineProd::newObject(const std::string& objectKey, const L1TMuonEndCapParamsO2ORcd& record) {
28  using namespace edm::es;
29 
30  const L1TMuonEndCapParamsRcd& baseRcd = record.template getRecord< L1TMuonEndCapParamsRcd >() ;
32  baseRcd.get( baseSettings ) ;
33 
34 
35  if (objectKey.empty()) {
36  edm::LogError( "L1-O2O: L1TMuonEndCapParamsOnlineProd" ) << "Key is empty, returning empty L1TMuonEndCapParams";
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  edm::LogInfo( "L1-O2O: L1TMuonEndCapParamsOnlineProd" ) << "Producing L1TMuonEndCapParams with TSC key = " << tscKey << " and RS key = " << rsKey ;
44 
45  std::string algo_key, hw_key;
46  std::string algo_payload, hw_payload;
47  try {
48  std::map<std::string,std::string> keys =
49  l1t::OnlineDBqueryHelper::fetch( {"HW","ALGO"},
50  "EMTF_KEYS",
51  tscKey,
53  );
54 
55  hw_key = keys["HW"];
56  algo_key = keys["ALGO"];
57 
58  hw_payload = l1t::OnlineDBqueryHelper::fetch( {"CONF"},
59  "EMTF_CLOBS",
60  hw_key,
62  ) ["CONF"];
63 
64  algo_payload = l1t::OnlineDBqueryHelper::fetch( {"CONF"},
65  "EMTF_CLOBS",
66  algo_key,
68  ) ["CONF"];
69 
70  } catch ( std::runtime_error &e ) {
71  edm::LogError( "L1-O2O: L1TMuonEndCapParamsOnlineProd" ) << e.what();
72  throw std::runtime_error("Broken key");
73  }
74 
75  // for debugging purposes dump the configs to local files
76  {
77  std::ofstream output(std::string("/tmp/").append(hw_key.substr(0,hw_key.find("/"))).append(".xml"));
78  output << hw_payload;
79  output.close();
80  }
81  {
82  std::ofstream output(std::string("/tmp/").append(algo_key.substr(0,algo_key.find("/"))).append(".xml"));
83  output << algo_payload;
84  output.close();
85  }
86 
87  l1t::XmlConfigParser xmlRdr;
88  l1t::TriggerSystem trgSys;
89 
90  xmlRdr.readDOMFromString( hw_payload );
91  xmlRdr.readRootElement ( trgSys );
92 
93  xmlRdr.readDOMFromString( algo_payload );
94  xmlRdr.readRootElement ( trgSys );
95 
96  trgSys.setConfigured();
97 
98  std::map<std::string, l1t::Parameter> conf = trgSys.getParameters("EMTF-1"); // any processor will do
99 
100  std::string core_fwv = conf["core_firmware_version"].getValueAsStr();
101  tm brokenTime;
102  strptime(core_fwv.c_str(), "%Y-%m-%d %T", &brokenTime);
103  time_t fw_sinceEpoch = timegm(&brokenTime);
104 
105  std::string pclut_v = conf["pc_lut_version"].getValueAsStr();
106  strptime(pclut_v.c_str(), "%Y-%m-%d", &brokenTime);
107  time_t pclut_sinceEpoch = timegm(&brokenTime);
108 
110 
111  data.SetFirmwareVersion( fw_sinceEpoch );
112  data.SetPtAssignVersion( conf["pt_lut_version"].getValue<unsigned int>() );
113  data.SetPrimConvVersion( pclut_sinceEpoch );
114 
115  std::shared_ptr< L1TMuonEndCapParams > retval( data.getWriteInstance() );
116 
117  return retval;
118 }
119 
120 //define this as a plug-in
void setConfigured(bool state=true) noexcept
Definition: TriggerSystem.h:73
JetCorrectorParameters::Record record
Definition: classes.h:7
void SetFirmwareVersion(unsigned version)
std::shared_ptr< L1TMuonEndCapParams > newObject(const std::string &objectKey, const L1TMuonEndCapParamsO2ORcd &record) override
L1TMuonEndCapParamsOnlineProd(const edm::ParameterSet &)
void readDOMFromString(const std::string &str, xercesc::DOMDocument *&doc)
void SetPtAssignVersion(unsigned version)
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
void SetPrimConvVersion(unsigned version)
L1TMuonEndCapParams * getWriteInstance()
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
const std::map< std::string, Parameter > & getParameters(const char *processor) const
void readRootElement(TriggerSystem &aTriggerSystem, const std::string &sysId="")
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82