Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:12:03

0001 #ifndef Framework_IOVSyncValue_h
0002 #define Framework_IOVSyncValue_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     Framework
0006 // Class  :     IOVSyncValue
0007 //
0008 /**\class IOVSyncValue IOVSyncValue.h FWCore/Framework/interface/IOVSyncValue.h
0009 
0010  Description: Provides the information needed to synchronize the EventSetup IOV with an Event
0011 
0012  Usage:
0013     <usage>
0014 
0015 */
0016 //
0017 // Original Author:  Chris Jones
0018 //         Created:  Wed Aug  3 18:35:24 EDT 2005
0019 //
0020 
0021 // system include files
0022 #include <functional>
0023 
0024 // user include files
0025 #include "DataFormats/Provenance/interface/EventID.h"
0026 #include "DataFormats/Provenance/interface/Timestamp.h"
0027 
0028 // forward declarations
0029 
0030 namespace edm {
0031   class IOVSyncValue {
0032   public:
0033     IOVSyncValue();
0034     //virtual ~IOVSyncValue();
0035     explicit IOVSyncValue(const EventID& iID);
0036     explicit IOVSyncValue(const Timestamp& iTime);
0037     IOVSyncValue(const EventID& iID, const Timestamp& iTime);
0038 
0039     // ---------- const member functions ---------------------
0040     const EventID& eventID() const { return eventID_; }
0041     LuminosityBlockNumber_t luminosityBlockNumber() const { return eventID_.luminosityBlock(); }
0042     const Timestamp& time() const { return time_; }
0043 
0044     bool operator==(const IOVSyncValue& iRHS) const { return comparable(iRHS) && doOp<std::equal_to>(iRHS); }
0045     bool operator!=(const IOVSyncValue& iRHS) const { return (!comparable(iRHS)) || doOp<std::not_equal_to>(iRHS); }
0046 
0047     bool operator<(const IOVSyncValue& iRHS) const { return doOp<std::less>(iRHS); }
0048     bool operator<=(const IOVSyncValue& iRHS) const { return doOp<std::less_equal>(iRHS); }
0049     bool operator>(const IOVSyncValue& iRHS) const { return doOp<std::greater>(iRHS); }
0050     bool operator>=(const IOVSyncValue& iRHS) const { return doOp<std::greater_equal>(iRHS); }
0051 
0052     /** returns true if comparison operations are possible. Comparisons only fail if
0053       a time only value is compared to a run/lumi/event only value.
0054        */
0055     bool comparable(const IOVSyncValue& iOther) const {
0056       return (haveID_ == iOther.haveID_) || (haveTime_ == iOther.haveTime_);
0057     }
0058 
0059     // ---------- static member functions --------------------
0060     static const IOVSyncValue& invalidIOVSyncValue();
0061     static const IOVSyncValue& endOfTime();
0062     static const IOVSyncValue& beginOfTime();
0063 
0064     // ---------- member functions ---------------------------
0065 
0066   private:
0067     //IOVSyncValue(const IOVSyncValue&); // stop default
0068 
0069     //const IOVSyncValue& operator=(const IOVSyncValue&); // stop default
0070     void throwInvalidComparison() const;
0071     template <template <typename> class Op>
0072     bool doOp(const IOVSyncValue& iRHS) const {
0073       bool returnValue = false;
0074       if (haveID_ && iRHS.haveID_) {
0075         if (luminosityBlockNumber() == 0 || iRHS.luminosityBlockNumber() == 0 ||
0076             luminosityBlockNumber() == iRHS.luminosityBlockNumber()) {
0077           Op<EventID> op;
0078           returnValue = op(eventID_, iRHS.eventID_);
0079         } else {
0080           if (iRHS.eventID_.run() == eventID_.run()) {
0081             Op<LuminosityBlockNumber_t> op;
0082             returnValue = op(luminosityBlockNumber(), iRHS.luminosityBlockNumber());
0083           } else {
0084             Op<RunNumber_t> op;
0085             returnValue = op(eventID_.run(), iRHS.eventID_.run());
0086           }
0087         }
0088 
0089       } else if (haveTime_ && iRHS.haveTime_) {
0090         Op<Timestamp> op;
0091         returnValue = op(time_, iRHS.time_);
0092       } else {
0093         //error
0094         throwInvalidComparison();
0095       }
0096       return returnValue;
0097     }
0098 
0099     // ---------- member data --------------------------------
0100     EventID eventID_;
0101     Timestamp time_;
0102     bool haveID_;
0103     bool haveTime_;
0104   };
0105 
0106 }  // namespace edm
0107 
0108 #endif