Go to the documentation of this file.00001 #ifndef CondCore_IOVService_IOVProxy_h
00002 #define CondCore_IOVService_IOVProxy_h
00003
00004 #include "CondCore/DBCommon/interface/DbSession.h"
00005
00006 #include "CondFormats/Common/interface/IOVSequence.h"
00007 #include "CondFormats/Common/interface/SequenceState.h"
00008 #include "CondFormats/Common/interface/Time.h"
00009
00010
00011 #include <boost/shared_ptr.hpp>
00012 #include <boost/iterator/transform_iterator.hpp>
00013 #include <boost/iterator/counting_iterator.hpp>
00014
00015 namespace cond {
00016
00017 class IOVSequence;
00018
00019 struct IOVProxyData {
00020 explicit IOVProxyData( cond::DbSession& dbs ) :
00021 dbSession(dbs),
00022 data(),
00023 token(""){
00024 }
00025
00026 IOVProxyData(cond::DbSession& dbs,
00027 const std::string & tok) :
00028 dbSession(dbs),
00029 data(),
00030 token(tok){
00031 refresh();
00032 }
00033
00034 ~IOVProxyData(){
00035 }
00036
00037 void refresh();
00038
00039 std::pair<int,int> range( cond::Time_t since, cond::Time_t till );
00040
00041 cond::DbSession dbSession;
00042 boost::shared_ptr<cond::IOVSequence> data;
00043 std::string token;
00044 };
00045
00046 class IOVElementProxy {
00047 public:
00048 IOVElementProxy() :
00049 m_since(cond::invalidTime),
00050 m_till(cond::invalidTime),
00051 m_token("") {}
00052
00053 IOVElementProxy(cond::Time_t is, cond::Time_t it, std::string const& itoken):
00054 m_since(is),
00055 m_till(it),
00056 m_token(itoken) {}
00057
00058 void set(cond::Time_t is, cond::Time_t it, std::string const& itoken) {
00059 m_since=is;
00060 m_till=it;
00061 m_token=itoken;
00062 }
00063
00064 void set(IOVSequence const & v, int i);
00065
00066 cond::Time_t since() const {
00067 return m_since;
00068 }
00069
00070 cond::Time_t till() const {
00071 return m_till;
00072 }
00073
00074 std::string const & token() const {
00075 return m_token;
00076 }
00077
00078 private:
00079 cond::Time_t m_since;
00080 cond::Time_t m_till;
00081 std::string m_token;
00082 };
00083
00084 class IterHelp {
00085 public:
00086 typedef IOVElementProxy result_type;
00087 IterHelp() : iov(0){}
00088 IterHelp( IOVProxyData & in);
00089
00090 result_type const & operator()(int i) const {
00091 if (iov) elem.set(*iov,i);
00092 return elem;
00093 }
00094
00095 private:
00096 IOVSequence const * iov;
00097 mutable IOVElementProxy elem;
00098 };
00099
00100 typedef boost::transform_iterator<IterHelp,boost::counting_iterator<int> > iov_range_iterator;
00101
00102 class IOVRange {
00103 public:
00104
00105 typedef iov_range_iterator const_iterator;
00106
00107 public:
00108 IOVRange();
00109
00110 IOVRange( const boost::shared_ptr<IOVProxyData>& iov, int low, int high );
00111
00112 IOVRange( const IOVRange& rhs );
00113
00114 IOVRange& operator=( const IOVRange& rhs );
00115
00116 const_iterator begin() const {
00117 return boost::make_transform_iterator(boost::counting_iterator<int>(m_low),
00118 IterHelp(*m_iov));
00119 }
00120
00121 const_iterator end() const {
00122
00123
00124 int index = m_high + 1;
00125 return boost::make_transform_iterator(boost::counting_iterator<int>(index),
00126 IterHelp(*m_iov));
00127 }
00128
00129 const_iterator find(cond::Time_t time) const;
00130
00131 IOVElementProxy front() const;
00132
00133 IOVElementProxy back() const;
00134
00135 size_t size() const;
00136
00137 private:
00138 boost::shared_ptr<IOVProxyData> m_iov;
00139 int m_low;
00140 int m_high;
00141 };
00142
00143
00144
00145 class IOVProxy {
00146 public:
00147 typedef iov_range_iterator const_iterator;
00148
00149 public:
00150 IOVProxy();
00151
00152 ~IOVProxy();
00153
00154 explicit IOVProxy(cond::DbSession& dbSession);
00155
00156 IOVProxy(cond::DbSession& dbSession, const std::string & token );
00157
00158 IOVProxy( boost::shared_ptr<IOVProxyData>& data );
00159
00160 IOVProxy( const IOVProxy& rhs );
00161
00162 IOVProxy& operator=( const IOVProxy& rhs );
00163
00164 void load( const std::string & token );
00165
00166 bool refresh();
00167
00168 const std::string& token();
00169
00170 bool isValid( cond::Time_t currenttime );
00171
00172 std::pair<cond::Time_t, cond::Time_t> validity( cond::Time_t currenttime );
00173
00174 const_iterator begin() const {
00175 return boost::make_transform_iterator(boost::counting_iterator<int>(0),
00176 IterHelp(*m_iov));
00177 }
00178
00179 const_iterator end() const {
00180 int index = size();
00181 return boost::make_transform_iterator(boost::counting_iterator<int>(index),
00182 IterHelp(*m_iov));
00183 }
00184
00185
00186 const_iterator find(cond::Time_t time) const;
00187
00188
00189 IOVRange head(int n) const;
00190
00191
00192 IOVRange tail(int n) const;
00193
00194 IOVRange range(cond::Time_t since, cond::Time_t till) const;
00195
00196 IOVRange rangeHead(cond::Time_t since, cond::Time_t till, int n) const;
00197
00198 IOVRange rangeTail(cond::Time_t since, cond::Time_t till, int n) const;
00199
00200 int size() const;
00201
00202 IOVSequence const & iov() const;
00203
00204 TimeType timetype() const;
00205
00206 cond::Time_t firstSince() const;
00207
00208 cond::Time_t lastTill() const;
00209
00210 std::set<std::string> const& payloadClasses() const;
00211
00212 std::string comment() const;
00213
00214 int revision() const;
00215
00216 cond::Time_t timestamp() const;
00217
00218 SequenceState state() const {
00219 return SequenceState(iov());
00220 }
00221
00222 DbSession& db() const;
00223
00224 private:
00225 boost::shared_ptr<IOVProxyData> m_iov;
00226
00227 };
00228 }
00229
00230 #endif // CondCore_IOVService_IOVProxy_h