CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EventRange.cc
Go to the documentation of this file.
3 #include <cassert>
4 #include <ostream>
5 //#include <limits>
6 
7 namespace edm {
9  // Special cases since 0 means maximum
10  startEventID_(0U, 0U, EventID::maxEventNumber()),
11  endEventID_(0U, 0U, EventID::maxEventNumber()) {
12  }
13 
15  RunNumber_t endRun, LumiNumber_t endLumi, EventNumber_t endEvent) :
16  // Special cases since 0 means maximum
17  startEventID_(startRun, startLumi, startEvent != 0 ? startEvent : EventID::maxEventNumber()),
18  endEventID_(endRun, endLumi, endEvent != 0 ? endEvent : EventID::maxEventNumber()) {
19  assert((startLumi == 0) == (endLumi == 0));
20  }
21 
23  startEventID_(begin),
24  endEventID_(end) {
25  }
26 
27  std::ostream& operator<<(std::ostream& oStream, EventRange const& r) {
28  if (r.startLumi() == 0) {
29  oStream << "'" << r.startRun() << ":" << r.startEvent() << "-"
30  << r.endRun() << ":" << r.endEvent() << "'";
31  } else {
32  oStream << "'" << r.startRun() << ":" << r.startLumi() << ":" << r.startEvent() << "-"
33  << r.endRun() << ":" << r.endLumi() << ":" << r.endEvent() << "'";
34  }
35  return oStream;
36  }
37 
38  bool contains(EventRange const& lh, EventID const& rh) {
39  if (lh.startLumi() == 0) {
40  return (contains_(lh, EventID(rh.run(), 0U, rh.event())));
41  }
42  return (contains_(lh, rh));
43  }
44 
45  bool contains_(EventRange const& lh, EventID const& rh) {
46  return (rh >= lh.startEventID() && rh <= lh.endEventID());
47  }
48 
49  bool contains(EventRange const& lh, EventRange const& rh) {
50  assert((lh.startLumi() == 0) == (rh.startLumi() == 0));
51  return (contains(lh, rh.startEventID()) && contains(lh, rh.endEventID()));
52  }
53 
54  bool overlaps(EventRange const& lh, EventRange const& rh) {
55  assert((lh.startLumi() == 0) == (rh.startLumi() == 0));
56  return !distinct(lh, rh);
57  }
58 
59  bool lessThanSpecial(EventRange const& lh, EventRange const& rh) {
60  // First, separate the ranges so that those with 0 lumiID go first.
61  if ((lh.startLumi() == 0) != (rh.startLumi() == 0)) {
62  return lh.startLumi() == 0;
63  }
64  return lh.endEventID() < rh.startEventID();
65  }
66 
67  bool lessThan(EventRange const& lh, EventRange const& rh) {
68  assert((lh.startLumi() == 0) == (rh.startLumi() == 0));
69  return lh.endEventID() < rh.startEventID();
70  }
71 
72  bool distinct(EventRange const& lh, EventRange const& rh) {
73  assert((lh.startLumi() == 0) == (rh.startLumi() == 0));
74  return lessThan(lh, rh) || lessThan(rh, lh);
75  }
76 
77  namespace {
78  bool mergeSpecial(EventRange& lh, EventRange& rh) {
79  // Don't combine a range with 0 lumiID with a range with non-zero lumiID.
80  if ((lh.startLumi() == 0) != (rh.startLumi() == 0)) {
81  return false;
82  }
83  if (overlaps(lh, rh)) {
84  EventID begin = min(lh.startEventID(), rh.startEventID());
85  EventID end = max(lh.endEventID(), rh.endEventID());
86  rh = lh = EventRange(begin, end);
87  return true;
88  }
89  return false;
90  }
91 
92  bool sortByStartEventIDSpecial(EventRange const& lh, EventRange const& rh) {
93  // First, separate the ranges so that those with 0 lumiID go first.
94  if ((lh.startLumi() == 0) != (rh.startLumi() == 0)) {
95  return lh.startLumi() == 0;
96  }
97  return lh.startEventID() < rh.startEventID();
98  }
99  }
100 
101  std::vector<EventRange>&
102  sortAndRemoveOverlaps(std::vector<EventRange>& eventRange) {
103  if (eventRange.size() <= 1U) return eventRange;
104  sort_all(eventRange, sortByStartEventIDSpecial);
105  for (std::vector<EventRange>::iterator i = eventRange.begin() + 1, e = eventRange.end();
106  i != e; ++i) {
107  std::vector<EventRange>::iterator iprev = i - 1;
108  if (mergeSpecial(*iprev, *i)) {
109  i = eventRange.erase(iprev);
110  e = eventRange.end();
111  }
112  }
113  return eventRange;
114  }
115 }
RunNumber_t run() const
Definition: EventID.h:39
EventNumber_t event() const
Definition: EventID.h:41
int i
Definition: DBlmapReader.cc:9
LumiNumber_t startLumi() const
Definition: EventRange.h:51
bool contains(EventRange const &lh, EventID const &rh)
Definition: EventRange.cc:38
unsigned int EventNumber_t
Definition: EventRange.h:30
RunNumber_t startRun() const
Definition: EventRange.h:49
bool int lh
Definition: SIMDVec.h:19
bool distinct(EventRange const &lh, EventRange const &rh)
Definition: EventRange.cc:72
RunNumber_t endRun() const
Definition: EventRange.h:50
EventID startEventID() const
Definition: EventRange.h:47
bool lessThanSpecial(EventRange const &lh, EventRange const &rh)
Definition: EventRange.cc:59
EventNumber_t endEvent() const
Definition: EventRange.h:54
EventID endEventID() const
Definition: EventRange.h:48
EventID const & min(EventID const &lh, EventID const &rh)
Definition: EventID.h:129
#define end
Definition: vmac.h:37
LumiNumber_t endLumi() const
Definition: EventRange.h:52
void sort_all(RandomAccessSequence &s)
wrappers for std::sort
Definition: Algorithms.h:120
bool contains_(EventRange const &lh, EventID const &rh)
Definition: EventRange.cc:45
EventNumber_t startEvent() const
Definition: EventRange.h:53
bool overlaps(EventRange const &lh, EventRange const &rh)
Definition: EventRange.cc:54
#define begin
Definition: vmac.h:30
std::vector< EventRange > & sortAndRemoveOverlaps(std::vector< EventRange > &eventRange)
Definition: EventRange.cc:102
bool lessThan(EventRange const &lh, EventRange const &rh)
Definition: EventRange.cc:67
unsigned int RunNumber_t
Definition: EventRange.h:32
unsigned int LumiNumber_t
Definition: EventRange.h:31
std::ostream & operator<<(std::ostream &ost, const HLTGlobalStatus &hlt)
Formatted printout of trigger tbale.
EventID const & max(EventID const &lh, EventID const &rh)
Definition: EventID.h:134