FlushingGenerator_source.cc
Go to the documentation of this file.
7 
8 #include <cassert>
9 #include <iostream>
10 
11 namespace arttest {
12  class FlushingGeneratorDetail;
13 }
14 
16 public:
19 
22  art::SourceHelper const& sHelper);
23 
24  void closeCurrentFile();
25 
26  void readFile(std::string const& name, art::FileBlock*& fb);
27 
28  bool readNext(art::RunPrincipal* const inR,
29  art::SubRunPrincipal* const inSR,
30  art::RunPrincipal*& outR,
31  art::SubRunPrincipal*& outSR,
32  art::EventPrincipal*& outE);
33 
34 private:
37  size_t ev_num_;
39 };
40 
42  fhicl::ParameterSet const&,
44  art::SourceHelper const& sHelper)
45  : readFileCalled_(false), sHelper_(sHelper), ev_num_(0), curr_evid_(1, 0, 1)
46 {}
47 
48 void
50 {}
51 
52 void
54  art::FileBlock*& fb)
55 {
56  assert(!readFileCalled_);
57  assert(name.empty());
58  readFileCalled_ = true;
59  fb = new art::FileBlock(art::FileFormatVersion(1, "FlushingGenerator2012"),
60  "nothing");
61 }
62 
63 bool
65  art::SubRunPrincipal* const inSR,
66  art::RunPrincipal*& outR,
67  art::SubRunPrincipal*& outSR,
68  art::EventPrincipal*& outE)
69 {
70  art::Timestamp runstart;
71  if (++ev_num_ > 17) { // Done.
72  return false;
73  } else if (ev_num_ == 3) { // Flush subrun, current run.
74  art::EventID const evid(art::EventID::flushEvent(inR->runID()));
75  outSR = sHelper_.makeSubRunPrincipal(evid.subRunID(), runstart);
76  outE = sHelper_.makeEventPrincipal(evid, runstart);
78  } else if (ev_num_ == 6) { // Flush run.
80  outR = sHelper_.makeRunPrincipal(evid.runID(), runstart);
81  outSR = sHelper_.makeSubRunPrincipal(evid.subRunID(), runstart);
82  outE = sHelper_.makeEventPrincipal(evid, runstart);
84  } else if (ev_num_ == 11 || ev_num_ == 12 ||
85  ev_num_ == 16) { // Flush event. current run, next subrun
87  runstart);
88  art::EventID const evid(art::EventID::flushEvent(outSR->subRunID()));
89  outE = sHelper_.makeEventPrincipal(evid, runstart);
91  } else {
92  if (inR == nullptr || inR->runID() != curr_evid_.runID()) {
93  outR = sHelper_.makeRunPrincipal(curr_evid_.runID(), runstart);
94  }
95  if (inSR == nullptr || inSR->subRunID() != curr_evid_.subRunID()) {
96  outSR = sHelper_.makeSubRunPrincipal(curr_evid_.subRunID(), runstart);
97  }
98  outE = sHelper_.makeEventPrincipal(curr_evid_, runstart);
100  }
101  std::cout << "ev_num_ = " << ev_num_ << std::endl;
102  return true;
103 }
104 
105 // Trait definition (must precede source typedef).
106 namespace art {
107  template <>
109  static constexpr bool value = true;
110  };
111 } // namespace art
112 
113 // Source declaration.
114 namespace arttest {
116 }
117 
RunID const & runID() const
Definition: EventID.h:93
static constexpr EventID flushEvent() noexcept
Definition: EventID.h:222
SubRunID const & subRunID() const
Definition: EventID.h:105
EventID next() const
Definition: EventID.h:135
RunID const & runID() const
Definition: Principal.cc:1174
static const double ps
Definition: Units.h:103
FlushingGeneratorDetail & operator=(FlushingGeneratorDetail const &)=delete
art::Source< FlushingGeneratorDetail > FlushingGenerator
std::string string
Definition: nybbler.cc:12
SubRunPrincipal * makeSubRunPrincipal(SubRunAuxiliary const &subRunAux) const
Definition: SourceHelper.cc:83
RunPrincipal * makeRunPrincipal(RunAuxiliary const &runAux) const
Definition: SourceHelper.cc:55
bool readNext(art::RunPrincipal *const inR, art::SubRunPrincipal *const inSR, art::RunPrincipal *&outR, art::SubRunPrincipal *&outSR, art::EventPrincipal *&outE)
SubRunID subRunID() const
Definition: Principal.cc:1180
EventID nextSubRun(EventNumber_t first=IDNumber< Level::Event >::first()) const
Definition: EventID.h:148
FlushingGeneratorDetail(FlushingGeneratorDetail const &)=delete
void readFile(std::string const &name, art::FileBlock *&fb)
EventPrincipal * makeEventPrincipal(EventAuxiliary const &eventAux, std::unique_ptr< History > &&history) const
EventID nextRun() const
Definition: EventID.h:154
#define DEFINE_ART_INPUT_SOURCE(klass)