LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
art::RangeSet Class Reference

#include "RangeSet.h"

Public Types

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

Public Member Functions

 RangeSet (RunNumber_t)
 
 RangeSet (RunNumber_t, std::vector< EventRange > const &eventRanges)
 
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
 
auto begin () const
 
auto end () const
 
unsigned checksum () const
 
decltype(auto) front ()
 
decltype(auto) back ()
 
void assign_ranges (const_iterator b, const_iterator e)
 
void update (EventID const &)
 
template<typename... ARGS>
void emplace_range (ARGS &&...)
 
RangeSetcollapse ()
 
RangeSetmerge (RangeSet const &other)
 
std::pair< const_iterator, 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 RangeSet invalid ()
 
static RangeSet forRun (RunID)
 
static RangeSet forSubRun (SubRunID)
 
static constexpr unsigned invalidChecksum ()
 

Private Member Functions

 RangeSet ()=default
 
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 24 of file RangeSet.h.

Member Typedef Documentation

Definition at line 33 of file RangeSet.h.

Constructor & Destructor Documentation

RangeSet::RangeSet ( RunNumber_t  r)
explicit

Definition at line 63 of file RangeSet.cc.

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

Definition at line 65 of file RangeSet.cc.

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

67  : run_{r}, ranges_{eventRanges}
68 {
69  sort();
70  collapse();
71 }
RunNumber_t run_
Definition: RangeSet.h:144
RangeSet & collapse()
Definition: RangeSet.cc:74
std::vector< EventRange > ranges_
Definition: RangeSet.h:145
void sort()
Definition: RangeSet.h:114
art::RangeSet::RangeSet ( )
explicitprivatedefault

Member Function Documentation

void RangeSet::assign_ranges ( const_iterator  b,
const_iterator  e 
)

Definition at line 109 of file RangeSet.cc.

References ranges_, and require_not_full_run().

111 {
113  ranges_.assign(b, e);
114 }
std::vector< EventRange > ranges_
Definition: RangeSet.h:145
void require_not_full_run()
Definition: RangeSet.h:135
decltype(auto) art::RangeSet::back ( void  )
inline

Definition at line 88 of file RangeSet.h.

References e, and fhicl::other.

Referenced by collapse(), and update().

89  {
90  return ranges_.back();
91  }
std::vector< EventRange > ranges_
Definition: RangeSet.h:145
auto art::RangeSet::begin ( ) const
inline

Definition at line 70 of file RangeSet.h.

Referenced by art::ClosedRangeSetHandler::begin(), art::OpenRangeSetHandler::do_getSeenRanges(), split_range(), and to_compact_string().

71  {
72  return ranges_.begin();
73  }
std::vector< EventRange > ranges_
Definition: RangeSet.h:145
unsigned RangeSet::checksum ( ) const

Definition at line 184 of file RangeSet.cc.

References checksum_, and to_compact_string().

185 {
186  // Could cache checksums to improve performance when necessary.
188 }
unsigned checksum_
Definition: RangeSet.h:149
std::string to_compact_string() const
Definition: RangeSet.cc:265
unsigned checksum() const
Definition: RangeSet.cc:184
void art::RangeSet::clear ( void  )
inline

Definition at line 120 of file RangeSet.h.

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

121  {
122  ranges_.clear();
123  }
std::vector< EventRange > ranges_
Definition: RangeSet.h:145
RangeSet & RangeSet::collapse ( )

Definition at line 74 of file RangeSet.cc.

References back(), e, is_sorted(), isCollapsed_, art::errors::LogicError, ranges_, run_, and art::throw_if_not_disjoint().

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

75 {
76  if (isCollapsed_) {
77  return *this;
78  }
79 
80  if (ranges_.size() < 2) {
81  isCollapsed_ = true;
82  return *this;
83  }
84 
85  if (!is_sorted())
86  throw art::Exception(art::errors::LogicError, "RangeSet::collapse()")
87  << "A range set must be sorted before it is collapsed.\n";
88 
89  auto processing = ranges_;
90  decltype(ranges_) result;
91  result.reserve(ranges_.size());
92  result.push_back(ranges_.front());
93  for (auto ir = ranges_.cbegin() + 1, e = ranges_.cend(); ir != e; ++ir) {
94  auto const& r = *ir;
95  auto& back = result.back();
96  if (back.is_adjacent(r)) {
97  back.merge(r);
98  } else {
100  result.push_back(r);
101  }
102  }
103  std::swap(ranges_, result);
104  isCollapsed_ = true;
105  return *this;
106 }
RunNumber_t run_
Definition: RangeSet.h:144
std::vector< EventRange > ranges_
Definition: RangeSet.h:145
for(int i=0;i< 401;i++)
bool is_sorted() const
Definition: RangeSet.cc:259
void throw_if_not_disjoint(RunNumber_t const rn, EventRange const &left, EventRange const &right) noexcept(false)
Definition: RangeSet.cc:333
bool isCollapsed_
Definition: RangeSet.h:148
void swap(art::HLTGlobalStatus &lhs, art::HLTGlobalStatus &rhs)
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
Float_t e
Definition: plot.C:34
decltype(auto) back()
Definition: RangeSet.h:88
decltype(auto) front()
Definition: RangeSet.h:83
bool RangeSet::contains ( RunNumber_t  r,
SubRunNumber_t  s,
EventNumber_t  e 
) const

Definition at line 214 of file RangeSet.cc.

References ranges_, and run_.

Referenced by split_range().

217 {
218  if (run_ != r)
219  return false;
220 
221  for (auto const& range : ranges_) {
222  if (range.contains(s, e))
223  return true;
224  }
225 
226  return false;
227 }
RunNumber_t run_
Definition: RangeSet.h:144
Float_t s
Definition: plot.C:23
std::vector< EventRange > ranges_
Definition: RangeSet.h:145
Float_t e
Definition: plot.C:34
template<typename... ARGS>
void art::RangeSet::emplace_range ( ARGS &&  ...)
template<typename... ARGS>
void art::RangeSet::emplace_range ( ARGS &&...  args)

Definition at line 173 of file RangeSet.h.

174  {
176  ranges_.emplace_back(std::forward<ARGS>(args)...);
177  isCollapsed_ = false;
178  }
std::vector< EventRange > ranges_
Definition: RangeSet.h:145
bool isCollapsed_
Definition: RangeSet.h:148
void require_not_full_run()
Definition: RangeSet.h:135
bool RangeSet::empty ( void  ) const

Definition at line 204 of file RangeSet.cc.

References ranges_.

Referenced by art::disjoint_ranges().

205 {
206  for (auto const& range : ranges_) {
207  if (!range.empty())
208  return false;
209  }
210  return true;
211 }
std::vector< EventRange > ranges_
Definition: RangeSet.h:145
auto art::RangeSet::end ( void  ) const
inline

Definition at line 75 of file RangeSet.h.

Referenced by art::OpenRangeSetHandler::do_rebase(), art::OpenRangeSetHandler::do_update(), art::ClosedRangeSetHandler::end(), split_range(), and to_compact_string().

76  {
77  return ranges_.end();
78  }
std::vector< EventRange > ranges_
Definition: RangeSet.h:145
decltype(auto) art::RangeSet::front ( void  )
inline

Definition at line 83 of file RangeSet.h.

84  {
85  return ranges_.front();
86  }
std::vector< EventRange > ranges_
Definition: RangeSet.h:145
bool RangeSet::has_disjoint_ranges ( ) const

Definition at line 191 of file RangeSet.cc.

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

Referenced by art::disjoint_ranges().

192 {
193  if (isCollapsed_ || is_sorted()) {
194  return ranges_.size() < 2ull ? true : disjoint(ranges_);
195  }
196 
197  RangeSet tmp{*this};
198  tmp.sort();
199  tmp.collapse();
200  return tmp.has_disjoint_ranges();
201 }
std::vector< EventRange > ranges_
Definition: RangeSet.h:145
Float_t tmp
Definition: plot.C:37
bool is_sorted() const
Definition: RangeSet.cc:259
bool isCollapsed_
Definition: RangeSet.h:148
static constexpr unsigned art::RangeSet::invalidChecksum ( )
inlinestatic

Definition at line 126 of file RangeSet.h.

References max.

127  {
129  }
Int_t max
Definition: plot.C:27
bool art::RangeSet::is_collapsed ( ) const
inline

Definition at line 56 of file RangeSet.h.

57  {
58  return isCollapsed_;
59  }
bool isCollapsed_
Definition: RangeSet.h:148
bool RangeSet::is_full_run ( ) const

Definition at line 246 of file RangeSet.cc.

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

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

247 {
248  return ranges_.size() == 1ull &&
250 }
std::vector< EventRange > ranges_
Definition: RangeSet.h:145
EventRange full_run_event_range()
Definition: RangeSet.cc:38
bool RangeSet::is_full_subRun ( ) const

Definition at line 253 of file RangeSet.cc.

References ranges_.

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

254 {
255  return ranges_.size() == 1ull && ranges_.front().is_full_subRun();
256 }
std::vector< EventRange > ranges_
Definition: RangeSet.h:145
bool RangeSet::is_sorted ( ) const

Definition at line 259 of file RangeSet.cc.

References ranges_.

Referenced by collapse(), and has_disjoint_ranges().

260 {
261  return std::is_sorted(ranges_.cbegin(), ranges_.cend());
262 }
std::vector< EventRange > ranges_
Definition: RangeSet.h:145
bool RangeSet::is_valid ( ) const

Definition at line 230 of file RangeSet.cc.

References is_full_run(), ranges_, and run_.

Referenced by art::RootOutputFile::fillBranches(), art::RootOutputFile::getProduct(), art::RootDelayedReader::getProduct_(), art::SummedValue< T >::isValid(), merge(), art::Run::put_(), art::SubRun::put_(), and art::SummedValue< T >::update_impl().

231 {
233  return false;
234  }
235  if (is_full_run()) {
236  return true;
237  }
238  for (auto const& range : ranges_) {
239  if (!range.is_valid())
240  return false;
241  }
242  return true;
243 }
RunNumber_t run_
Definition: RangeSet.h:144
std::vector< EventRange > ranges_
Definition: RangeSet.h:145
bool is_full_run() const
Definition: RangeSet.cc:246
RangeSet & RangeSet::merge ( RangeSet const &  other)

Definition at line 134 of file RangeSet.cc.

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

Referenced by art::RootDelayedReader::getProduct_(), and art::SummedValue< T >::update_impl().

135 {
136  if (!other.is_valid())
137  return *this;
138 
139  if (!is_valid())
140  run_ = other.run();
141 
142  std::vector<EventRange> merged;
143  std::merge(ranges_.begin(),
144  ranges_.end(),
145  other.ranges_.begin(),
146  other.ranges_.end(),
147  std::back_inserter(merged));
148  std::unique(merged.begin(), merged.end());
149  std::swap(ranges_, merged);
150  isCollapsed_ = false;
151  collapse();
152  return *this;
153 }
RunNumber_t run_
Definition: RangeSet.h:144
RangeSet & collapse()
Definition: RangeSet.cc:74
std::vector< EventRange > ranges_
Definition: RangeSet.h:145
bool isCollapsed_
Definition: RangeSet.h:148
void swap(art::HLTGlobalStatus &lhs, art::HLTGlobalStatus &rhs)
bool is_valid() const
Definition: RangeSet.cc:230
std::vector<EventRange> const& art::RangeSet::ranges ( ) const
inline

Definition at line 42 of file RangeSet.h.

References art::is_valid().

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

43  {
44  return ranges_;
45  }
std::vector< EventRange > ranges_
Definition: RangeSet.h:145
void art::RangeSet::require_not_full_run ( )
inlineprivate

Definition at line 135 of file RangeSet.h.

References art::errors::LogicError.

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

136  {
137  if (is_full_run())
139  "RangeSet::require_not_full_run")
140  << "\nA RangeSet created using RangeSet::forRun cannot be "
141  "modified.\n";
142  }
bool is_full_run() const
Definition: RangeSet.cc:246
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
void art::RangeSet::set_run ( RunNumber_t const  r)
inline

Definition at line 108 of file RangeSet.h.

109  {
110  run_ = r;
111  }
RunNumber_t run_
Definition: RangeSet.h:144
void art::RangeSet::sort ( void  )
inline

Definition at line 114 of file RangeSet.h.

Referenced by RangeSet().

115  {
116  cet::sort_all(ranges_);
117  }
std::vector< EventRange > ranges_
Definition: RangeSet.h:145
std::pair< RangeSet::const_iterator, bool > RangeSet::split_range ( SubRunNumber_t  s,
EventNumber_t  e 
)

Definition at line 156 of file RangeSet.cc.

References begin(), contains(), e, end(), ranges_, require_not_full_run(), art::right(), and s.

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

157 {
159  bool did_split{false};
160  auto result = ranges_.end();
161  auto foundRange =
162  std::find_if(ranges_.cbegin(), ranges_.cend(), [s, e](auto const& r) {
163  return r.contains(s, e);
164  });
165 
166  // Split only if:
167  // - the range is found (i.e. the event is contained by the found range)
168  // - the range is valid
169  // - the size of the range is greater than 1
170  if (foundRange != ranges_.cend() && foundRange->is_valid() &&
171  foundRange->size() > 1ull) {
172  auto const begin = foundRange->begin();
173  auto const end = foundRange->end();
174  auto leftIt = ranges_.emplace(foundRange, s, begin, e);
175  result = std::next(leftIt);
176  EventRange right{s, e, end};
177  std::swap(*result, right);
178  did_split = true;
179  }
180  return std::make_pair(result, did_split);
181 }
Float_t s
Definition: plot.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:112
auto begin() const
Definition: RangeSet.h:70
std::vector< EventRange > ranges_
Definition: RangeSet.h:145
auto end() const
Definition: RangeSet.h:75
void swap(art::HLTGlobalStatus &lhs, art::HLTGlobalStatus &rhs)
void require_not_full_run()
Definition: RangeSet.h:135
Float_t e
Definition: plot.C:34
std::string RangeSet::to_compact_string ( ) const

Definition at line 265 of file RangeSet.cc.

References begin(), end(), ranges_, run_, s, and art::to_string().

Referenced by checksum().

266 {
267  using namespace std;
268  string s{to_string(run_)};
269  if (!ranges_.empty())
270  s += ":";
271  for (auto const& r : ranges_) {
272  s += to_string(r.subRun());
273  s += "[";
274  s += to_string(r.begin());
275  s += ",";
276  s += to_string(r.end());
277  s += ")";
278  }
279  return s;
280 }
RunNumber_t run_
Definition: RangeSet.h:144
Float_t s
Definition: plot.C:23
std::vector< EventRange > ranges_
Definition: RangeSet.h:145
STL namespace.
std::string to_string(ModuleType mt)
Definition: ModuleType.h:32
void art::RangeSet::update ( EventID const &  id)

Definition at line 117 of file RangeSet.cc.

References back(), ranges_, require_not_full_run(), and run_.

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

118 {
120  if (ranges_.empty()) {
121  run_ = id.run();
122  ranges_.emplace_back(id.subRun(), id.event(), id.next().event());
123  return;
124  }
125  auto& back = ranges_.back();
126  if (back.subRun() == id.subRun() && back.end() == id.event()) {
127  back.set_end(id.next().event());
128  } else {
129  ranges_.emplace_back(id.subRun(), id.event(), id.next().event());
130  }
131 }
RunNumber_t run_
Definition: RangeSet.h:144
std::vector< EventRange > ranges_
Definition: RangeSet.h:145
void require_not_full_run()
Definition: RangeSet.h:135
decltype(auto) back()
Definition: RangeSet.h:88
Event finding and building.

Member Data Documentation

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

Definition at line 149 of file RangeSet.h.

Referenced by checksum().

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

Definition at line 148 of file RangeSet.h.

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

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

Definition at line 144 of file RangeSet.h.

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


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