File indexing completed on 2024-09-07 04:37:16
0001 #ifndef SISTRIPPOPCON_UNITTEST_HANDLER_GAIN_H
0002 #define SISTRIPPOPCON_UNITTEST_HANDLER_GAIN_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 #include <ctime>
0023
0024 #include "CLHEP/Random/RandFlat.h"
0025 #include "CLHEP/Random/RandGauss.h"
0026
0027 #include "CondFormats/SiStripObjects/interface/SiStripNoises.h"
0028 #include "CondFormats/SiStripObjects/interface/SiStripApvGain.h"
0029 #include "CalibTracker/SiStripCommon/interface/SiStripDetInfoFileReader.h"
0030
0031 namespace popcon {
0032
0033 template <typename T>
0034 class SiStripPopConHandlerUnitTestGain : public popcon::PopConSourceHandler<T> {
0035 public:
0036 enum DataType { UNDEFINED = 0, _Cabling = 1, _Pedestal = 2, _Noise = 3, _Threshold = 4, _BadStrip = 5, _Gain = 6 };
0037
0038
0039
0040 SiStripPopConHandlerUnitTestGain(const edm::ParameterSet& pset)
0041 : m_name(pset.getUntrackedParameter<std::string>("name", "SiStripPopPopConConfigDbObjHandler")),
0042 m_since(pset.getUntrackedParameter<uint32_t>("since", 5)),
0043 m_debugMode(pset.getUntrackedParameter<bool>("debug", true)) {}
0044
0045
0046
0047 ~SiStripPopConHandlerUnitTestGain() override {}
0048
0049
0050
0051 void getNewObjects() override {
0052 edm::LogInfo("SiStripPopPopConConfigDbObjHandler") << "[getNewObjects] for PopCon application " << m_name;
0053
0054 if (m_debugMode) {
0055 std::stringstream ss;
0056 ss << "\n\n------- " << m_name << " - > getNewObjects\n";
0057 if (this->tagInfo().size) {
0058
0059 ss << "got offlineInfo" << this->tagInfo().name << ", size " << this->tagInfo().size
0060 << " , last object valid since " << this->tagInfo().lastInterval.since << " token "
0061 << this->tagInfo().lastInterval.payloadId << "\n\n UserText " << this->userTextLog() << "\n LogDBEntry \n"
0062 << this->logDBEntry().logId << "\n"
0063 << this->logDBEntry().destinationDB << "\n"
0064 << this->logDBEntry().provenance << "\n"
0065 << this->logDBEntry().usertext << "\n"
0066 << this->logDBEntry().iovtag << "\n"
0067 << this->logDBEntry().iovtimetype << "\n"
0068 << this->logDBEntry().payloadIdx << "\n"
0069 << this->logDBEntry().payloadClass << "\n"
0070 << this->logDBEntry().payloadToken << "\n"
0071 << this->logDBEntry().exectime << "\n"
0072 << this->logDBEntry().execmessage << "\n"
0073 << "\n\n-- user text "
0074 << this->logDBEntry().usertext.substr(this->logDBEntry().usertext.find_last_of('@'));
0075 } else {
0076 ss << " First object for this tag ";
0077 }
0078 edm::LogInfo("SiStripPopPopConConfigDbObjHandler") << ss.str();
0079 }
0080 if (isTransferNeeded())
0081 setForTransfer();
0082
0083 edm::LogInfo("SiStripPopPopConConfigDbObjHandler")
0084 << "[getNewObjects] for PopCon application " << m_name << " Done\n--------------\n";
0085 }
0086
0087
0088
0089 std::string id() const override { return m_name; }
0090
0091 private:
0092
0093
0094 DataType getDataType() {
0095 if (typeid(T) == typeid(SiStripFedCabling)) {
0096 edm::LogInfo("SiStripPopPopConConfigDbObjHandler")
0097 << "[getDataType] for PopCon application " << m_name << " " << typeid(T).name();
0098 return _Cabling;
0099 }
0100 return UNDEFINED;
0101 }
0102
0103
0104
0105 bool isTransferNeeded() {
0106 edm::LogInfo("SiStripPopPopConConfigDbObjHandler") << "[isTransferNeeded] checking for transfer" << std::endl;
0107 std::stringstream ss_logdb, ss;
0108 std::stringstream ss1;
0109
0110
0111 if (this->tagInfo().size)
0112 ss_logdb << this->logDBEntry().usertext.substr(this->logDBEntry().usertext.find_last_of('@'));
0113 else
0114 ss_logdb << "";
0115
0116 ss << "@ " << clock();
0117
0118 if (!strcmp(ss.str().c_str(), ss_logdb.str().c_str())) {
0119
0120 edm::LogInfo("SiStripPopPopConConfigDbObjHandler")
0121 << "[isTransferNeeded] the selected conditions are already uploaded in the last iov ("
0122 << this->tagInfo().lastInterval.since << ") open for the object " << this->logDBEntry().payloadClass
0123 << " in the db " << this->logDBEntry().destinationDB << " parameters: " << ss.str()
0124 << "\n NO TRANSFER NEEDED";
0125 return false;
0126 }
0127 this->m_userTextLog = ss.str();
0128 edm::LogInfo("SiStripPopPopConConfigDbObjHandler")
0129 << "[isTransferNeeded] the selected conditions will be uploaded: " << ss.str() << "\n A- " << ss.str()
0130 << "\n B- " << ss_logdb.str() << "\n Fine";
0131
0132 return true;
0133 }
0134
0135
0136
0137 void setForTransfer() {
0138 edm::LogInfo("SiStripPopPopConConfigDbObjHandler")
0139 << "[setForTransfer] " << m_name << " getting data to be transferred " << std::endl;
0140
0141 T* obj = nullptr;
0142
0143 fillObject(obj);
0144
0145 if (!this->tagInfo().size)
0146 m_since = 1;
0147 else if (m_debugMode)
0148 m_since = this->tagInfo().lastInterval.since + 1;
0149
0150 if (obj != nullptr) {
0151 edm::LogInfo("SiStripPopPopConConfigDbObjHandler") << "setting since = " << m_since << std::endl;
0152 this->m_to_transfer.push_back(std::make_pair(obj, m_since));
0153 } else {
0154 edm::LogError("SiStripPopPopConConfigDbObjHandler")
0155 << "[setForTransfer] " << m_name << " : NULL pointer of obj " << typeid(T).name()
0156 << " reported by SiStripCondObjBuilderFromDb\n Transfer aborted" << std::endl;
0157 }
0158 }
0159
0160 private:
0161
0162 std::string m_name;
0163 unsigned long long m_since;
0164 bool m_debugMode;
0165 edm::Service<SiStripCondObjBuilderFromDb> condObjBuilder;
0166
0167 void fillObject(T*& obj) {
0168 std::cout << __LINE__ << std::endl;
0169
0170 if (typeid(T) == typeid(SiStripApvGain)) {
0171 std::cout << __LINE__ << std::endl;
0172
0173 obj = new SiStripApvGain();
0174
0175 const auto detInfo =
0176 SiStripDetInfoFileReader::read(edm::FileInPath{SiStripDetInfoFileReader::kDefaultFile}.fullPath());
0177 int count = -1;
0178 for (const auto& it : detInfo.getAllData()) {
0179 count++;
0180
0181 SiStripApvGain::InputVector inputApvGain;
0182 for (int apv = 0; apv < it.second.nApvs; ++(++apv)) {
0183 float MeanTick = 555.;
0184 float RmsTick = 55.;
0185
0186 float tick = CLHEP::RandGauss::shoot(MeanTick, RmsTick);
0187
0188 if (count < 6)
0189 edm::LogInfo("SiStripGainBuilder") << "detid " << it.first << " \t"
0190 << " APV " << apv << " \t" << tick << " \t" << std::endl;
0191 inputApvGain.push_back(tick);
0192 inputApvGain.push_back(tick);
0193 }
0194
0195 SiStripApvGain::Range gain_range(inputApvGain.begin(), inputApvGain.end());
0196 if (!obj->put(it.first, gain_range))
0197 edm::LogError("SiStripGainBuilder") << "[SiStripGainBuilder::analyze] detid already exists" << std::endl;
0198 }
0199 }
0200 }
0201 };
0202
0203 }
0204
0205 #endif