CMS 3D CMS Logo

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 
14  LuminosityBlockNumber_t startLumi,
15  EventNumber_t startEvent,
18  EventNumber_t endEvent)
19  : // Special cases since 0 means maximum
20  startEventID_(startRun, startLumi, startEvent != 0 ? startEvent : EventID::maxEventNumber()),
21  endEventID_(endRun, endLumi, endEvent != 0 ? endEvent : EventID::maxEventNumber()) {
22  assert((startLumi == 0) == (endLumi == 0));
23  }
24 
25  EventRange::EventRange(EventID const& begin, EventID const& end) : startEventID_(begin), endEventID_(end) {}
26 
27  std::ostream& operator<<(std::ostream& oStream, EventRange const& r) {
28  if (r.startLumi() == 0) {
29  oStream << "'" << r.startRun() << ":" << r.startEvent() << "-" << r.endRun() << ":" << r.endEvent() << "'";
30  } else {
31  oStream << "'" << r.startRun() << ":" << r.startLumi() << ":" << r.startEvent() << "-" << r.endRun() << ":"
32  << r.endLumi() << ":" << r.endEvent() << "'";
33  }
34  return oStream;
35  }
36 
37  bool contains(EventRange const& lh, EventID const& rh) {
38  if (lh.startLumi() == 0) {
39  return (contains_(lh, EventID(rh.run(), 0U, rh.event())));
40  }
41  return (contains_(lh, rh));
42  }
43 
44  bool contains_(EventRange const& lh, EventID const& rh) { return (rh >= lh.startEventID() && rh <= lh.endEventID()); }
45 
46  bool contains(EventRange const& lh, EventRange const& rh) {
47  assert((lh.startLumi() == 0) == (rh.startLumi() == 0));
48  return (contains(lh, rh.startEventID()) && contains(lh, rh.endEventID()));
49  }
50 
51  bool overlaps(EventRange const& lh, EventRange const& rh) {
52  assert((lh.startLumi() == 0) == (rh.startLumi() == 0));
53  return !distinct(lh, rh);
54  }
55 
56  bool lessThanSpecial(EventRange const& lh, EventRange const& rh) {
57  // First, separate the ranges so that those with 0 lumiID go first.
58  if ((lh.startLumi() == 0) != (rh.startLumi() == 0)) {
59  return lh.startLumi() == 0;
60  }
61  return lh.endEventID() < rh.startEventID();
62  }
63 
64  bool lessThan(EventRange const& lh, EventRange const& rh) {
65  assert((lh.startLumi() == 0) == (rh.startLumi() == 0));
66  return lh.endEventID() < rh.startEventID();
67  }
68 
69  bool distinct(EventRange const& lh, EventRange const& rh) {
70  assert((lh.startLumi() == 0) == (rh.startLumi() == 0));
71  return lessThan(lh, rh) || lessThan(rh, lh);
72  }
73 
74  namespace {
75  bool mergeSpecial(EventRange& lh, EventRange& rh) {
76  // Don't combine a range with 0 lumiID with a range with non-zero lumiID.
77  if ((lh.startLumi() == 0) != (rh.startLumi() == 0)) {
78  return false;
79  }
80  if (overlaps(lh, rh)) {
81  EventID begin = min(lh.startEventID(), rh.startEventID());
82  EventID end = max(lh.endEventID(), rh.endEventID());
83  rh = lh = EventRange(begin, end);
84  return true;
85  }
86  return false;
87  }
88 
89  bool sortByStartEventIDSpecial(EventRange const& lh, EventRange const& rh) {
90  // First, separate the ranges so that those with 0 lumiID go first.
91  if ((lh.startLumi() == 0) != (rh.startLumi() == 0)) {
92  return lh.startLumi() == 0;
93  }
94  return lh.startEventID() < rh.startEventID();
95  }
96  } // namespace
97 
98  std::vector<EventRange>& sortAndRemoveOverlaps(std::vector<EventRange>& eventRange) {
99  if (eventRange.size() <= 1U)
100  return eventRange;
101  sort_all(eventRange, sortByStartEventIDSpecial);
102  for (std::vector<EventRange>::iterator i = eventRange.begin() + 1, e = eventRange.end(); i != e; ++i) {
103  std::vector<EventRange>::iterator iprev = i - 1;
104  if (mergeSpecial(*iprev, *i)) {
105  i = eventRange.erase(iprev);
106  e = eventRange.end();
107  }
108  }
109  return eventRange;
110  }
111 } // namespace edm
EventID startEventID() const
Definition: EventRange.h:46
bool contains(EventRange const &lh, EventID const &rh)
Definition: EventRange.cc:37
EventID endEventID() const
Definition: EventRange.h:47
unsigned long long EventNumber_t
bool int lh
Definition: SIMDVec.h:20
assert(be >=bs)
unsigned int LuminosityBlockNumber_t
bool distinct(EventRange const &lh, EventRange const &rh)
Definition: EventRange.cc:69
bool lessThanSpecial(EventRange const &lh, EventRange const &rh)
Definition: EventRange.cc:56
LuminosityBlockNumber_t endLumi() const
Definition: EventRange.h:51
EventID const & min(EventID const &lh, EventID const &rh)
Definition: EventID.h:116
RunNumber_t run() const
Definition: EventID.h:38
LuminosityBlockNumber_t startLumi() const
Definition: EventRange.h:50
void sort_all(RandomAccessSequence &s)
wrappers for std::sort
Definition: Algorithms.h:92
bool contains_(EventRange const &lh, EventID const &rh)
Definition: EventRange.cc:44
bool overlaps(EventRange const &lh, EventRange const &rh)
Definition: EventRange.cc:51
HLT enums.
std::vector< EventRange > & sortAndRemoveOverlaps(std::vector< EventRange > &eventRange)
Definition: EventRange.cc:98
bool lessThan(EventRange const &lh, EventRange const &rh)
Definition: EventRange.cc:64
unsigned int RunNumber_t
std::ostream & operator<<(std::ostream &ost, const HLTGlobalStatus &hlt)
Formatted printout of trigger table.
EventNumber_t event() const
Definition: EventID.h:40
EventID const & max(EventID const &lh, EventID const &rh)
Definition: EventID.h:118