Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
art::RangeSet Class Reference

#include <RangeSet.h>

Public Types

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

Public Member Functions

 ~RangeSet ()
 
 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, boolsplit_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

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 28 of file RangeSet.h.

Constructor & Destructor Documentation

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

Definition at line 71 of file RangeSet.cc.

71 : RangeSet{r, {}} {}
art::RangeSet::RangeSet ( RunNumber_t  r,
std::vector< EventRange > const &  eventRanges 
)
explicit

Definition at line 73 of file RangeSet.cc.

74  : run_{r}, ranges_{eventRanges}
75  {
76  sort();
77  collapse();
78  }
RunNumber_t run_
Definition: RangeSet.h:110
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

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.

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
const double e
void require_not_full_run()
Definition: RangeSet.cc:390
static bool * b
Definition: config.cpp:1043
EventRange & art::RangeSet::at ( std::size_t  )

Definition at line 246 of file RangeSet.cc.

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.

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.

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.

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

Definition at line 213 of file RangeSet.cc.

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.

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.

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
decltype(auto) constexpr cend(T &&obj)
ADL-aware version of std::cend.
Definition: StdUtils.h:87
static QCString result
std::vector< EventRange > ranges_
Definition: RangeSet.h:111
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:92
fInnerVessel push_back(Point(-578.400000, 0.000000, 0.000000))
const double e
void swap(Handle< T > &a, Handle< T > &b)
bool isCollapsed_
Definition: RangeSet.h:114
EventRange & front()
Definition: RangeSet.cc:234
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
for(std::string line;std::getline(inFile, line);)
Definition: regex_t.cc:37
decltype(auto) constexpr cbegin(T &&obj)
ADL-aware version of std::cbegin.
Definition: StdUtils.h:82
bool merge(EventRange const &other)
Definition: EventRange.cc:199
EventRange & back()
Definition: RangeSet.cc:240
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.

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
std::vector< EventRange > ranges_
Definition: RangeSet.h:111
const double e
static QCString * s
Definition: config.cpp:1042
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.

121  {
123  ranges_.emplace_back(std::forward<ARGS>(args)...);
124  isCollapsed_ = false;
125  }
std::vector< EventRange > ranges_
Definition: RangeSet.h:111
static QCString args
Definition: declinfo.cpp:674
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.

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 ( ) const

Definition at line 207 of file RangeSet.cc.

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.

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.

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  }
static QCString result
std::vector< EventRange > ranges_
Definition: RangeSet.h:111
const double e
T copy(T const &v)
static bool * b
Definition: config.cpp:1043
RangeSet art::RangeSet::forRun ( RunID  rid)
static

Definition at line 51 of file RangeSet.cc.

52  {
53  return RangeSet{rid.run(), {detail::full_run_event_range()}};
54  }
EventRange full_run_event_range()
Definition: RangeSet.cc:81
RangeSet art::RangeSet::forSubRun ( SubRunID  srid)
static

Definition at line 57 of file RangeSet.cc.

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.

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.

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
bool is_sorted() const
Definition: RangeSet.cc:136
bool isCollapsed_
Definition: RangeSet.h:114
string tmp
Definition: languages.py:63
RangeSet art::RangeSet::invalid ( )
static

Definition at line 45 of file RangeSet.cc.

46  {
47  return RangeSet{};
48  }
static constexpr unsigned art::RangeSet::invalidChecksum ( )
inlinestatic

Definition at line 32 of file RangeSet.h.

33  {
35  }
static int max(int a, int b)
bool art::RangeSet::is_collapsed ( ) const

Definition at line 142 of file RangeSet.cc.

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.

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.

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.

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

Definition at line 117 of file RangeSet.cc.

118  {
120  }
RunNumber_t run_
Definition: RangeSet.h:110
static constexpr type invalid() noexcept
Definition: IDNumber.h:82
RangeSet & art::RangeSet::merge ( RangeSet const &  other)

Definition at line 295 of file RangeSet.cc.

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
void swap(Handle< T > &a, Handle< T > &b)
bool isCollapsed_
Definition: RangeSet.h:114
size_t art::RangeSet::next_subrun_or_end ( std::size_t const  b) const

Definition at line 220 of file RangeSet.cc.

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
static bool * b
Definition: config.cpp:1043
static constexpr double sr
Definition: Units.h:166
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.

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.

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
RunNumber_t art::RangeSet::run ( ) const

Definition at line 89 of file RangeSet.cc.

90  {
91  return run_;
92  }
RunNumber_t run_
Definition: RangeSet.h:110
void art::RangeSet::set_run ( RunNumber_t const  r)

Definition at line 372 of file RangeSet.cc.

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

Definition at line 378 of file RangeSet.cc.

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

Definition at line 345 of file RangeSet.cc.

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};
366  did_split = true;
367  }
368  return make_pair(static_cast<size_t>(result - ranges_.cbegin()), did_split);
369  }
constexpr auto const & right(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:102
static QCString result
std::vector< EventRange > ranges_
Definition: RangeSet.h:111
const double e
void swap(Handle< T > &a, Handle< T > &b)
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
static QCString * s
Definition: config.cpp:1042
string art::RangeSet::to_compact_string ( ) const

Definition at line 148 of file RangeSet.cc.

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
std::vector< EventRange > ranges_
Definition: RangeSet.h:111
STL namespace.
std::string to_string(ModuleType const mt)
Definition: ModuleType.h:34
static QCString * s
Definition: config.cpp:1042
void art::RangeSet::update ( EventID const &  id)

Definition at line 326 of file RangeSet.cc.

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

Member Data Documentation

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

Definition at line 115 of file RangeSet.h.

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

Definition at line 114 of file RangeSet.h.

std::vector<EventRange> art::RangeSet::ranges_ {}
private

Definition at line 111 of file RangeSet.h.

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

Definition at line 110 of file RangeSet.h.


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