Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:14:23

0001 #include <iostream>
0002 #include <fstream>
0003 #include <strstream>
0004 
0005 #include "CondTools/L1TriggerExt/interface/L1ConfigOnlineProdBaseExt.h"
0006 #include "CondFormats/L1TObjects/interface/L1TMuonGlobalParams.h"
0007 #include "CondFormats/DataRecord/interface/L1TMuonGlobalParamsRcd.h"
0008 #include "CondFormats/DataRecord/interface/L1TMuonGlobalParamsO2ORcd.h"
0009 #include "L1Trigger/L1TMuon/interface/L1TMuonGlobalParamsHelper.h"
0010 #include "L1Trigger/L1TMuon/interface/L1TMuonGlobalParams_PUBLIC.h"
0011 #include "L1Trigger/L1TCommon/interface/TriggerSystem.h"
0012 #include "L1Trigger/L1TCommon/interface/XmlConfigParser.h"
0013 #include "OnlineDBqueryHelper.h"
0014 
0015 class L1TMuonGlobalParamsOnlineProd : public L1ConfigOnlineProdBaseExt<L1TMuonGlobalParamsO2ORcd, L1TMuonGlobalParams> {
0016 private:
0017   const bool transactionSafe;
0018   const edm::ESGetToken<L1TMuonGlobalParams, L1TMuonGlobalParamsRcd> baseSettings_token;
0019 
0020 public:
0021   std::unique_ptr<const L1TMuonGlobalParams> newObject(const std::string &objectKey,
0022                                                        const L1TMuonGlobalParamsO2ORcd &record) override;
0023 
0024   L1TMuonGlobalParamsOnlineProd(const edm::ParameterSet &);
0025   ~L1TMuonGlobalParamsOnlineProd(void) override {}
0026 };
0027 
0028 L1TMuonGlobalParamsOnlineProd::L1TMuonGlobalParamsOnlineProd(const edm::ParameterSet &iConfig)
0029     : L1ConfigOnlineProdBaseExt<L1TMuonGlobalParamsO2ORcd, L1TMuonGlobalParams>(iConfig),
0030       transactionSafe(iConfig.getParameter<bool>("transactionSafe")),
0031       baseSettings_token(wrappedSetWhatProduced(iConfig).consumes()) {}
0032 
0033 std::unique_ptr<const L1TMuonGlobalParams> L1TMuonGlobalParamsOnlineProd::newObject(
0034     const std::string &objectKey, const L1TMuonGlobalParamsO2ORcd &record) {
0035   const L1TMuonGlobalParamsRcd &baseRcd = record.template getRecord<L1TMuonGlobalParamsRcd>();
0036   auto const &baseSettings = baseRcd.get(baseSettings_token);
0037 
0038   if (objectKey.empty()) {
0039     edm::LogError("L1-O2O: L1TMuonGlobalParamsOnlineProd") << "Key is empty";
0040     if (transactionSafe)
0041       throw std::runtime_error("SummaryForFunctionManager: uGMT  | Faulty  | Empty objectKey");
0042     else {
0043       edm::LogError("L1-O2O: L1TMuonGlobalParams") << "returning unmodified prototype of L1TMuonGlobalParams";
0044       return std::make_unique<const L1TMuonGlobalParams>(baseSettings);
0045     }
0046   }
0047 
0048   std::string tscKey = objectKey.substr(0, objectKey.find(':'));
0049   std::string rsKey = objectKey.substr(objectKey.find(':') + 1, std::string::npos);
0050 
0051   edm::LogInfo("L1-O2O: L1TMuonGlobalParamsOnlineProd")
0052       << "Producing L1TMuonGlobalParams with TSC key =" << tscKey << " and RS key = " << rsKey;
0053 
0054   std::string algo_key, hw_key;
0055   std::string hw_payload;
0056   std::map<std::string, std::string> rs_payloads, algo_payloads;
0057   try {
0058     std::map<std::string, std::string> keys =
0059         l1t::OnlineDBqueryHelper::fetch({"ALGO", "HW"}, "UGMT_KEYS", tscKey, m_omdsReader);
0060     algo_key = keys["ALGO"];
0061     hw_key = keys["HW"];
0062 
0063     hw_payload = l1t::OnlineDBqueryHelper::fetch({"CONF"}, "UGMT_CLOBS", hw_key, m_omdsReader)["CONF"];
0064 
0065     std::map<std::string, std::string> rsKeys =
0066         l1t::OnlineDBqueryHelper::fetch({"MP7", "MP7_MONI", "AMC13_MONI"}, "UGMT_RS_KEYS", rsKey, m_omdsReader);
0067 
0068     std::map<std::string, std::string> algoKeys =
0069         l1t::OnlineDBqueryHelper::fetch({"MP7", "LUTS"}, "UGMT_ALGO_KEYS", algo_key, m_omdsReader);
0070 
0071     for (auto &key : rsKeys)
0072       rs_payloads[key.second] =
0073           l1t::OnlineDBqueryHelper::fetch({"CONF"}, "UGMT_CLOBS", key.second, m_omdsReader)["CONF"];
0074 
0075     for (auto &key : algoKeys)
0076       algo_payloads[key.second] =
0077           l1t::OnlineDBqueryHelper::fetch({"CONF"}, "UGMT_CLOBS", key.second, m_omdsReader)["CONF"];
0078   } catch (std::runtime_error &e) {
0079     edm::LogError("L1-O2O: L1TMuonGlobalParamsOnlineProd") << e.what();
0080     if (transactionSafe)
0081       throw std::runtime_error("SummaryForFunctionManager: uGMT  | Faulty  | Broken key");
0082     else {
0083       edm::LogError("L1-O2O: L1TMuonGlobalParamsOnlineProd") << "returning unmodified prototype of L1TMuonGlobalParams";
0084       return std::make_unique<const L1TMuonGlobalParams>(baseSettings);
0085     }
0086   }
0087 
0088   // for debugging dump the configs to local files
0089   {
0090     std::ofstream output(std::string("/tmp/").append(hw_key.substr(0, hw_key.find('/'))).append(".xml"));
0091     output << hw_payload;
0092     output.close();
0093   }
0094   for (auto &conf : rs_payloads) {
0095     std::ofstream output(std::string("/tmp/").append(conf.first.substr(0, conf.first.find("/"))).append(".xml"));
0096     output << conf.second;
0097     output.close();
0098   }
0099   for (auto &conf : algo_payloads) {
0100     std::ofstream output(std::string("/tmp/").append(conf.first.substr(0, conf.first.find("/"))).append(".xml"));
0101     output << conf.second;
0102     output.close();
0103   }
0104 
0105   // finally, push all payloads to the XML parser and construct the TrigSystem objects with each of those
0106   l1t::XmlConfigParser xmlRdr;
0107   l1t::TriggerSystem trgSys;
0108 
0109   try {
0110     // HW settings should always go first
0111     xmlRdr.readDOMFromString(hw_payload);
0112     xmlRdr.readRootElement(trgSys);
0113 
0114     // now let's parse ALGO and then RS settings
0115     for (auto &conf : algo_payloads) {
0116       xmlRdr.readDOMFromString(conf.second);
0117       xmlRdr.readRootElement(trgSys);
0118     }
0119     for (auto &conf : rs_payloads) {
0120       xmlRdr.readDOMFromString(conf.second);
0121       xmlRdr.readRootElement(trgSys);
0122     }
0123     trgSys.setConfigured();
0124   } catch (std::runtime_error &e) {
0125     edm::LogError("L1-O2O: L1TMuonGlobalParamsOnlineProd") << e.what();
0126     if (transactionSafe)
0127       throw std::runtime_error("SummaryForFunctionManager: uGMT  | Faulty  | Cannot parse XMLs");
0128     else {
0129       edm::LogError("L1-O2O: L1TMuonGlobalParamsOnlineProd") << "returning unmodified prototype of L1TMuonGlobalParams";
0130       return std::make_unique<const L1TMuonGlobalParams>(baseSettings);
0131     }
0132   }
0133 
0134   L1TMuonGlobalParamsHelper m_params_helper(baseSettings);
0135   try {
0136     m_params_helper.loadFromOnline(trgSys);
0137   } catch (std::runtime_error &e) {
0138     edm::LogError("L1-O2O: L1TMuonGlobalParamsOnlineProd") << e.what();
0139     if (transactionSafe)
0140       throw std::runtime_error("SummaryForFunctionManager: uGMT  | Faulty  | Cannot run helper");
0141     else {
0142       edm::LogError("L1-O2O: L1TMuonGlobalParamsOnlineProd") << "returning unmodified prototype of L1TMuonGlobalParams";
0143       return std::make_unique<const L1TMuonGlobalParams>(baseSettings);
0144     }
0145   }
0146 
0147   auto retval = std::make_unique<const L1TMuonGlobalParams>(cast_to_L1TMuonGlobalParams(m_params_helper));
0148 
0149   edm::LogInfo("L1-O2O: L1TMuonGlobalParamsOnlineProd")
0150       << "SummaryForFunctionManager: uGMT  | OK      | All looks good";
0151   return retval;
0152 }
0153 
0154 //define this as a plug-in
0155 DEFINE_FWK_EVENTSETUP_MODULE(L1TMuonGlobalParamsOnlineProd);