CMS 3D CMS Logo

/data/git/CMSSW_5_3_11_patch5/src/DataFormats/Provenance/interface/LuminosityBlockID.h

Go to the documentation of this file.
00001 #ifndef DataFormats_Provenance_LuminosityBlockID_h
00002 #define DataFormats_Provenance_LuminosityBlockID_h
00003 // -*- C++ -*-
00004 //
00005 // Package:     DataFormats/Provenance
00006 // Class  :     LuminosityBlockID
00007 //
00016 //
00017 //
00018 
00019 // system include files
00020 #include <functional>
00021 #include <iosfwd>
00022 #include "boost/cstdint.hpp"
00023 
00024 // user include files
00025 #include "DataFormats/Provenance/interface/RunID.h"
00026 
00027 // forward declarations
00028 namespace edm {
00029 
00030    typedef unsigned int LuminosityBlockNumber_t;
00031 
00032   class LuminosityBlockID {
00033    public:
00034       LuminosityBlockID() : run_(0), luminosityBlock_(0) {}
00035       explicit LuminosityBlockID(boost::uint64_t id);
00036       LuminosityBlockID(RunNumber_t iRun, LuminosityBlockNumber_t iLuminosityBlock) :
00037         run_(iRun), luminosityBlock_(iLuminosityBlock) {}
00038 
00039       //virtual ~LuminosityBlockID();
00040 
00041       // ---------- const member functions ---------------------
00042       RunNumber_t run() const { return run_; }
00043       LuminosityBlockNumber_t luminosityBlock() const { return luminosityBlock_; }
00044 
00045       boost::uint64_t value() const;
00046 
00047       //moving from one LuminosityBlockID to another one
00048       LuminosityBlockID next() const {
00049          if(luminosityBlock_ != maxLuminosityBlockNumber()) {
00050             return LuminosityBlockID(run_, luminosityBlock_+1);
00051          }
00052          return LuminosityBlockID(run_+1, 1);
00053       }
00054       LuminosityBlockID nextRun() const {
00055          return LuminosityBlockID(run_+1, 0);
00056       }
00057       LuminosityBlockID nextRunFirstLuminosityBlock() const {
00058          return LuminosityBlockID(run_+1, 1);
00059       }
00060       LuminosityBlockID previousRunLastLuminosityBlock() const {
00061          if(run_ > 1) {
00062             return LuminosityBlockID(run_-1, maxLuminosityBlockNumber());
00063          }
00064          return LuminosityBlockID(0,0);
00065       }
00066 
00067       LuminosityBlockID previous() const {
00068          if(luminosityBlock_ > 1) {
00069             return LuminosityBlockID(run_, luminosityBlock_-1);
00070          }
00071          if(run_ != 0) {
00072             return LuminosityBlockID(run_ -1, maxLuminosityBlockNumber());
00073          }
00074          return LuminosityBlockID(0,0);
00075       }
00076 
00077       bool operator==(LuminosityBlockID const& iRHS) const {
00078          return iRHS.run_ == run_ && iRHS.luminosityBlock_ == luminosityBlock_;
00079       }
00080       bool operator!=(LuminosityBlockID const& iRHS) const {
00081          return ! (*this == iRHS);
00082       }
00083 
00084       bool operator<(LuminosityBlockID const& iRHS) const {
00085          return doOp<std::less>(iRHS);
00086       }
00087       bool operator<=(LuminosityBlockID const& iRHS) const {
00088          return doOp<std::less_equal>(iRHS);
00089       }
00090       bool operator>(LuminosityBlockID const& iRHS) const {
00091          return doOp<std::greater>(iRHS);
00092       }
00093       bool operator>=(LuminosityBlockID const& iRHS) const {
00094          return doOp<std::greater_equal>(iRHS);
00095       }
00096 
00097       // ---------- static functions ---------------------------
00098 
00099       static LuminosityBlockNumber_t maxLuminosityBlockNumber() {
00100          return 0xFFFFFFFFU;
00101       }
00102 
00103       static LuminosityBlockID firstValidLuminosityBlock() {
00104          return LuminosityBlockID(1, 1);
00105       }
00106       // ---------- member functions ---------------------------
00107 
00108    private:
00109       template<template <typename> class Op>
00110       bool doOp(LuminosityBlockID const& iRHS) const {
00111          //Run takes presidence for comparisions
00112          if(run_ == iRHS.run_) {
00113             Op<LuminosityBlockNumber_t> op_e;
00114             return op_e(luminosityBlock_, iRHS.luminosityBlock_);
00115          }
00116          Op<RunNumber_t> op;
00117          return op(run_, iRHS.run_) ;
00118       }
00119       //LuminosityBlockID(LuminosityBlockID const&); // stop default
00120 
00121       //LuminosityBlockID const& operator=(LuminosityBlockID const&); // stop default
00122 
00123       // ---------- member data --------------------------------
00124       RunNumber_t run_;
00125       LuminosityBlockNumber_t luminosityBlock_;
00126   };
00127 
00128   std::ostream& operator<<(std::ostream& oStream, LuminosityBlockID const& iID);
00129 
00130   inline
00131   LuminosityBlockID const& min(LuminosityBlockID const& lh, LuminosityBlockID const& rh) {
00132     return (rh < lh ? rh : lh);
00133   }
00134 
00135   inline
00136   LuminosityBlockID const& max(LuminosityBlockID const& lh, LuminosityBlockID const& rh) {
00137     return (rh < lh ? lh : rh);
00138   }
00139 
00140 }
00141 #endif