Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-01-16 23:25:21

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 : public std::iterator<std::input_iterator_tag, cond::Iov_t> {
0038       public:
0039         //
0040         Iterator();
0041         Iterator(IOVContainer::const_iterator current, const IOVArray* parent);
0042 
0043         Iterator(const Iterator& rhs);
0044 
0045         //
0046         Iterator& operator=(const Iterator& rhs);
0047 
0048         // returns a VALUE not a reference!
0049         cond::Iov_t operator*();
0050 
0051         //
0052         Iterator& operator++();
0053         Iterator operator++(int);
0054 
0055         //
0056         bool operator==(const Iterator& rhs) const;
0057         bool operator!=(const Iterator& rhs) const;
0058 
0059       private:
0060         IOVContainer::const_iterator m_current;
0061         const IOVArray* m_parent;
0062       };
0063       friend class Iterator;
0064 
0065     public:
0066       const cond::Tag_t& tagInfo() const;
0067 
0068       // 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.
0069       // returns data only when a find or a load( tag, true ) have been at least called once.
0070       Iterator begin() const;
0071 
0072       // the real end of the LOADED iov sequence subset.
0073       Iterator end() const;
0074 
0075       // searches the array for a valid iov containing the specified time.
0076       // if the available iov sequence subset contains the target time, it does not issue a new query.
0077       // otherwise, a new query will be executed using the resolved group boundaries.
0078       Iterator find(cond::Time_t time) const;
0079 
0080       size_t size() const;
0081 
0082       // returns true if at least one IOV is in the sequence.
0083       bool isEmpty() const;
0084 
0085     private:
0086       friend class IOVProxy;
0087       std::unique_ptr<IOVContainer> m_array;
0088       cond::Tag_t m_tagInfo;
0089     };
0090 
0091     // value semantics. to be used WITHIN the parent session transaction ( therefore the session should be kept alive ).
0092     class IOVProxy {
0093     public:
0094       //
0095       IOVProxy();
0096 
0097       // the only way to construct it from scratch...
0098       explicit IOVProxy(const std::shared_ptr<SessionImpl>& session);
0099 
0100       //
0101       IOVProxy(const IOVProxy& rhs);
0102 
0103       //
0104       IOVProxy& operator=(const IOVProxy& rhs);
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     private:
0157       void checkTransaction(const std::string& ctx) const;
0158       void resetIOVCache();
0159       void loadGroups();
0160       void fetchSequence(cond::Time_t lowerGroup, cond::Time_t higherGroup);
0161 
0162     private:
0163       std::shared_ptr<IOVProxyData> m_data;
0164       std::shared_ptr<SessionImpl> m_session;
0165     };
0166 
0167   }  // namespace persistency
0168 }  // namespace cond
0169 
0170 #endif