GTProxy

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
#ifndef CondCore_CondDB_GTProxy_h
#define CondCore_CondDB_GTProxy_h
//
// Package:     CondDB
// Class  :     GTProxy
//
/**\class GTProxy GTProxy.h CondCore/CondDB/interface/GTProxy.h
   Description: service for read/only access to the condition Global Tags.  
*/
//
// Author:      Giacomo Govi
// Created:     Jul 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 {

    // required to handle the tag overriding
    std::string fullyQualifiedTag(const std::string& tag, const std::string& connectionString);
    std::pair<std::string, std::string> parseTag(const std::string& tag);

    class SessionImpl;
    class GTProxyData;

    // value semantics. to be used WITHIN the parent session transaction ( therefore the session should be kept alive ).
    class GTProxy {
    public:
      typedef std::vector<std::tuple<std::string, std::string, std::string> > GTContainer;

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

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

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

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

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

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

      private:
        GTContainer::const_iterator m_current;
      };

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

      //
      GTProxy(const GTProxy& rhs);

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

      // loads in memory the gtag information and the tags. to be resurrected after the changeover.
      //void load( const std::string& gtName );

      // overloading for pre- and post-fix. Used in the ORA implementation
      void load(const std::string& gtName, const std::string& preFix = "", const std::string& postFix = "");

      // reset the data in memory and execute again the queries for the current tag
      void reload();

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

      std::string name() const;

      cond::Time_t validity() const;

      boost::posix_time::ptime snapshotTime() const;

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

      //
      Iterator end() const;

      //
      int size() const;

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

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

  }  // namespace persistency
}  // namespace cond

#endif