Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:01:43

0001 #ifndef PopConSourceHandler_H
0002 #define PopConSourceHandler_H
0003 
0004 #include "CondCore/CondDB/interface/Session.h"
0005 #include "CondCore/CondDB/interface/Time.h"
0006 
0007 #include <algorithm>
0008 #include <functional>
0009 #include <memory>
0010 #include <string>
0011 #include <vector>
0012 
0013 namespace cond {
0014   class Summary;
0015 }
0016 
0017 #include "CondFormats/Common/interface/GenericSummary.h"
0018 
0019 namespace popcon {
0020 
0021   /** Online DB source handler, aims at returning the vector of data to be 
0022    * transferred to the online database
0023    * Subdetector developers inherit over this class with template parameter of 
0024    * payload class; 
0025    * need just to implement the getNewObjects method that loads the calibs,
0026    * the sourceId methods that return a text identifier of the source,
0027    * and provide a constructor that accept a ParameterSet
0028    */
0029   template <class T>
0030   class PopConSourceHandler {
0031   public:
0032     typedef T value_type;
0033     typedef PopConSourceHandler<T> self;
0034     typedef cond::Time_t Time_t;
0035 
0036     typedef std::map<Time_t, std::shared_ptr<T> > Container;
0037     typedef std::unique_ptr<T> Ref;
0038 
0039     PopConSourceHandler() : m_tagInfo(nullptr), m_logDBEntry(nullptr) {}
0040 
0041     virtual ~PopConSourceHandler() {}
0042 
0043     cond::TagInfo_t const& tagInfo() const { return *m_tagInfo; }
0044 
0045     // return last paylod of the tag
0046     Ref lastPayload() const { return m_session.fetchPayload<T>(tagInfo().lastInterval.payloadId); }
0047 
0048     // return last successful log entry for the tag in question
0049     cond::LogDBEntry_t const& logDBEntry() const { return *m_logDBEntry; }
0050 
0051     // FIX ME
0052     void initialize(const cond::persistency::Session& dbSession,
0053                     cond::TagInfo_t const& tagInfo,
0054                     cond::LogDBEntry_t const& logDBEntry) {
0055       m_session = dbSession;
0056       m_tagInfo = &tagInfo;
0057       m_logDBEntry = &logDBEntry;
0058     }
0059 
0060     // this is the only mandatory interface
0061     std::pair<Container const*, std::string const> operator()(const cond::persistency::Session& session,
0062                                                               cond::TagInfo_t const& tagInfo,
0063                                                               cond::LogDBEntry_t const& logDBEntry) const {
0064       const_cast<self*>(this)->initialize(session, tagInfo, logDBEntry);
0065       return std::pair<Container const*, std::string const>(&(const_cast<self*>(this)->returnData()), userTextLog());
0066     }
0067 
0068     Container const& returnData() {
0069       getNewObjects();
0070       for (auto item : m_to_transfer) {
0071         std::shared_ptr<T> payload(item.first);
0072         m_iovs.insert(std::make_pair(item.second, payload));
0073       }
0074       return m_iovs;
0075     }
0076 
0077     std::string const& userTextLog() const { return m_userTextLog; }
0078 
0079     //Implement to fill m_to_transfer vector and  m_userTextLog
0080     //use getOfflineInfo to get the contents of offline DB
0081     virtual void getNewObjects() = 0;
0082 
0083     // return a string identifing the source
0084     virtual std::string id() const = 0;
0085 
0086   protected:
0087     cond::persistency::Session& dbSession() const { return m_session; }
0088 
0089   private:
0090     mutable cond::persistency::Session m_session;
0091 
0092     cond::TagInfo_t const* m_tagInfo;
0093 
0094     cond::LogDBEntry_t const* m_logDBEntry;
0095 
0096   protected:
0097     //vector of payload objects and iovinfo to be transferred
0098     //class looses ownership of payload object
0099     std::vector<std::pair<T*, Time_t> > m_to_transfer;
0100 
0101     Container m_iovs;
0102 
0103     std::string m_userTextLog;
0104   };
0105 }  // namespace popcon
0106 #endif