Iterator

RunInfoProxy

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
#ifndef CondCore_CondDB_RunInfoProxy_h
#define CondCore_CondDB_RunInfoProxy_h
//
// Package:     CondDB
// Class  :     RunInfoProxy
//
/**\class RunInfoProxy RunInfoProxy.h CondCore/CondDB/interface/RunInfoProxy.h
   Description: service for read/only access to the Run information.  
*/
//
// Author:      Giacomo Govi
// Created:     Dec 2016
//

#include "CondCore/CondDB/interface/Types.h"
//

namespace cond {

  namespace persistency {

    class SessionImpl;
    class RunInfoProxyData;

    // value semantics. to be used WITHIN the parent session transaction ( therefore the session should be kept alive ).
    class RunInfoProxy {
    public:
      typedef std::vector<std::tuple<Time_t, boost::posix_time::ptime, boost::posix_time::ptime> > RunInfoData;

    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::RunInfo_t;
        using difference_type = void;  // Not used
        using pointer = void;          // Not used
        using reference = void;        // Not used

        //
        Iterator();
        explicit Iterator(RunInfoData::const_iterator current);
        Iterator(const Iterator& rhs);

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

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

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

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

      private:
        RunInfoData::const_iterator m_current;
      };

    public:
      RunInfoProxy();

      //
      explicit RunInfoProxy(const std::shared_ptr<SessionImpl>& session);

      //
      RunInfoProxy(const RunInfoProxy& rhs);

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

      // loads in memory the RunInfo data for the specified run range
      void load(Time_t low, Time_t up);

      // loads in memory the RunInfo data for the specified run range
      void load(const boost::posix_time::ptime& low, const boost::posix_time::ptime& up);

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

      // start the iteration.
      Iterator begin() const;

      //
      Iterator end() const;

      //
      Iterator find(Time_t target) const;

      //
      Iterator find(const boost::posix_time::ptime& target) const;

      //
      cond::RunInfo_t get(Time_t target) const;

      //
      cond::RunInfo_t get(const boost::posix_time::ptime& target) const;

      //
      int size() const;

    private:
      void checkTransaction(const std::string& ctx);

    private:
      std::shared_ptr<RunInfoProxyData> m_data;
      std::shared_ptr<SessionImpl> m_session;
    };

  }  // namespace persistency
}  // namespace cond

#endif