CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/CondCore/IOVService/interface/IOVProxy.h

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 #include "CondFormats/Common/interface/IOVSequence.h"
00006 #include "CondFormats/Common/interface/SequenceState.h"
00007 
00008 #include <string>
00009 #include "CondFormats/Common/interface/Time.h"
00010 #include <boost/shared_ptr.hpp>
00011 #include <boost/iterator/transform_iterator.hpp>
00012 #include <boost/iterator/counting_iterator.hpp>
00013 
00014 namespace cond {
00015   
00016   class IOVSequence;
00017   typedef  IOVSequence IOV;
00018   
00019   class IOVElementProxy {
00020   public:
00021     IOVElementProxy() : m_since(cond::invalidTime), m_till(cond::invalidTime), m_dbSession(){}
00022     explicit IOVElementProxy(cond::DbSession& dbSession) : 
00023       m_since(cond::invalidTime), m_till(cond::invalidTime), m_dbSession( dbSession ){}
00024     IOVElementProxy(cond::Time_t is,
00025                     cond::Time_t it,
00026                     std::string const& itoken,
00027                     cond::DbSession& dbSession) :
00028       m_since(is), m_till(it), m_token(itoken), m_dbSession( dbSession ){}
00029     
00030     void set(cond::Time_t is,
00031              cond::Time_t it,
00032              std::string const& itoken ) {
00033       m_since=is; m_till=it; m_token=itoken;
00034     }
00035     
00036     void set(IOV const & v, int i);
00037     
00038     cond::Time_t since() const {return m_since;}
00039     cond::Time_t till() const {return m_till;}
00040     std::string const & token() const {return m_token;}
00041     std::string const & wrapperToken() const {return m_token;}
00042     cond::DbSession& db() const { return m_dbSession; }
00043 
00044   private:
00045     cond::Time_t m_since;
00046     cond::Time_t m_till;
00047     std::string  m_token;
00048     mutable cond::DbSession m_dbSession;
00049   };
00050   
00051   
00052   namespace impl {
00053     struct IOVImpl;
00054   }
00055   
00056   /* IOV as the user wants it
00057    */
00058   class IOVProxy {
00059   public:
00060     
00061     IOVProxy();
00062     ~IOVProxy();
00063     
00064     IOVProxy(cond::DbSession& dbSession,
00065              const std::string & token,
00066              bool nolib,
00067              bool keepOpen);
00068     
00069     struct IterHelp {
00070       typedef IOVElementProxy result_type;
00071       IterHelp() : iov(0){}
00072       IterHelp(impl::IOVImpl & in);
00073 
00074         result_type const & operator()(int i) const {
00075           if (iov) elem.set(*iov,i);
00076           return elem;
00077         }
00078 
00079         private:
00080         IOV const * iov;
00081         mutable IOVElementProxy elem;
00082     };
00083     
00084     typedef boost::transform_iterator<IterHelp,boost::counting_iterator<int> > const_iterator;
00085     
00086     const_iterator begin() const {
00087       return  boost::make_transform_iterator(boost::counting_iterator<int>(m_low),
00088                                              IterHelp(*m_iov));
00089     }
00090     
00091     const_iterator end() const {
00092       return  boost::make_transform_iterator(boost::counting_iterator<int>(m_high),
00093                                              IterHelp(*m_iov));
00094     }
00095     
00096     // find in range...
00097     const_iterator find(cond::Time_t time) const;
00098 
00099     // limit range
00100     void resetRange() const;
00101     void setRange(cond::Time_t since, cond::Time_t  till) const;
00102     // limit to the first n 
00103     void head(int n) const;
00104     // limit to the last n
00105     void tail(int n) const;
00106 
00107     int size() const;
00108     IOV const & iov() const;
00109     TimeType timetype() const;
00110     std::string payloadContainerName() const;
00111     std::string comment() const;
00112     int revision() const;
00113     cond::Time_t timestamp() const;
00114 
00115     SequenceState state() const {
00116       return SequenceState(iov());
00117     }
00118 
00119 
00120  
00121 
00122     DbSession& db() const;
00123  
00124     bool refresh();
00125 
00126   private:
00127     boost::shared_ptr<impl::IOVImpl> m_iov;
00128     mutable int m_low;
00129     mutable int m_high;
00130     
00131   };
00132 }
00133 
00134 #endif // CondCore_IOVService_IOVProxy_h