Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:01:24

0001 #ifndef CondCore_CondDB_GTProxy_h
0002 #define CondCore_CondDB_GTProxy_h
0003 //
0004 // Package:     CondDB
0005 // Class  :     GTProxy
0006 //
0007 /**\class GTProxy GTProxy.h CondCore/CondDB/interface/GTProxy.h
0008    Description: service for read/only access to the condition Global Tags.  
0009 */
0010 //
0011 // Author:      Giacomo Govi
0012 // Created:     Jul 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     // required to handle the tag overriding
0025     std::string fullyQualifiedTag(const std::string& tag, const std::string& connectionString);
0026     std::pair<std::string, std::string> parseTag(const std::string& tag);
0027 
0028     class SessionImpl;
0029     class GTProxyData;
0030 
0031     // value semantics. to be used WITHIN the parent session transaction ( therefore the session should be kept alive ).
0032     class GTProxy {
0033     public:
0034       typedef std::vector<std::tuple<std::string, std::string, std::string> > GTContainer;
0035 
0036     public:
0037       // more or less compliant with typical iterator semantics...
0038       class Iterator {
0039       public:
0040         // C++17 compliant iterator definition
0041         using iterator_category = std::input_iterator_tag;
0042         using value_type = cond::GTEntry_t;
0043         using difference_type = void;  // Not used
0044         using pointer = void;          // Not used
0045         using reference = void;        // Not used
0046 
0047         //
0048         Iterator();
0049         explicit Iterator(GTContainer::const_iterator current);
0050         Iterator(const Iterator& rhs);
0051 
0052         //
0053         Iterator& operator=(const Iterator& rhs);
0054 
0055         // returns a VALUE not a reference!
0056         cond::GTEntry_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         GTContainer::const_iterator m_current;
0068       };
0069 
0070     public:
0071       GTProxy();
0072       // the only way to construct it from scratch...
0073       explicit GTProxy(const std::shared_ptr<SessionImpl>& session);
0074 
0075       //
0076       GTProxy(const GTProxy& rhs);
0077 
0078       //
0079       GTProxy& operator=(const GTProxy& rhs);
0080 
0081       // loads in memory the gtag information and the tags. to be resurrected after the changeover.
0082       //void load( const std::string& gtName );
0083 
0084       // overloading for pre- and post-fix. Used in the ORA implementation
0085       void load(const std::string& gtName, const std::string& preFix = "", const std::string& postFix = "");
0086 
0087       // reset the data in memory and execute again the queries for the current tag
0088       void reload();
0089 
0090       // clear all the iov data in memory
0091       void reset();
0092 
0093       std::string name() const;
0094 
0095       cond::Time_t validity() const;
0096 
0097       boost::posix_time::ptime snapshotTime() const;
0098 
0099       // start the iteration.
0100       Iterator begin() const;
0101 
0102       //
0103       Iterator end() const;
0104 
0105       //
0106       int size() const;
0107 
0108     private:
0109       void checkTransaction(const std::string& ctx);
0110 
0111     private:
0112       std::shared_ptr<GTProxyData> m_data;
0113       std::shared_ptr<SessionImpl> m_session;
0114     };
0115 
0116   }  // namespace persistency
0117 }  // namespace cond
0118 
0119 #endif