Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:54:32

0001 #include "DataFormats/Provenance/interface/LuminosityBlockRange.h"
0002 #include "FWCore/Utilities/interface/Algorithms.h"
0003 #include <cassert>
0004 #include <ostream>
0005 //#include <limits>
0006 
0007 namespace edm {
0008 
0009   //   static unsigned int const shift = 8 * sizeof(unsigned int);
0010   //
0011   //   LuminosityBlockID::LuminosityBlockID(uint64_t id) :
0012   //    run_(static_cast<RunNumber_t>(id >> shift)),
0013   //    luminosityBlock_(static_cast<LuminosityBlockNumber_t>(std::numeric_limits<unsigned int>::max() & id))
0014   //   {
0015   //   }
0016   //
0017   //   uint64_t
0018   //   LuminosityBlockID::value() const {
0019   //    uint64_t id = run_;
0020   //    id = id << shift;
0021   //    id += luminosityBlock_;
0022   //    return id;
0023   //   }
0024 
0025   LuminosityBlockRange::LuminosityBlockRange()
0026       :  // Special cases since 0 means maximum
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       :  // Special cases since 0 means maximum
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   }  // namespace
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 }  // namespace edm