CMS 3D CMS Logo

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
electrons_cff.bool
bool
Definition: electrons_cff.py:366
L1TMuonGlobalParamsOnlineProd::baseSettings_token
const edm::ESGetToken< L1TMuonGlobalParams, L1TMuonGlobalParamsRcd > baseSettings_token
Definition: L1TMuonGlobalParamsOnlineProd.cc:18
L1TMuonGlobalParamsOnlineProd::newObject
std::unique_ptr< const L1TMuonGlobalParams > newObject(const std::string &objectKey, const L1TMuonGlobalParamsO2ORcd &record) override
Definition: L1TMuonGlobalParamsOnlineProd.cc:33
L1TMuonGlobalParamsOnlineProd::transactionSafe
const bool transactionSafe
Definition: L1TMuonGlobalParamsOnlineProd.cc:17
L1ConfigOnlineProdBaseExt< L1TMuonGlobalParamsO2ORcd, L1TMuonGlobalParams >::m_omdsReader
l1t::OMDSReader m_omdsReader
Definition: L1ConfigOnlineProdBaseExt.h:47
l1t::OnlineDBqueryHelper::fetch
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)
Definition: OnlineDBqueryHelper.cc:3
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:72
l1t::XmlConfigParser::readRootElement
void readRootElement(TriggerSystem &aTriggerSystem, const std::string &sysId="")
Definition: XmlConfigParser.cc:189
L1TMuonGlobalParamsHelper::loadFromOnline
void loadFromOnline(l1t::TriggerSystem &trgSys, const std::string &processorId="")
Definition: L1TMuonGlobalParamsHelper.cc:115
L1TMuonGlobalParams
Definition: L1TMuonGlobalParams.h:21
GlobalPosition_Frontier_DevDB_cff.record
record
Definition: GlobalPosition_Frontier_DevDB_cff.py:10
L1ConfigOnlineProdBaseExt.h
relativeConstraints.keys
keys
Definition: relativeConstraints.py:89
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
XmlConfigParser.h
l1t::TriggerSystem
Definition: TriggerSystem.h:14
L1ConfigOnlineProdBaseExt
Definition: L1ConfigOnlineProdBaseExt.h:32
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
l1t::XmlConfigParser
Definition: XmlConfigParser.h:23
OnlineDBqueryHelper.h
L1TMuonGlobalParamsO2ORcd.h
edm::ParameterSet
Definition: ParameterSet.h:47
L1TMuonGlobalParams.h
mps_setup.append
append
Definition: mps_setup.py:85
L1TMuonGlobalParams_PUBLIC.h
L1TMuonGlobalParamsOnlineProd
Definition: L1TMuonGlobalParamsOnlineProd.cc:15
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
L1TMuonGlobalParamsRcd
Definition: L1TMuonGlobalParamsRcd.h:23
edm::ESGetToken< L1TMuonGlobalParams, L1TMuonGlobalParamsRcd >
L1TMuonGlobalParamsHelper.h
L1TMuonGlobalParamsOnlineProd::~L1TMuonGlobalParamsOnlineProd
~L1TMuonGlobalParamsOnlineProd(void) override
Definition: L1TMuonGlobalParamsOnlineProd.cc:25
L1TMuonGlobalParamsOnlineProd::L1TMuonGlobalParamsOnlineProd
L1TMuonGlobalParamsOnlineProd(const edm::ParameterSet &)
Definition: L1TMuonGlobalParamsOnlineProd.cc:28
L1TMuonGlobalParamsO2ORcd
Definition: L1TMuonGlobalParamsO2ORcd.h:26
DEFINE_FWK_EVENTSETUP_MODULE
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
TriggerSystem.h
cast_to_L1TMuonGlobalParams
const L1TMuonGlobalParams & cast_to_L1TMuonGlobalParams(const L1TMuonGlobalParams_PUBLIC &x)
Definition: L1TMuonGlobalParams_PUBLIC.cc:10
edm::eventsetup::EventSetupRecordImplementation::get
PRODUCT const & get(ESGetToken< PRODUCT, T > const &iToken) const
Definition: EventSetupRecordImplementation.h:74
L1TCaloParamsObjectKeysOnline_cfi.transactionSafe
transactionSafe
Definition: L1TCaloParamsObjectKeysOnline_cfi.py:7
l1t::XmlConfigParser::readDOMFromString
void readDOMFromString(const std::string &str, xercesc::DOMDocument *&doc)
l1t::TriggerSystem::setConfigured
void setConfigured(bool state=true) noexcept
Definition: TriggerSystem.h:74
crabWrapper.key
key
Definition: crabWrapper.py:19
L1TMuonGlobalParamsRcd.h
L1TMuonGlobalParamsHelper
Definition: L1TMuonGlobalParamsHelper.h:24
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37