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:
19 
20 public:
21  std::unique_ptr<const L1TMuonGlobalParams> newObject(const std::string &objectKey,
22  const L1TMuonGlobalParamsO2ORcd &record) override;
23 
26 };
27 
30  wrappedSetWhatProduced(iConfig).setConsumes(baseSettings_token);
31  transactionSafe = iConfig.getParameter<bool>("transactionSafe");
32 }
33 
34 std::unique_ptr<const L1TMuonGlobalParams> L1TMuonGlobalParamsOnlineProd::newObject(
35  const std::string &objectKey, const L1TMuonGlobalParamsO2ORcd &record) {
36  const L1TMuonGlobalParamsRcd &baseRcd = record.template getRecord<L1TMuonGlobalParamsRcd>();
37  auto const &baseSettings = baseRcd.get(baseSettings_token);
38 
39  if (objectKey.empty()) {
40  edm::LogError("L1-O2O: L1TMuonGlobalParamsOnlineProd") << "Key is empty";
41  if (transactionSafe)
42  throw std::runtime_error("SummaryForFunctionManager: uGMT | Faulty | Empty objectKey");
43  else {
44  edm::LogError("L1-O2O: L1TMuonGlobalParams") << "returning unmodified prototype of L1TMuonGlobalParams";
45  return std::make_unique<const L1TMuonGlobalParams>(baseSettings);
46  }
47  }
48 
49  std::string tscKey = objectKey.substr(0, objectKey.find(":"));
50  std::string rsKey = objectKey.substr(objectKey.find(":") + 1, std::string::npos);
51 
52  edm::LogInfo("L1-O2O: L1TMuonGlobalParamsOnlineProd")
53  << "Producing L1TMuonGlobalParams with TSC key =" << tscKey << " and RS key = " << rsKey;
54 
55  std::string algo_key, hw_key;
56  std::string hw_payload;
57  std::map<std::string, std::string> rs_payloads, algo_payloads;
58  try {
59  std::map<std::string, std::string> keys =
60  l1t::OnlineDBqueryHelper::fetch({"ALGO", "HW"}, "UGMT_KEYS", tscKey, m_omdsReader);
61  algo_key = keys["ALGO"];
62  hw_key = keys["HW"];
63 
64  hw_payload = l1t::OnlineDBqueryHelper::fetch({"CONF"}, "UGMT_CLOBS", hw_key, m_omdsReader)["CONF"];
65 
66  std::map<std::string, std::string> rsKeys =
67  l1t::OnlineDBqueryHelper::fetch({"MP7", "MP7_MONI", "AMC13_MONI"}, "UGMT_RS_KEYS", rsKey, m_omdsReader);
68 
69  std::map<std::string, std::string> algoKeys =
70  l1t::OnlineDBqueryHelper::fetch({"MP7", "LUTS"}, "UGMT_ALGO_KEYS", algo_key, m_omdsReader);
71 
72  for (auto &key : rsKeys)
73  rs_payloads[key.second] =
74  l1t::OnlineDBqueryHelper::fetch({"CONF"}, "UGMT_CLOBS", key.second, m_omdsReader)["CONF"];
75 
76  for (auto &key : algoKeys)
77  algo_payloads[key.second] =
78  l1t::OnlineDBqueryHelper::fetch({"CONF"}, "UGMT_CLOBS", key.second, m_omdsReader)["CONF"];
79  } catch (std::runtime_error &e) {
80  edm::LogError("L1-O2O: L1TMuonGlobalParamsOnlineProd") << e.what();
81  if (transactionSafe)
82  throw std::runtime_error("SummaryForFunctionManager: uGMT | Faulty | Broken key");
83  else {
84  edm::LogError("L1-O2O: L1TMuonGlobalParamsOnlineProd") << "returning unmodified prototype of L1TMuonGlobalParams";
85  return std::make_unique<const L1TMuonGlobalParams>(baseSettings);
86  }
87  }
88 
89  // for debugging dump the configs to local files
90  {
91  std::ofstream output(std::string("/tmp/").append(hw_key.substr(0, hw_key.find("/"))).append(".xml"));
92  output << hw_payload;
93  output.close();
94  }
95  for (auto &conf : rs_payloads) {
96  std::ofstream output(std::string("/tmp/").append(conf.first.substr(0, conf.first.find("/"))).append(".xml"));
97  output << conf.second;
98  output.close();
99  }
100  for (auto &conf : algo_payloads) {
101  std::ofstream output(std::string("/tmp/").append(conf.first.substr(0, conf.first.find("/"))).append(".xml"));
102  output << conf.second;
103  output.close();
104  }
105 
106  // finally, push all payloads to the XML parser and construct the TrigSystem objects with each of those
107  l1t::XmlConfigParser xmlRdr;
108  l1t::TriggerSystem trgSys;
109 
110  try {
111  // HW settings should always go first
112  xmlRdr.readDOMFromString(hw_payload);
113  xmlRdr.readRootElement(trgSys);
114 
115  // now let's parse ALGO and then RS settings
116  for (auto &conf : algo_payloads) {
117  xmlRdr.readDOMFromString(conf.second);
118  xmlRdr.readRootElement(trgSys);
119  }
120  for (auto &conf : rs_payloads) {
121  xmlRdr.readDOMFromString(conf.second);
122  xmlRdr.readRootElement(trgSys);
123  }
124  trgSys.setConfigured();
125  } catch (std::runtime_error &e) {
126  edm::LogError("L1-O2O: L1TMuonGlobalParamsOnlineProd") << e.what();
127  if (transactionSafe)
128  throw std::runtime_error("SummaryForFunctionManager: uGMT | Faulty | Cannot parse XMLs");
129  else {
130  edm::LogError("L1-O2O: L1TMuonGlobalParamsOnlineProd") << "returning unmodified prototype of L1TMuonGlobalParams";
131  return std::make_unique<const L1TMuonGlobalParams>(baseSettings);
132  }
133  }
134 
135  L1TMuonGlobalParamsHelper m_params_helper(baseSettings);
136  try {
137  m_params_helper.loadFromOnline(trgSys);
138  } catch (std::runtime_error &e) {
139  edm::LogError("L1-O2O: L1TMuonGlobalParamsOnlineProd") << e.what();
140  if (transactionSafe)
141  throw std::runtime_error("SummaryForFunctionManager: uGMT | Faulty | Cannot run helper");
142  else {
143  edm::LogError("L1-O2O: L1TMuonGlobalParamsOnlineProd") << "returning unmodified prototype of L1TMuonGlobalParams";
144  return std::make_unique<const L1TMuonGlobalParams>(baseSettings);
145  }
146  }
147 
148  auto retval = std::make_unique<const L1TMuonGlobalParams>(cast_to_L1TMuonGlobalParams(m_params_helper));
149 
150  edm::LogInfo("L1-O2O: L1TMuonGlobalParamsOnlineProd")
151  << "SummaryForFunctionManager: uGMT | OK | All looks good";
152  return retval;
153 }
154 
155 //define this as a plug-in
L1TMuonGlobalParamsOnlineProd::newObject
std::unique_ptr< const L1TMuonGlobalParams > newObject(const std::string &objectKey, const L1TMuonGlobalParamsO2ORcd &record) override
Definition: L1TMuonGlobalParamsOnlineProd.cc:34
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:32
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
edm::LogInfo
Definition: MessageLogger.h:254
GlobalPosition_Frontier_DevDB_cff.record
record
Definition: GlobalPosition_Frontier_DevDB_cff.py:10
L1ConfigOnlineProdBaseExt.h
relativeConstraints.keys
keys
Definition: relativeConstraints.py:89
L1TMuonGlobalParamsOnlineProd::transactionSafe
bool transactionSafe
Definition: L1TMuonGlobalParamsOnlineProd.cc:17
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:36
edm::LogError
Definition: MessageLogger.h:183
L1TMuonGlobalParams.h
mps_setup.append
append
Definition: mps_setup.py:85
L1TMuonGlobalParams_PUBLIC.h
L1TMuonGlobalParamsOnlineProd
Definition: L1TMuonGlobalParamsOnlineProd.cc:15
L1TMuonGlobalParamsRcd
Definition: L1TMuonGlobalParamsRcd.h:23
edm::ESGetToken< L1TMuonGlobalParams, L1TMuonGlobalParamsRcd >
L1TMuonGlobalParamsHelper.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
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
L1TMuonGlobalParamsOnlineProd::baseSettings_token
edm::ESGetToken< L1TMuonGlobalParams, L1TMuonGlobalParamsRcd > baseSettings_token
Definition: L1TMuonGlobalParamsOnlineProd.cc:18
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
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
L1ConfigOnlineProdBaseExt< L1TMuonGlobalParamsO2ORcd, L1TMuonGlobalParams >::wrappedSetWhatProduced
edm::ESConsumesCollectorT< L1TMuonGlobalParamsO2ORcd > wrappedSetWhatProduced(const edm::ParameterSet &)
Definition: L1ConfigOnlineProdBaseExt.h:93
L1TMuonGlobalParamsRcd.h
L1TMuonGlobalParamsHelper
Definition: L1TMuonGlobalParamsHelper.h:24
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37