File indexing completed on 2024-04-06 12:05:04
0001 #include "DataFormats/Provenance/interface/LuminosityBlockRange.h"
0002 #include "FWCore/Utilities/interface/Algorithms.h"
0003 #include <cassert>
0004 #include <ostream>
0005
0006
0007 namespace edm {
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025 LuminosityBlockRange::LuminosityBlockRange()
0026 :
0027 startLumiID_(0, LuminosityBlockID::maxLuminosityBlockNumber()),
0028 endLumiID_(0, LuminosityBlockID::maxLuminosityBlockNumber()) {}
0029
0030 LuminosityBlockRange::LuminosityBlockRange(RunNumber_t startRun,
0031 LuminosityBlockNumber_t startLuminosityBlock,
0032 RunNumber_t endRun,
0033 LuminosityBlockNumber_t endLuminosityBlock)
0034 :
0035 startLumiID_(startRun,
0036 startLuminosityBlock != 0 ? startLuminosityBlock : LuminosityBlockID::maxLuminosityBlockNumber()),
0037 endLumiID_(endRun,
0038 endLuminosityBlock != 0 ? endLuminosityBlock : LuminosityBlockID::maxLuminosityBlockNumber()) {}
0039
0040 LuminosityBlockRange::LuminosityBlockRange(LuminosityBlockID const& begin, LuminosityBlockID const& end)
0041 : startLumiID_(begin), endLumiID_(end) {}
0042
0043 std::ostream& operator<<(std::ostream& oStream, LuminosityBlockRange const& r) {
0044 oStream << "'" << r.startRun() << ":" << r.startLumi() << "-" << r.endRun() << ":" << r.endLumi() << "'";
0045 return oStream;
0046 }
0047
0048 bool contains(LuminosityBlockRange const& lh, LuminosityBlockID const& rh) {
0049 if (rh >= lh.startLumiID() && rh <= lh.endLumiID()) {
0050 return true;
0051 }
0052 return false;
0053 }
0054
0055 bool contains(LuminosityBlockRange const& lh, LuminosityBlockRange const& rh) {
0056 if (contains(lh, rh.startLumiID()) && contains(lh, rh.endLumiID())) {
0057 return true;
0058 }
0059 return false;
0060 }
0061
0062 bool overlaps(LuminosityBlockRange const& lh, LuminosityBlockRange const& rh) { return !distinct(lh, rh); }
0063
0064 bool lessThan(LuminosityBlockRange const& lh, LuminosityBlockRange const& rh) {
0065 return lh.endLumiID() < rh.startLumiID();
0066 }
0067
0068 bool distinct(LuminosityBlockRange const& lh, LuminosityBlockRange const& rh) {
0069 return lessThan(lh, rh) || lessThan(rh, lh);
0070 }
0071
0072 bool merge(LuminosityBlockRange& lh, LuminosityBlockRange& rh) {
0073 if (overlaps(lh, rh)) {
0074 LuminosityBlockID begin = min(lh.startLumiID(), rh.startLumiID());
0075 LuminosityBlockID end = max(lh.endLumiID(), rh.endLumiID());
0076 rh = lh = LuminosityBlockRange(begin, end);
0077 return true;
0078 }
0079 return false;
0080 }
0081
0082 namespace {
0083 bool sortByStartLuminosityBlockID(LuminosityBlockRange const& lh, LuminosityBlockRange const& rh) {
0084 assert((lh.startLumi() == 0) == (rh.startLumi() == 0));
0085 return lh.startLumiID() < rh.startLumiID();
0086 }
0087 }
0088
0089 std::vector<LuminosityBlockRange>& sortAndRemoveOverlaps(std::vector<LuminosityBlockRange>& lumiRange) {
0090 if (lumiRange.size() <= 1U)
0091 return lumiRange;
0092 sort_all(lumiRange, sortByStartLuminosityBlockID);
0093 for (std::vector<LuminosityBlockRange>::iterator i = lumiRange.begin() + 1, e = lumiRange.end(); i != e; ++i) {
0094 std::vector<LuminosityBlockRange>::iterator iprev = i - 1;
0095 if (merge(*iprev, *i)) {
0096 i = lumiRange.erase(iprev);
0097 e = lumiRange.end();
0098 }
0099 }
0100 return lumiRange;
0101 }
0102 }