File indexing completed on 2024-04-06 12:02:51
0001 #ifndef PopConBTransitionSourceHandler_H
0002 #define PopConBTransitionSourceHandler_H
0003
0004 #include "CondCore/CondDB/interface/ConnectionPool.h"
0005 #include "CondCore/CondDB/interface/IOVProxy.h"
0006 #include "CondCore/PopCon/interface/PopConSourceHandler.h"
0007 #include "CondFormats/RunInfo/interface/RunInfo.h"
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0010 #include <string>
0011
0012 namespace popcon {
0013 template <class T>
0014 class PopConESTransitionSourceHandler : public PopConSourceHandler<T> {
0015 public:
0016 PopConESTransitionSourceHandler(edm::ParameterSet const& pset)
0017 : m_run(pset.getParameter<edm::ParameterSet>("ESTransition").getParameter<unsigned long long>("runNumber")),
0018
0019 m_tagForRunInfo(
0020 pset.getParameter<edm::ParameterSet>("ESTransition").getParameter<std::string>("tagForRunInfo")),
0021 m_ESGain(pset.getParameter<edm::ParameterSet>("ESTransition").getParameter<std::string>("ESGain")),
0022 m_tagForLowGain(
0023 pset.getParameter<edm::ParameterSet>("ESTransition").getParameter<std::string>("ESLowGainTag")),
0024 m_tagForHighGain(
0025 pset.getParameter<edm::ParameterSet>("ESTransition").getParameter<std::string>("ESHighGainTag")),
0026 m_connectionString(pset.getParameter<edm::ParameterSet>("ESTransition").getParameter<std::string>("connect")),
0027 m_connectionPset(
0028 pset.getParameter<edm::ParameterSet>("ESTransition").getParameter<edm::ParameterSet>("DBParameters")) {
0029 edm::LogInfo("PopConESTransitionSourceHandler") << "["
0030 << "PopConESTransitionSourceHandler:" << __func__ << "]: "
0031 << "Initialising Connection Pool" << std::endl;
0032 m_connection.setParameters(m_connectionPset);
0033 m_connection.configure();
0034 }
0035
0036 ~PopConESTransitionSourceHandler() override {}
0037
0038 std::string id() const final { return std::string("PopConESTransitionSourceHandler"); }
0039
0040 bool checkLowGain() {
0041
0042 bool isLowGain = true;
0043 cond::persistency::Session& session = PopConSourceHandler<T>::dbSession();
0044
0045 cond::persistency::TransactionScope trans(session.transaction());
0046 edm::LogInfo("PopConESTransitionSourceHandler")
0047 << "["
0048 << "PopConESTransitionSourceHandler::" << __func__ << "]: "
0049 << "Loading tag for RunInfo " << m_tagForRunInfo << " and IOV valid for run number: " << m_run << std::endl;
0050 cond::persistency::IOVProxy iov = session.readIov(m_tagForRunInfo);
0051 cond::Iov_t currentIov = iov.getInterval(m_run);
0052 LogDebug("PopConESTransitionSourceHandler")
0053 << "Loaded IOV sequence from tag " << m_tagForRunInfo << " with size: " << iov.loadedSize()
0054 << ", IOV valid for run number " << m_run << " starting from: " << currentIov.since
0055 << ", with corresponding payload hash: " << currentIov.payloadId << std::endl;
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067 if (m_ESGain == "HIGH") {
0068 isLowGain = false;
0069 } else {
0070 isLowGain = true;
0071 }
0072 trans.close();
0073 return isLowGain;
0074 }
0075
0076 virtual void getObjectsForESTransition(bool isLowGain) {
0077
0078 cond::persistency::Session& session = PopConSourceHandler<T>::dbSession();
0079 cond::persistency::TransactionScope trans(session.transaction());
0080 edm::LogInfo("PopConESTransitionSourceHandler") << "["
0081 << "PopConESTransitionSourceHandler::" << __func__ << "]: "
0082 << "Loading tag for ES " << (isLowGain ? "LowGain" : "HighGain")
0083 << ": " << (isLowGain ? m_tagForLowGain : m_tagForHighGain)
0084 << " and IOV valid for run number: " << m_run << std::endl;
0085 cond::persistency::IOVProxy iov = session.readIov(isLowGain ? m_tagForLowGain : m_tagForHighGain);
0086 cond::Iov_t currentIov = iov.getInterval(m_run);
0087 LogDebug("PopConESTransitionSourceHandler")
0088 << "Loaded IOV sequence from tag " << (isLowGain ? m_tagForLowGain : m_tagForHighGain)
0089 << " with size: " << iov.loadedSize() << ", IOV valid for run number " << m_run
0090 << " starting from: " << currentIov.since << ", with corresponding payload hash: " << currentIov.payloadId
0091 << std::endl;
0092 std::string destTag = this->tagInfo().name;
0093 if (currentIov.payloadId != this->tagInfo().lastInterval.payloadId) {
0094 std::ostringstream ss;
0095 ss << "Adding iov with since " << m_run << " pointing to hash " << currentIov.payloadId
0096 << " corresponding to the ES Gain " << (isLowGain ? "LOW" : "HIGH");
0097 edm::LogInfo("PopConESTransitionSourceHandler")
0098 << "["
0099 << "PopConESTransitionSourceHandler::" << __func__ << "]: " << ss.str() << std::endl;
0100 cond::persistency::IOVEditor editor;
0101 if (session.existsIov(destTag)) {
0102 editor = session.editIov(destTag);
0103 } else {
0104 editor = session.createIov<T>(destTag, iov.tagInfo().timeType);
0105 editor.setDescription("Tag created by PopConESTransitionSourceHandler");
0106 }
0107 editor.insert(m_run, currentIov.payloadId);
0108 editor.flush();
0109 this->m_userTextLog = ss.str();
0110 } else {
0111 edm::LogInfo("PopConESTransitionSourceHandler")
0112 << "["
0113 << "PopConESTransitionSourceHandler::" << __func__ << "]: "
0114 << "The payload with hash " << currentIov.payloadId << " corresponding to ES Gain"
0115 << (isLowGain ? "LOW" : "HIGH") << " is still valid for run " << m_run << " in the destination tag "
0116 << destTag << ".\nNo transfer needed." << std::endl;
0117 }
0118 trans.close();
0119 }
0120
0121 void getNewObjects() final {
0122
0123 edm::LogInfo("PopConESTransitionSourceHandler")
0124 << "["
0125 << "PopConESTransitionSourceHandler::" << __func__ << "]: "
0126 << "Destination Tag Info: name " << this->tagInfo().name << ", size " << this->tagInfo().size
0127 << ", last object valid since " << this->tagInfo().lastInterval.since << ", hash "
0128 << this->tagInfo().lastInterval.payloadId << std::endl;
0129
0130
0131
0132
0133 if (this->tagInfo().size > 0 && this->tagInfo().lastInterval.since >= m_run) {
0134 edm::LogInfo("PopConESTransitionSourceHandler")
0135 << "["
0136 << "PopConESTransitionSourceHandler::" << __func__ << "]: "
0137 << "last IOV " << this->tagInfo().lastInterval.since
0138 << (this->tagInfo().lastInterval.since == m_run ? " is equal to" : " is larger than")
0139 << " the run proposed for insertion " << m_run << ". No transfer needed." << std::endl;
0140 return;
0141 }
0142 bool isLowGain = checkLowGain();
0143 getObjectsForESTransition(isLowGain);
0144 edm::LogInfo("PopConESTransitionSourceHandler") << "["
0145 << "PopConESTransitionSourceHandler::" << __func__ << "]: "
0146 << "END." << std::endl;
0147 }
0148
0149 private:
0150 unsigned long long m_run;
0151 double m_currentThreshold;
0152
0153 std::string m_tagForRunInfo;
0154
0155 std::string m_ESGain;
0156 std::string m_tagForLowGain;
0157 std::string m_tagForHighGain;
0158 std::string m_connectionString;
0159 edm::ParameterSet m_connectionPset;
0160 cond::persistency::ConnectionPool m_connection;
0161 };
0162 }
0163
0164 #endif