Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:09:18

0001 #ifndef DQMOffline_CalibTracker_SiStripDQMPopConSourceHandler_H
0002 #define DQMOffline_CalibTracker_SiStripDQMPopConSourceHandler_H
0003 
0004 #include "CondCore/PopCon/interface/PopConSourceHandler.h"
0005 
0006 #include "FWCore/Framework/interface/EventSetup.h"
0007 #include "FWCore/Framework/interface/ConsumesCollector.h"
0008 #include "DQMServices/Core/interface/DQMStore.h"
0009 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0010 
0011 /**
0012   @class SiStripDQMPopConSourceHandler
0013   @author M. De Mattia
0014   @author P. David (merge service functionality into base class)
0015 
0016   Base class for SiStrip popcon::PopConSourceHandler (reading from DQM) and writing in the Database.
0017 */
0018 template <typename T>
0019 class SiStripDQMPopConSourceHandler : public popcon::PopConSourceHandler<T> {
0020 public:
0021   typedef dqm::legacy::DQMStore DQMStore;
0022 
0023   explicit SiStripDQMPopConSourceHandler(const edm::ParameterSet& pset)
0024       : m_name{pset.getUntrackedParameter<std::string>("name", "SiStripPopConDbObjHandler")},
0025         m_since{pset.getUntrackedParameter<uint32_t>("since", 5)},
0026         m_runNumber{pset.getParameter<uint32_t>("RunNb")},
0027         m_iovSequence{pset.getUntrackedParameter<bool>("iovSequence", true)}  // flag: check compatibility
0028         ,
0029         m_debugMode{pset.getUntrackedParameter<bool>("debug", false)} {}
0030 
0031   ~SiStripDQMPopConSourceHandler() override {}
0032 
0033   // popcon::PopConSourceHandler interface methods
0034   void getNewObjects() override;
0035   std::string id() const override { return m_name; }
0036 
0037   virtual T* getObj() const = 0;
0038 
0039   virtual std::string getMetaDataString() const;
0040   virtual bool checkForCompatibility(const std::string& otherMetaData) const {
0041     return otherMetaData != getMetaDataString();
0042   }
0043 
0044   // additional methods needed for SiStripPopConDQMEDHarvester
0045   virtual void initES(const edm::EventSetup&) {}
0046   virtual void dqmEndJob(DQMStore::IBooker& booker, DQMStore::IGetter& getter) {}
0047 
0048 protected:
0049   uint32_t getRunNumber() const { return m_runNumber; }
0050 
0051 private:
0052   std::string m_name;
0053   unsigned long long m_since;
0054   uint32_t m_runNumber;
0055   bool m_iovSequence;
0056   bool m_debugMode;
0057 
0058   // helper methods
0059   bool isTransferNeeded();
0060   void setForTransfer();
0061 };
0062 
0063 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0064 
0065 #include <sstream>
0066 
0067 template <typename T>
0068 void SiStripDQMPopConSourceHandler<T>::getNewObjects() {
0069   edm::LogInfo("SiStripPopConDbObjHandler")
0070       << "[SiStripPopConDbObjHandler::getNewObjects] for PopCon application " << m_name;
0071 
0072   if (m_debugMode) {
0073     std::stringstream ss;
0074     ss << "\n\n------- " << m_name << " - > getNewObjects\n";
0075     if (this->tagInfo().size) {
0076       //check whats already inside of database
0077       ss << "\ngot offlineInfo" << this->tagInfo().name << "\n size " << this->tagInfo().size
0078          << "\n last object valid since " << this->tagInfo().lastInterval.since << "\n token "
0079          << this->tagInfo().lastInterval.payloadId << "\n UserText " << this->userTextLog() << "\n LogDBEntry \n"
0080          << this->logDBEntry().logId << "\n"
0081          << this->logDBEntry().destinationDB << "\n"
0082          << this->logDBEntry().provenance << "\n"
0083          << this->logDBEntry().usertext << "\n"
0084          << this->logDBEntry().iovtag << "\n"
0085          << this->logDBEntry().iovtimetype << "\n"
0086          << this->logDBEntry().payloadIdx << "\n"
0087          << this->logDBEntry().payloadClass << "\n"
0088          << this->logDBEntry().payloadToken << "\n"
0089          << this->logDBEntry().exectime << "\n"
0090          << this->logDBEntry().execmessage << "\n";
0091       if (!this->logDBEntry().usertext.empty())
0092         ss << "\n-- user text " << this->logDBEntry().usertext.substr(this->logDBEntry().usertext.find_last_of('@'));
0093     } else {
0094       ss << " First object for this tag ";
0095     }
0096     edm::LogInfo("SiStripPopConDbObjHandler") << ss.str();
0097   }
0098 
0099   if (isTransferNeeded())
0100     setForTransfer();
0101 
0102   edm::LogInfo("SiStripPopConDbObjHandler")
0103       << "[SiStripPopConDbObjHandler::getNewObjects] for PopCon application " << m_name << " Done\n--------------\n";
0104 }
0105 
0106 template <typename T>
0107 bool SiStripDQMPopConSourceHandler<T>::isTransferNeeded() {
0108   edm::LogInfo("SiStripPopConDbObjHandler") << "[SiStripPopConDbObjHandler::isTransferNeeded] checking for transfer ";
0109 
0110   if (m_iovSequence && (m_since <= this->tagInfo().lastInterval.since)) {
0111     edm::LogInfo("SiStripPopConDbObjHandler")
0112         << "[SiStripPopConDbObjHandler::isTransferNeeded] \nthe current starting iov " << m_since
0113         << "\nis not compatible with the last iov (" << this->tagInfo().lastInterval.since << ") open for the object "
0114         << this->logDBEntry().payloadClass << " \nin the db " << this->logDBEntry().destinationDB
0115         << " \n NO TRANSFER NEEDED";
0116     return false;
0117   }
0118 
0119   std::string ss_logdb{};
0120 
0121   //get log information from previous upload
0122   if (!this->logDBEntry().usertext.empty())
0123     ss_logdb = this->logDBEntry().usertext.substr(this->logDBEntry().usertext.find_last_of('@') + 2);
0124 
0125   std::string ss = getMetaDataString();
0126   if ((!m_iovSequence) || checkForCompatibility(ss_logdb)) {
0127     this->m_userTextLog = "@ " + ss;
0128 
0129     edm::LogInfo("SiStripPopConDbObjHandler")
0130         << "[SiStripPopConDbObjHandler::isTransferNeeded] \nthe selected conditions will be uploaded: " << ss
0131         << "\n Current MetaData - " << ss << "\n Last Uploaded MetaData- " << ss_logdb << "\n Fine";
0132 
0133     return true;
0134   } else if (m_iovSequence) {
0135     edm::LogInfo("SiStripPopConDbObjHandler")
0136         << "[SiStripPopConDbObjHandler::isTransferNeeded] \nthe current MetaData conditions " << ss
0137         << "\nare not compatible with the MetaData Conditions of the last iov (" << this->tagInfo().lastInterval.since
0138         << ") open for the object " << this->logDBEntry().payloadClass << " \nin the db "
0139         << this->logDBEntry().destinationDB << " \nConditions: " << ss_logdb << "\n NO TRANSFER NEEDED";
0140     return false;
0141   } else {
0142     return true;
0143   }
0144 }
0145 
0146 template <typename T>
0147 void SiStripDQMPopConSourceHandler<T>::setForTransfer() {
0148   edm::LogInfo("SiStripPopConDbObjHandler")
0149       << "[SiStripPopConDbObjHandler::setForTransfer] " << m_name << " getting data to be transferred ";
0150 
0151   if (!this->tagInfo().size)
0152     m_since = 1;
0153   else if (m_debugMode)
0154     m_since = this->tagInfo().lastInterval.since + 1;
0155 
0156   T* obj = this->getObj();
0157   if (obj) {
0158     edm::LogInfo("SiStripPopConDbObjHandler") << "setting since = " << m_since;
0159     this->m_to_transfer.push_back(std::make_pair(obj, m_since));
0160   } else {
0161     edm::LogError("SiStripPopConDbObjHandler")
0162         << "[SiStripPopConDbObjHandler::setForTransfer] " << m_name << "  : NULL pointer of obj " << typeid(T).name()
0163         << " reported by SiStripCondObjBuilderFromDb\n Transfer aborted";
0164   }
0165 }
0166 
0167 template <class T>
0168 std::string SiStripDQMPopConSourceHandler<T>::getMetaDataString() const {
0169   std::cout << "SiStripPedestalsDQMService::getMetaDataString" << std::endl;
0170   std::stringstream ss;
0171   ss << "Run " << m_runNumber << std::endl;
0172   return ss.str();
0173 }
0174 
0175 #endif  // DQMOffline_CalibTracker_SiStripDQMPopConSourceHandler_H