RangeSet.h
Go to the documentation of this file.
1 #ifndef canvas_Persistency_Provenance_RangeSet_h
2 #define canvas_Persistency_Provenance_RangeSet_h
3 
10 
11 #include <algorithm>
12 #include <ostream>
13 #include <set>
14 #include <vector>
15 
16 namespace art {
17 
18  class EventID;
19 
20  namespace detail {
21  EventRange full_run_event_range();
22  }
23 
24  class RangeSet {
25  public:
26  static RangeSet invalid();
27  static RangeSet forRun(RunID);
28  static RangeSet forSubRun(SubRunID);
29 
30  explicit RangeSet(RunNumber_t);
31  explicit RangeSet(RunNumber_t, std::vector<EventRange> const& eventRanges);
32 
33  using const_iterator = std::vector<EventRange>::const_iterator;
34 
36  run() const
37  {
38  return run_;
39  }
40 
41  std::vector<EventRange> const&
42  ranges() const
43  {
44  return ranges_;
45  }
46 
48 
49  bool is_valid() const;
50 
51  bool is_full_run() const;
52  bool is_full_subRun() const;
53  bool is_sorted() const;
54 
55  bool
56  is_collapsed() const
57  {
58  return isCollapsed_;
59  }
60 
61  std::string to_compact_string() const;
62  bool has_disjoint_ranges() const;
63 
64  // Empty means that no events are represented by this RangeSet.
65  // It does not necessarily mean that the ranges_ data member is
66  // empty.
67  bool empty() const;
68 
69  auto
70  begin() const
71  {
72  return ranges_.begin();
73  }
74  auto
75  end() const
76  {
77  return ranges_.end();
78  }
79 
80  unsigned checksum() const;
81 
82  decltype(auto)
83  front()
84  {
85  return ranges_.front();
86  }
87  decltype(auto)
88  back()
89  {
90  return ranges_.back();
91  }
92 
93  void assign_ranges(const_iterator b, const_iterator e);
94 
95  void update(EventID const&);
96 
97  template <typename... ARGS>
98  void emplace_range(ARGS&&...);
99 
100  RangeSet& collapse();
101  RangeSet& merge(RangeSet const& other);
102 
103  // For a range [1,6) split into [1,3) and [3,6) the specified
104  // event number is the new 'end' of the left range (3).
105  std::pair<const_iterator, bool> split_range(SubRunNumber_t, EventNumber_t);
106 
107  void
109  {
110  run_ = r;
111  }
112 
113  void
115  {
116  cet::sort_all(ranges_);
117  }
118 
119  void
121  {
122  ranges_.clear();
123  }
124 
125  static constexpr unsigned
127  {
129  }
130 
131  private:
132  explicit RangeSet() = default;
133 
134  void
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  }
143 
145  std::vector<EventRange> ranges_{};
146 
147  // Auxiliary info
148  bool isCollapsed_{false};
149  mutable unsigned checksum_{invalidChecksum()};
150  };
151 
152  //==========================================================
153  // Non-member functions
154 
155  bool operator==(RangeSet const& l, RangeSet const& r);
156  bool same_ranges(RangeSet const& l, RangeSet const& r);
157  bool disjoint_ranges(RangeSet const& l, RangeSet const& r);
158  void throw_if_not_disjoint(RunNumber_t const rn,
159  EventRange const& left,
160  EventRange const& right) noexcept(false);
161 
162  // If one range-set is a superset of the other, the return value is
163  // 'true'. If two range-sets are the same, then they are also
164  // overlapping.
165  bool overlapping_ranges(RangeSet const& l, RangeSet const& r);
166  std::ostream& operator<<(std::ostream& os, RangeSet const& rs);
167 
168  //==========================================================
169  // RangeSet implementation details
170 
171  template <typename... ARGS>
172  void
174  {
175  require_not_full_run();
176  ranges_.emplace_back(std::forward<ARGS>(args)...);
177  isCollapsed_ = false;
178  }
179 }
180 
181 #endif /* canvas_Persistency_Provenance_RangeSet_h */
182 
183 // Local variables:
184 // mode: c++
185 // End:
constexpr auto const & right(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:112
void clear()
Definition: RangeSet.h:120
std::vector< EventRange >::const_iterator const_iterator
Definition: RangeSet.h:33
auto begin() const
Definition: RangeSet.h:70
void set_run(RunNumber_t const r)
Definition: RangeSet.h:108
EventRange full_run_event_range()
dictionary contains
constexpr bool is_valid(IDNumber_t< L > const id)
Definition: IDNumber.h:112
auto end() const
Definition: RangeSet.h:75
static constexpr unsigned invalidChecksum()
Definition: RangeSet.h:126
void throw_if_not_disjoint(RunNumber_t const rn, EventRange const &left, EventRange const &right) noexcept(false)
RunNumber_t run() const
Definition: RangeSet.h:36
void sort_all(RandCont &)
std::vector< EventRange > const & ranges() const
Definition: RangeSet.h:42
std::enable_if_t< detail::are_handles< T, U >::value, bool > disjoint_ranges(T const &a, U const &b)
IDNumber_t< Level::SubRun > SubRunNumber_t
Definition: IDNumber.h:118
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
constexpr auto const & left(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:104
void require_not_full_run()
Definition: RangeSet.h:135
std::ostream & operator<<(std::ostream &os, LinuxMallInfo const &info)
Definition: LinuxMallInfo.h:55
void sort()
Definition: RangeSet.h:114
std::enable_if_t< detail::are_handles< T, U >::value, bool > overlapping_ranges(T const &a, U const &b)
std::enable_if_t< detail::are_handles< T, U >::value, bool > same_ranges(T const &a, U const &b)
const hit & b
Definition: hits.cxx:21
IDNumber_t< Level::Event > EventNumber_t
Definition: IDNumber.h:117
TRandom3 r(0)
Service to store calibration data products (CDP) in the SQLite3 metadatabase of a file...
Definition: FillParentInfo.h:8
bool operator==(Provenance const &a, Provenance const &b)
Definition: Provenance.h:168
Float_t e
Definition: plot.C:35
T max(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:68
void emplace_range(ARGS &&...)
bool is_collapsed() const
Definition: RangeSet.h:56
IDNumber_t< Level::Run > RunNumber_t
Definition: IDNumber.h:119
enum BeamMode string