Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-04-02 23:19:22

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       IOVProxy() = default;
0102 
0103       // the only way to construct it from scratch...
0104       explicit IOVProxy(const std::shared_ptr<SessionImpl>& session);
0105 
0106       IOVArray selectAll();
0107       IOVArray selectAll(const boost::posix_time::ptime& snapshottime);
0108 
0109       IOVArray selectRange(const cond::Time_t& begin, const cond::Time_t& end);
0110       IOVArray selectRange(const cond::Time_t& begin,
0111                            const cond::Time_t& end,
0112                            const boost::posix_time::ptime& snapshottime);
0113 
0114       bool selectRange(const cond::Time_t& begin, const cond::Time_t& end, IOVContainer& destination);
0115 
0116       cond::Tag_t tagInfo() const;
0117 
0118       cond::TagInfo_t iovSequenceInfo() const;
0119 
0120       // searches the DB for a valid iov containing the specified time.
0121       // if the available iov sequence subset contains the target time, it does not issue a new query.
0122       // otherwise, a new query will be executed using the resolved group boundaries.
0123       // throws if the target time cannot be found.
0124       cond::Iov_t getInterval(cond::Time_t time);
0125 
0126       std::tuple<std::string, boost::posix_time::ptime, boost::posix_time::ptime> getMetadata() const;
0127 
0128       // loads in memory the tag information and the iov groups
0129       // full=true load the full iovSequence
0130       void load(const std::string& tag);
0131 
0132       // loads in memory the tag information and the iov groups
0133       void load(const std::string& tag, const boost::posix_time::ptime& snapshottime);
0134 
0135       // clear all the iov data in memory
0136       void reset();
0137 
0138       // it does NOT use the cache, every time it performs a new query.
0139       cond::Iov_t getLast();
0140 
0141       // the size of the LOADED iov sequence subset.
0142       int loadedSize() const;
0143 
0144       // the size of the entire iov sequence. Peforms a query at every call.
0145       int sequenceSize() const;
0146 
0147       // for reporting
0148       size_t numberOfQueries() const;
0149 
0150       // for debugging
0151       std::pair<cond::Time_t, cond::Time_t> loadedGroup() const;
0152 
0153       // maybe will be removed with a re-design of the top level interface (ESSources )
0154       const std::shared_ptr<SessionImpl>& session() const;
0155 
0156       void setPrintDebug(bool printDebug) { m_printDebug = printDebug; }
0157 
0158     private:
0159       void checkTransaction(const std::string& ctx) const;
0160       void resetIOVCache();
0161       void loadGroups();
0162       void fetchSequence(cond::Time_t lowerGroup, cond::Time_t higherGroup);
0163 
0164     private:
0165       std::shared_ptr<IOVProxyData> m_data;
0166       std::shared_ptr<SessionImpl> m_session;
0167 
0168       // whether additional debug info should be printed in fetchSequence
0169       bool m_printDebug = false;
0170     };
0171 
0172   }  // namespace persistency
0173 }  // namespace cond
0174 
0175 #endif