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