Macros | Functions
ClosedRangeSetHandler_t.cc File Reference
#include "boost/test/unit_test.hpp"
#include "art/Framework/Principal/ClosedRangeSetHandler.h"
#include "art/test/Framework/Principal/SimpleEvent.h"
#include "canvas/Persistency/Common/detail/aggregate.h"
#include "canvas/Persistency/Provenance/RangeSet.h"
#include <vector>

Go to the source code of this file.

Macros

#define BOOST_TEST_MODULE   (ClosedRangeSetHandler_t)
 

Functions

 BOOST_AUTO_TEST_CASE (EmptyRunAndSubRuns)
 
 BOOST_AUTO_TEST_CASE (SplitOnNonLastSubRunEvent)
 
 BOOST_AUTO_TEST_CASE (SplitOnLastSubRunEvent)
 

Macro Definition Documentation

#define BOOST_TEST_MODULE   (ClosedRangeSetHandler_t)

Definition at line 1 of file ClosedRangeSetHandler_t.cc.

Function Documentation

BOOST_AUTO_TEST_CASE ( EmptyRunAndSubRuns  )

Definition at line 102 of file ClosedRangeSetHandler_t.cc.

103 {
104  // In this case, no events were seen in any of the runs/subruns. So
105  // flush the ranges.
106  for (std::size_t i{0}; i != 3; ++i) {
107  srHandlers[i]->flushRanges();
108  auto const& rs = RangeSet{1, eventRanges(i)};
109  BOOST_TEST(srHandlers[i]->seenRanges() == rs);
110  }
111 
112  rHandler->flushRanges();
113  std::vector<EventRange> runRef;
114  for (std::size_t i{0}; i != 3; ++i) {
115  concatenate(runRef, eventRanges(i));
116  }
117  RangeSet const runRSRef{1, runRef};
118  BOOST_TEST(rHandler->seenRanges() == runRSRef);
119 }
std::string concatenate(H const &h, T const &...t)
Definition: select.h:138
BOOST_AUTO_TEST_CASE ( SplitOnNonLastSubRunEvent  )

Definition at line 121 of file ClosedRangeSetHandler_t.cc.

122 {
123  // For this test, we're in the middle of processing SubRun 1 at
124  // event 5, when we decide to switch to a new input file. In this
125  // case, 5 IS NOT the last processed event in the SubRun.
126 
127  std::vector<SimpleEvent> events;
128  events.emplace_back(EventID{1, 1, 3}, false);
129  events.emplace_back(EventID{1, 1, 4}, false);
130  events.emplace_back(EventID{1, 1, 5}, false);
131 
132  auto const& srHandler = srHandlers[1];
133  // Process events
134  for (auto const& e : events) {
135  srHandler->update(e.id, e.lastInSubRun);
136  rHandler->update(e.id, e.lastInSubRun);
137  }
138 
139  // Simulate file switch
140  // 1. Maybe split range
141  srHandler->maybeSplitRange();
142  rHandler->maybeSplitRange();
143 
144  {
145  std::vector<EventRange> subRunRef;
146  subRunRef.emplace_back(1, 1, 6);
147  RangeSet const subRunRSRef{1, subRunRef};
148  BOOST_TEST(srHandler->seenRanges() == subRunRSRef);
149  }
150 
151  {
152  std::vector<EventRange> runRef;
153  runRef.emplace_back(0, 5, 11);
154  runRef.emplace_back(1, 1, 6);
155  RangeSet const runRSRef{1, runRef};
156  BOOST_TEST(rHandler->seenRanges() == runRSRef);
157  }
158 
159  // 2. Rebase ranges
160  srHandler->rebase();
161  rHandler->rebase();
162 
163  // Process last event
164  SimpleEvent const lastEvent{EventID{1, 1, 10}, true};
165  srHandler->update(lastEvent.id, lastEvent.lastInSubRun);
166  rHandler->update(lastEvent.id, lastEvent.lastInSubRun);
167 
168  // Simulate end of subrun and run
169  srHandler->flushRanges();
170  rHandler->flushRanges();
171  {
172  std::vector<EventRange> subRunRef;
173  subRunRef.emplace_back(1, 6, 7);
174  subRunRef.emplace_back(1, 9, 15);
175  RangeSet const subRunRSRef{1, subRunRef};
176  BOOST_TEST(srHandler->seenRanges() == subRunRSRef);
177  }
178  {
179  std::vector<EventRange> runRef;
180  runRef.emplace_back(1, 6, 7);
181  runRef.emplace_back(1, 9, 15);
182  runRef.emplace_back(2, 3, 15);
183  RangeSet const runRSRef{1, runRef};
184  BOOST_TEST(rHandler->seenRanges() == runRSRef);
185  }
186 }
const double e
BOOST_AUTO_TEST_CASE ( SplitOnLastSubRunEvent  )

Definition at line 188 of file ClosedRangeSetHandler_t.cc.

189 {
190  // For this test, we're in the middle of processing SubRun 1 at
191  // event 5, when we decide to switch to a new input file. In this
192  // case, 5 IS the last processed event in the SubRun.
193 
194  std::vector<SimpleEvent> events;
195  events.emplace_back(EventID{1, 1, 3}, false);
196  events.emplace_back(EventID{1, 1, 4}, false);
197  events.emplace_back(EventID{1, 1, 5}, true);
198 
199  auto const& srHandler = srHandlers[1];
200  // Process events
201  for (auto const& e : events) {
202  srHandler->update(e.id, e.lastInSubRun);
203  rHandler->update(e.id, e.lastInSubRun);
204  }
205 
206  // Simulate file switch
207  srHandler->maybeSplitRange();
208  rHandler->maybeSplitRange();
209  {
210  RangeSet const subRunRSRef{1, eventRanges(1)};
211  BOOST_TEST(srHandler->seenRanges() == subRunRSRef);
212  }
213  {
214  std::vector<EventRange> runRef;
215  concatenate(runRef, eventRanges(0));
216  concatenate(runRef, eventRanges(1));
217  RangeSet const runRSRef{1, runRef};
218  BOOST_TEST(rHandler->seenRanges() == runRSRef);
219  }
220  srHandler->rebase();
221  rHandler->rebase();
222 
223  // Both RangeSets should now be empty (have not yet processed any
224  // events from SubRun 2).
225  RangeSet const emptyRS{1, std::vector<EventRange>{}};
226  BOOST_TEST(srHandler->seenRanges() == emptyRS);
227  BOOST_TEST(rHandler->seenRanges() == emptyRS);
228 }
std::string concatenate(H const &h, T const &...t)
Definition: select.h:138
const double e