CMS 3D CMS Logo

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