OpenRangeSetHandler_t.cc
Go to the documentation of this file.
1 // Test of OpenRangeSetHandler
2 
3 #define BOOST_TEST_MODULE (OpenRangeSetHandler_t)
4 #include "boost/test/unit_test.hpp"
5 
10 
11 #include <vector>
12 
13 using namespace art;
14 using namespace std;
16 
17 namespace {
18 
19  // Event ranges:
20  // SubRun: 0 Event range: [1,4)
21  // SubRun: 1 Event range: [1,4)
22  // SubRun: 2 Event range: [1,4)
23  auto
24  eventRanges(unsigned const sr)
25  {
26  vector<EventRange> const ranges{EventRange{sr, 1, 4}};
27  return ranges;
28  }
29 
30  template <typename T>
31  auto
32  concatenate(vector<T>& l, vector<T> const& r)
33  {
35  }
36 
37  struct RSHandler {
38  RSHandler()
39  {
40  // Run 1 SubRuns 0-2
41  for (unsigned sr{0}; sr != 3; ++sr) {
42  events.emplace_back(EventID{1, sr, 1}, false);
43  events.emplace_back(EventID{1, sr, 2}, false);
44  events.emplace_back(EventID{1, sr, 3}, true);
45  }
46  }
47  vector<SimpleEvent> events;
48  unique_ptr<RangeSetHandler> srHandler = make_unique<OpenRangeSetHandler>(1);
49  unique_ptr<RangeSetHandler> rHandler = make_unique<OpenRangeSetHandler>(1);
50  };
51 } // namespace
52 
53 BOOST_FIXTURE_TEST_SUITE(OpenRangeSetHandler_t, RSHandler)
54 
56 {
57  // RangeSet reference
58 
59  // Process events
60  for (auto const& e : events) {
61  rHandler->update(e.id, e.lastInSubRun);
62  srHandler->update(e.id, e.lastInSubRun);
63  if (e.lastInSubRun) {
64  srHandler->flushRanges();
65  {
66  RangeSet subRunRS{1};
67  subRunRS.emplace_range(e.id.subRun(), 1, 4);
68  BOOST_TEST(srHandler->seenRanges() == subRunRS);
69  }
70  srHandler = make_unique<OpenRangeSetHandler>(1); // New subrun
71  }
72  }
73 
74  vector<EventRange> ranges;
75  for (unsigned sr{0}; sr != 3; ++sr) {
76  concatenate(ranges, eventRanges(sr));
77  }
78  RangeSet const runRS{1, ranges};
79  BOOST_TEST(rHandler->seenRanges() == runRS);
80 }
81 
82 BOOST_AUTO_TEST_CASE(FileSwitchAfterEvent)
83 {
84  // Process 5 events
85  for (std::size_t i{0}; i != 5; ++i) {
86  auto const& e = events[i];
87  srHandler->update(e.id, e.lastInSubRun);
88  rHandler->update(e.id, e.lastInSubRun);
89  if (e.lastInSubRun) {
90  srHandler->flushRanges();
91  {
92  RangeSet subRunRS{1};
93  subRunRS.emplace_range(e.id.subRun(), 1, 4);
94  BOOST_TEST(srHandler->seenRanges() == subRunRS);
95  }
96  srHandler = make_unique<OpenRangeSetHandler>(1); // New subrun
97  }
98  }
99 
100  // Simulate file-switch
101  srHandler->maybeSplitRange();
102  rHandler->maybeSplitRange();
103  {
104  vector<EventRange> runRanges{EventRange{0, 1, 4}};
105  vector<EventRange> subRunRanges{EventRange{1, 1, 3}};
106  concatenate(runRanges, subRunRanges);
107  RangeSet const subRunRS{1, subRunRanges};
108  RangeSet const runRS{1, runRanges};
109  BOOST_TEST(srHandler->seenRanges() == subRunRS);
110  BOOST_TEST(rHandler->seenRanges() == runRS);
111  }
112  srHandler->rebase();
113  rHandler->rebase();
114 
115  // Process remaining events
116  // ... first do rest of SubRun 1
117  auto const& e = events[5];
118  srHandler->update(e.id, e.lastInSubRun);
119  rHandler->update(e.id, e.lastInSubRun);
120  srHandler->flushRanges();
121  {
122  RangeSet subRunRS{1};
123  subRunRS.emplace_range(1, 3, 4);
124  BOOST_TEST(srHandler->seenRanges() == subRunRS);
125  }
126  srHandler = make_unique<OpenRangeSetHandler>(1); // New subrun
127 
128  for (std::size_t i{6}; i != events.size(); ++i) {
129  auto const& e = events[i];
130  srHandler->update(e.id, e.lastInSubRun);
131  rHandler->update(e.id, e.lastInSubRun);
132  }
133 
134  // End job
135  srHandler->flushRanges();
136  rHandler->flushRanges();
137  {
138  vector<EventRange> runRanges{EventRange{1, 3, 4}};
139  vector<EventRange> subRunRanges{EventRange{2, 1, 4}};
140  concatenate(runRanges, subRunRanges);
141  RangeSet const subRunRS{1, subRunRanges};
142  RangeSet const runRS{1, runRanges};
143  BOOST_TEST(srHandler->seenRanges() == subRunRS);
144  BOOST_TEST(rHandler->seenRanges() == runRS);
145  }
146 }
147 
148 BOOST_AUTO_TEST_CASE(FileSwitchAfterSubRun)
149 {
150  // Process 6 events
151  for (std::size_t i{0}; i != 6; ++i) {
152  auto const& e = events[i];
153  srHandler->update(e.id, e.lastInSubRun);
154  rHandler->update(e.id, e.lastInSubRun);
155  if (e.lastInSubRun) {
156  srHandler->flushRanges();
157  {
158  RangeSet subRunRS{1};
159  subRunRS.emplace_range(e.id.subRun(), 1, 4);
160  BOOST_TEST(srHandler->seenRanges() == subRunRS);
161  }
162  srHandler = make_unique<OpenRangeSetHandler>(1); // New subrun
163  }
164  }
165 
166  // Simulate file-switch
167  srHandler->maybeSplitRange();
168  rHandler->maybeSplitRange();
169  {
170  vector<EventRange> runRanges;
171  for (std::size_t i{0}; i != 2; ++i) {
172  concatenate(runRanges, eventRanges(i));
173  }
174  RangeSet const subRunRS{1, std::vector<EventRange>{}};
175  RangeSet const runRS{1, runRanges};
176  BOOST_TEST(srHandler->seenRanges() == subRunRS);
177  BOOST_TEST(rHandler->seenRanges() == runRS);
178  }
179  srHandler->rebase();
180  rHandler->rebase();
181 
182  for (std::size_t i{6}; i != events.size(); ++i) {
183  auto const& e = events[i];
184  srHandler->update(e.id, e.lastInSubRun);
185  rHandler->update(e.id, e.lastInSubRun);
186  }
187 
188  // End job
189  srHandler->flushRanges();
190  rHandler->flushRanges();
191  {
192  vector<EventRange> const ranges{EventRange{2, 1, 4}};
193  RangeSet const rs{1, ranges};
194  BOOST_TEST(srHandler->seenRanges() == rs);
195  BOOST_TEST(rHandler->seenRanges() == rs);
196  }
197 }
198 
199 BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(Simple)
Definition: types.h:35
std::string concatenate(H const &h, T const &...t)
Definition: select.h:138
STL namespace.
static QStrList * l
Definition: config.cpp:1044
const double e
static constexpr double sr
Definition: Units.h:166
void emplace_range(ARGS &&...)