SimpleSource_source.cc
Go to the documentation of this file.
1 // Our simulated input file format is:
2 // A parameter in a parameter set, which contains a vector of vector of int.
3 // Each inner vector is a triplet of run/subrun/event number.
4 // -1 means no new item of that type
5 //
6 
18 #include "fhiclcpp/ParameterSet.h"
19 
20 #include <string>
21 #include <vector>
22 
23 namespace art {
24  namespace test {
25  class SimpleSource;
26  }
27 } // namespace art
28 
29 namespace art {
30  // We don't want the file services: we must say so by specializing the
31  // template *before* specifying the typedef.
32  template <>
34  static constexpr bool value{false};
35  };
36 } // namespace art
37 
39 public:
42  art::SourceHelper const& sHelper);
43 
44  void closeCurrentFile();
45 
46  void readFile(std::string const& name, FileBlock*& fb);
47 
48  bool readNext(RunPrincipal const* const inR,
49  SubRunPrincipal const* const inSR,
50  RunPrincipal*& outR,
51  SubRunPrincipal*& outSR,
52  EventPrincipal*& outE);
53 
54 protected:
55  using eventNumbers_t = std::vector<std::tuple<int, int, int>>;
57 
58  iter current_{};
59  iter end_{};
61  eventNumbers_t fileData_{};
62 
64  std::string currentFilename_{};
65  RunID currentRunID_{};
66  SubRunID currentSubRunID_{};
67  EventID currentEventID_{};
68 
70 };
71 
74  art::SourceHelper const& sHelper)
75  : data_{ps}
76  , sHelper_{sHelper}
77  , vtl_{helper.reconstitutes<std::vector<double>, art::InEvent>("m3")}
78 {
79  helper.reconstitutes<int, art::InEvent>("m1");
80  helper.reconstitutes<double, art::InSubRun>("s1");
81  helper.reconstitutes<double, art::InRun>("r1");
82  helper.reconstitutes<bool, art::InEvent>("m2", "a");
83  helper.reconstitutes<bool, art::InEvent>("m2", "b");
84  helper.reconstitutes<art::Ptr<double>, art::InEvent>("m3");
85 }
86 
87 void
89 {
90  fileData_.clear();
91  current_ = iter{};
92  end_ = iter{};
93 }
94 
95 void
97 {
98  if (!data_.get_if_present(name, fileData_)) {
100  << "ToyReader expects to find a parameter representing a file's\n"
101  << "contents whose name is " << name << "\n";
102  }
104  current_ = fileData_.begin();
105  end_ = fileData_.end();
106  fb = new art::FileBlock{art::FileFormatVersion{1, "SimpleSource 2017"},
108 }
109 
110 bool
112  SubRunPrincipal const* const,
113  RunPrincipal*& outR,
114  SubRunPrincipal*& outSR,
115  EventPrincipal*& outE)
116 {
118  using std::make_unique;
119 
120  // Have we any more to read?
121  if (current_ == end_)
122  return false;
123 
124  int r, sr, e;
125  std::tie(r, sr, e) = *current_;
126  ++current_;
127 
128  if (r != -1) // New run
129  {
132  put_product_in_principal(make_unique<double>(76.5), *outR, "r1");
133  }
134  if (sr != -1) // New subrun
135  {
138  put_product_in_principal(make_unique<double>(7.0), *outSR, "s1");
139  }
140  if (e != -1) // New event
141  {
144  put_product_in_principal(make_unique<int>(26), *outE, "m1");
145  put_product_in_principal(make_unique<bool>(false), *outE, "m2", "a");
146  put_product_in_principal(make_unique<bool>(true), *outE, "m2", "b");
147  {
148  std::vector<double> nums{1.0, 3.7, 5.2};
150  make_unique<decltype(nums)>(std::move(nums)), *outE, "m3");
151  }
153  make_unique<art::Ptr<double>>(sHelper_.makePtr<double>(vtl_, *outE, 1)),
154  *outE,
155  "m3");
156  }
157  return true;
158 }
159 
Ptr< T > makePtr(TypeLabel const &t, Principal const &p, typename Ptr< T >::key_type key) const
fhicl::ParameterSet data_
static const double ps
Definition: Units.h:103
std::string string
Definition: nybbler.cc:12
std::vector< std::tuple< int, int, int >> eventNumbers_t
Definition: test.py:1
SubRunPrincipal * makeSubRunPrincipal(SubRunAuxiliary const &subRunAux) const
Definition: SourceHelper.cc:83
RunPrincipal * makeRunPrincipal(RunAuxiliary const &runAux) const
Definition: SourceHelper.cc:55
art::SourceHelper const & sHelper_
void readFile(string fileName, string &content)
Definition: test_suite.cc:18
SimpleSource(fhicl::ParameterSet const &ps, art::ProductRegistryHelper &help, art::SourceHelper const &sHelper)
const double e
intermediate_table::const_iterator const_iterator
eventNumbers_t::const_iterator iter
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
void readFile(std::string const &name, FileBlock *&fb)
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={})
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
IDNumber_t< Level::Event > EventNumber_t
Definition: IDNumber.h:118
EventPrincipal * makeEventPrincipal(EventAuxiliary const &eventAux, std::unique_ptr< History > &&history) const
#define DEFINE_ART_INPUT_SOURCE(klass)
static const double sr
Definition: Units.h:167
bool readNext(RunPrincipal const *const inR, SubRunPrincipal const *const inSR, RunPrincipal *&outR, SubRunPrincipal *&outSR, EventPrincipal *&outE)
IDNumber_t< Level::Run > RunNumber_t
Definition: IDNumber.h:120