ToySource.cc
Go to the documentation of this file.
10 #include "fhiclcpp/ParameterSet.h"
11 
14  art::SourceHelper const& sHelper)
15  : data_{ps}
16  , sHelper_{sHelper}
17  , throw_on_construction_{ps.get<bool>("throw_on_construction", false)}
18  , throw_on_closeCurrentFile_{ps.get<bool>("throw_on_closeCurrentFile", false)}
19  , throw_on_readNext_{ps.get<bool>("throw_on_readNext", false)}
20  , throw_on_readFile_{ps.get<bool>("throw_on_construction", false)}
21  , vtl_{helper.reconstitutes<std::vector<double>, art::InEvent>("m3")}
22 {
24  throw_exception_from("ToySource");
25  helper.reconstitutes<int, art::InEvent>("m1");
26  helper.reconstitutes<double, art::InSubRun>("s1");
27  helper.reconstitutes<double, art::InRun>("r1");
28  helper.reconstitutes<bool, art::InEvent>("m2", "a");
29  helper.reconstitutes<bool, art::InEvent>("m2", "b");
30  helper.reconstitutes<art::Ptr<double>, art::InEvent>("m3");
31 }
32 
33 void
35 {
37  throw_exception_from("closeCurrentFile");
38  fileData_.clear();
39  current_ = iter{};
40  end_ = iter{};
41 }
42 
43 bool
45  art::SubRunPrincipal const* const inSR,
46  art::RunPrincipal*& outR,
47  art::SubRunPrincipal*& outSR,
48  art::EventPrincipal*& outE)
49 {
51  using std::make_unique;
52 
54  throw_exception_from("readNext");
55  // Have we any more to read?
56  if (current_ == end_)
57  return false;
58 
59  if (data_.get<bool>("returnTrueWithoutNewFault", false))
60  return true;
61 
62  bool readSomething{false};
63 
64  static auto const timeStamp = art::Timestamp::invalidTimestamp();
65 
66  int rN, srN, eN;
67  std::tie(rN, srN, eN) = *current_;
68 
69  if (rN != -1) // New run
70  {
71  outR = sHelper_.makeRunPrincipal(rN, timeStamp);
72  put_product_in_principal(make_unique<double>(76.5), *outR, "r1");
73  readSomething = true;
74  }
75  if (srN != -1) // New subrun
76  {
77  assert(outR || inR); // Must have one or the other.
78  art::SubRunID newSRID;
79  if (data_.get<bool>("newRunSameSubRunFault", false) && inSR) {
80  newSRID = inSR->subRunID();
81  } else {
82  newSRID = art::SubRunID(outR ? outR->run() : inR->run(), srN);
83  }
84  outSR = sHelper_.makeSubRunPrincipal(newSRID, timeStamp);
85  put_product_in_principal(make_unique<double>(7.0), *outSR, "s1");
86  readSomething = true;
87  }
88  if (eN != -1) {
89  assert(outSR || inSR);
90  outE = sHelper_.makeEventPrincipal(outR ? outR->run() : inR->run(),
91  outSR ? outSR->subRun() : inSR->subRun(),
92  eN, // event number
93  timeStamp);
94  put_product_in_principal(make_unique<int>(26), *outE, "m1");
95  put_product_in_principal(make_unique<bool>(false), *outE, "m2", "a");
96  put_product_in_principal(make_unique<bool>(true), *outE, "m2", "b");
97  {
98  std::vector<double> nums{1.0, 3.7, 5.2};
100  make_unique<decltype(nums)>(std::move(nums)), *outE, "m3");
101  }
103  make_unique<art::Ptr<double>>(sHelper_.makePtr<double>(vtl_, *outE, 1)),
104  *outE,
105  "m3");
106 
107  readSomething = true;
108  }
109  if (readSomething) {
110  if (data_.get<bool>("returnFalseWithNewFault", false))
111  return false;
112  } else {
114  << "Did not read expected info from 'file.'\n";
115  }
116  ++current_;
117  return true;
118 }
119 
120 void
122 {
124  << "Expected exception from DETAIL::" << funcname << '\n';
125 }
Ptr< T > makePtr(TypeLabel const &t, Principal const &p, typename Ptr< T >::key_type key) const
RunNumber_t run() const
Definition: Principal.cc:1192
static const double ps
Definition: Units.h:103
static void throw_exception_from(const char *funcname)
Definition: ToySource.cc:121
bool readNext(art::RunPrincipal const *const inR, art::SubRunPrincipal const *const inSR, art::RunPrincipal *&outR, art::SubRunPrincipal *&outSR, art::EventPrincipal *&outE)
Definition: ToySource.cc:44
SubRunPrincipal * makeSubRunPrincipal(SubRunAuxiliary const &subRunAux) const
Definition: SourceHelper.cc:83
RunPrincipal * makeRunPrincipal(RunAuxiliary const &runAux) const
Definition: SourceHelper.cc:55
bool const throw_on_construction_
Definition: ToySource.h:54
art::TypeLabel vtl_
Definition: ToySource.h:59
T get(std::string const &key) const
Definition: ParameterSet.h:231
vv_t::const_iterator iter
Definition: ToySource.h:45
bool const throw_on_readNext_
Definition: ToySource.h:56
SubRunID subRunID() const
Definition: Principal.cc:1180
bool const throw_on_readFile_
Definition: ToySource.h:57
fhicl::ParameterSet data_
Definition: ToySource.h:49
std::enable_if_t<(P::branch_type==InEvent)||(P::branch_type==InResults)> put_product_in_principal(std::unique_ptr< T > &&product, P &principal, std::string const &module_label, std::string const &instance_name={})
void closeCurrentFile()
Definition: ToySource.cc:34
static constexpr Timestamp invalidTimestamp()
Definition: Timestamp.h:83
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
art::SourceHelper const & sHelper_
Definition: ToySource.h:52
bool const throw_on_closeCurrentFile_
Definition: ToySource.h:55
EventPrincipal * makeEventPrincipal(EventAuxiliary const &eventAux, std::unique_ptr< History > &&history) const
SubRunNumber_t subRun() const
Definition: Principal.cc:1204
ToySource(fhicl::ParameterSet const &ps, art::ProductRegistryHelper &help, art::SourceHelper const &sHelper)
Definition: ToySource.cc:12