00001 #ifndef CondCore_IOVService_IOVProxy_h
00002 #define CondCore_IOVService_IOVProxy_h
00003
00004 #include <string>
00005 #include "CondCore/DBCommon/interface/Time.h"
00006 #include <boost/shared_ptr.hpp>
00007 #include <boost/iterator/transform_iterator.hpp>
00008 #include <boost/iterator/counting_iterator.hpp>
00009
00010 namespace cond {
00011
00012 class IOV;
00013 class PoolTransaction;
00014
00015 class IOVElement {
00016 public:
00017 IOVElement() : m_since(0), m_till(0), m_db(0){}
00018 IOVElement(PoolTransaction * idb) : m_since(0), m_till(0), m_db(idb){}
00019 IOVElement(cond::Time_t is,
00020 cond::Time_t it,
00021 std::string const& itoken,
00022 PoolTransaction * idb) :
00023 m_since(is), m_till(it), m_token(itoken), m_db(idb){}
00024
00025 void set(cond::Time_t is,
00026 cond::Time_t it,
00027 std::string const& itoken ) {
00028 m_since=is; m_till=it; m_token=itoken;
00029 }
00030
00031 void set(IOV const & v, int i);
00032
00033 cond::Time_t since() const {return m_since;}
00034 cond::Time_t till() const {return m_till;}
00035 std::string const & payloadToken() const {return m_token;}
00036 PoolTransaction * db() const { return m_db;}
00037 private:
00038 cond::Time_t m_since;
00039 cond::Time_t m_till;
00040 std::string m_token;
00041 PoolTransaction * m_db;
00042 };
00043
00044
00045 namespace impl {
00046 struct IOVImpl;
00047 }
00048
00049
00050
00051 class IOVProxy {
00052 public:
00053
00054 IOVProxy();
00055 ~IOVProxy();
00056
00057 IOVProxy(cond::PoolTransaction& db,
00058 const std::string & token, bool nolib);
00059
00060 struct IterHelp {
00061 typedef IOVElement result_type;
00062 IterHelp(impl::IOVImpl & in);
00063
00064 result_type const & operator()(int i) const {
00065 elem.set(iov,i);
00066 return elem;
00067 }
00068
00069 private:
00070 IOV const & iov;
00071 mutable IOVElement elem;
00072 };
00073
00074 typedef boost::transform_iterator<IterHelp,boost::counting_iterator<int> > const_iterator;
00075
00076 const_iterator begin() const {
00077 return boost::make_transform_iterator(boost::counting_iterator<int>(m_low),
00078 IterHelp(*m_iov));
00079 }
00080
00081 const_iterator end() const {
00082 return boost::make_transform_iterator(boost::counting_iterator<int>(m_high),
00083 IterHelp(*m_iov));
00084 }
00085
00086
00087 void setRange(cond::Time_t since, cond::Time_t till) const;
00088
00089 void head(int n) const;
00090
00091 void tail(int n) const;
00092
00093 int size() const;
00094 IOV const & iov() const;
00095 TimeType timetype() const;
00096
00097 private:
00098 boost::shared_ptr<impl::IOVImpl> m_iov;
00099 mutable int m_low;
00100 mutable int m_high;
00101
00102 };
00103 }
00104
00105 #endif // CondCore_IOVService_IOVProxy_h