CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/CondCore/PopCon/interface/PopCon.h

Go to the documentation of this file.
00001 
00002 #ifndef POPCON_POPCON_H
00003 #define POPCON_POPCON_H
00004 //
00005 // Author: Vincenzo Innocente
00006 // Original Author:  Marcin BOGUSZ
00007 // 
00008 
00009 
00010 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
00011 #include "FWCore/ServiceRegistry/interface/Service.h"
00012 
00013 #include "CondCore/DBCommon/interface/TagInfo.h"
00014 #include "CondCore/DBCommon/interface/LogDBEntry.h"
00015 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00016 
00017 #include "FWCore/ParameterSet/interface/ParameterSetfwd.h"
00018 
00019 #include "CondCore/DBCommon/interface/Time.h"
00020 
00021 #include "CondCore/DBCommon/interface/IOVInfo.h"
00022 
00023 
00024 #include <boost/bind.hpp>
00025 #include <algorithm>
00026 #include <vector>
00027 #include <string>
00028 
00029 
00030 #include<iostream>
00031 
00032 namespace cond {
00033   class Summary;
00034 }
00035 
00036 
00037 namespace popcon {
00038 
00039 
00040   /* Populator of the Condition DB
00041    *
00042    */
00043   class PopCon {
00044   public:
00045     typedef cond::Time_t Time_t;
00046     typedef cond::Summary Summary;
00047 
00048     PopCon(const edm::ParameterSet& pset);
00049      
00050      virtual ~PopCon();
00051 
00052      template<typename Source>
00053        void write(Source const & source);
00054 
00055      template<typename T>
00056      void writeOne(T * payload, Time_t time);
00057 
00058    
00059     
00060      
00061   private:
00062      void initialize();
00063      void finalize(Time_t lastTill);
00064 
00065 
00066   private:
00067 
00068     edm::Service<cond::service::PoolDBOutputService> m_dbService;
00069     
00070     std::string  m_record;
00071     
00072     std::string m_payload_name;
00073     
00074     bool m_LoggingOn;
00075     
00076     bool m_IsDestDbCheckedInQueryLog;
00077 
00078     std::string m_tag;
00079     
00080     cond::TagInfo m_tagInfo;
00081     
00082     cond::LogDBEntry m_logDBEntry;
00083 
00084     bool m_close;
00085     Time_t m_lastTill;
00086 
00087     
00088   };
00089 
00090 
00091   template<typename T>
00092   void PopCon::writeOne(T * payload, Time_t time) {
00093     m_dbService->writeOne(payload, time, m_record, m_LoggingOn);
00094   }
00095 
00096   
00097   template<typename Container>
00098   void displayHelper(Container const & payloads) {
00099     typename Container::const_iterator it;
00100     for (it = payloads.begin(); it != payloads.end(); it++)
00101       edm::LogInfo ("PopCon")<< "Since " << (*it).time << std::endl;
00102   }     
00103   
00104   
00105   template<typename Container>
00106   const std::string displayIovHelper(Container const & payloads) {
00107     if (payloads.empty()) return "Nothing to transfer;";
00108     std::ostringstream s;    
00109     // when only 1 payload is transferred; 
00110     if ( payloads.size()==1)  
00111       s <<"Since " << (*payloads.begin()).time <<  "; " ;
00112     else{
00113       // when more than one payload are transferred;  
00114       s <<   "first payload Since " <<  (*payloads.begin()).time <<  ","
00115         << "last payload Since "  << (*payloads.rbegin()).time <<  ";" ;  
00116     }  
00117     return s.str();
00118   }
00119   
00120   
00121   
00122   
00123   
00124   template<typename Source>
00125   void PopCon::write(Source const & source) {
00126     typedef typename Source::value_type value_type;
00127     typedef typename Source::Container Container;
00128     
00129     initialize();
00130     std::pair<Container const *, std::string const> ret = source(m_dbService->session(),
00131                                                                  m_tagInfo,m_logDBEntry); 
00132     Container const & payloads = *ret.first;
00133     
00134     if(m_LoggingOn)
00135       m_dbService->setLogHeaderForRecord(m_record,source.id(),"PopCon v4.0; " + 
00136                                          cond::userInfo() + displayIovHelper(payloads) +  ret.second);
00137     
00138     displayHelper(payloads);
00139     
00140     std::for_each(payloads.begin(),payloads.end(),
00141                   boost::bind(&popcon::PopCon::writeOne<value_type>,this,
00142                               boost::bind(&Container::value_type::payload,_1),
00143                               boost::bind(&Container::value_type::time,_1)
00144                               )
00145                    );
00146     
00147     
00148     finalize(payloads.empty() ? Time_t(0): payloads.back().time);
00149   }
00150  
00151 }
00152 
00153 #endif //  POPCON_POPCON_H
00154 
00155