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().payloadName<< "\n" 00060 << this->logDBEntry().payloadToken<< "\n" 00061 << this->logDBEntry().payloadContainer<< "\n" 00062 << this->logDBEntry().exectime<< "\n" 00063 << this->logDBEntry().execmessage<< "\n"; 00064 if(this->logDBEntry().usertext!="") 00065 ss<< "\n-- user text " << this->logDBEntry().usertext.substr(this->logDBEntry().usertext.find_last_of("@")) ; 00066 00067 } else { 00068 ss << " First object for this tag "; 00069 } 00070 edm::LogInfo ("DQMHistoryPopConHandler") << ss.str(); 00071 /* if (m_debugMode){ */ 00072 /* } */ 00073 00074 condObjBuilder->initialize(); 00075 00076 if (isTransferNeeded()) 00077 setForTransfer(); 00078 00079 edm::LogInfo ("DQMHistoryPopConHandler") << "[DQMHistoryPopConHandler::getNewObjects] for PopCon application " << m_name << " Done\n--------------\n"; 00080 } 00081 00082 00083 //--------------------------------------- 00084 // 00085 std::string id() const { return m_name;} 00086 00087 private: 00088 //methods 00089 00090 //--------------------------------------- 00091 // 00092 bool isTransferNeeded(){ 00093 00094 edm::LogInfo ("DQMHistoryPopConHandler") << "[DQMHistoryPopConHandler::isTransferNeeded] checking for transfer " << std::endl; 00095 00096 if(m_iovSequence && m_since<=this->tagInfo().lastInterval.first){ 00097 edm::LogInfo ("DQMHistoryPopConHandler") 00098 << "[DQMHistoryPopConHandler::isTransferNeeded] \nthe current starting iov " << m_since 00099 << "\nis not compatible with the last iov (" 00100 << this->tagInfo().lastInterval.first << ") open for the object " 00101 << this->logDBEntry().payloadName << " \nin the db " 00102 << this->logDBEntry().destinationDB << " \n NO TRANSFER NEEDED"; 00103 return false; 00104 } 00105 00106 std::stringstream ss_logdb, ss; 00107 00108 //get log information from previous upload 00109 if (this->logDBEntry().usertext!="") 00110 ss_logdb << this->logDBEntry().usertext.substr(this->logDBEntry().usertext.find_last_of("@")+2); 00111 00112 00113 condObjBuilder->getMetaDataString(ss); 00114 if ((m_iovSequence && condObjBuilder->checkForCompatibility(ss_logdb.str())) || !m_iovSequence){ 00115 00116 this->m_userTextLog = "@ " + ss.str(); 00117 00118 edm::LogInfo ("DQMHistoryPopConHandler") 00119 << "[DQMHistoryPopConHandler::isTransferNeeded] \nthe selected conditions will be uploaded: " << ss.str() 00120 << "\n Current MetaData - "<< ss.str() << "\n Last Uploaded MetaData- " << ss_logdb.str() << "\n Fine"; 00121 00122 return true; 00123 } else if (m_iovSequence && !condObjBuilder->checkForCompatibility(ss_logdb.str())) { 00124 edm::LogInfo ("DQMHistoryPopConHandler") 00125 << "[DQMHistoryPopConHandler::isTransferNeeded] \nthe current MetaData conditions " << ss.str() 00126 << "\nare not compatible with the MetaData Conditions of the last iov (" 00127 << this->tagInfo().lastInterval.first << ") open for the object " 00128 << this->logDBEntry().payloadName << " \nin the db " 00129 << this->logDBEntry().destinationDB << " \nConditions: " << ss_logdb.str() << "\n NO TRANSFER NEEDED"; 00130 return false; 00131 } 00132 return false; 00133 } 00134 00135 00136 //--------------------------------------- 00137 // 00138 void setForTransfer(){ 00139 edm::LogInfo ("DQMHistoryPopConHandler") << "[DQMHistoryPopConHandler::setForTransfer] " << m_name << " getting data to be transferred " << std::endl; 00140 00141 HDQMSummary *obj=0; 00142 condObjBuilder->getObj(obj); 00143 00144 if(!this->tagInfo().size) 00145 m_since=1; 00146 else 00147 if (m_debugMode) 00148 m_since=this->tagInfo().lastInterval.first+1; 00149 00150 if (obj!=0){ 00151 00152 edm::LogInfo ("DQMHistoryPopConHandler") <<"setting since = "<< m_since <<std::endl; 00153 this->m_to_transfer.push_back(std::make_pair(obj,m_since)); 00154 }else{ 00155 edm::LogError ("DQMHistoryPopConHandler") <<"[DQMHistoryPopConHandler::setForTransfer] " << m_name << " : NULL pointer of obj HDQMSummary reported by SiStripCondObjBuilderFromDb\n Transfer aborted"<<std::endl; 00156 } 00157 } 00158 00159 private: 00160 // data members 00161 std::string m_name; 00162 unsigned long long m_since; 00163 bool m_debugMode; 00164 bool m_iovSequence; 00165 edm::Service<U> condObjBuilder; 00166 }; 00167 } 00168 00169 #endif //DQMHISTORYPOPCON_DB_HANDLER_H