Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:31:14

0001 #include <iostream>
0002 #include <fstream>
0003 #include <ctime>
0004 #include <string>
0005 #include <map>
0006 
0007 #include "CondTools/L1TriggerExt/interface/L1ConfigOnlineProdBaseExt.h"
0008 #include "CondFormats/L1TObjects/interface/L1TMuonEndCapParams.h"
0009 #include "CondFormats/DataRecord/interface/L1TMuonEndCapParamsRcd.h"
0010 #include "CondFormats/DataRecord/interface/L1TMuonEndCapParamsO2ORcd.h"
0011 #include "L1Trigger/L1TCommon/interface/TriggerSystem.h"
0012 #include "L1Trigger/L1TCommon/interface/XmlConfigParser.h"
0013 #include "OnlineDBqueryHelper.h"
0014 
0015 class L1TMuonEndCapParamsOnlineProd : public L1ConfigOnlineProdBaseExt<L1TMuonEndCapParamsO2ORcd, L1TMuonEndCapParams> {
0016 private:
0017   const bool transactionSafe;
0018   const edm::ESGetToken<L1TMuonEndCapParams, L1TMuonEndCapParamsRcd> baseSettings_token;
0019 
0020 public:
0021   std::unique_ptr<const L1TMuonEndCapParams> newObject(const std::string& objectKey,
0022                                                        const L1TMuonEndCapParamsO2ORcd& record) override;
0023 
0024   L1TMuonEndCapParamsOnlineProd(const edm::ParameterSet&);
0025   ~L1TMuonEndCapParamsOnlineProd(void) override {}
0026 };
0027 
0028 L1TMuonEndCapParamsOnlineProd::L1TMuonEndCapParamsOnlineProd(const edm::ParameterSet& iConfig)
0029     : L1ConfigOnlineProdBaseExt<L1TMuonEndCapParamsO2ORcd, L1TMuonEndCapParams>(iConfig),
0030       transactionSafe(iConfig.getParameter<bool>("transactionSafe")),
0031       baseSettings_token(wrappedSetWhatProduced(iConfig).consumes()) {}
0032 
0033 std::unique_ptr<const L1TMuonEndCapParams> L1TMuonEndCapParamsOnlineProd::newObject(
0034     const std::string& objectKey, const L1TMuonEndCapParamsO2ORcd& record) {
0035   const L1TMuonEndCapParamsRcd& baseRcd = record.template getRecord<L1TMuonEndCapParamsRcd>();
0036   auto const& baseSettings = baseRcd.get(baseSettings_token);
0037 
0038   if (objectKey.empty()) {
0039     edm::LogError("L1-O2O: L1TMuonEndCapParamsOnlineProd") << "Key is empty";
0040     if (transactionSafe)
0041       throw std::runtime_error("SummaryForFunctionManager: EMTF  | Faulty  | Empty objectKey");
0042     else {
0043       edm::LogError("L1-O2O: L1TMuonEndCapParamsOnlineProd") << "returning unmodified prototype of L1TMuonEndCapParams";
0044       return std::make_unique<const L1TMuonEndCapParams>(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: L1TMuonEndCapParamsOnlineProd")
0052       << "Producing L1TMuonEndCapParams with TSC key = " << tscKey << " and RS key = " << rsKey;
0053 
0054   std::string algo_key, hw_key;
0055   std::string algo_payload, hw_payload;
0056   try {
0057     std::map<std::string, std::string> keys =
0058         l1t::OnlineDBqueryHelper::fetch({"HW", "ALGO"}, "EMTF_KEYS", tscKey, m_omdsReader);
0059 
0060     hw_key = keys["HW"];
0061     algo_key = keys["ALGO"];
0062 
0063     hw_payload = l1t::OnlineDBqueryHelper::fetch({"CONF"}, "EMTF_CLOBS", hw_key, m_omdsReader)["CONF"];
0064 
0065     algo_payload = l1t::OnlineDBqueryHelper::fetch({"CONF"}, "EMTF_CLOBS", algo_key, m_omdsReader)["CONF"];
0066 
0067   } catch (std::runtime_error& e) {
0068     edm::LogError("L1-O2O: L1TMuonEndCapParamsOnlineProd") << e.what();
0069     if (transactionSafe)
0070       throw std::runtime_error("SummaryForFunctionManager: EMTF  | Faulty  | Broken key");
0071     else {
0072       edm::LogError("L1-O2O: L1TMuonEndCapParamsOnlineProd") << "returning unmodified prototype of L1TMuonEndCapParams";
0073       return std::make_unique<const L1TMuonEndCapParams>(baseSettings);
0074     }
0075   }
0076 
0077   // for debugging purposes dump the configs to local files
0078   {
0079     std::ofstream output(std::string("/tmp/").append(hw_key.substr(0, hw_key.find('/'))).append(".xml"));
0080     output << hw_payload;
0081     output.close();
0082   }
0083   {
0084     std::ofstream output(std::string("/tmp/").append(algo_key.substr(0, algo_key.find('/'))).append(".xml"));
0085     output << algo_payload;
0086     output.close();
0087   }
0088 
0089   l1t::XmlConfigParser xmlRdr;
0090   l1t::TriggerSystem trgSys;
0091 
0092   try {
0093     xmlRdr.readDOMFromString(hw_payload);
0094     xmlRdr.readRootElement(trgSys);
0095 
0096     xmlRdr.readDOMFromString(algo_payload);
0097     xmlRdr.readRootElement(trgSys);
0098 
0099     trgSys.setConfigured();
0100   } catch (std::runtime_error& e) {
0101     edm::LogError("L1-O2O: L1TMuonEndCapParamsOnlineProd") << e.what();
0102     if (transactionSafe)
0103       throw std::runtime_error("SummaryForFunctionManager: EMTF  | Faulty  | Cannot parse XMLs");
0104     else {
0105       edm::LogError("L1-O2O: L1TMuonEndCapParamsOnlineProd") << "returning unmodified prototype of L1TMuonEndCapParams";
0106       return std::make_unique<const L1TMuonEndCapParams>(baseSettings);
0107     }
0108   }
0109 
0110   // Changed from "EMTF-1" to "EMTFp1", but is this backwards compatible? Does it need to be? - AWB 10.04.2018
0111   std::map<std::string, l1t::Parameter> conf = trgSys.getParameters("EMTFp1");  // any processor will do
0112   // if (conf still empty) conf = trgSys.getParameters("EMTF+1"); // Should add some conditional for backwards-compatibility
0113 
0114   std::string core_fwv = conf["core_firmware_version"].getValueAsStr();
0115   tm brokenTime;
0116   strptime(core_fwv.c_str(), "%Y-%m-%d %T", &brokenTime);
0117   time_t fw_sinceEpoch = timegm(&brokenTime);
0118 
0119   //    std::string pclut_v = conf["pc_lut_version"].getValueAsStr();
0120   //    strptime(pclut_v.c_str(), "%Y-%m-%d", &brokenTime);
0121   //    time_t pclut_sinceEpoch = timegm(&brokenTime);
0122 
0123   auto retval = std::make_unique<L1TMuonEndCapParams>();
0124 
0125   retval->firmwareVersion_ = fw_sinceEpoch;
0126   retval->PtAssignVersion_ = conf["pt_lut_version"].getValue<unsigned int>();
0127   retval->PhiMatchWindowSt1_ = 1;  //pclut_sinceEpoch;
0128 
0129   edm::LogInfo("L1-O2O: L1TMuonEndCapParamsOnlineProd")
0130       << "SummaryForFunctionManager: EMTF  | OK      | All looks good";
0131   return retval;
0132 }
0133 
0134 //define this as a plug-in
0135 DEFINE_FWK_EVENTSETUP_MODULE(L1TMuonEndCapParamsOnlineProd);