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 
13 #include "OnlineDBqueryHelper.h"
14 
15 class L1TMuonEndCapParamsOnlineProd : public L1ConfigOnlineProdBaseExt<L1TMuonEndCapParamsO2ORcd,L1TMuonEndCapParams> {
16 private:
18 public:
19  std::shared_ptr<L1TMuonEndCapParams> newObject(const std::string& objectKey, const L1TMuonEndCapParamsO2ORcd& record) override ;
20 
23 };
24 
26  transactionSafe = iConfig.getParameter<bool>("transactionSafe");
27 }
28 
29 std::shared_ptr<L1TMuonEndCapParams> L1TMuonEndCapParamsOnlineProd::newObject(const std::string& objectKey, const L1TMuonEndCapParamsO2ORcd& record) {
30  using namespace edm::es;
31 
32  const L1TMuonEndCapParamsRcd& baseRcd = record.template getRecord< L1TMuonEndCapParamsRcd >() ;
34  baseRcd.get( baseSettings ) ;
35 
36 
37  if (objectKey.empty()) {
38  edm::LogError( "L1-O2O: L1TMuonEndCapParamsOnlineProd" ) << "Key is empty";
39  if( transactionSafe )
40  throw std::runtime_error("SummaryForFunctionManager: BMTF | Faulty | Empty objectKey");
41  else {
42  edm::LogError( "L1-O2O: L1TMuonEndCapParamsOnlineProd" ) << "returning unmodified prototype of L1TMuonEndCapParams";
43  return std::make_shared< L1TMuonEndCapParams >( *(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  edm::LogInfo( "L1-O2O: L1TMuonEndCapParamsOnlineProd" ) << "Producing L1TMuonEndCapParams with TSC key = " << tscKey << " and RS key = " << rsKey ;
51 
52  std::string algo_key, hw_key;
53  std::string algo_payload, hw_payload;
54  try {
55  std::map<std::string,std::string> keys =
56  l1t::OnlineDBqueryHelper::fetch( {"HW","ALGO"},
57  "EMTF_KEYS",
58  tscKey,
60  );
61 
62  hw_key = keys["HW"];
63  algo_key = keys["ALGO"];
64 
65  hw_payload = l1t::OnlineDBqueryHelper::fetch( {"CONF"},
66  "EMTF_CLOBS",
67  hw_key,
69  ) ["CONF"];
70 
71  algo_payload = l1t::OnlineDBqueryHelper::fetch( {"CONF"},
72  "EMTF_CLOBS",
73  algo_key,
75  ) ["CONF"];
76 
77  } catch ( std::runtime_error &e ) {
78  edm::LogError( "L1-O2O: L1TMuonEndCapParamsOnlineProd" ) << e.what();
79  if( transactionSafe )
80  throw std::runtime_error("SummaryForFunctionManager: EMTF | Faulty | Broken key");
81  else {
82  edm::LogError( "L1-O2O: L1TMuonEndCapParamsOnlineProd" ) << "returning unmodified prototype of L1TMuonEndCapParams";
83  return std::make_shared< L1TMuonEndCapParams >( *(baseSettings.product()) ) ;
84  }
85  }
86 
87  // for debugging purposes dump the configs to local files
88  {
89  std::ofstream output(std::string("/tmp/").append(hw_key.substr(0,hw_key.find("/"))).append(".xml"));
90  output << hw_payload;
91  output.close();
92  }
93  {
94  std::ofstream output(std::string("/tmp/").append(algo_key.substr(0,algo_key.find("/"))).append(".xml"));
95  output << algo_payload;
96  output.close();
97  }
98 
99  l1t::XmlConfigParser xmlRdr;
100  l1t::TriggerSystem trgSys;
101 
102  try {
103  xmlRdr.readDOMFromString( hw_payload );
104  xmlRdr.readRootElement ( trgSys );
105 
106  xmlRdr.readDOMFromString( algo_payload );
107  xmlRdr.readRootElement ( trgSys );
108 
109  trgSys.setConfigured();
110  } catch ( std::runtime_error &e ) {
111  edm::LogError( "L1-O2O: L1TMuonEndCapParamsOnlineProd" ) << e.what();
112  if( transactionSafe )
113  throw std::runtime_error("SummaryForFunctionManager: EMTF | Faulty | Cannot parse XMLs");
114  else {
115  edm::LogError( "L1-O2O: L1TMuonEndCapParamsOnlineProd" ) << "returning unmodified prototype of L1TMuonEndCapParams";
116  return std::make_shared< L1TMuonEndCapParams >( *(baseSettings.product()) ) ;
117  }
118  }
119 
120  // Changed from "EMTF-1" to "EMTFp1", but is this backwards compatible? Does it need to be? - AWB 10.04.2018
121  std::map<std::string, l1t::Parameter> conf = trgSys.getParameters("EMTFp1"); // any processor will do
122  // if (conf still empty) conf = trgSys.getParameters("EMTF+1"); // Should add some conditional for backwards-compatibility
123 
124  std::string core_fwv = conf["core_firmware_version"].getValueAsStr();
125  tm brokenTime;
126  strptime(core_fwv.c_str(), "%Y-%m-%d %T", &brokenTime);
127  time_t fw_sinceEpoch = timegm(&brokenTime);
128 
129 // std::string pclut_v = conf["pc_lut_version"].getValueAsStr();
130 // strptime(pclut_v.c_str(), "%Y-%m-%d", &brokenTime);
131 // time_t pclut_sinceEpoch = timegm(&brokenTime);
132 
133  std::shared_ptr< L1TMuonEndCapParams > retval( new L1TMuonEndCapParams() );
134 
135  retval->firmwareVersion_ = fw_sinceEpoch;
136  retval->PtAssignVersion_ = conf["pt_lut_version"].getValue<unsigned int>();
137  retval->PhiMatchWindowSt1_ = 1; //pclut_sinceEpoch;
138 
139  edm::LogInfo( "L1-O2O: L1TMuonEndCapParamsOnlineProd" ) << "SummaryForFunctionManager: EMTF | OK | All looks good";
140  return retval;
141 }
142 
143 //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
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)
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
#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="")