CMS 3D CMS Logo

L1TMuonBarrelParamsOnlineProd.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <fstream>
3 
11 #include "OnlineDBqueryHelper.h"
12 
13 #include "xercesc/util/PlatformUtils.hpp"
14 using namespace XERCES_CPP_NAMESPACE;
15 
16 class L1TMuonBarrelParamsOnlineProd : public L1ConfigOnlineProdBaseExt<L1TMuonBarrelParamsO2ORcd, L1TMuonBarrelParams> {
17 private:
18  const bool transactionSafe;
20 
21 public:
22  std::unique_ptr<const L1TMuonBarrelParams> newObject(const std::string& objectKey,
23  const L1TMuonBarrelParamsO2ORcd& record) override;
24 
27 };
28 
31  transactionSafe(iConfig.getParameter<bool>("transactionSafe")),
32  baseSettings_token(wrappedSetWhatProduced(iConfig).consumes()) {}
33 
34 std::unique_ptr<const L1TMuonBarrelParams> L1TMuonBarrelParamsOnlineProd::newObject(
35  const std::string& objectKey, const L1TMuonBarrelParamsO2ORcd& record) {
36  const L1TMuonBarrelParamsRcd& baseRcd = record.template getRecord<L1TMuonBarrelParamsRcd>();
37  auto const& baseSettings = baseRcd.get(baseSettings_token);
38 
39  if (objectKey.empty()) {
40  edm::LogError("L1-O2O: L1TMuonBarrelParamsOnlineProd") << "Key is empty, returning empty L1TMuonBarrelParams";
41  if (transactionSafe)
42  throw std::runtime_error("SummaryForFunctionManager: BMTF | Faulty | Empty objectKey");
43  else {
44  edm::LogError("L1-O2O: L1TMuonBarrelParamsOnlineProd") << "returning unmodified prototype of L1TMuonBarrelParams";
45  return std::make_unique<const L1TMuonBarrelParams>(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: L1TMuonBarrelParamsOnlineProd")
53  << "Producing L1TMuonBarrelParams with TSC key = " << tscKey << " and RS key = " << rsKey;
54 
55  std::string algo_key, hw_key;
56  std::string mp7_key, amc13_key;
57  std::string hw_payload, algo_payload, mp7_payload, amc13_payload;
58  try {
59  std::map<std::string, std::string> keys =
60  l1t::OnlineDBqueryHelper::fetch({"ALGO", "HW"}, "BMTF_KEYS", tscKey, m_omdsReader);
61  algo_key = keys["ALGO"];
62  hw_key = keys["HW"];
63 
64  hw_payload = l1t::OnlineDBqueryHelper::fetch({"CONF"}, "BMTF_CLOBS", hw_key, m_omdsReader)["CONF"];
65 
66  algo_payload = l1t::OnlineDBqueryHelper::fetch({"CONF"}, "BMTF_CLOBS", algo_key, m_omdsReader)["CONF"];
67 
68  std::map<std::string, std::string> rsKeys =
69  l1t::OnlineDBqueryHelper::fetch({"MP7", "AMC13"}, "BMTF_RS_KEYS", rsKey, m_omdsReader);
70  mp7_key = rsKeys["MP7"];
71  amc13_key = rsKeys["AMC13"];
72 
73  mp7_payload = l1t::OnlineDBqueryHelper::fetch({"CONF"}, "BMTF_CLOBS", mp7_key, m_omdsReader)["CONF"];
74  amc13_payload = l1t::OnlineDBqueryHelper::fetch({"CONF"}, "BMTF_CLOBS", amc13_key, m_omdsReader)["CONF"];
75 
76  } catch (std::runtime_error& e) {
77  edm::LogError("L1-O2O: L1TMuonBarrelParamsOnlineProd") << e.what();
78  if (transactionSafe)
79  throw std::runtime_error(std::string("SummaryForFunctionManager: BMTF | Faulty | ") + e.what());
80  else {
81  edm::LogError("L1-O2O: L1TMuonBarrelParamsOnlineProd") << "returning unmodified prototype of L1TMuonBarrelParams";
82  return std::make_unique<const L1TMuonBarrelParams>(baseSettings);
83  }
84  }
85 
86  // for debugging 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  std::ofstream output(std::string("/tmp/").append(mp7_key.substr(0, mp7_key.find('/'))).append(".xml"));
99  output << mp7_payload;
100  output.close();
101  }
102  {
103  std::ofstream output(std::string("/tmp/").append(amc13_key.substr(0, amc13_key.find('/'))).append(".xml"));
104  output << amc13_payload;
105  output.close();
106  }
107 
108  // finally, push all payloads to the XML parser and construct the TrigSystem objects with each of those
109  l1t::XmlConfigParser xmlRdr;
110  l1t::TriggerSystem parsedXMLs;
111  try {
112  // HW settings should always go first
113  xmlRdr.readDOMFromString(hw_payload);
114  xmlRdr.readRootElement(parsedXMLs);
115 
116  // now let's parse ALGO settings
117  xmlRdr.readDOMFromString(algo_payload);
118  xmlRdr.readRootElement(parsedXMLs);
119 
120  // remaining RS settings
121  xmlRdr.readDOMFromString(mp7_payload);
122  xmlRdr.readRootElement(parsedXMLs);
123 
124  xmlRdr.readDOMFromString(amc13_payload);
125  xmlRdr.readRootElement(parsedXMLs);
126  parsedXMLs.setConfigured();
127 
128  } catch (std::runtime_error& e) {
129  edm::LogError("L1-O2O: L1TMuonBarrelParamsOnlineProd") << e.what();
130  if (transactionSafe)
131  throw std::runtime_error(std::string("SummaryForFunctionManager: BMTF | Faulty | ") + e.what());
132  else {
133  edm::LogError("L1-O2O: L1TMuonBarrelParamsOnlineProd") << "returning unmodified prototype of L1TMuonBarrelParams";
134  return std::make_unique<const L1TMuonBarrelParams>(baseSettings);
135  }
136  }
137 
138  L1TMuonBarrelParamsHelper m_params_helper(baseSettings);
139  try {
140  m_params_helper.configFromDB(parsedXMLs);
141  } catch (std::runtime_error& e) {
142  edm::LogError("L1-O2O: L1TMuonBarrelParamsOnlineProd") << e.what();
143  if (transactionSafe)
144  throw std::runtime_error(std::string("SummaryForFunctionManager: BMTF | Faulty | ") + e.what());
145  else {
146  edm::LogError("L1-O2O: L1TMuonBarrelParamsOnlineProd") << "returning unmodified prototype of L1TMuonBarrelParams";
147  return std::make_unique<const L1TMuonBarrelParams>(baseSettings);
148  }
149  }
150 
151  auto retval = std::make_unique<const L1TMuonBarrelParams>(m_params_helper);
152 
153  edm::LogInfo("L1-O2O: L1TCaloParamsOnlineProd") << "SummaryForFunctionManager: BMTF | OK | All looks good";
154  return retval;
155 }
156 
157 //define this as a plug-in
electrons_cff.bool
bool
Definition: electrons_cff.py:366
L1TMuonBarrelParamsHelper
Definition: L1TMuonBarrelParamsHelper.h:30
L1ConfigOnlineProdBaseExt< L1TMuonBarrelParamsO2ORcd, L1TMuonBarrelParams >::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
L1TMuonBarrelParamsOnlineProd::transactionSafe
const bool transactionSafe
Definition: L1TMuonBarrelParamsOnlineProd.cc:18
L1TMuonBarrelParamsO2ORcd.h
l1t::XmlConfigParser::readRootElement
void readRootElement(TriggerSystem &aTriggerSystem, const std::string &sysId="")
Definition: XmlConfigParser.cc:189
L1TMuonBarrelParams.h
GlobalPosition_Frontier_DevDB_cff.record
record
Definition: GlobalPosition_Frontier_DevDB_cff.py:10
L1ConfigOnlineProdBaseExt.h
L1TMuonBarrelParamsHelper.h
relativeConstraints.keys
keys
Definition: relativeConstraints.py:89
L1TMuonBarrelParamsOnline_cfi.L1TMuonBarrelParamsOnlineProd
L1TMuonBarrelParamsOnlineProd
Definition: L1TMuonBarrelParamsOnline_cfi.py:18
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
L1TMuonBarrelParamsO2ORcd
Definition: L1TMuonBarrelParamsO2ORcd.h:15
XmlConfigParser.h
l1t::TriggerSystem
Definition: TriggerSystem.h:14
L1ConfigOnlineProdBaseExt
Definition: L1ConfigOnlineProdBaseExt.h:32
L1TMuonBarrelParamsOnlineProd::~L1TMuonBarrelParamsOnlineProd
~L1TMuonBarrelParamsOnlineProd(void) override
Definition: L1TMuonBarrelParamsOnlineProd.cc:26
XERCES_CPP_NAMESPACE
Definition: XmlConfigParser.h:12
L1TMuonBarrelParamsRcd.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
l1t::XmlConfigParser
Definition: XmlConfigParser.h:23
OnlineDBqueryHelper.h
edm::ParameterSet
Definition: ParameterSet.h:47
mps_setup.append
append
Definition: mps_setup.py:85
L1TMuonBarrelParamsHelper::configFromDB
void configFromDB(l1t::TriggerSystem &trgSys)
Definition: L1TMuonBarrelParamsHelper.cc:124
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
edm::ESGetToken< L1TMuonBarrelParams, L1TMuonBarrelParamsRcd >
L1TMuonBarrelParamsOnlineProd::baseSettings_token
const edm::ESGetToken< L1TMuonBarrelParams, L1TMuonBarrelParamsRcd > baseSettings_token
Definition: L1TMuonBarrelParamsOnlineProd.cc:19
L1TMuonBarrelParamsOnlineProd::newObject
std::unique_ptr< const L1TMuonBarrelParams > newObject(const std::string &objectKey, const L1TMuonBarrelParamsO2ORcd &record) override
Definition: L1TMuonBarrelParamsOnlineProd.cc:34
DEFINE_FWK_EVENTSETUP_MODULE
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
L1TMuonBarrelParamsOnlineProd::L1TMuonBarrelParamsOnlineProd
L1TMuonBarrelParamsOnlineProd(const edm::ParameterSet &)
Definition: L1TMuonBarrelParamsOnlineProd.cc:29
L1TMuonBarrelParamsOnlineProd
Definition: L1TMuonBarrelParamsOnlineProd.cc:16
TriggerSystem.h
edm::eventsetup::EventSetupRecordImplementation::get
PRODUCT const & get(ESGetToken< PRODUCT, T > const &iToken) const
Definition: EventSetupRecordImplementation.h:74
L1TMuonBarrelParams
Definition: L1TMuonBarrelParams.h:23
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
L1TMuonBarrelParamsRcd
Definition: L1TMuonBarrelParamsRcd.h:13
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37