GeneratorTest_source.cc
Go to the documentation of this file.
9 
10 #include <cassert>
11 
12 namespace arttest {
13  class GeneratorTestDetail;
14 }
15 
17 public:
20 
23  art::SourceHelper const& sHelper);
24 
25  void closeCurrentFile();
26 
27  void readFile(std::string const& name, art::FileBlock*& fb);
28 
29  bool readNext(art::RunPrincipal const* const inR,
30  art::SubRunPrincipal const* const inSR,
31  art::RunPrincipal*& outR,
32  art::SubRunPrincipal*& outSR,
33  art::EventPrincipal*& outE);
34 
35 private:
36  bool readFileCalled_{false};
38  size_t ev_num_{};
39  // Test tool invocation from within source.
40  std::unique_ptr<arttest::ReadNextArbitrator> readNext_;
41 };
42 
44  fhicl::ParameterSet const& pset,
46  art::SourceHelper const& sHelper)
47  : sHelper_{sHelper}
48  , readNext_{art::make_tool<ReadNextArbitrator>(
49  pset.get<fhicl::ParameterSet>("readNextImpl"))}
50 {}
51 
52 void
54 {}
55 
56 void
58  art::FileBlock*& fb)
59 {
60  assert(!readFileCalled_);
61  assert(name.empty());
62  readFileCalled_ = true;
63  fb = new art::FileBlock(art::FileFormatVersion(1, "GeneratorTest2012"),
64  "nothing");
65 }
66 
67 bool
69  art::SubRunPrincipal const* const inSR,
70  art::RunPrincipal*& outR,
71  art::SubRunPrincipal*& outSR,
72  art::EventPrincipal*& outE)
73 {
74  art::Timestamp runstart;
75  if (++ev_num_ > readNext_->threshold()) {
76  return false;
77  }
78  if (inR == nullptr) {
79  outR = sHelper_.makeRunPrincipal(1, runstart);
80  }
81  if (inSR == nullptr) {
82  art::SubRunID srid{outR ? outR->run() : inR->run(), 0};
83  outSR = sHelper_.makeSubRunPrincipal(srid.run(), srid.subRun(), runstart);
84  }
85  outE = sHelper_.makeEventPrincipal(outR ? outR->run() : inR->run(),
86  outSR ? outSR->subRun() : inSR->subRun(),
87  ev_num_,
88  runstart);
89  return true;
90 }
91 
92 // Trait definition (must precede source typedef).
93 namespace art {
94  template <>
96  static constexpr bool value = true;
97  };
98 } // namespace art
99 
100 // Source declaration.
101 namespace arttest {
103 }
104 
RunNumber_t run() const
Definition: Principal.cc:1192
GeneratorTestDetail & operator=(GeneratorTestDetail const &)=delete
static const double ps
Definition: Units.h:103
std::unique_ptr< arttest::ReadNextArbitrator > readNext_
std::string string
Definition: nybbler.cc:12
bool readNext(art::RunPrincipal const *const inR, art::SubRunPrincipal const *const inSR, art::RunPrincipal *&outR, art::SubRunPrincipal *&outSR, art::EventPrincipal *&outE)
SubRunPrincipal * makeSubRunPrincipal(SubRunAuxiliary const &subRunAux) const
Definition: SourceHelper.cc:83
RunPrincipal * makeRunPrincipal(RunAuxiliary const &runAux) const
Definition: SourceHelper.cc:55
GeneratorTestDetail(GeneratorTestDetail const &)=delete
art::SourceHelper const & sHelper_
EventPrincipal * makeEventPrincipal(EventAuxiliary const &eventAux, std::unique_ptr< History > &&history) const
#define DEFINE_ART_INPUT_SOURCE(klass)
void readFile(std::string const &name, art::FileBlock *&fb)
SubRunNumber_t subRun() const
Definition: Principal.cc:1204
art::Source< GeneratorTestDetail > GeneratorTest