CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/CondTools/SiStrip/interface/SiStripPopConDbObjHandler.h

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