CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/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().payloadClass<< "\n"
00066              << this->logDBEntry().payloadToken<< "\n"
00067              << this->logDBEntry().exectime<< "\n"
00068              << this->logDBEntry().execmessage<< "\n"
00069              << "\n\n-- user text " << this->logDBEntry().usertext.substr(this->logDBEntry().usertext.find_last_of("@")) ;
00070         } else {
00071           ss << " First object for this tag ";
00072         }
00073         edm::LogInfo   ("SiStripPopPopConConfigDbObjHandler") << ss.str();
00074       }
00075       if (isTransferNeeded())
00076         setForTransfer();
00077   
00078       edm::LogInfo   ("SiStripPopPopConConfigDbObjHandler") << "[getNewObjects] for PopCon application " << m_name << " Done\n--------------\n";
00079     }
00080 
00081 
00082     //---------------------------------------
00083     //
00084     std::string id() const { return m_name;}
00085 
00086     //---------------------------------------
00087     //
00088     bool isTransferNeeded(){
00089 
00090 
00091       edm::LogInfo   ("SiStripPopPopConConfigDbObjHandler") << "[isTransferNeeded] checking for transfer: " << typeid(T).name()  <<   std::endl;
00092       std::stringstream ss_logdb, ss;
00093 
00094       //get log information from previous upload
00095       if (this->logDBEntry().usertext!="")
00096         ss_logdb << this->logDBEntry().usertext.substr(this->logDBEntry().usertext.find_first_of("@"));
00097       else
00098         ss_logdb << "";
00099 
00100       std::string label="";
00101       if(typeid(T)==typeid(SiStripFedCabling))
00102         label="Cabling";
00103 
00104       if(typeid(T)==typeid(SiStripApvGain))
00105         label="ApvTiming";
00106       
00107       if(typeid(T)==typeid(SiStripLatency))
00108         label="ApvLatency";
00109 
00110       if(!condObjBuilder->checkForCompatibility(ss_logdb,ss,label)){
00111         //string are equal, no need to do transfer
00112         edm::LogInfo   ("SiStripPopPopConConfigDbObjHandler") 
00113           << "[isTransferNeeded] the selected conditions are already uploaded in the last iov ("  
00114           << this->tagInfo().lastInterval.first << ") open for the object " 
00115           << this->logDBEntry().payloadClass << " in the db " 
00116           << this->logDBEntry().destinationDB << " parameters: "  << ss_logdb.str() << "\n NO TRANSFER NEEDED";
00117         return false;
00118       }
00119       
00120       this->m_userTextLog = ss.str();
00121       edm::LogInfo   ("SiStripPopPopConConfigDbObjHandler") 
00122         << "[isTransferNeeded] the selected conditions will be uploaded: " << ss.str() 
00123         << "\n Going to Upload: "<< ss.str()  << "\n Last Upload: " << ss_logdb.str() << "\n Fine";
00124 
00125       return true;
00126     }
00127 
00128 
00129     //---------------------------------------
00130     //
00131     void setForTransfer(){
00132       edm::LogInfo   ("SiStripPopPopConConfigDbObjHandler") << "[setForTransfer] " << m_name << " getting data to be transferred "  << std::endl;
00133       
00134       T *obj=0; 
00135       condObjBuilder->getValue(obj);
00136 
00137       edm::LogInfo   ("SiStripPopPopConConfigDbObjHandler") << "[setForTransfer] " << m_name << " got data to be transferred from condObjBuilder "  << std::endl;
00138 
00139       if(!this->tagInfo().size)
00140         m_since=1;
00141       else
00142         if (m_debugMode)
00143           m_since=this->tagInfo().lastInterval.first+1; 
00144       edm::LogInfo   ("SiStripPopPopConConfigDbObjHandler") <<"[setForTransfer] setting since = "<< m_since <<std::endl;
00145 
00146       if (obj!=0){
00147 
00148         edm::LogInfo   ("SiStripPopPopConConfigDbObjHandler") <<"[setForTransfer] filling map m_to_transfer" <<std::endl;
00149         this->m_to_transfer.push_back(std::make_pair(obj,m_since));
00150       }else{
00151         edm::LogError   ("SiStripPopPopConConfigDbObjHandler") <<"[setForTransfer] " << m_name << "  : NULL pointer of obj " << typeid(T).name() << " reported by SiStripCondObjBuilderFromDb\n Transfer aborted"<<std::endl;
00152       }
00153     }
00154 
00155     private: 
00156     // data members
00157     std::string m_name;
00158     unsigned long long m_since;
00159     bool m_debugMode;
00160     edm::Service<SiStripCondObjBuilderFromDb> condObjBuilder;
00161   };
00162 }
00163 
00164 #endif //SISTRIPPOPCON_CONFIGDB_HANDLER_H