CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/OnlineDB/SiStripO2O/plugins/SiStripPopConConfigDbObjHandler.h

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