LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
art::RangeSet Class Reference

#include "RangeSet.h"

Public Types

using const_iterator = std::vector< EventRange >::const_iterator
 

Public Member Functions

 ~RangeSet ()
 
 RangeSet (RunNumber_t)
 
 RangeSet (RunNumber_t, std::vector< EventRange > const &eventRanges)
 
 RangeSet (RangeSet const &)
 
 RangeSet (RangeSet &&)
 
RangeSetoperator= (RangeSet const &)
 
RangeSetoperator= (RangeSet &&)
 
RunNumber_t run () const
 
std::vector< EventRange > const & ranges () const
 
bool contains (RunNumber_t, SubRunNumber_t, EventNumber_t) const
 
bool is_valid () const
 
bool is_full_run () const
 
bool is_full_subRun () const
 
bool is_sorted () const
 
bool is_collapsed () const
 
std::string to_compact_string () const
 
bool has_disjoint_ranges () const
 
bool empty () const
 
const_iterator begin () const
 
const_iterator end () const
 
std::size_t begin_idx () const
 
std::size_t end_idx () const
 
unsigned checksum () const
 
std::size_t next_subrun_or_end (std::size_t const b) const
 
EventRangefront ()
 
EventRangeback ()
 
EventRangeat (std::size_t)
 
std::vector< EventRangeextract_ranges (std::size_t const b, std::size_t const e)
 
void assign_ranges (RangeSet const &rs, std::size_t const b, std::size_t const e)
 
void update (EventID const &)
 
template<typename... ARGS>
void emplace_range (ARGS &&...)
 
RangeSetcollapse ()
 
RangeSetmerge (RangeSet const &other)
 
std::pair< std::size_t, bool > split_range (SubRunNumber_t, EventNumber_t)
 
void set_run (RunNumber_t const r)
 
void sort ()
 
void clear ()
 
template<typename... ARGS>
void emplace_range (ARGS &&...args)
 

Static Public Member Functions

static constexpr unsigned invalidChecksum ()
 
static RangeSet invalid ()
 
static RangeSet forRun (RunID)
 
static RangeSet forSubRun (SubRunID)
 

Private Member Functions

 RangeSet ()
 
void require_not_full_run ()
 

Private Attributes

RunNumber_t run_ {IDNumber<Level::Run>::invalid()}
 
std::vector< EventRangeranges_ {}
 
bool isCollapsed_ {false}
 
unsigned checksum_ {invalidChecksum()}
 

Detailed Description

Definition at line 25 of file RangeSet.h.

Member Typedef Documentation

Definition at line 27 of file RangeSet.h.

Constructor & Destructor Documentation

art::RangeSet::~RangeSet ( )
default
art::RangeSet::RangeSet ( RunNumber_t  r)
explicit

Definition at line 71 of file RangeSet.cc.

References r.

71 : RangeSet{r, {}} {}
TRandom r
Definition: spectrum.C:23
art::RangeSet::RangeSet ( RunNumber_t  r,
std::vector< EventRange > const &  eventRanges 
)
explicit

Definition at line 73 of file RangeSet.cc.

References collapse(), ranges_, and sort().

74  : run_{r}, ranges_{eventRanges}
75  {
76  sort();
77  collapse();
78  }
RunNumber_t run_
Definition: RangeSet.h:110
TRandom r
Definition: spectrum.C:23
std::vector< EventRange > ranges_
Definition: RangeSet.h:111
RangeSet & collapse()
Definition: RangeSet.cc:262
void sort()
Definition: RangeSet.cc:378
art::RangeSet::RangeSet ( RangeSet const &  )
default
art::RangeSet::RangeSet ( RangeSet &&  )
default
art::RangeSet::RangeSet ( )
explicitprivatedefault

Member Function Documentation

void art::RangeSet::assign_ranges ( RangeSet const &  rs,
std::size_t const  b,
std::size_t const  e 
)

Definition at line 317 of file RangeSet.cc.

References e, ranges_, and require_not_full_run().

318  {
320  if (!rs.ranges_.empty() && (e >= 1) && (e <= rs.ranges_.size())) {
321  ranges_.assign(rs.ranges_.cbegin() + b, rs.ranges_.cbegin() + e);
322  }
323  }
std::vector< EventRange > ranges_
Definition: RangeSet.h:111
void require_not_full_run()
Definition: RangeSet.cc:390
Float_t e
Definition: plot.C:35
EventRange & art::RangeSet::at ( std::size_t  )

Definition at line 246 of file RangeSet.cc.

References ranges_.

Referenced by art::ClosedRangeSetHandler::do_update().

247  {
248  return ranges_.at(idx);
249  }
std::vector< EventRange > ranges_
Definition: RangeSet.h:111
EventRange & art::RangeSet::back ( )

Definition at line 240 of file RangeSet.cc.

References ranges_.

Referenced by collapse(), and update().

241  {
242  return ranges_.back();
243  }
std::vector< EventRange > ranges_
Definition: RangeSet.h:111
RangeSet::const_iterator art::RangeSet::begin ( ) const

Definition at line 201 of file RangeSet.cc.

References ranges_.

Referenced by split_range().

202  {
203  return ranges_.cbegin();
204  }
std::vector< EventRange > ranges_
Definition: RangeSet.h:111
size_t art::RangeSet::begin_idx ( ) const

Definition at line 189 of file RangeSet.cc.

Referenced by art::ClosedRangeSetHandler::begin_idx(), and art::OpenRangeSetHandler::do_getSeenRanges().

190  {
191  return 0;
192  }
unsigned art::RangeSet::checksum ( ) const

Definition at line 213 of file RangeSet.cc.

References checksum_, and to_compact_string().

214  {
215  // Could cache checksums to improve performance when necessary.
216  return checksum_ = cet::crc32{to_compact_string()}.digest();
217  }
unsigned checksum_
Definition: RangeSet.h:115
std::string to_compact_string() const
Definition: RangeSet.cc:148
void art::RangeSet::clear ( )

Definition at line 384 of file RangeSet.cc.

References ranges_.

Referenced by art::OpenRangeSetHandler::do_rebase().

385  {
386  ranges_.clear();
387  }
std::vector< EventRange > ranges_
Definition: RangeSet.h:111
RangeSet & art::RangeSet::collapse ( )

Definition at line 262 of file RangeSet.cc.

References back(), e, art::EventRange::is_adjacent(), is_sorted(), isCollapsed_, art::errors::LogicError, art::EventRange::merge(), r, ranges_, run_, std::swap(), and art::throw_if_not_disjoint().

Referenced by art::disjoint_ranges(), merge(), art::Run::put(), art::SubRun::put(), and RangeSet().

263  {
264  if (isCollapsed_) {
265  return *this;
266  }
267  if (ranges_.size() < 2) {
268  isCollapsed_ = true;
269  return *this;
270  }
271  if (!is_sorted())
272  throw art::Exception(art::errors::LogicError, "RangeSet::collapse()")
273  << "A range set must be sorted before it is collapsed.\n";
274 
275  auto processing = ranges_;
276  decltype(ranges_) result;
277  result.reserve(ranges_.size());
278  result.push_back(ranges_.front());
279  for (auto ir = ranges_.cbegin() + 1, e = ranges_.cend(); ir != e; ++ir) {
280  auto const& r = *ir;
281  auto& back = result.back();
282  if (back.is_adjacent(r)) {
283  back.merge(r);
284  } else {
286  result.push_back(r);
287  }
288  }
289  std::swap(ranges_, result);
290  isCollapsed_ = true;
291  return *this;
292  }
RunNumber_t run_
Definition: RangeSet.h:110
TRandom r
Definition: spectrum.C:23
decltype(auto) constexpr cend(T &&obj)
ADL-aware version of std::cend.
Definition: StdUtils.h:93
std::vector< EventRange > ranges_
Definition: RangeSet.h:111
for(Int_t i=0;i< nentries;i++)
Definition: comparison.C:30
bool is_sorted() const
Definition: RangeSet.cc:136
void throw_if_not_disjoint(RunNumber_t const rn, EventRange const &left, EventRange const &right) noexcept(false)
Definition: RangeSet.cc:453
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:101
bool isCollapsed_
Definition: RangeSet.h:114
EventRange & front()
Definition: RangeSet.cc:234
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
decltype(auto) constexpr cbegin(T &&obj)
ADL-aware version of std::cbegin.
Definition: StdUtils.h:85
void swap(lar::deep_const_fwd_iterator_nested< CITER, INNERCONTEXTRACT > &a, lar::deep_const_fwd_iterator_nested< CITER, INNERCONTEXTRACT > &b)
bool merge(EventRange const &other)
Definition: EventRange.cc:199
EventRange & back()
Definition: RangeSet.cc:240
Float_t e
Definition: plot.C:35
bool is_adjacent(EventRange const &other) const noexcept
Definition: EventRange.cc:152
bool art::RangeSet::contains ( RunNumber_t  r,
SubRunNumber_t  s,
EventNumber_t  e 
) const

Definition at line 101 of file RangeSet.cc.

References ranges_, and run_.

104  {
105  if (run_ != r) {
106  return false;
107  }
108  for (auto const& range : ranges_) {
109  if (range.contains(s, e)) {
110  return true;
111  }
112  }
113  return false;
114  }
RunNumber_t run_
Definition: RangeSet.h:110
TRandom r
Definition: spectrum.C:23
std::vector< EventRange > ranges_
Definition: RangeSet.h:111
Float_t e
Definition: plot.C:35
template<typename... ARGS>
void art::RangeSet::emplace_range ( ARGS &&  ...)
template<typename... ARGS>
void art::RangeSet::emplace_range ( ARGS &&...  args)

Definition at line 120 of file RangeSet.h.

References art::disjoint_ranges(), art::left(), art::detail::operator<<(), art::detail::operator==(), art::overlapping_ranges(), r, art::right(), art::same_ranges(), and art::throw_if_not_disjoint().

121  {
123  ranges_.emplace_back(std::forward<ARGS>(args)...);
124  isCollapsed_ = false;
125  }
std::vector< EventRange > ranges_
Definition: RangeSet.h:111
bool isCollapsed_
Definition: RangeSet.h:114
void require_not_full_run()
Definition: RangeSet.cc:390
bool art::RangeSet::empty ( ) const

Definition at line 179 of file RangeSet.cc.

References ranges_.

Referenced by art::disjoint_ranges().

180  {
181  for (auto const& range : ranges_) {
182  if (!range.empty())
183  return false;
184  }
185  return true;
186  }
std::vector< EventRange > ranges_
Definition: RangeSet.h:111
RangeSet::const_iterator art::RangeSet::end ( void  ) const

Definition at line 207 of file RangeSet.cc.

References ranges_.

Referenced by split_range().

208  {
209  return ranges_.cend();
210  }
std::vector< EventRange > ranges_
Definition: RangeSet.h:111
size_t art::RangeSet::end_idx ( ) const

Definition at line 195 of file RangeSet.cc.

References ranges_.

Referenced by art::OpenRangeSetHandler::do_rebase(), art::OpenRangeSetHandler::do_update(), art::ClosedRangeSetHandler::end_idx(), and next_subrun_or_end().

196  {
197  return static_cast<size_t>(ranges_.cend() - ranges_.cbegin());
198  }
std::vector< EventRange > ranges_
Definition: RangeSet.h:111
vector< EventRange > art::RangeSet::extract_ranges ( std::size_t const  b,
std::size_t const  e 
)

Definition at line 252 of file RangeSet.cc.

References e, and ranges_.

Referenced by art::ClosedRangeSetHandler::do_rebase().

253  {
254  vector<EventRange> result;
255  if (!ranges_.empty() && (e >= 1) && (e <= ranges_.size())) {
256  copy(ranges_.cbegin() + b, ranges_.cbegin() + e, back_inserter(result));
257  }
258  return result;
259  }
std::vector< EventRange > ranges_
Definition: RangeSet.h:111
Float_t e
Definition: plot.C:35
RangeSet art::RangeSet::forRun ( RunID  rid)
static
RangeSet art::RangeSet::forSubRun ( SubRunID  srid)
static

Definition at line 57 of file RangeSet.cc.

References art::SubRunID::run(), and art::SubRunID::subRun().

Referenced by art::detail::Producer::doBeginSubRun(), art::ProducingService::doPostReadSubRun(), art::SubRun::put(), and art::rangeSetFor().

58  {
59  return RangeSet{srid.run(), {EventRange::forSubRun(srid.subRun())}};
60  }
static EventRange forSubRun(SubRunNumber_t s) noexcept
Definition: EventRange.cc:37
EventRange & art::RangeSet::front ( )

Definition at line 234 of file RangeSet.cc.

References ranges_.

235  {
236  return ranges_.front();
237  }
std::vector< EventRange > ranges_
Definition: RangeSet.h:111
bool art::RangeSet::has_disjoint_ranges ( ) const

Definition at line 167 of file RangeSet.cc.

References is_sorted(), isCollapsed_, ranges_, and tmp.

Referenced by art::disjoint_ranges().

168  {
169  if (isCollapsed_ || is_sorted()) {
170  return (ranges_.size() < 2ull) ? true : disjoint(ranges_);
171  }
172  RangeSet tmp{*this};
173  tmp.sort();
174  tmp.collapse();
175  return tmp.has_disjoint_ranges();
176  }
std::vector< EventRange > ranges_
Definition: RangeSet.h:111
Float_t tmp
Definition: plot.C:35
bool is_sorted() const
Definition: RangeSet.cc:136
bool isCollapsed_
Definition: RangeSet.h:114
static constexpr unsigned art::RangeSet::invalidChecksum ( )
inlinestatic

Definition at line 31 of file RangeSet.h.

References util::begin(), clear(), e, util::empty(), util::end(), art::is_valid(), fhicl::other, and r.

32  {
33  return std::numeric_limits<unsigned>::max();
34  }
bool art::RangeSet::is_collapsed ( ) const

Definition at line 142 of file RangeSet.cc.

References isCollapsed_.

143  {
144  return isCollapsed_;
145  }
bool isCollapsed_
Definition: RangeSet.h:114
bool art::RangeSet::is_full_run ( ) const

Definition at line 123 of file RangeSet.cc.

References art::detail::full_run_event_range(), and ranges_.

Referenced by art::operator<<(), art::Run::put(), and require_not_full_run().

124  {
125  return ranges_.size() == 1ull &&
127  }
std::vector< EventRange > ranges_
Definition: RangeSet.h:111
EventRange full_run_event_range()
Definition: RangeSet.cc:81
bool art::RangeSet::is_full_subRun ( ) const

Definition at line 130 of file RangeSet.cc.

References ranges_.

Referenced by art::SubRun::put().

131  {
132  return (ranges_.size() == 1ull) && ranges_.front().is_full_subRun();
133  }
std::vector< EventRange > ranges_
Definition: RangeSet.h:111
bool art::RangeSet::is_sorted ( ) const

Definition at line 136 of file RangeSet.cc.

References ranges_.

Referenced by collapse(), and has_disjoint_ranges().

137  {
138  return std::is_sorted(ranges_.cbegin(), ranges_.cend());
139  }
std::vector< EventRange > ranges_
Definition: RangeSet.h:111
bool art::RangeSet::is_valid ( ) const
RangeSet & art::RangeSet::merge ( RangeSet const &  other)

Definition at line 295 of file RangeSet.cc.

References collapse(), is_valid(), isCollapsed_, ranges_, run(), run_, and std::swap().

Referenced by art::SummedValue< sumdata::POTSummary >::update_impl().

296  {
297  if (!other.is_valid()) {
298  return *this;
299  }
300  if (!is_valid()) {
301  run_ = other.run();
302  }
303  vector<EventRange> merged;
304  std::merge(ranges_.cbegin(),
305  ranges_.cend(),
306  other.ranges_.cbegin(),
307  other.ranges_.cend(),
308  back_inserter(merged));
309  unique(merged.begin(), merged.end());
310  std::swap(ranges_, merged);
311  isCollapsed_ = false;
312  collapse();
313  return *this;
314  }
RunNumber_t run_
Definition: RangeSet.h:110
std::vector< EventRange > ranges_
Definition: RangeSet.h:111
bool is_valid() const
Definition: RangeSet.cc:117
RangeSet & collapse()
Definition: RangeSet.cc:262
bool isCollapsed_
Definition: RangeSet.h:114
void swap(lar::deep_const_fwd_iterator_nested< CITER, INNERCONTEXTRACT > &a, lar::deep_const_fwd_iterator_nested< CITER, INNERCONTEXTRACT > &b)
size_t art::RangeSet::next_subrun_or_end ( std::size_t const  b) const

Definition at line 220 of file RangeSet.cc.

References end_idx(), and ranges_.

Referenced by art::ClosedRangeSetHandler::do_update().

221  {
222  if (b == end_idx()) {
223  return end_idx();
224  }
225  auto const sr = ranges_.at(b).subRun();
226  auto pos =
227  find_if(ranges_.cbegin() + b, ranges_.cend(), [sr](auto const& range) {
228  return range.subRun() != sr;
229  });
230  return static_cast<size_t>(pos - ranges_.cbegin());
231  }
std::vector< EventRange > ranges_
Definition: RangeSet.h:111
std::size_t end_idx() const
Definition: RangeSet.cc:195
RangeSet & art::RangeSet::operator= ( RangeSet const &  )
default
RangeSet & art::RangeSet::operator= ( RangeSet &&  )
default
vector< EventRange > const & art::RangeSet::ranges ( ) const

Definition at line 95 of file RangeSet.cc.

References ranges_.

Referenced by art::disjoint_ranges(), art::operator<<(), and art::operator==().

96  {
97  return ranges_;
98  }
std::vector< EventRange > ranges_
Definition: RangeSet.h:111
void art::RangeSet::require_not_full_run ( )
private

Definition at line 390 of file RangeSet.cc.

References is_full_run(), and art::errors::LogicError.

Referenced by assign_ranges(), split_range(), and update().

391  {
392  if (is_full_run()) {
393  throw Exception(errors::LogicError, "RangeSet::require_not_full_run")
394  << "\nA RangeSet created using RangeSet::forRun cannot be modified.\n";
395  }
396  }
bool is_full_run() const
Definition: RangeSet.cc:123
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
void art::RangeSet::set_run ( RunNumber_t const  r)

Definition at line 372 of file RangeSet.cc.

References r, and run_.

373  {
374  run_ = r;
375  }
RunNumber_t run_
Definition: RangeSet.h:110
TRandom r
Definition: spectrum.C:23
void art::RangeSet::sort ( void  )

Definition at line 378 of file RangeSet.cc.

References ranges_.

Referenced by RangeSet().

379  {
380  cet::sort_all(ranges_);
381  }
std::vector< EventRange > ranges_
Definition: RangeSet.h:111
pair< std::size_t, bool > art::RangeSet::split_range ( SubRunNumber_t  s,
EventNumber_t  e 
)

Definition at line 345 of file RangeSet.cc.

References begin(), e, end(), r, ranges_, require_not_full_run(), art::right(), and std::swap().

Referenced by art::ClosedRangeSetHandler::do_maybeSplitRange().

346  {
348  bool did_split = false;
349  auto result = ranges_.end();
350  auto foundRange =
351  find_if(ranges_.cbegin(), ranges_.cend(), [s, e](auto const& r) {
352  return r.contains(s, e);
353  });
354  // Split only if:
355  // - the range is found (i.e. the event is contained by the found range)
356  // - the range is valid
357  // - the size of the range is greater than 1
358  if ((foundRange != ranges_.cend()) && foundRange->is_valid() &&
359  (foundRange->size() > 1ull)) {
360  auto const begin = foundRange->begin();
361  auto const end = foundRange->end();
362  auto leftIt = ranges_.emplace(foundRange, s, begin, e);
363  result = next(leftIt);
364  EventRange right{s, e, end};
365  std::swap(*result, right);
366  did_split = true;
367  }
368  return make_pair(static_cast<size_t>(result - ranges_.cbegin()), did_split);
369  }
TRandom r
Definition: spectrum.C:23
constexpr auto const & right(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:102
std::vector< EventRange > ranges_
Definition: RangeSet.h:111
const_iterator end() const
Definition: RangeSet.cc:207
void require_not_full_run()
Definition: RangeSet.cc:390
const_iterator begin() const
Definition: RangeSet.cc:201
void swap(lar::deep_const_fwd_iterator_nested< CITER, INNERCONTEXTRACT > &a, lar::deep_const_fwd_iterator_nested< CITER, INNERCONTEXTRACT > &b)
Float_t e
Definition: plot.C:35
string art::RangeSet::to_compact_string ( ) const

Definition at line 148 of file RangeSet.cc.

References r, ranges_, run_, and art::to_string().

Referenced by checksum().

149  {
150  using namespace std;
151  string s{to_string(run_)};
152  if (!ranges_.empty()) {
153  s += ":";
154  }
155  for (auto const& r : ranges_) {
156  s += to_string(r.subRun());
157  s += "[";
158  s += to_string(r.begin());
159  s += ",";
160  s += to_string(r.end());
161  s += ")";
162  }
163  return s;
164  }
RunNumber_t run_
Definition: RangeSet.h:110
TRandom r
Definition: spectrum.C:23
std::vector< EventRange > ranges_
Definition: RangeSet.h:111
STL namespace.
std::string to_string(ModuleType const mt)
Definition: ModuleType.h:34
void art::RangeSet::update ( EventID const &  id)

Definition at line 326 of file RangeSet.cc.

References back(), art::EventRange::end(), ranges_, require_not_full_run(), run_, art::EventRange::set_end(), and art::EventRange::subRun().

Referenced by art::OpenRangeSetHandler::do_update().

327  {
329  if (ranges_.empty()) {
330  run_ = id.run();
331  ranges_.emplace_back(id.subRun(), id.event(), id.next().event());
332  return;
333  }
334  auto& back = ranges_.back();
335  if (back.subRun() == id.subRun() && back.end() == id.event()) {
336  back.set_end(id.next().event());
337  } else {
338  ranges_.emplace_back(id.subRun(), id.event(), id.next().event());
339  }
340  }
RunNumber_t run_
Definition: RangeSet.h:110
void set_end(EventNumber_t const e)
Definition: EventRange.cc:213
std::vector< EventRange > ranges_
Definition: RangeSet.h:111
EventNumber_t end() const noexcept
Definition: EventRange.cc:111
void require_not_full_run()
Definition: RangeSet.cc:390
SubRunNumber_t subRun() const noexcept
Definition: EventRange.cc:93
EventRange & back()
Definition: RangeSet.cc:240
Event finding and building.

Member Data Documentation

unsigned art::RangeSet::checksum_ {invalidChecksum()}
mutableprivate

Definition at line 115 of file RangeSet.h.

Referenced by checksum().

bool art::RangeSet::isCollapsed_ {false}
private

Definition at line 114 of file RangeSet.h.

Referenced by collapse(), has_disjoint_ranges(), is_collapsed(), and merge().

RunNumber_t art::RangeSet::run_ {IDNumber<Level::Run>::invalid()}
private

Definition at line 110 of file RangeSet.h.

Referenced by collapse(), contains(), is_valid(), merge(), run(), set_run(), to_compact_string(), and update().


The documentation for this class was generated from the following files: