File indexing completed on 2024-09-07 04:37:16
0001 #ifndef SISTRIPPOPCON_CONFIGDB_HANDLER_H
0002 #define SISTRIPPOPCON_CONFIGDB_HANDLER_H
0003
0004 #include "FWCore/ParameterSet/interface/ParameterSetfwd.h"
0005 #include "FWCore/ServiceRegistry/interface/Service.h"
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 #include "FWCore/ParameterSet/interface/ParameterSetfwd.h"
0008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0009
0010 #include "CondCore/PopCon/interface/PopConSourceHandler.h"
0011 #include "CondCore/CondDB/interface/Types.h"
0012
0013 #include "OnlineDB/SiStripESSources/interface/SiStripCondObjBuilderFromDb.h"
0014 #include "OnlineDB/SiStripConfigDb/interface/SiStripDbParams.h"
0015 #include "OnlineDB/SiStripConfigDb/interface/SiStripPartition.h"
0016
0017 #include <sstream>
0018 #include <vector>
0019 #include <string>
0020 #include <iostream>
0021 #include <typeinfo>
0022
0023 namespace popcon {
0024
0025 template <typename T>
0026 class SiStripPopConConfigDbObjHandler : public popcon::PopConSourceHandler<T> {
0027 public:
0028
0029
0030 SiStripPopConConfigDbObjHandler(const edm::ParameterSet& pset)
0031 : m_name(pset.getUntrackedParameter<std::string>("name", "SiStripPopPopConConfigDbObjHandler")),
0032 m_since(pset.getUntrackedParameter<uint32_t>("since", 5)),
0033 m_debugMode(pset.getUntrackedParameter<bool>("debug", false)) {}
0034
0035
0036
0037 ~SiStripPopConConfigDbObjHandler() override {}
0038
0039
0040
0041 void getNewObjects() override {
0042 edm::LogInfo("SiStripPopPopConConfigDbObjHandler") << "[getNewObjects] for PopCon application " << m_name;
0043
0044 if (m_debugMode) {
0045 std::stringstream ss;
0046 ss << "\n\n------- " << m_name << " - > getNewObjects\n";
0047 if (this->tagInfo().size) {
0048
0049 ss << "got offlineInfo" << this->tagInfo().name << ", size " << this->tagInfo().size
0050 << " , last object valid since " << this->tagInfo().lastInterval.since << " token "
0051 << this->tagInfo().lastInterval.payloadId << "\n\n UserText " << this->userTextLog() << "\n LogDBEntry \n"
0052 << this->logDBEntry().logId << "\n"
0053 << this->logDBEntry().destinationDB << "\n"
0054 << this->logDBEntry().provenance << "\n"
0055 << this->logDBEntry().usertext << "\n"
0056 << this->logDBEntry().iovtag << "\n"
0057 << this->logDBEntry().iovtimetype << "\n"
0058 << this->logDBEntry().payloadIdx << "\n"
0059 << this->logDBEntry().payloadClass << "\n"
0060 << this->logDBEntry().payloadToken << "\n"
0061 << this->logDBEntry().exectime << "\n"
0062 << this->logDBEntry().execmessage << "\n"
0063 << "\n\n-- user text "
0064 << this->logDBEntry().usertext.substr(this->logDBEntry().usertext.find_last_of('@'));
0065 } else {
0066 ss << " First object for this tag ";
0067 }
0068 edm::LogInfo("SiStripPopPopConConfigDbObjHandler") << ss.str();
0069 }
0070 if (isTransferNeeded())
0071 setForTransfer();
0072
0073 edm::LogInfo("SiStripPopPopConConfigDbObjHandler")
0074 << "[getNewObjects] for PopCon application " << m_name << " Done\n--------------\n";
0075 }
0076
0077
0078
0079 std::string id() const override { return m_name; }
0080
0081
0082
0083 bool isTransferNeeded() {
0084 edm::LogInfo("SiStripPopPopConConfigDbObjHandler")
0085 << "[isTransferNeeded] checking for transfer: " << typeid(T).name() << std::endl;
0086 std::stringstream ss_logdb, ss;
0087
0088
0089 if (!this->logDBEntry().usertext.empty())
0090 ss_logdb << this->logDBEntry().usertext.substr(this->logDBEntry().usertext.find_first_of('@'));
0091 else
0092 ss_logdb << "";
0093
0094 std::string label = "";
0095 if (typeid(T) == typeid(SiStripFedCabling))
0096 label = "Cabling";
0097
0098 if (typeid(T) == typeid(SiStripApvGain))
0099 label = "ApvTiming";
0100
0101 if (typeid(T) == typeid(SiStripLatency))
0102 label = "ApvLatency";
0103
0104 if (!condObjBuilder->checkForCompatibility(ss_logdb, ss, label)) {
0105
0106 edm::LogInfo("SiStripPopPopConConfigDbObjHandler")
0107 << "[isTransferNeeded] the selected conditions are already uploaded in the last iov ("
0108 << this->tagInfo().lastInterval.since << ") open for the object " << this->logDBEntry().payloadClass
0109 << " in the db " << this->logDBEntry().destinationDB << " parameters: " << ss_logdb.str()
0110 << "\n NO TRANSFER NEEDED";
0111 return false;
0112 }
0113
0114 this->m_userTextLog = ss.str();
0115 edm::LogInfo("SiStripPopPopConConfigDbObjHandler")
0116 << "[isTransferNeeded] the selected conditions will be uploaded: " << ss.str()
0117 << "\n Going to Upload: " << ss.str() << "\n Last Upload: " << ss_logdb.str() << "\n Fine";
0118
0119 return true;
0120 }
0121
0122
0123
0124 void setForTransfer() {
0125 edm::LogInfo("SiStripPopPopConConfigDbObjHandler")
0126 << "[setForTransfer] " << m_name << " getting data to be transferred " << std::endl;
0127
0128 T* obj = nullptr;
0129 condObjBuilder->getValue(obj);
0130
0131 edm::LogInfo("SiStripPopPopConConfigDbObjHandler")
0132 << "[setForTransfer] " << m_name << " got data to be transferred from condObjBuilder " << std::endl;
0133
0134 if (!this->tagInfo().size)
0135 m_since = 1;
0136 else if (m_debugMode)
0137 m_since = this->tagInfo().lastInterval.since + 1;
0138 edm::LogInfo("SiStripPopPopConConfigDbObjHandler") << "[setForTransfer] setting since = " << m_since << std::endl;
0139
0140 if (obj != nullptr) {
0141 edm::LogInfo("SiStripPopPopConConfigDbObjHandler") << "[setForTransfer] filling map m_to_transfer" << std::endl;
0142 this->m_to_transfer.push_back(std::make_pair(obj, m_since));
0143 } else {
0144 edm::LogError("SiStripPopPopConConfigDbObjHandler")
0145 << "[setForTransfer] " << m_name << " : NULL pointer of obj " << typeid(T).name()
0146 << " reported by SiStripCondObjBuilderFromDb\n Transfer aborted" << std::endl;
0147 }
0148 }
0149
0150 private:
0151
0152 std::string m_name;
0153 unsigned long long m_since;
0154 bool m_debugMode;
0155 edm::Service<SiStripCondObjBuilderFromDb> condObjBuilder;
0156 };
0157 }
0158
0159 #endif