LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
RangeSet.h
Go to the documentation of this file.
1 #ifndef canvas_Persistency_Provenance_RangeSet_h
2 #define canvas_Persistency_Provenance_RangeSet_h
3 // vim: set sw=2 expandtab :
4 
9 
10 #include <cstddef>
11 #include <limits>
12 #include <ostream>
13 #include <string>
14 #include <utility>
15 #include <vector>
16 
17 namespace art {
18 
19  class EventID;
20 
21  namespace detail {
22  EventRange full_run_event_range();
23  }
24 
25  class RangeSet {
26  public:
28 
29  // Static API
30  static constexpr unsigned
32  {
33  return std::numeric_limits<unsigned>::max();
34  }
35 
36  static RangeSet invalid();
37  static RangeSet forRun(RunID);
38  static RangeSet forSubRun(SubRunID);
39 
40  // Special Member Functions
41  ~RangeSet();
42 
43  explicit RangeSet(RunNumber_t);
44  explicit RangeSet(RunNumber_t, std::vector<EventRange> const& eventRanges);
45 
46  RangeSet(RangeSet const&);
47  RangeSet(RangeSet&&);
48  RangeSet& operator=(RangeSet const&);
49  RangeSet& operator=(RangeSet&&);
50 
51  // API provided to user
52  RunNumber_t run() const;
53  std::vector<EventRange> const& ranges() const;
54 
55  bool contains(RunNumber_t, SubRunNumber_t, EventNumber_t) const;
56 
57  bool is_valid() const;
58  bool is_full_run() const;
59  bool is_full_subRun() const;
60  bool is_sorted() const;
61  bool is_collapsed() const;
62 
63  std::string to_compact_string() const;
64  bool has_disjoint_ranges() const;
65  // Empty means that no events are represented by this RangeSet.
66  // It does not necessarily mean that the ranges_ data member is
67  // empty.
68  bool empty() const;
69 
70  const_iterator begin() const;
71  const_iterator end() const;
72  std::size_t begin_idx() const;
73  std::size_t end_idx() const;
74 
75  unsigned checksum() const;
76  std::size_t next_subrun_or_end(std::size_t const b) const;
77 
78  EventRange& front();
79  EventRange& back();
80  EventRange& at(std::size_t);
81 
82  std::vector<EventRange> extract_ranges(std::size_t const b,
83  std::size_t const e);
84 
85  void assign_ranges(RangeSet const& rs,
86  std::size_t const b,
87  std::size_t const e);
88 
89  void update(EventID const&);
90 
91  template <typename... ARGS>
92  void emplace_range(ARGS&&...);
93 
94  RangeSet& collapse();
95  RangeSet& merge(RangeSet const& other);
96 
97  // For a range [1,6) split into [1,3) and [3,6) the specified
98  // event number is the new 'end' of the left range (3).
99  std::pair<std::size_t, bool> split_range(SubRunNumber_t, EventNumber_t);
100 
101  void set_run(RunNumber_t const r);
102  void sort();
103  void clear();
104 
105  private:
106  explicit RangeSet();
107 
108  void require_not_full_run();
109 
111  std::vector<EventRange> ranges_{};
112 
113  // Auxiliary info
114  bool isCollapsed_{false};
115  mutable unsigned checksum_{invalidChecksum()};
116  };
117 
118  template <typename... ARGS>
119  void
120  RangeSet::emplace_range(ARGS&&... args)
121  {
122  require_not_full_run();
123  ranges_.emplace_back(std::forward<ARGS>(args)...);
124  isCollapsed_ = false;
125  }
126 
127  bool operator==(RangeSet const& l, RangeSet const& r);
128 
129  bool same_ranges(RangeSet const& l, RangeSet const& r);
130 
131  bool disjoint_ranges(RangeSet const& l, RangeSet const& r);
132  void throw_if_not_disjoint(RunNumber_t const rn,
133  EventRange const& left,
134  EventRange const& right) noexcept(false);
135 
136  // If one range-set is a superset of the other, the return value is
137  // 'true'. If two range-sets are the same, then they are also
138  // overlapping.
139  bool overlapping_ranges(RangeSet const& l, RangeSet const& r);
140 
141  std::ostream& operator<<(std::ostream& os, RangeSet const& rs);
142 
143 } // namespace art
144 
145 #endif /* canvas_Persistency_Provenance_RangeSet_h */
146 
147 // Local variables:
148 // mode: c++
149 // End:
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 >::const_iterator const_iterator
Definition: RangeSet.h:27
std::enable_if_t< detail::are_handles_v< T, U >, bool > overlapping_ranges(T const &a, U const &b)
EventRange full_run_event_range()
Definition: RangeSet.cc:81
intermediate_table::const_iterator const_iterator
static constexpr unsigned invalidChecksum()
Definition: RangeSet.h:31
void throw_if_not_disjoint(RunNumber_t const rn, EventRange const &left, EventRange const &right) noexcept(false)
Definition: RangeSet.cc:453
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:77
std::enable_if_t< detail::are_handles_v< T, U >, bool > disjoint_ranges(T const &a, U const &b)
constexpr bool is_valid(IDNumber_t< L > const id) noexcept
Definition: IDNumber.h:113
IDNumber_t< Level::SubRun > SubRunNumber_t
Definition: IDNumber.h:119
std::ostream & operator<<(std::ostream &os, Analyzer::Table< T > const &t)
Definition: Analyzer.h:135
constexpr auto const & left(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:94
std::enable_if_t< detail::are_handles_v< T, U >, bool > same_ranges(T const &a, U const &b)
IDNumber_t< Level::Event > EventNumber_t
Definition: IDNumber.h:118
Definition: MVAAlg.h:12
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:69
Float_t e
Definition: plot.C:35
void emplace_range(ARGS &&...)
vec_iX clear()
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.
Definition: StdUtils.h:109
bool operator==(ModuleKeyAndType const &a, ModuleKeyAndType const &b) noexcept
IDNumber_t< Level::Run > RunNumber_t
Definition: IDNumber.h:120