ToyRawInputTester_module.cc
Go to the documentation of this file.
11 #include "fhiclcpp/parse.h"
12 
13 #include <iostream>
14 #include <sstream>
15 #include <string>
16 #include <tuple>
17 #include <vector>
18 
19 namespace arttest {
20  class ToyRawInputTester;
21 }
22 
23 using strings = std::vector<std::string>;
24 using std::ostringstream;
25 using std::string;
26 
27 using namespace art;
28 
30 public:
32  : art::EDAnalyzer{p}, fileNames_{p.get<strings>("fileNames")}, pset_{p}
33  {
34  numFilesExpected_ = fileNames_.size();
35  ostringstream expected;
36  for (size_t i = 0; i != numFilesExpected_; ++i) {
37  expected << "open " << fileNames_[i] << '\n';
38 
39  std::vector<std::tuple<int, int, int>> tokens;
40  try { // Assume it's a real filename
41  fhicl::intermediate_table raw_config;
42  cet::filepath_lookup_after1 lookupPolicy(".:");
43  fhicl::parse_document(fileNames_[i], lookupPolicy, raw_config);
44  fhicl::ParameterSet file_pset;
45  make_ParameterSet(raw_config, file_pset);
46  assert(file_pset.get_if_present("data", tokens));
47  }
48  catch (...) { // Attempt to read the parameter set by that name instead.
49  assert(p.get_if_present(fileNames_[i], tokens));
50  }
51  RunNumber_t currentRun = -1;
52  SubRunNumber_t currentSubRun = -1;
53  for (auto const& token : tokens) {
54  int newRun, newSubRun, newEvent;
55  std::tie(newRun, newSubRun, newEvent) = token;
56  if (newRun != -1) {
57  ++numRunsExpected_;
58  currentRun = newRun;
59  expected << "begin " << RunID(currentRun) << '\n';
60  }
61  if (newSubRun != -1) {
62  ++numSubRunsExpected_;
63  currentSubRun = newSubRun;
64  expected << "begin " << SubRunID(currentRun, currentSubRun) << '\n';
65  }
66  if (newEvent != -1) {
67  ++numEventsExpected_;
68  expected << "event " << EventID(currentRun, currentSubRun, newEvent)
69  << '\n';
70  }
71  }
72  }
73  expectedMessage_ = expected.str();
74  }
75 
76  void
78  {
79  ++numFilesSeen_;
80  messages_ << "open " << fb.fileName() << '\n';
81  }
82 
83  void
84  beginRun(art::Run const& r) override
85  {
86  ++numRunsSeen_;
87  messages_ << "begin " << r.id() << '\n';
88  }
89 
90  void
91  beginSubRun(art::SubRun const& sr) override
92  {
93  ++numSubRunsSeen_;
94  messages_ << "begin " << sr.id() << '\n';
95  }
96 
97  void
98  analyze(art::Event const& e) override
99  {
100  ++numEventsSeen_;
101  messages_ << "event " << e.id() << '\n';
102  }
103 
104  void
105  endJob() override
106  {
107  cet::HorizontalRule constexpr rule{72};
108  std::cerr << rule('-') << '\n'
109  << expectedMessage_ << rule('-') << '\n'
110  << rule('+') << '\n'
111  << messages_.str() << rule('+') << '\n';
112  assert(numFilesSeen_ == numFilesExpected_);
113  assert(numRunsSeen_ == numRunsExpected_);
114  assert(numSubRunsSeen_ == numSubRunsExpected_);
115  assert(numEventsSeen_ == numEventsExpected_);
116  assert(expectedMessage_ == messages_.str());
117  }
118 
119 private:
120  size_t numEventsSeen_{};
121  size_t numEventsExpected_{};
122  size_t numSubRunsSeen_{};
123  size_t numSubRunsExpected_{};
124  size_t numRunsSeen_{};
125  size_t numRunsExpected_{};
126  size_t numFilesSeen_{};
127  size_t numFilesExpected_{};
130  ostringstream messages_{};
131  string expectedMessage_{};
132 };
133 
std::vector< std::string > strings
void beginRun(art::Run const &r) override
RunID id() const
Definition: Run.cc:24
const char expected[]
Definition: Exception_t.cc:22
std::string string
Definition: nybbler.cc:12
void make_ParameterSet(intermediate_table const &tbl, ParameterSet &ps)
Definition: Run.h:21
const double e
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:68
std::string const & fileName() const
Definition: FileBlock.cc:34
void analyze(art::Event const &e) override
ToyRawInputTester(fhicl::ParameterSet const &p)
IDNumber_t< Level::SubRun > SubRunNumber_t
Definition: IDNumber.h:119
bool get_if_present(std::string const &key, T &value) const
Definition: ParameterSet.h:208
p
Definition: test.py:228
void beginSubRun(art::SubRun const &sr) override
SubRunID id() const
Definition: SubRun.cc:21
static const double sr
Definition: Units.h:167
EventID id() const
Definition: Event.cc:37
void respondToOpenInputFile(art::FileBlock const &fb) override
void parse_document(std::string const &filename, cet::filepath_maker &maker, intermediate_table &result)
Definition: parse.cc:856
IDNumber_t< Level::Run > RunNumber_t
Definition: IDNumber.h:120