CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/DataFormats/Provenance/src/LuminosityBlockRange.cc

Go to the documentation of this file.
00001 #include "DataFormats/Provenance/interface/LuminosityBlockRange.h"
00002 #include "FWCore/Utilities/interface/Algorithms.h"
00003 #include <cassert>
00004 #include <ostream>
00005 //#include <limits>
00006 
00007 
00008 
00009 namespace edm {
00010 
00011 //   static unsigned int const shift = 8 * sizeof(unsigned int);
00012 //
00013 //   LuminosityBlockID::LuminosityBlockID(boost::uint64_t id) :
00014 //    run_(static_cast<RunNumber_t>(id >> shift)),
00015 //    luminosityBlock_(static_cast<LuminosityBlockNumber_t>(std::numeric_limits<unsigned int>::max() & id))
00016 //   {
00017 //   }
00018 //
00019 //   boost::uint64_t
00020 //   LuminosityBlockID::value() const {
00021 //    boost::uint64_t id = run_;
00022 //    id = id << shift;
00023 //    id += luminosityBlock_;
00024 //    return id;
00025 //   }
00026 
00027 
00028   LuminosityBlockRange::LuminosityBlockRange() :
00029     // Special cases since 0 means maximum
00030     startLumiID_(0, LuminosityBlockID::maxLuminosityBlockNumber()),
00031     endLumiID_(0, LuminosityBlockID::maxLuminosityBlockNumber()){
00032   }
00033 
00034   LuminosityBlockRange::LuminosityBlockRange(RunNumber_t startRun, LuminosityBlockNumber_t startLuminosityBlock,
00035                                              RunNumber_t endRun,   LuminosityBlockNumber_t endLuminosityBlock) :
00036     // Special cases since 0 means maximum
00037     startLumiID_(startRun, startLuminosityBlock != 0 ? startLuminosityBlock : LuminosityBlockID::maxLuminosityBlockNumber()),
00038     endLumiID_(endRun, endLuminosityBlock !=0 ? endLuminosityBlock : LuminosityBlockID::maxLuminosityBlockNumber()) {
00039   }
00040 
00041   LuminosityBlockRange::LuminosityBlockRange(LuminosityBlockID const& begin, LuminosityBlockID const& end) :
00042     startLumiID_(begin),
00043     endLumiID_(end) {
00044   }
00045 
00046   std::ostream& operator<<(std::ostream& oStream, LuminosityBlockRange const& r) {
00047     oStream << "'" << r.startRun() << ":" << r.startLumi() << "-"
00048                    << r.endRun()   << ":" << r.endLumi()   << "'" ;
00049     return oStream;
00050   }
00051 
00052   bool contains(LuminosityBlockRange const& lh, LuminosityBlockID const& rh) {
00053     if (rh >= lh.startLumiID() && rh <= lh.endLumiID()) {
00054       return true;
00055     }
00056     return false;
00057   }
00058 
00059   bool contains(LuminosityBlockRange const& lh, LuminosityBlockRange const& rh) {
00060     if (contains(lh,rh.startLumiID()) && contains(lh,rh.endLumiID())) {
00061       return true;
00062     }
00063     return false;
00064   }
00065 
00066   bool overlaps(LuminosityBlockRange const& lh, LuminosityBlockRange const& rh) {
00067     return !distinct(lh, rh);
00068   }
00069 
00070   bool lessThan(LuminosityBlockRange const& lh, LuminosityBlockRange const& rh) {
00071     return lh.endLumiID() < rh.startLumiID();
00072   }
00073 
00074   bool distinct(LuminosityBlockRange const& lh, LuminosityBlockRange const& rh) {
00075     return lessThan(lh, rh) || lessThan(rh, lh);
00076   }
00077 
00078   bool merge(LuminosityBlockRange& lh, LuminosityBlockRange& rh) {
00079     if (overlaps(lh, rh)) {
00080       LuminosityBlockID begin = min(lh.startLumiID(), rh.startLumiID());
00081       LuminosityBlockID end = max(lh.endLumiID(), rh.endLumiID());
00082       rh = lh = LuminosityBlockRange(begin, end);
00083       return true;
00084     }
00085     return false;
00086   }
00087 
00088   namespace {
00089     bool sortByStartLuminosityBlockID(LuminosityBlockRange const& lh, LuminosityBlockRange const& rh) {
00090       assert((lh.startLumi() == 0) == (rh.startLumi() == 0));
00091       return lh.startLumiID() < rh.startLumiID();
00092     }
00093   }
00094 
00095   std::vector<LuminosityBlockRange>&
00096   sortAndRemoveOverlaps(std::vector<LuminosityBlockRange>& lumiRange) {
00097     if (lumiRange.size() <= 1U) return lumiRange;
00098     sort_all(lumiRange, sortByStartLuminosityBlockID);
00099     for (std::vector<LuminosityBlockRange>::iterator i = lumiRange.begin() + 1, e = lumiRange.end();
00100         i != e; ++i) {
00101       std::vector<LuminosityBlockRange>::iterator iprev = i - 1;
00102       if (merge(*iprev, *i)) {
00103         i = lumiRange.erase(iprev);
00104         e = lumiRange.end();
00105       }
00106     }
00107     return lumiRange;
00108   }
00109 }