CMS 3D CMS Logo

CMSSW_4_4_3_patch1/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)
00022                       , m_till(cond::invalidTime)
00023                       , m_token("") {}
00024     
00025     IOVElementProxy(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     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  
00042   private:
00043     cond::Time_t m_since;
00044     cond::Time_t m_till;
00045     std::string m_token;
00046   };
00047   
00048   
00049   namespace impl {
00050     struct IOVImpl;
00051   }
00052   
00053   /* IOV as the user wants it
00054    */
00055   class IOVProxy {
00056   public:
00057     
00058     IOVProxy();
00059     ~IOVProxy();
00060     
00061     explicit IOVProxy(cond::DbSession& dbSession);
00062 
00063     IOVProxy(cond::DbSession& dbSession,
00064              const std::string & token );
00065 
00066     void load( const std::string & token );
00067     
00068     struct IterHelp {
00069       typedef IOVElementProxy result_type;
00070       IterHelp() : iov(0){}
00071       IterHelp(impl::IOVImpl & in);
00072 
00073         result_type const & operator()(int i) const {
00074           if (iov) elem.set(*iov,i);
00075           return elem;
00076         }
00077 
00078         private:
00079         IOV const * iov;
00080         mutable IOVElementProxy elem;
00081     };
00082     
00083     typedef boost::transform_iterator<IterHelp,boost::counting_iterator<int> > const_iterator;
00084     
00085     const_iterator begin() const {
00086       return  boost::make_transform_iterator(boost::counting_iterator<int>(m_low),
00087                                              IterHelp(*m_iov));
00088     }
00089     
00090     const_iterator end() const {
00091       return  boost::make_transform_iterator(boost::counting_iterator<int>(m_high),
00092                                              IterHelp(*m_iov));
00093     }
00094     
00095     // find in range...
00096     const_iterator find(cond::Time_t time) const;
00097 
00098     // limit range
00099     void resetRange() const;
00100     void setRange(cond::Time_t since, cond::Time_t  till) const;
00101     // limit to the first n 
00102     void head(int n) const;
00103     // limit to the last n
00104     void tail(int n) const;
00105 
00106     int size() const;
00107     IOV const & iov() const;
00108     TimeType timetype() const;
00109     std::set<std::string> const& payloadClasses() const;
00110     std::string comment() const;
00111     int revision() const;
00112     cond::Time_t timestamp() const;
00113 
00114     SequenceState state() const {
00115       return SequenceState(iov());
00116     }
00117 
00118 
00119  
00120 
00121     DbSession& db() const;
00122  
00123     bool refresh();
00124 
00125   private:
00126     boost::shared_ptr<impl::IOVImpl> m_iov;
00127     mutable int m_low;
00128     mutable int m_high;
00129     
00130   };
00131 }
00132 
00133 #endif // CondCore_IOVService_IOVProxy_h