CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
L1TMuonGlobalParamsOnlineProd.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <fstream>
3 #include <strstream>
4 
13 #include "OnlineDBqueryHelper.h"
14 
15 class L1TMuonGlobalParamsOnlineProd : public L1ConfigOnlineProdBaseExt<L1TMuonGlobalParamsO2ORcd, L1TMuonGlobalParams> {
16 private:
17  const bool transactionSafe;
19 
20 public:
21  std::unique_ptr<const L1TMuonGlobalParams> newObject(const std::string &objectKey,
22  const L1TMuonGlobalParamsO2ORcd &record) override;
23 
26 };
27 
30  transactionSafe(iConfig.getParameter<bool>("transactionSafe")),
31  baseSettings_token(wrappedSetWhatProduced(iConfig).consumes()) {}
32 
33 std::unique_ptr<const L1TMuonGlobalParams> L1TMuonGlobalParamsOnlineProd::newObject(
34  const std::string &objectKey, const L1TMuonGlobalParamsO2ORcd &record) {
35  const L1TMuonGlobalParamsRcd &baseRcd = record.template getRecord<L1TMuonGlobalParamsRcd>();
36  auto const &baseSettings = baseRcd.get(baseSettings_token);
37 
38  if (objectKey.empty()) {
39  edm::LogError("L1-O2O: L1TMuonGlobalParamsOnlineProd") << "Key is empty";
40  if (transactionSafe)
41  throw std::runtime_error("SummaryForFunctionManager: uGMT | Faulty | Empty objectKey");
42  else {
43  edm::LogError("L1-O2O: L1TMuonGlobalParams") << "returning unmodified prototype of L1TMuonGlobalParams";
44  return std::make_unique<const L1TMuonGlobalParams>(baseSettings);
45  }
46  }
47 
48  std::string tscKey = objectKey.substr(0, objectKey.find(':'));
49  std::string rsKey = objectKey.substr(objectKey.find(':') + 1, std::string::npos);
50 
51  edm::LogInfo("L1-O2O: L1TMuonGlobalParamsOnlineProd")
52  << "Producing L1TMuonGlobalParams with TSC key =" << tscKey << " and RS key = " << rsKey;
53 
54  std::string algo_key, hw_key;
55  std::string hw_payload;
56  std::map<std::string, std::string> rs_payloads, algo_payloads;
57  try {
58  std::map<std::string, std::string> keys =
59  l1t::OnlineDBqueryHelper::fetch({"ALGO", "HW"}, "UGMT_KEYS", tscKey, m_omdsReader);
60  algo_key = keys["ALGO"];
61  hw_key = keys["HW"];
62 
63  hw_payload = l1t::OnlineDBqueryHelper::fetch({"CONF"}, "UGMT_CLOBS", hw_key, m_omdsReader)["CONF"];
64 
65  std::map<std::string, std::string> rsKeys =
66  l1t::OnlineDBqueryHelper::fetch({"MP7", "MP7_MONI", "AMC13_MONI"}, "UGMT_RS_KEYS", rsKey, m_omdsReader);
67 
68  std::map<std::string, std::string> algoKeys =
69  l1t::OnlineDBqueryHelper::fetch({"MP7", "LUTS"}, "UGMT_ALGO_KEYS", algo_key, m_omdsReader);
70 
71  for (auto &key : rsKeys)
72  rs_payloads[key.second] =
73  l1t::OnlineDBqueryHelper::fetch({"CONF"}, "UGMT_CLOBS", key.second, m_omdsReader)["CONF"];
74 
75  for (auto &key : algoKeys)
76  algo_payloads[key.second] =
77  l1t::OnlineDBqueryHelper::fetch({"CONF"}, "UGMT_CLOBS", key.second, m_omdsReader)["CONF"];
78  } catch (std::runtime_error &e) {
79  edm::LogError("L1-O2O: L1TMuonGlobalParamsOnlineProd") << e.what();
80  if (transactionSafe)
81  throw std::runtime_error("SummaryForFunctionManager: uGMT | Faulty | Broken key");
82  else {
83  edm::LogError("L1-O2O: L1TMuonGlobalParamsOnlineProd") << "returning unmodified prototype of L1TMuonGlobalParams";
84  return std::make_unique<const L1TMuonGlobalParams>(baseSettings);
85  }
86  }
87 
88  // for debugging dump the configs to local files
89  {
90  std::ofstream output(std::string("/tmp/").append(hw_key.substr(0, hw_key.find('/'))).append(".xml"));
91  output << hw_payload;
92  output.close();
93  }
94  for (auto &conf : rs_payloads) {
95  std::ofstream output(std::string("/tmp/").append(conf.first.substr(0, conf.first.find("/"))).append(".xml"));
96  output << conf.second;
97  output.close();
98  }
99  for (auto &conf : algo_payloads) {
100  std::ofstream output(std::string("/tmp/").append(conf.first.substr(0, conf.first.find("/"))).append(".xml"));
101  output << conf.second;
102  output.close();
103  }
104 
105  // finally, push all payloads to the XML parser and construct the TrigSystem objects with each of those
106  l1t::XmlConfigParser xmlRdr;
107  l1t::TriggerSystem trgSys;
108 
109  try {
110  // HW settings should always go first
111  xmlRdr.readDOMFromString(hw_payload);
112  xmlRdr.readRootElement(trgSys);
113 
114  // now let's parse ALGO and then RS settings
115  for (auto &conf : algo_payloads) {
116  xmlRdr.readDOMFromString(conf.second);
117  xmlRdr.readRootElement(trgSys);
118  }
119  for (auto &conf : rs_payloads) {
120  xmlRdr.readDOMFromString(conf.second);
121  xmlRdr.readRootElement(trgSys);
122  }
123  trgSys.setConfigured();
124  } catch (std::runtime_error &e) {
125  edm::LogError("L1-O2O: L1TMuonGlobalParamsOnlineProd") << e.what();
126  if (transactionSafe)
127  throw std::runtime_error("SummaryForFunctionManager: uGMT | Faulty | Cannot parse XMLs");
128  else {
129  edm::LogError("L1-O2O: L1TMuonGlobalParamsOnlineProd") << "returning unmodified prototype of L1TMuonGlobalParams";
130  return std::make_unique<const L1TMuonGlobalParams>(baseSettings);
131  }
132  }
133 
134  L1TMuonGlobalParamsHelper m_params_helper(baseSettings);
135  try {
136  m_params_helper.loadFromOnline(trgSys);
137  } catch (std::runtime_error &e) {
138  edm::LogError("L1-O2O: L1TMuonGlobalParamsOnlineProd") << e.what();
139  if (transactionSafe)
140  throw std::runtime_error("SummaryForFunctionManager: uGMT | Faulty | Cannot run helper");
141  else {
142  edm::LogError("L1-O2O: L1TMuonGlobalParamsOnlineProd") << "returning unmodified prototype of L1TMuonGlobalParams";
143  return std::make_unique<const L1TMuonGlobalParams>(baseSettings);
144  }
145  }
146 
147  auto retval = std::make_unique<const L1TMuonGlobalParams>(cast_to_L1TMuonGlobalParams(m_params_helper));
148 
149  edm::LogInfo("L1-O2O: L1TMuonGlobalParamsOnlineProd")
150  << "SummaryForFunctionManager: uGMT | OK | All looks good";
151  return retval;
152 }
153 
154 //define this as a plug-in
const L1TMuonGlobalParams & cast_to_L1TMuonGlobalParams(const L1TMuonGlobalParams_PUBLIC &x)
void setConfigured(bool state=true) noexcept
Definition: TriggerSystem.h:74
boost::dynamic_bitset append(const boost::dynamic_bitset<> &bs1, const boost::dynamic_bitset<> &bs2)
this method takes two bitsets bs1 and bs2 and returns result of bs2 appended to the end of bs1 ...
std::unique_ptr< const L1TMuonGlobalParams > newObject(const std::string &objectKey, const L1TMuonGlobalParamsO2ORcd &record) override
const edm::ESGetToken< L1TMuonGlobalParams, L1TMuonGlobalParamsRcd > baseSettings_token
Log< level::Error, false > LogError
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)
void loadFromOnline(l1t::TriggerSystem &trgSys, const std::string &processorId="")
tuple key
prepare the HTCondor submission files and eventually submit them
Log< level::Info, false > LogInfo
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
void readRootElement(TriggerSystem &aTriggerSystem, const std::string &sysId="")
L1TMuonGlobalParamsOnlineProd(const edm::ParameterSet &)