EventRange.cc
Go to the documentation of this file.
2 // vim: set sw=2 expandtab :
3 
6 
7 #include <ostream>
8 
9 using namespace std;
10 
11 namespace art {
12 
13  namespace {
14 
15  void
16  require_ordering(EventNumber_t const b, EventNumber_t const e)
17  {
18  if (b > e) {
20  << "The 'begin' value for an EventRange must be less "
21  << "than the 'end' value.\n"
22  << " begin: " << b << " end: " << e << '\n';
23  }
24  }
25 
26  } // unnamed namespace
27 
28  // Note: static.
29  EventRange
30  EventRange::invalid() noexcept
31  {
32  return EventRange{};
33  }
34 
35  // Note: static.
37  EventRange::forSubRun(SubRunNumber_t const s) noexcept
38  {
40  }
41 
42  // Note: static.
43  bool
44  EventRange::are_valid(EventRange const& l, EventRange const& r) noexcept
45  {
46  return l.is_valid() && r.is_valid();
47  }
48 
49  EventRange::~EventRange() noexcept = default;
50  EventRange::EventRange() noexcept = default;
51 
52  EventRange::EventRange(SubRunNumber_t const s,
53  EventNumber_t const b,
54  EventNumber_t const e)
55  : subRun_{s}, begin_{b}, end_{e}
56  {
57  require_ordering(begin_, end_);
58  }
59 
60  EventRange::EventRange(EventRange const& rhs) noexcept = default;
61  EventRange::EventRange(EventRange&& rhs) noexcept = default;
62 
63  EventRange& EventRange::operator=(EventRange const& rhs) noexcept = default;
64 
65  EventRange& EventRange::operator=(EventRange&& rhs) noexcept = default;
66 
67  bool
68  EventRange::operator<(EventRange const& other) const noexcept
69  {
70  if (subRun_ == other.subRun_) {
71  if (begin_ == other.begin_) {
72  return end_ < other.end_;
73  }
74  return begin_ < other.begin_;
75  }
76  return subRun_ < other.subRun_;
77  }
78 
79  bool
80  EventRange::operator==(EventRange const& other) const noexcept
81  {
82  return (subRun_ == other.subRun_) && (begin_ == other.begin_) &&
83  (end_ == other.end_);
84  }
85 
86  bool
87  EventRange::operator!=(EventRange const& other) const noexcept
88  {
89  return !operator==(other);
90  }
91 
94  {
95  return subRun_;
96  }
97 
98  bool
100  {
101  return begin_ == end_;
102  }
103 
106  {
107  return begin_;
108  }
109 
112  {
113  return end_;
114  }
115 
116  bool
118  {
120  }
121 
122  unsigned long long
124  {
125  return is_valid() ? (end_ - begin_) : -1ull;
126  }
127 
128  bool
130  {
133  }
134 
135  bool
137  noexcept
138  {
139  return (subRun_ == s) && (e >= begin_) && (e < end_);
140  }
141 
142  bool
143  EventRange::is_same(EventRange const& other) const noexcept
144  {
145  if (!are_valid(*this, other)) {
146  return false;
147  }
148  return operator==(other);
149  }
150 
151  bool
152  EventRange::is_adjacent(EventRange const& other) const noexcept
153  {
154  if (!are_valid(*this, other)) {
155  return false;
156  }
157  return (subRun_ == other.subRun_) && (end_ == other.begin_);
158  }
159 
160  bool
161  EventRange::is_disjoint(EventRange const& other) const noexcept
162  {
163  if (!are_valid(*this, other)) {
164  return false;
165  }
166  return (subRun_ == other.subRun_) ? (end_ <= other.begin_) : true;
167  }
168 
169  bool
170  EventRange::is_subset(EventRange const& other) const noexcept
171  {
172  if (!are_valid(*this, other)) {
173  return false;
174  }
175  return (subRun_ == other.subRun_) && (begin_ >= other.begin_) &&
176  (end_ <= other.end_);
177  }
178 
179  bool
180  EventRange::is_superset(EventRange const& other) const noexcept
181  {
182  if (!are_valid(*this, other)) {
183  return false;
184  }
185  return (subRun_ == other.subRun_) && (begin_ <= other.begin_) &&
186  (end_ >= other.end_);
187  }
188 
189  bool
191  {
192  if (!are_valid(*this, other)) {
193  return false;
194  }
195  return !is_disjoint(other) && !is_subset(other) && !is_superset(other);
196  }
197 
198  bool
200  {
202  if (!are_valid(*this, other)) {
203  return false;
204  }
205  bool const mergeable = is_adjacent(other);
206  if (mergeable) {
207  end_ = other.end_;
208  }
209  return mergeable;
210  }
211 
212  void
214  {
216  require_ordering(begin_, e);
217  end_ = e;
218  }
219 
220  void
222  {
223  if (is_full_subRun()) {
224  throw Exception{errors::LogicError} << "\nAn EventRange created using "
225  "EventRange::forSubRun cannot be "
226  "modified.\n";
227  }
228  }
229 
230  ostream&
231  operator<<(ostream& os, EventRange const& r)
232  {
233  os << "SubRun: " << r.subRun();
234  if (r.is_full_subRun()) {
235  os << " (full sub-run)";
236  } else {
237  os << " Event range: [" << r.begin() << ',' << r.end() << ')';
238  }
239  return os;
240  }
241 
242 } // namespace art
void set_end(EventNumber_t const e)
Definition: EventRange.cc:213
bool empty() const noexcept
Definition: EventRange.cc:99
bool is_full_subRun() const noexcept
Definition: EventRange.cc:129
void require_not_full_SubRun() const
Definition: EventRange.cc:221
STL namespace.
bool operator==(EventRange const &other) const noexcept
Definition: EventRange.cc:80
unsigned long long size() const noexcept
Definition: EventRange.cc:123
SubRunNumber_t subRun_
Definition: EventRange.h:71
EventNumber_t end() const noexcept
Definition: EventRange.cc:111
static QStrList * l
Definition: config.cpp:1044
EventRange() noexcept
bool contains(SubRunNumber_t s, EventNumber_t e) const noexcept
Definition: EventRange.cc:136
std::ostream & operator<<(std::ostream &os, const GroupSelector &gs)
const double e
constexpr bool is_valid(IDNumber_t< L > const id) noexcept
Definition: IDNumber.h:113
bool is_same(EventRange const &other) const noexcept
Definition: EventRange.cc:143
IDNumber_t< Level::SubRun > SubRunNumber_t
Definition: IDNumber.h:119
bool is_disjoint(EventRange const &other) const noexcept
Definition: EventRange.cc:161
bool operator!=(EventRange const &other) const noexcept
Definition: EventRange.cc:87
EventNumber_t end_
Definition: EventRange.h:73
EventNumber_t begin_
Definition: EventRange.h:72
bool is_valid() const noexcept
Definition: EventRange.cc:117
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
EventNumber_t begin() const noexcept
Definition: EventRange.cc:105
static bool are_valid(EventRange const &l, EventRange const &r) noexcept
Definition: EventRange.cc:44
bool is_subset(EventRange const &other) const noexcept
Definition: EventRange.cc:170
EventRange & operator=(EventRange const &) noexcept
SubRunNumber_t subRun() const noexcept
Definition: EventRange.cc:93
IDNumber_t< Level::Event > EventNumber_t
Definition: IDNumber.h:118
static bool * b
Definition: config.cpp:1043
bool is_superset(EventRange const &other) const noexcept
Definition: EventRange.cc:180
bool merge(EventRange const &other)
Definition: EventRange.cc:199
bool is_adjacent(EventRange const &other) const noexcept
Definition: EventRange.cc:152
static QCString * s
Definition: config.cpp:1042
bool operator<(EventRange const &other) const noexcept
Definition: EventRange.cc:68
bool is_overlapping(EventRange const &other) const noexcept
Definition: EventRange.cc:190