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 
27  public: // TYPES
29 
30  public: // MEMBER FUNCTIONS -- Static API
31  static constexpr unsigned
33  {
35  }
36 
37  static RangeSet invalid();
38  static RangeSet forRun(RunID);
39  static RangeSet forSubRun(SubRunID);
40 
41  public: // MEMBER FUNCTIONS -- Special Member Functions
42  ~RangeSet();
43 
44  explicit RangeSet();
45  explicit RangeSet(RunNumber_t);
46  explicit RangeSet(RunNumber_t, std::vector<EventRange> const& eventRanges);
47 
48  RangeSet(RangeSet const&);
49  RangeSet(RangeSet&&);
50  RangeSet& operator=(RangeSet const&);
51  RangeSet& operator=(RangeSet&&);
52 
53  public: // MEMBER FUNCTIONS -- API provided to user
54  RunNumber_t run() const;
55  std::vector<EventRange> const& ranges() const;
56 
57  bool contains(RunNumber_t, SubRunNumber_t, EventNumber_t) const;
58 
59  bool is_valid() const;
60  bool is_full_run() const;
61  bool is_full_subRun() const;
62  bool is_sorted() const;
63  bool is_collapsed() const;
64 
65  std::string to_compact_string() const;
66  bool has_disjoint_ranges() const;
67  // Empty means that no events are represented by this RangeSet.
68  // It does not necessarily mean that the ranges_ data member is
69  // empty.
70  bool empty() const;
71 
72  const_iterator begin() const;
73  const_iterator end() const;
74  std::size_t begin_idx() const;
75  std::size_t end_idx() const;
76 
77  unsigned checksum() const;
78  std::size_t next_subrun_or_end(std::size_t const b) const;
79 
80  EventRange& front();
81  EventRange& back();
82  EventRange& at(std::size_t);
83 
84  std::vector<EventRange> extract_ranges(std::size_t const b,
85  std::size_t const e);
86 
87  void assign_ranges(RangeSet const& rs,
88  std::size_t const b,
89  std::size_t const e);
90 
91  void update(EventID const&);
92 
93  template <typename... ARGS>
94  void emplace_range(ARGS&&...);
95 
96  RangeSet& collapse();
97  RangeSet& merge(RangeSet const& other);
98 
99  // For a range [1,6) split into [1,3) and [3,6) the specified
100  // event number is the new 'end' of the left range (3).
101  std::pair<std::size_t, bool> split_range(SubRunNumber_t, EventNumber_t);
102 
103  void set_run(RunNumber_t const r);
104  void sort();
105  void clear();
106 
107  private:
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
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:
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
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:28
std::string string
Definition: nybbler.cc:12
EventRange full_run_event_range()
Definition: RangeSet.cc:81
intermediate_table::const_iterator const_iterator
static constexpr unsigned invalidChecksum()
Definition: RangeSet.h:32
static QCString args
Definition: declinfo.cpp:674
static QStrList * l
Definition: config.cpp:1044
void throw_if_not_disjoint(RunNumber_t const rn, EventRange const &left, EventRange const &right) noexcept(false)
Definition: RangeSet.cc:453
const double e
constexpr bool is_valid(IDNumber_t< L > const id) noexcept
Definition: IDNumber.h:113
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:119
std::ostream & operator<<(std::ostream &os, Analyzer::Table< T > const &t)
Definition: Analyzer.h:136
static int max(int a, int b)
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< 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)
IDNumber_t< Level::Event > EventNumber_t
Definition: IDNumber.h:118
static bool * b
Definition: config.cpp:1043
vector< vector< double > > clear
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:72
void emplace_range(ARGS &&...)
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.
Definition: StdUtils.h:97
bool operator==(ModuleKeyAndType const &a, ModuleKeyAndType const &b) noexcept
IDNumber_t< Level::Run > RunNumber_t
Definition: IDNumber.h:120