IOVArray

IOVProxy

Iterator

Macros

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
#ifndef CondCore_CondDB_IOVProxy_h
#define CondCore_CondDB_IOVProxy_h
//
// Package:     CondDB
// Class  :     IOVProxy
//
/**\class IOVProxy IOVProxy.h CondCore/CondDB/interface/IOVProxy.h
   Description: service for read/only access to the condition IOVs.  
*/
//
// Author:      Giacomo Govi
// Created:     Apr 2013
//

#include "CondCore/CondDB/interface/Time.h"
#include "CondCore/CondDB/interface/Types.h"
//
#include <boost/date_time/posix_time/posix_time.hpp>

namespace cond {

  namespace persistency {

    class SessionImpl;
    class IOVProxyData;

    typedef std::vector<std::tuple<cond::Time_t, cond::Hash> > IOVContainer;

    class IOVArray {
    public:
      IOVArray();
      IOVArray(const IOVArray& rhs);
      IOVArray& operator=(const IOVArray& rhs);

    public:
      // more or less compliant with typical iterator semantics...
      class Iterator {
      public:
        // C++17 compliant iterator definition
        using iterator_category = std::input_iterator_tag;
        using value_type = cond::Iov_t;
        using difference_type = void;  // Not used
        using pointer = void;          // Not used
        using reference = void;        // Not used

        //
        Iterator();
        Iterator(IOVContainer::const_iterator current, const IOVArray* parent);

        Iterator(const Iterator& rhs);

        //
        Iterator& operator=(const Iterator& rhs);

        // returns a VALUE not a reference!
        cond::Iov_t operator*();

        //
        Iterator& operator++();
        Iterator operator++(int);

        //
        bool operator==(const Iterator& rhs) const;
        bool operator!=(const Iterator& rhs) const;

      private:
        IOVContainer::const_iterator m_current;
        const IOVArray* m_parent;
      };
      friend class Iterator;

    public:
      const cond::Tag_t& tagInfo() const;

      // 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.
      // returns data only when a find or a load( tag, true ) have been at least called once.
      Iterator begin() const;

      // the real end of the LOADED iov sequence subset.
      Iterator end() const;

      // searches the array for a valid iov containing the specified time.
      // if the available iov sequence subset contains the target time, it does not issue a new query.
      // otherwise, a new query will be executed using the resolved group boundaries.
      Iterator find(cond::Time_t time) const;

      size_t size() const;

      // returns true if at least one IOV is in the sequence.
      bool isEmpty() const;

    private:
      friend class IOVProxy;
      std::unique_ptr<IOVContainer> m_array;
      cond::Tag_t m_tagInfo;
    };

    // value semantics. to be used WITHIN the parent session transaction ( therefore the session should be kept alive ).
    class IOVProxy {
    public:
      IOVProxy() = default;

      // the only way to construct it from scratch...
      explicit IOVProxy(const std::shared_ptr<SessionImpl>& session);

      IOVArray selectAll();
      IOVArray selectAll(const boost::posix_time::ptime& snapshottime);

      IOVArray selectRange(const cond::Time_t& begin, const cond::Time_t& end);
      IOVArray selectRange(const cond::Time_t& begin,
                           const cond::Time_t& end,
                           const boost::posix_time::ptime& snapshottime);

      bool selectRange(const cond::Time_t& begin, const cond::Time_t& end, IOVContainer& destination);

      cond::Tag_t tagInfo() const;

      cond::TagInfo_t iovSequenceInfo() const;

      // searches the DB for a valid iov containing the specified time.
      // if the available iov sequence subset contains the target time, it does not issue a new query.
      // otherwise, a new query will be executed using the resolved group boundaries.
      // throws if the target time cannot be found.
      cond::Iov_t getInterval(cond::Time_t time);

      std::tuple<std::string, boost::posix_time::ptime, boost::posix_time::ptime> getMetadata() const;

      // loads in memory the tag information and the iov groups
      // full=true load the full iovSequence
      void load(const std::string& tag);

      // loads in memory the tag information and the iov groups
      void load(const std::string& tag, const boost::posix_time::ptime& snapshottime);

      // clear all the iov data in memory
      void reset();

      // it does NOT use the cache, every time it performs a new query.
      cond::Iov_t getLast();

      // the size of the LOADED iov sequence subset.
      int loadedSize() const;

      // the size of the entire iov sequence. Peforms a query at every call.
      int sequenceSize() const;

      // for reporting
      size_t numberOfQueries() const;

      // for debugging
      std::pair<cond::Time_t, cond::Time_t> loadedGroup() const;

      // maybe will be removed with a re-design of the top level interface (ESSources )
      const std::shared_ptr<SessionImpl>& session() const;

      void setPrintDebug(bool printDebug) { m_printDebug = printDebug; }

    private:
      void checkTransaction(const std::string& ctx) const;
      void resetIOVCache();
      void loadGroups();
      void fetchSequence(cond::Time_t lowerGroup, cond::Time_t higherGroup);

    private:
      std::shared_ptr<IOVProxyData> m_data;
      std::shared_ptr<SessionImpl> m_session;

      // whether additional debug info should be printed in fetchSequence
      bool m_printDebug = false;
    };

  }  // namespace persistency
}  // namespace cond

#endif