Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef CondCore_CondDB_IOVProxy_h
0002 #define CondCore_CondDB_IOVProxy_h
0003 //
0004 // Package:     CondDB
0005 // Class  :     IOVProxy
0006 //
0007 /**\class IOVProxy IOVProxy.h CondCore/CondDB/interface/IOVProxy.h
0008    Description: service for read/only access to the condition IOVs.  
0009 */
0010 //
0011 // Author:      Giacomo Govi
0012 // Created:     Apr 2013
0013 //
0014 
0015 #include "CondCore/CondDB/interface/Time.h"
0016 #include "CondCore/CondDB/interface/Types.h"
0017 //
0018 #include <boost/date_time/posix_time/posix_time.hpp>
0019 
0020 namespace cond {
0021 
0022   namespace persistency {
0023 
0024     class SessionImpl;
0025     class IOVProxyData;
0026 
0027     typedef std::vector<std::tuple<cond::Time_t, cond::Hash> > IOVContainer;
0028 
0029     class IOVArray {
0030     public:
0031       IOVArray();
0032       IOVArray(const IOVArray& rhs);
0033       IOVArray& operator=(const IOVArray& rhs);
0034 
0035     public:
0036       // more or less compliant with typical iterator semantics...
0037       class Iterator {
0038       public:
0039         // C++17 compliant iterator definition
0040         using iterator_category = std::input_iterator_tag;
0041         using value_type = cond::Iov_t;
0042         using difference_type = void;  // Not used
0043         using pointer = void;          // Not used
0044         using reference = void;        // Not used
0045 
0046         //
0047         Iterator();
0048         Iterator(IOVContainer::const_iterator current, const IOVArray* parent);
0049 
0050         Iterator(const Iterator& rhs);
0051 
0052         //
0053         Iterator& operator=(const Iterator& rhs);
0054 
0055         // returns a VALUE not a reference!
0056         cond::Iov_t operator*();
0057 
0058         //
0059         Iterator& operator++();
0060         Iterator operator++(int);
0061 
0062         //
0063         bool operator==(const Iterator& rhs) const;
0064         bool operator!=(const Iterator& rhs) const;
0065 
0066       private:
0067         IOVContainer::const_iterator m_current;
0068         const IOVArray* m_parent;
0069       };
0070       friend class Iterator;
0071 
0072     public:
0073       const cond::Tag_t& tagInfo() const;
0074 
0075       // start the iteration. it referes to the LOADED iov sequence subset, which consists in two consecutive groups - or the entire sequence if it has been requested.
0076       // returns data only when a find or a load( tag, true ) have been at least called once.
0077       Iterator begin() const;
0078 
0079       // the real end of the LOADED iov sequence subset.
0080       Iterator end() const;
0081 
0082       // searches the array for a valid iov containing the specified time.
0083       // if the available iov sequence subset contains the target time, it does not issue a new query.
0084       // otherwise, a new query will be executed using the resolved group boundaries.
0085       Iterator find(cond::Time_t time) const;
0086 
0087       size_t size() const;
0088 
0089       // returns true if at least one IOV is in the sequence.
0090       bool isEmpty() const;
0091 
0092     private:
0093       friend class IOVProxy;
0094       std::unique_ptr<IOVContainer> m_array;
0095       cond::Tag_t m_tagInfo;
0096     };
0097 
0098     // value semantics. to be used WITHIN the parent session transaction ( therefore the session should be kept alive ).
0099     class IOVProxy {
0100     public:
0101       //
0102       IOVProxy();
0103 
0104       // the only way to construct it from scratch...
0105       explicit IOVProxy(const std::shared_ptr<SessionImpl>& session);
0106 
0107       //
0108       IOVProxy(const IOVProxy& rhs);
0109 
0110       //
0111       IOVProxy& operator=(const IOVProxy& rhs);
0112 
0113       IOVArray selectAll();
0114       IOVArray selectAll(const boost::posix_time::ptime& snapshottime);
0115 
0116       IOVArray selectRange(const cond::Time_t& begin, const cond::Time_t& end);
0117       IOVArray selectRange(const cond::Time_t& begin,
0118                            const cond::Time_t& end,
0119                            const boost::posix_time::ptime& snapshottime);
0120 
0121       bool selectRange(const cond::Time_t& begin, const cond::Time_t& end, IOVContainer& destination);
0122 
0123       cond::Tag_t tagInfo() const;
0124 
0125       cond::TagInfo_t iovSequenceInfo() const;
0126 
0127       // searches the DB for a valid iov containing the specified time.
0128       // if the available iov sequence subset contains the target time, it does not issue a new query.
0129       // otherwise, a new query will be executed using the resolved group boundaries.
0130       // throws if the target time cannot be found.
0131       cond::Iov_t getInterval(cond::Time_t time);
0132 
0133       std::tuple<std::string, boost::posix_time::ptime, boost::posix_time::ptime> getMetadata() const;
0134 
0135       // loads in memory the tag information and the iov groups
0136       // full=true load the full iovSequence
0137       void load(const std::string& tag);
0138 
0139       // loads in memory the tag information and the iov groups
0140       void load(const std::string& tag, const boost::posix_time::ptime& snapshottime);
0141 
0142       // clear all the iov data in memory
0143       void reset();
0144 
0145       // it does NOT use the cache, every time it performs a new query.
0146       cond::Iov_t getLast();
0147 
0148       // the size of the LOADED iov sequence subset.
0149       int loadedSize() const;
0150 
0151       // the size of the entire iov sequence. Peforms a query at every call.
0152       int sequenceSize() const;
0153 
0154       // for reporting
0155       size_t numberOfQueries() const;
0156 
0157       // for debugging
0158       std::pair<cond::Time_t, cond::Time_t> loadedGroup() const;
0159 
0160       // maybe will be removed with a re-design of the top level interface (ESSources )
0161       const std::shared_ptr<SessionImpl>& session() const;
0162 
0163     private:
0164       void checkTransaction(const std::string& ctx) const;
0165       void resetIOVCache();
0166       void loadGroups();
0167       void fetchSequence(cond::Time_t lowerGroup, cond::Time_t higherGroup);
0168 
0169     private:
0170       std::shared_ptr<IOVProxyData> m_data;
0171       std::shared_ptr<SessionImpl> m_session;
0172     };
0173 
0174   }  // namespace persistency
0175 }  // namespace cond
0176 
0177 #endif