ClosedRangeSetHandler.cc
Go to the documentation of this file.
2 // vim: set sw=2 expandtab :
3 
8 
9 #include <utility>
10 
11 namespace art {
12 
13  namespace {
14  constexpr auto invalid_eid [[maybe_unused]] =
16  } // unnamed namespace
17 
19 
20  ClosedRangeSetHandler::EventInfo::EventInfo() noexcept = default;
21  ClosedRangeSetHandler::EventInfo::EventInfo(EventInfo const& rhs) noexcept =
22  default;
23 
24  ClosedRangeSetHandler::EventInfo::EventInfo(EventInfo&& rhs) noexcept =
25  default;
26 
27  ClosedRangeSetHandler::EventInfo& ClosedRangeSetHandler::EventInfo::operator=(
28  EventInfo const& rhs) noexcept = default;
29 
30  ClosedRangeSetHandler::EventInfo& ClosedRangeSetHandler::EventInfo::operator=(
31  EventInfo&& rhs) noexcept = default;
32 
33  EventID const&
35  {
36  return id_;
37  }
38 
39  bool
41  {
42  return lastInSubRun_;
43  }
44 
45  void
46  ClosedRangeSetHandler::EventInfo::set(EventID const& eid, bool const last)
47  {
48  id_ = eid;
49  lastInSubRun_ = last;
50  }
51 
52  // Note: RangeSet has a data member that is a vector, and the vector
53  // dtor is not noexcept, so we cannot be noexcept either!
55 
56  // Note: RangeSet has a data member that is a vector, and the vector
57  // ctor is not noexcept, so we cannot be noexcept either!
59  : ranges_{rs}, idx_{0}, eventInfo_{}
60  {}
61 
62  // Note: RangeSet has a data member that is a vector, and the vector
63  // copy ctor is not noexcept, so we cannot be noexcept either!
65  ClosedRangeSetHandler const& rhs) = default;
66 
67  // Note: RangeSet has a data member that is a vector, and a vector
68  // move constructor is not noexcept, so we cannot be noexcept
69  // either!
71  default;
72 
73  // Note: RangeSet has a data member that is a vector, and the vector
74  // copy assignment is not noexcept, so we cannot be noexcept either!
76  ClosedRangeSetHandler const& rhs) = default;
77 
78  // Note: RangeSet has a data member that is a vector, and a vector
79  // move assignment is not noexcept, so we cannot be noexcept either!
81  ClosedRangeSetHandler&& rhs) = default;
82 
85  {
86  return eventInfo_;
87  }
88 
89  size_t
91  {
92  return ranges_.begin_idx();
93  }
94 
95  size_t
97  {
98  return ranges_.end_idx();
99  }
100 
103  {
104  return HandlerType::Closed;
105  }
106 
107  RangeSet
109  {
110  RangeSet tmp{ranges_.run()};
111  tmp.assign_ranges(ranges_, begin_idx(), idx_);
112  return tmp;
113  }
114 
115  void
116  ClosedRangeSetHandler::do_update(EventID const& id, bool const lastInSubRun)
117  {
118  eventInfo_.set(id, lastInSubRun);
119  if (lastInSubRun) {
121  return;
122  }
123  while (idx_ != end_idx() &&
124  !ranges_.at(idx_).contains(id.subRun(), id.event())) {
125  ++idx_;
126  }
127  }
128 
129  void
131  {
132  idx_ = end_idx();
133  }
134 
135  void
137  {
138  if (eventInfo_.lastInSubRun()) {
139  // No need to split.
140  return;
141  }
142  if (!eventInfo_.id().isValid()) {
143  // Have not read any events yet.
144  return;
145  }
146  if (eventInfo_.id().isFlush()) {
147  // Should not happen, be careful anyway.
148  return;
149  }
150  if (idx_ == end_idx()) {
151  // No need to split.
152  return;
153  }
154  auto split_range = ranges_.split_range(eventInfo_.id().subRun(),
155  eventInfo_.id().next().event());
156  if (split_range.second) {
157  // The split did happen, update our idx to the right-hand
158  // side of the split (our ranges has already been updated).
159  idx_ = split_range.first;
160  }
161  }
162 
163  void
165  {
166  auto rebasedRanges = ranges_.extract_ranges(idx_, end_idx());
167  RangeSet tmpRS{ranges_.run(), rebasedRanges};
168  ClosedRangeSetHandler tmp{tmpRS};
169  std::swap(*this, tmp);
170  }
171 
174  {
175  return new ClosedRangeSetHandler{*this};
176  }
177 
178 } // namespace art
bool isValid() const
Definition: EventID.h:122
EventID next() const
Definition: EventID.h:134
std::pair< std::size_t, bool > split_range(SubRunNumber_t, EventNumber_t)
Definition: RangeSet.cc:345
HandlerType do_type() const override
static constexpr type invalid() noexcept
Definition: IDNumber.h:17
ClosedRangeSetHandler(RangeSet const &inputRangeSet)
bool isFlush() const
Definition: EventID.h:128
RunNumber_t run() const
Definition: RangeSet.cc:89
bool contains(SubRunNumber_t s, EventNumber_t e) const noexcept
Definition: EventRange.cc:136
ClosedRangeSetHandler & operator=(ClosedRangeSetHandler const &)
void swap(Handle< T > &a, Handle< T > &b)
Framework includes.
std::size_t end_idx() const
Definition: RangeSet.cc:195
std::vector< EventRange > extract_ranges(std::size_t const b, std::size_t const e)
Definition: RangeSet.cc:252
string tmp
Definition: languages.py:63
RangeSet do_getSeenRanges() const override
void set(EventID const &eid, bool const last)
EventInfo const & eventInfo() const
void do_update(EventID const &, bool lastInSubRun) override
EventNumber_t event() const
Definition: EventID.h:116
RangeSetHandler * do_clone() const override
std::size_t next_subrun_or_end(std::size_t const b) const
Definition: RangeSet.cc:220
EventRange & at(std::size_t)
Definition: RangeSet.cc:246
SubRunNumber_t subRun() const
Definition: EventID.h:110
std::size_t begin_idx() const
Definition: RangeSet.cc:189