CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_6/src/DQMServices/Diagnostic/interface/DQMHistoryPopConHandler.h

Go to the documentation of this file.
00001 #ifndef SISTRIPPOPCON_DB_HANDLE_H
00002 #define DQMHISTORYPOPCON_DB_HANDLER_H
00003 
00004 #include "FWCore/ServiceRegistry/interface/Service.h"
00005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00007 
00008 #include "CondCore/PopCon/interface/PopConSourceHandler.h"
00009 #include "CondCore/DBCommon/interface/TagInfo.h"
00010 #include "CondCore/DBCommon/interface/LogDBEntry.h"
00011 #include "CondFormats/DQMObjects/interface/HDQMSummary.h"
00012 
00013 #include <sstream>
00014 #include <vector>
00015 #include <string>
00016 #include <iostream>
00017 #include <typeinfo>
00018 
00019 namespace popcon{
00020   
00021   template <typename U>
00022     class DQMHistoryPopConHandler : public popcon::PopConSourceHandler<HDQMSummary>{
00023     public:
00024 
00025     DQMHistoryPopConHandler(const edm::ParameterSet& pset):
00026       m_name(pset.getUntrackedParameter<std::string>("name","DQMHistoryPopConHandler")),
00027       m_since(pset.getUntrackedParameter<uint32_t>("since",5)),
00028       m_debugMode(pset.getUntrackedParameter<bool>("debug",false)),
00029       m_iovSequence(pset.getUntrackedParameter<bool>("iovSequence",false)){}; 
00030 
00031     //---------------------------------------
00032     //
00033     ~DQMHistoryPopConHandler(){}; 
00034 
00035     //---------------------------------------
00036     //
00037     void getNewObjects(){
00038       edm::LogInfo   ("DQMHistoryPopConHandler") << "[DQMHistoryPopConHandler::getNewObjects] for PopCon application " << m_name;
00039      
00040         std::stringstream ss;
00041         ss << "\n\n------- " << m_name 
00042            << " - > getNewObjects\n"; 
00043         if (this->tagInfo().size){
00044           //check whats already inside of database
00045           ss << "\ngot offlineInfo"<< this->tagInfo().name 
00046              << "\n size " << this->tagInfo().size 
00047              << "\n" << this->tagInfo().token 
00048              << "\n last object valid since " << this->tagInfo().lastInterval.first 
00049              << "\n token " << this->tagInfo().lastPayloadToken 
00050              << "\n UserText " << this->userTextLog()
00051              << "\n LogDBEntry \n" 
00052              << this->logDBEntry().logId<< "\n"
00053              << this->logDBEntry().destinationDB<< "\n"   
00054              << this->logDBEntry().provenance<< "\n"
00055              << this->logDBEntry().usertext<< "\n"
00056              << this->logDBEntry().iovtag<< "\n"
00057              << this->logDBEntry().iovtimetype<< "\n"
00058              << this->logDBEntry().payloadIdx<< "\n"
00059              << this->logDBEntry().payloadClass<< "\n"
00060              << this->logDBEntry().payloadToken<< "\n"
00061              << this->logDBEntry().exectime<< "\n"
00062              << this->logDBEntry().execmessage<< "\n";
00063           if(this->logDBEntry().usertext!="")
00064             ss<< "\n-- user text " << this->logDBEntry().usertext.substr(this->logDBEntry().usertext.find_last_of("@")) ;
00065           
00066         } else {
00067           ss << " First object for this tag ";
00068         }
00069         edm::LogInfo   ("DQMHistoryPopConHandler") << ss.str();
00070 /*       if (m_debugMode){ */
00071 /*       } */
00072       
00073       condObjBuilder->initialize(); 
00074       
00075       if (isTransferNeeded())
00076         setForTransfer();
00077 
00078       edm::LogInfo   ("DQMHistoryPopConHandler") << "[DQMHistoryPopConHandler::getNewObjects] for PopCon application " << m_name << " Done\n--------------\n";
00079     }
00080 
00081 
00082     //---------------------------------------
00083     //
00084     std::string id() const { return m_name;}
00085 
00086     private:
00087     //methods
00088     
00089     //---------------------------------------
00090     //
00091     bool isTransferNeeded(){
00092 
00093       edm::LogInfo   ("DQMHistoryPopConHandler") << "[DQMHistoryPopConHandler::isTransferNeeded] checking for transfer " << std::endl;
00094 
00095       if(m_iovSequence && m_since<=this->tagInfo().lastInterval.first){
00096         edm::LogInfo   ("DQMHistoryPopConHandler") 
00097           << "[DQMHistoryPopConHandler::isTransferNeeded] \nthe current starting iov " << m_since
00098           << "\nis not compatible with the last iov ("  
00099           << this->tagInfo().lastInterval.first << ") open for the object " 
00100           << this->logDBEntry().payloadClass << " \nin the db " 
00101           << this->logDBEntry().destinationDB << " \n NO TRANSFER NEEDED";
00102         return false;
00103       }
00104       
00105       std::stringstream ss_logdb, ss;
00106       
00107       //get log information from previous upload
00108       if (this->logDBEntry().usertext!="")
00109       ss_logdb << this->logDBEntry().usertext.substr(this->logDBEntry().usertext.find_last_of("@")+2);
00110 
00111 
00112       condObjBuilder->getMetaDataString(ss);
00113      if ((m_iovSequence && condObjBuilder->checkForCompatibility(ss_logdb.str())) || !m_iovSequence){
00114         
00115         this->m_userTextLog = "@ " + ss.str();
00116         
00117         edm::LogInfo   ("DQMHistoryPopConHandler") 
00118           << "[DQMHistoryPopConHandler::isTransferNeeded] \nthe selected conditions will be uploaded: " << ss.str()
00119           << "\n Current MetaData - "<< ss.str()  << "\n Last Uploaded MetaData- " << ss_logdb.str() << "\n Fine";
00120 
00121         return true;
00122      } else if (m_iovSequence && !condObjBuilder->checkForCompatibility(ss_logdb.str())) {
00123        edm::LogInfo   ("DQMHistoryPopConHandler") 
00124          << "[DQMHistoryPopConHandler::isTransferNeeded] \nthe current MetaData conditions " << ss.str() 
00125          << "\nare not compatible with the MetaData Conditions of the last iov ("  
00126          << this->tagInfo().lastInterval.first << ") open for the object " 
00127          << this->logDBEntry().payloadClass << " \nin the db " 
00128          << this->logDBEntry().destinationDB << " \nConditions: "  << ss_logdb.str() << "\n NO TRANSFER NEEDED";
00129        return false;
00130      }
00131      return false;
00132     }
00133 
00134 
00135     //---------------------------------------
00136     //
00137     void setForTransfer(){
00138       edm::LogInfo   ("DQMHistoryPopConHandler") << "[DQMHistoryPopConHandler::setForTransfer] " << m_name << " getting data to be transferred "  << std::endl;
00139       
00140       HDQMSummary *obj=0; 
00141       condObjBuilder->getObj(obj);
00142  
00143       if(!this->tagInfo().size)
00144         m_since=1;
00145       else
00146         if (m_debugMode)
00147           m_since=this->tagInfo().lastInterval.first+1; 
00148 
00149       if (obj!=0){
00150 
00151         edm::LogInfo   ("DQMHistoryPopConHandler") <<"setting since = "<< m_since <<std::endl;
00152         this->m_to_transfer.push_back(std::make_pair(obj,m_since));
00153       }else{
00154         edm::LogError   ("DQMHistoryPopConHandler") <<"[DQMHistoryPopConHandler::setForTransfer] " << m_name << "  : NULL pointer of obj HDQMSummary  reported by SiStripCondObjBuilderFromDb\n Transfer aborted"<<std::endl;
00155       }
00156     }
00157 
00158     private: 
00159     // data members
00160     std::string m_name;
00161     unsigned long long m_since;
00162     bool m_debugMode;
00163     bool m_iovSequence;
00164     edm::Service<U> condObjBuilder;
00165   };
00166 }
00167 
00168 #endif //DQMHISTORYPOPCON_DB_HANDLER_H