CMS 3D CMS Logo

L1TMuonOverlapFwVersionOnlineProd.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <fstream>
3 
10 #include "OnlineDBqueryHelper.h"
11 
12 #include "xercesc/util/PlatformUtils.hpp"
13 using namespace XERCES_CPP_NAMESPACE;
14 
16  : public L1ConfigOnlineProdBaseExt<L1TMuonOverlapFwVersionO2ORcd, L1TMuonOverlapFwVersion> {
17 private:
18  const bool transactionSafe;
20 
21 public:
22  std::unique_ptr<const L1TMuonOverlapFwVersion> newObject(const std::string& objectKey,
23  const L1TMuonOverlapFwVersionO2ORcd& record) override;
24 
26  ~L1TMuonOverlapFwVersionOnlineProd(void) override = default;
27 };
28 
29 void replaceAll(std::string& str, const std::string& from, const std::string& to) {
30  if (from.empty())
31  return;
32  size_t start_pos = 0;
33  while ((start_pos = str.find(from, start_pos)) != std::string::npos) {
34  str.replace(start_pos, from.length(), to);
35  start_pos += to.length();
36  }
37 }
38 
39 void removeAll(std::string& str, const std::string& from, const std::string& to) {
40  if (from.empty())
41  return;
42  size_t start_pos = 0;
43  while ((start_pos = str.find(from, start_pos)) != std::string::npos) {
44  size_t end_pos = str.find(to) + to.length();
45  int length = end_pos - start_pos;
46  str.replace(start_pos, length, "");
47  }
48 }
49 
52  transactionSafe(iConfig.getParameter<bool>("transactionSafe")),
53  baseSettings_token(wrappedSetWhatProduced(iConfig).consumes()) {}
54 
55 std::unique_ptr<const L1TMuonOverlapFwVersion> L1TMuonOverlapFwVersionOnlineProd::newObject(
57  const L1TMuonOverlapFwVersionRcd& baseRcd = record.template getRecord<L1TMuonOverlapFwVersionRcd>();
58  auto const& baseSettings = baseRcd.get(baseSettings_token);
59 
60  if (objectKey.empty()) {
61  edm::LogError("L1-O2O: L1TMuonOverlapFwVersionOnlineProd")
62  << "Key is empty, returning empty L1TMuonOverlapFwVersion";
63  if (transactionSafe)
64  throw std::runtime_error("SummaryForFunctionManager: OMTF | Faulty | Empty objectKey");
65  else {
66  edm::LogError("L1-O2O: L1TMuonOverlapFwVersionOnlineProd")
67  << "returning unmodified prototype of L1TMuonOverlapFwVersion";
68  return std::make_unique<const L1TMuonOverlapFwVersion>(baseSettings);
69  }
70  }
71 
72  edm::LogInfo("L1-O2O: L1TMuonOverlapFwVersionOnlineProd")
73  << "Producing L1TMuonOverlapFwVersion for key = " << objectKey;
74 
75  std::string payload, hw_fake;
76  std::string algoV_string, layersV_string, patternsV_string, synthDate;
77 
78  try {
79  payload = l1t::OnlineDBqueryHelper::fetch({"CONF"}, "OMTF_CLOBS", objectKey, m_omdsReader)["CONF"];
80 
81  } catch (std::runtime_error& e) {
82  edm::LogError("L1-O2O: L1TMuonOverlapFwVersionOnlineProd") << e.what();
83  if (transactionSafe)
84  throw std::runtime_error(std::string("SummaryForFunctionManager: OMTF | Faulty | ") + e.what());
85  else {
86  edm::LogError("L1-O2O: L1TMuonOverlapFwVersionOnlineProd")
87  << "returning unmodified prototype of L1TMuonOverlapFwVersion";
88  return std::make_unique<const L1TMuonOverlapFwVersion>(baseSettings);
89  }
90  }
91  // for debugging dump the configs to local files
92  {
93  std::ofstream output(std::string("/tmp/").append(objectKey.substr(0, objectKey.find('/'))).append(".xml"));
94  output << objectKey;
95  output.close();
96  }
97 
98  // finally push all payloads to the XML parser and construct the TrigSystem object
99  l1t::XmlConfigParser xmlRdr;
100  l1t::TriggerSystem parsedXMLs;
101 
102  try {
103  // no need to read all the HW settings, just define a dummy processor
104  hw_fake = "<system id=\"OMTF\"> </system>";
105  xmlRdr.readDOMFromString(hw_fake);
106  parsedXMLs.addProcessor("processors", "processors", "all_crates", "all_slots");
107  xmlRdr.readRootElement(parsedXMLs);
108 
109  // INFRA payload needs some editing to be suitable for the standard XML parser
110  replaceAll(payload, "infra", "algo");
111  removeAll(payload, "<context id=\"daq", "</context>");
112  removeAll(payload, "<context id=\"OMTF", "</context>");
113  xmlRdr.readDOMFromString(payload);
114  xmlRdr.readRootElement(parsedXMLs);
115 
116  parsedXMLs.setConfigured();
117 
118  } catch (std::runtime_error& e) {
119  edm::LogError("L1-O2O: L1TMuonOverlapFwVersionOnlineProd") << e.what();
120  if (transactionSafe)
121  throw std::runtime_error(std::string("SummaryForFunctionManager: OMTF | Faulty at parsing XML | ") + e.what());
122  else {
123  edm::LogError("L1-O2O: L1TMuonOverlapFwVersionOnlineProd")
124  << "returning unmodified prototype of L1TMuonOverlapFwVersion";
125  return std::make_unique<const L1TMuonOverlapFwVersion>(baseSettings);
126  }
127  }
128 
129  std::map<std::string, l1t::Parameter> conf = parsedXMLs.getParameters("processors");
130  algoV_string = conf["algorithmVer"].getValueAsStr();
131  layersV_string = conf["layersVer"].getValueAsStr();
132  patternsV_string = conf["patternsVer"].getValueAsStr();
133  synthDate = conf["synthDate"].getValueAsStr();
134 
135  unsigned algoV, layersV, patternsV;
136  std::stringstream ssalgoV, sslayersV, sspatternsV;
137  ssalgoV << std::hex << algoV_string.c_str();
138  ssalgoV >> algoV;
139  sslayersV << std::hex << layersV_string.c_str();
140  sslayersV >> layersV;
141  sspatternsV << std::hex << patternsV_string.c_str();
142  sspatternsV >> patternsV;
143  auto retval = std::make_unique<const L1TMuonOverlapFwVersion>(algoV, layersV, patternsV, synthDate);
144 
145  edm::LogInfo("L1-O2O: L1TMuonOverlapFwVersionOnlineProd")
146  << "SummaryForFunctionManager: OMTF | OK | All looks good";
147  return retval;
148 }
149 
150 //define this as a plug-in
void setConfigured(bool state=true) noexcept
Definition: TriggerSystem.h:74
Log< level::Error, false > LogError
PRODUCT const & get(ESGetToken< PRODUCT, T > const &iToken) const
void readDOMFromString(const std::string &str, xercesc::DOMDocument *&doc)
const std::map< std::string, Parameter > & getParameters(const char *processor) const
void replaceAll(std::string &str, const std::string &from, const std::string &to)
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:61
std::unique_ptr< const L1TMuonOverlapFwVersion > newObject(const std::string &objectKey, const L1TMuonOverlapFwVersionO2ORcd &record) override
Log< level::Info, false > LogInfo
L1TMuonOverlapFwVersionOnlineProd(const edm::ParameterSet &)
void readRootElement(TriggerSystem &aTriggerSystem, const std::string &sysId="")
void removeAll(std::string &str, const std::string &from, const std::string &to)
void addProcessor(const char *processor, const char *role, const char *crate, const char *slot)
Definition: output.py:1
#define str(s)
const edm::ESGetToken< L1TMuonOverlapFwVersion, L1TMuonOverlapFwVersionRcd > baseSettings_token