Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:22:24

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