Go to the documentation of this file.00001 #include "CondCore/IOVService/interface/IOVProxy.h"
00002
00003
00004 #include "CondCore/DBCommon/interface/Time.h"
00005 #include "CondCore/DBCommon/interface/ClassInfoLoader.h"
00006 #include "CondCore/DBCommon/interface/DbTransaction.h"
00007 #include "CondCore/DBCommon/interface/DbScopedTransaction.h"
00008
00009 #include "CondFormats/Common/interface/IOVSequence.h"
00010
00011 namespace cond {
00012 namespace impl {
00013
00014 struct IOVImpl {
00015 IOVImpl(cond::DbSession& dbs,
00016 const std::string & token,
00017 bool ,
00018 bool keepOpen) : poolDb(dbs), m_token(token), m_keepOpen(keepOpen){
00019 refresh();
00020 if (m_keepOpen) {
00021 if(poolDb.transaction().isActive() && !poolDb.transaction().isReadOnly())
00022 poolDb.transaction().start(false);
00023 else poolDb.transaction().start(true);
00024 }
00025 }
00026
00027 void refresh() {
00028 cond::DbScopedTransaction transaction(poolDb);
00029 if(transaction.isActive() && !transaction.isReadOnly())
00030 transaction.start(false);
00031 else transaction.start(true);
00032 iov = poolDb.getTypedObject<cond::IOVSequence>( m_token );
00033 transaction.commit();
00034
00035
00036
00037
00038
00039
00040
00041 }
00042
00043 ~IOVImpl(){
00044 if (m_keepOpen) poolDb.transaction().commit();
00045 }
00046
00047 cond::DbSession poolDb;
00048 boost::shared_ptr<cond::IOVSequence> iov;
00049 std::string m_token;
00050
00051 bool m_keepOpen;
00052 };
00053 }
00054
00055 void IOVElementProxy::set(IOVSequence const & v, int ii) {
00056 size_t i =ii;
00057 if (i>=v.iovs().size()) {
00058 set(cond::invalidTime, cond::invalidTime,"");
00059 return;
00060 }
00061 m_since = v.iovs()[i].sinceTime();
00062 m_till = (i+1==v.iovs().size()) ? v.lastTill() : v.iovs()[i+1].sinceTime()-1;
00063 m_token = v.iovs()[i].wrapperToken();
00064 }
00065
00066 IOVProxy::IterHelp::IterHelp(impl::IOVImpl & impl) :
00067 iov(&(*impl.iov)), elem(impl.poolDb){}
00068
00069 IOVProxy::IOVProxy() : m_low(0), m_high(0){}
00070
00071 IOVProxy::~IOVProxy() {}
00072
00073 IOVProxy::IOVProxy(cond::DbSession& dbSession,
00074 const std::string & token,
00075 bool nolib,
00076 bool keepOpen)
00077 :m_iov(new impl::IOVImpl(dbSession,token,nolib,keepOpen)), m_low(0), m_high(size()){}
00078
00079
00080 bool IOVProxy::refresh() {
00081 int oldsize = size();
00082 m_iov->refresh();
00083 bool anew = oldsize<size();
00084 if (anew) m_high = size();
00085 return anew;
00086 }
00087
00088 void IOVProxy::resetRange() const {
00089 m_low=0;
00090 m_high=size();
00091 }
00092
00093
00094 void IOVProxy::setRange(cond::Time_t since, cond::Time_t till) const {
00095 m_low = (since<iov().iovs().front().sinceTime()) ? 0 :
00096 iov().find(since)-iov().iovs().begin();
00097 m_high=iov().find(till)-iov().iovs().begin();
00098 m_high=std::min(m_high+1,size());
00099 }
00100
00101
00102
00103 void IOVProxy::head(int n) const {
00104 m_high = std::min(m_low+n,m_high);
00105 }
00106
00107 void IOVProxy::tail(int n) const {
00108 m_low = std::max(m_high-n,m_low);
00109 }
00110
00111
00112 IOVProxy::const_iterator IOVProxy::find(cond::Time_t time) const {
00113 int n = iov().find(time)-iov().iovs().begin();
00114 return (n<m_low || m_high<n ) ?
00115 end() :
00116 boost::make_transform_iterator(boost::counting_iterator<int>(n),
00117 IterHelp(*m_iov));
00118 }
00119
00120
00121 int IOVProxy::size() const {
00122 return iov().iovs().size();
00123 }
00124
00125 IOV const & IOVProxy::iov() const {
00126 return *(*m_iov).iov;
00127 }
00128
00129 TimeType IOVProxy::timetype() const {
00130 return iov().timeType();
00131 }
00132
00133
00134 std::string
00135 IOVProxy::payloadContainerName() const{
00136
00137 std::string payloadtokstr=iov().iovs().front().wrapperToken();
00138 std::pair<std::string,int> oidData = parseToken( payloadtokstr );
00139 return oidData.first;
00140 }
00141
00142 std::string
00143 IOVProxy::comment() const{
00144 return iov().comment();
00145 }
00146
00147 int
00148 IOVProxy::revision() const{
00149 return iov().revision();
00150 }
00151
00152 cond::Time_t IOVProxy::timestamp() const {
00153 return iov().timestamp();
00154 }
00155
00156 cond::DbSession& IOVProxy::db() const {
00157 return m_iov->poolDb;
00158 }
00159
00160
00161
00162 }