Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-05-19 01:11:42

0001 #ifndef DataFormats_Provenance_LuminosityBlockID_h
0002 #define DataFormats_Provenance_LuminosityBlockID_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     DataFormats/Provenance
0006 // Class  :     LuminosityBlockID
0007 //
0008 /**\class edm::LuminosityBlockID
0009 
0010  Description: Holds run and luminosityBlock number.
0011 
0012 */
0013 
0014 #include <functional>
0015 #include <iosfwd>
0016 
0017 #include "DataFormats/Provenance/interface/RunID.h"
0018 #include "DataFormats/Provenance/interface/RunLumiEventNumber.h"
0019 #include <cstdint>
0020 
0021 namespace edm {
0022 
0023   class LuminosityBlockID {
0024   public:
0025     LuminosityBlockID() : run_(invalidRunNumber), luminosityBlock_(invalidLuminosityBlockNumber) {}
0026     explicit LuminosityBlockID(uint64_t id);
0027     LuminosityBlockID(RunNumber_t iRun, LuminosityBlockNumber_t iLuminosityBlock)
0028         : run_(iRun), luminosityBlock_(iLuminosityBlock) {}
0029 
0030     // ---------- const member functions ---------------------
0031     RunNumber_t run() const { return run_; }
0032     LuminosityBlockNumber_t luminosityBlock() const { return luminosityBlock_; }
0033 
0034     uint64_t value() const;
0035 
0036     //moving from one LuminosityBlockID to another one
0037     LuminosityBlockID next() const {
0038       if (luminosityBlock_ != maxLuminosityBlockNumber()) {
0039         return LuminosityBlockID(run_, luminosityBlock_ + 1);
0040       }
0041       return LuminosityBlockID(run_ + 1, 1);
0042     }
0043     LuminosityBlockID nextRun() const { return LuminosityBlockID(run_ + 1, 0); }
0044     LuminosityBlockID nextRunFirstLuminosityBlock() const { return LuminosityBlockID(run_ + 1, 1); }
0045     LuminosityBlockID previousRunLastLuminosityBlock() const {
0046       if (run_ > 1) {
0047         return LuminosityBlockID(run_ - 1, maxLuminosityBlockNumber());
0048       }
0049       return LuminosityBlockID(0, 0);
0050     }
0051 
0052     LuminosityBlockID previous() const {
0053       if (luminosityBlock_ > 1) {
0054         return LuminosityBlockID(run_, luminosityBlock_ - 1);
0055       }
0056       if (run_ != 0) {
0057         return LuminosityBlockID(run_ - 1, maxLuminosityBlockNumber());
0058       }
0059       return LuminosityBlockID(0, 0);
0060     }
0061 
0062     bool operator==(LuminosityBlockID const& iRHS) const {
0063       return iRHS.run_ == run_ && iRHS.luminosityBlock_ == luminosityBlock_;
0064     }
0065     bool operator!=(LuminosityBlockID const& iRHS) const { return !(*this == iRHS); }
0066 
0067     bool operator<(LuminosityBlockID const& iRHS) const { return doOp<std::less>(iRHS); }
0068     bool operator<=(LuminosityBlockID const& iRHS) const { return doOp<std::less_equal>(iRHS); }
0069     bool operator>(LuminosityBlockID const& iRHS) const { return doOp<std::greater>(iRHS); }
0070     bool operator>=(LuminosityBlockID const& iRHS) const { return doOp<std::greater_equal>(iRHS); }
0071 
0072     // ---------- static functions ---------------------------
0073 
0074     static LuminosityBlockNumber_t maxLuminosityBlockNumber() { return 0xFFFFFFFFU; }
0075 
0076     static LuminosityBlockID firstValidLuminosityBlock() { return LuminosityBlockID(1, 1); }
0077 
0078   private:
0079     template <template <typename> class Op>
0080     bool doOp(LuminosityBlockID const& iRHS) const {
0081       //Run takes presidence for comparisions
0082       if (run_ == iRHS.run_) {
0083         Op<LuminosityBlockNumber_t> op_e;
0084         return op_e(luminosityBlock_, iRHS.luminosityBlock_);
0085       }
0086       Op<RunNumber_t> op;
0087       return op(run_, iRHS.run_);
0088     }
0089 
0090     // ---------- member data --------------------------------
0091     RunNumber_t run_;
0092     LuminosityBlockNumber_t luminosityBlock_;
0093   };
0094 
0095   std::ostream& operator<<(std::ostream& oStream, LuminosityBlockID const& iID);
0096 
0097   inline LuminosityBlockID const& min(LuminosityBlockID const& lh, LuminosityBlockID const& rh) {
0098     return (rh < lh ? rh : lh);
0099   }
0100 
0101   inline LuminosityBlockID const& max(LuminosityBlockID const& lh, LuminosityBlockID const& rh) {
0102     return (rh < lh ? lh : rh);
0103   }
0104 
0105 }  // namespace edm
0106 #endif