ToyRawFileInput_source.cc
Go to the documentation of this file.
1 // ------------------------------------------------------------
2 //
3 // ToyRawInput is a RawInputSource that pretends to reconstitute several
4 // products. It exercises the Source template.
5 //
6 // ------------------------------------------------------------
7 
12 #include "cetlib/filepath_maker.h"
13 #include "fhiclcpp/ParameterSet.h"
16 #include "fhiclcpp/parse.h"
17 
18 #include <memory>
19 
20 namespace arttest {
21  // ToyFile is the sort of class that experimenters who make use of
22  // Source must write.
24 
25  // ToyRawInput is an instantiation of the Source template.
27 } // namespace arttest
28 
29 class arttest::ToyFileReader final : public ToySource {
30 public:
33  art::SourceHelper const& sHelper);
34 
35  void readFile(std::string const& name, art::FileBlock*& fb) override;
36 };
37 
40  art::SourceHelper const& sHelper)
41  : ToySource(ps, help, sHelper)
42 {}
43 
44 void
46 {
48  throw_exception_from("readFile");
49  fhicl::intermediate_table raw_config;
50  cet::filepath_lookup_after1 lookupPolicy(".:");
51  fhicl::parse_document(name, lookupPolicy, raw_config);
52  fhicl::ParameterSet file_pset;
53  make_ParameterSet(raw_config, file_pset);
54 
55  if (!file_pset.get_if_present("data", fileData_)) {
57  << "ToyFileReader expects to find a parameter \"data\" representing a "
58  "file's\n"
59  << "contents in file " << name << "\n";
60  }
62  current_ = fileData_.begin();
63  end_ = fileData_.end();
64  fb = new art::FileBlock(art::FileFormatVersion(1, "ToyFileReader 2011a"),
66 }
67 
std::string currentFilename_
Definition: ToySource.h:53
art::Source< ToyFileReader > ToyRawFileInput
static const double ps
Definition: Units.h:103
std::string string
Definition: nybbler.cc:12
void readFile(std::string const &name, art::FileBlock *&fb) override
static void throw_exception_from(const char *funcname)
Definition: ToySource.cc:121
void make_ParameterSet(intermediate_table const &tbl, ParameterSet &ps)
bool get_if_present(std::string const &key, T &value) const
Definition: ParameterSet.h:208
bool const throw_on_readFile_
Definition: ToySource.h:57
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
#define DEFINE_ART_INPUT_SOURCE(klass)
ToyFileReader(fhicl::ParameterSet const &ps, art::ProductRegistryHelper &help, art::SourceHelper const &sHelper)
void parse_document(std::string const &filename, cet::filepath_maker &maker, intermediate_table &result)
Definition: parse.cc:856