File indexing completed on 2024-04-06 12:12:03
0001 #ifndef Framework_IOVSyncValue_h
0002 #define Framework_IOVSyncValue_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 #include <functional>
0023
0024
0025 #include "DataFormats/Provenance/interface/EventID.h"
0026 #include "DataFormats/Provenance/interface/Timestamp.h"
0027
0028
0029
0030 namespace edm {
0031 class IOVSyncValue {
0032 public:
0033 IOVSyncValue();
0034
0035 explicit IOVSyncValue(const EventID& iID);
0036 explicit IOVSyncValue(const Timestamp& iTime);
0037 IOVSyncValue(const EventID& iID, const Timestamp& iTime);
0038
0039
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
0053
0054
0055 bool comparable(const IOVSyncValue& iOther) const {
0056 return (haveID_ == iOther.haveID_) || (haveTime_ == iOther.haveTime_);
0057 }
0058
0059
0060 static const IOVSyncValue& invalidIOVSyncValue();
0061 static const IOVSyncValue& endOfTime();
0062 static const IOVSyncValue& beginOfTime();
0063
0064
0065
0066 private:
0067
0068
0069
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
0094 throwInvalidComparison();
0095 }
0096 return returnValue;
0097 }
0098
0099
0100 EventID eventID_;
0101 Timestamp time_;
0102 bool haveID_;
0103 bool haveTime_;
0104 };
0105
0106 }
0107
0108 #endif