Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef CondCore_CondDB_RunInfoProxy_h
0002 #define CondCore_CondDB_RunInfoProxy_h
0003 //
0004 // Package:     CondDB
0005 // Class  :     RunInfoProxy
0006 //
0007 /**\class RunInfoProxy RunInfoProxy.h CondCore/CondDB/interface/RunInfoProxy.h
0008    Description: service for read/only access to the Run information.  
0009 */
0010 //
0011 // Author:      Giacomo Govi
0012 // Created:     Dec 2016
0013 //
0014 
0015 #include "CondCore/CondDB/interface/Types.h"
0016 //
0017 
0018 namespace cond {
0019 
0020   namespace persistency {
0021 
0022     class SessionImpl;
0023     class RunInfoProxyData;
0024 
0025     // value semantics. to be used WITHIN the parent session transaction ( therefore the session should be kept alive ).
0026     class RunInfoProxy {
0027     public:
0028       typedef std::vector<std::tuple<Time_t, boost::posix_time::ptime, boost::posix_time::ptime> > RunInfoData;
0029 
0030     public:
0031       // more or less compliant with typical iterator semantics...
0032       class Iterator {
0033       public:
0034         // C++17 compliant iterator definition
0035         using iterator_category = std::input_iterator_tag;
0036         using value_type = cond::RunInfo_t;
0037         using difference_type = void;  // Not used
0038         using pointer = void;          // Not used
0039         using reference = void;        // Not used
0040 
0041         //
0042         Iterator();
0043         explicit Iterator(RunInfoData::const_iterator current);
0044         Iterator(const Iterator& rhs);
0045 
0046         //
0047         Iterator& operator=(const Iterator& rhs);
0048 
0049         // returns a VALUE not a reference!
0050         cond::RunInfo_t operator*();
0051 
0052         //
0053         Iterator& operator++();
0054         Iterator operator++(int);
0055 
0056         //
0057         bool operator==(const Iterator& rhs) const;
0058         bool operator!=(const Iterator& rhs) const;
0059 
0060       private:
0061         RunInfoData::const_iterator m_current;
0062       };
0063 
0064     public:
0065       RunInfoProxy();
0066 
0067       //
0068       explicit RunInfoProxy(const std::shared_ptr<SessionImpl>& session);
0069 
0070       //
0071       RunInfoProxy(const RunInfoProxy& rhs);
0072 
0073       //
0074       RunInfoProxy& operator=(const RunInfoProxy& rhs);
0075 
0076       // loads in memory the RunInfo data for the specified run range
0077       void load(Time_t low, Time_t up);
0078 
0079       // loads in memory the RunInfo data for the specified run range
0080       void load(const boost::posix_time::ptime& low, const boost::posix_time::ptime& up);
0081 
0082       // clear all the iov data in memory
0083       void reset();
0084 
0085       // start the iteration.
0086       Iterator begin() const;
0087 
0088       //
0089       Iterator end() const;
0090 
0091       //
0092       Iterator find(Time_t target) const;
0093 
0094       //
0095       Iterator find(const boost::posix_time::ptime& target) const;
0096 
0097       //
0098       cond::RunInfo_t get(Time_t target) const;
0099 
0100       //
0101       cond::RunInfo_t get(const boost::posix_time::ptime& target) const;
0102 
0103       //
0104       int size() const;
0105 
0106     private:
0107       void checkTransaction(const std::string& ctx);
0108 
0109     private:
0110       std::shared_ptr<RunInfoProxyData> m_data;
0111       std::shared_ptr<SessionImpl> m_session;
0112     };
0113 
0114   }  // namespace persistency
0115 }  // namespace cond
0116 
0117 #endif