CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/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 
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       return  boost::make_transform_iterator(boost::counting_iterator<int>(m_high),
00123                                              IterHelp(*m_iov));
00124     }
00125     
00126     const_iterator find(cond::Time_t time) const;
00127 
00128     IOVElementProxy front() const;
00129 
00130     IOVElementProxy back() const;
00131 
00132     size_t size() const;
00133 
00134   private:
00135     boost::shared_ptr<IOVProxyData> m_iov;
00136     int m_low;
00137     int m_high;
00138   };
00139 
00140   /* IOV as the user wants it
00141    */
00142   class IOVProxy {
00143   public:
00144     typedef iov_range_iterator const_iterator;
00145 
00146   public:  
00147     IOVProxy();
00148 
00149     ~IOVProxy();
00150     
00151     explicit IOVProxy(cond::DbSession& dbSession);
00152 
00153     IOVProxy(cond::DbSession& dbSession, const std::string & token );
00154 
00155     IOVProxy( boost::shared_ptr<IOVProxyData>& data );
00156 
00157     IOVProxy( const IOVProxy& rhs );
00158 
00159     IOVProxy& operator=( const IOVProxy& rhs );
00160 
00161     void load( const std::string & token );
00162 
00163     bool refresh();
00164 
00165     const std::string& token(); 
00166     
00167     bool isValid( cond::Time_t currenttime );
00168 
00169     std::pair<cond::Time_t, cond::Time_t> validity( cond::Time_t currenttime );
00170     
00171     const_iterator begin() const {
00172       return  boost::make_transform_iterator(boost::counting_iterator<int>(0),
00173                                              IterHelp(*m_iov));
00174     }
00175     
00176     const_iterator end() const {
00177       return  boost::make_transform_iterator(boost::counting_iterator<int>(size()),
00178                                              IterHelp(*m_iov));
00179     }
00180 
00181     // find 
00182     const_iterator find(cond::Time_t time) const;
00183 
00184     // limit to the first n 
00185     IOVRange head(int n) const;
00186 
00187     // limit to the last n
00188     IOVRange tail(int n) const;
00189 
00190     IOVRange range(cond::Time_t since, cond::Time_t  till) const;
00191 
00192     IOVRange rangeHead(cond::Time_t since, cond::Time_t  till, int n) const;
00193 
00194     IOVRange rangeTail(cond::Time_t since, cond::Time_t  till, int n) const;
00195 
00196     int size() const;
00197 
00198     IOVSequence const & iov() const;
00199     
00200     TimeType timetype() const;
00201 
00202     cond::Time_t firstSince() const;
00203 
00204     cond::Time_t lastTill() const;
00205 
00206     std::set<std::string> const& payloadClasses() const;
00207 
00208     std::string comment() const;
00209 
00210     int revision() const;
00211 
00212     cond::Time_t timestamp() const;
00213 
00214     SequenceState state() const {
00215       return SequenceState(iov());
00216     }
00217 
00218     DbSession& db() const;
00219 
00220   private:
00221     boost::shared_ptr<IOVProxyData> m_iov;
00222     
00223   };
00224 }
00225 
00226 #endif // CondCore_IOVService_IOVProxy_h