Public Member Functions | Protected Types | Static Protected Member Functions | Protected Attributes | List of all members
arttest::ToySource Class Referenceabstract

#include <ToySource.h>

Inheritance diagram for arttest::ToySource:
arttest::ToyFileReader arttest::ToyReader

Public Member Functions

 ToySource (fhicl::ParameterSet const &ps, art::ProductRegistryHelper &help, art::SourceHelper const &sHelper)
 
virtual ~ToySource ()=default
 
void closeCurrentFile ()
 
virtual void readFile (std::string const &name, art::FileBlock *&fb)=0
 
bool readNext (art::RunPrincipal const *const inR, art::SubRunPrincipal const *const inSR, art::RunPrincipal *&outR, art::SubRunPrincipal *&outSR, art::EventPrincipal *&outE)
 

Protected Types

using vv_t = std::vector< std::tuple< int, int, int >>
 
using iter = vv_t::const_iterator
 

Static Protected Member Functions

static void throw_exception_from (const char *funcname)
 

Protected Attributes

iter current_ {}
 
iter end_ {}
 
fhicl::ParameterSet data_
 
vv_t fileData_ {}
 
art::SourceHelper const & sHelper_
 
std::string currentFilename_ {}
 
bool const throw_on_construction_
 
bool const throw_on_closeCurrentFile_
 
bool const throw_on_readNext_
 
bool const throw_on_readFile_
 
art::TypeLabel vtl_
 

Detailed Description

Definition at line 22 of file ToySource.h.

Member Typedef Documentation

Definition at line 45 of file ToySource.h.

using arttest::ToySource::vv_t = std::vector<std::tuple<int, int, int>>
protected

Definition at line 44 of file ToySource.h.

Constructor & Destructor Documentation

arttest::ToySource::ToySource ( fhicl::ParameterSet const &  ps,
art::ProductRegistryHelper help,
art::SourceHelper const &  sHelper 
)

Definition at line 12 of file ToySource.cc.

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 }
static const double ps
Definition: Units.h:103
static void throw_exception_from(const char *funcname)
Definition: ToySource.cc:121
bool const throw_on_construction_
Definition: ToySource.h:54
art::TypeLabel vtl_
Definition: ToySource.h:59
bool const throw_on_readNext_
Definition: ToySource.h:56
bool const throw_on_readFile_
Definition: ToySource.h:57
fhicl::ParameterSet data_
Definition: ToySource.h:49
art::SourceHelper const & sHelper_
Definition: ToySource.h:52
bool const throw_on_closeCurrentFile_
Definition: ToySource.h:55
virtual arttest::ToySource::~ToySource ( )
virtualdefault

Member Function Documentation

void arttest::ToySource::closeCurrentFile ( )

Definition at line 34 of file ToySource.cc.

35 {
37  throw_exception_from("closeCurrentFile");
38  fileData_.clear();
39  current_ = iter{};
40  end_ = iter{};
41 }
static void throw_exception_from(const char *funcname)
Definition: ToySource.cc:121
vv_t::const_iterator iter
Definition: ToySource.h:45
bool const throw_on_closeCurrentFile_
Definition: ToySource.h:55
virtual void arttest::ToySource::readFile ( std::string const &  name,
art::FileBlock *&  fb 
)
pure virtual
bool arttest::ToySource::readNext ( art::RunPrincipal const *const  inR,
art::SubRunPrincipal const *const  inSR,
art::RunPrincipal *&  outR,
art::SubRunPrincipal *&  outSR,
art::EventPrincipal *&  outE 
)

Definition at line 44 of file ToySource.cc.

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 }
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 void throw_exception_from(const char *funcname)
Definition: ToySource.cc:121
SubRunPrincipal * makeSubRunPrincipal(SubRunAuxiliary const &subRunAux) const
Definition: SourceHelper.cc:83
RunPrincipal * makeRunPrincipal(RunAuxiliary const &runAux) const
Definition: SourceHelper.cc:55
art::TypeLabel vtl_
Definition: ToySource.h:59
T get(std::string const &key) const
Definition: ParameterSet.h:231
bool const throw_on_readNext_
Definition: ToySource.h:56
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={})
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
EventPrincipal * makeEventPrincipal(EventAuxiliary const &eventAux, std::unique_ptr< History > &&history) const
SubRunNumber_t subRun() const
Definition: SubRunID.h:90
void arttest::ToySource::throw_exception_from ( const char *  funcname)
staticprotected

Definition at line 121 of file ToySource.cc.

122 {
124  << "Expected exception from DETAIL::" << funcname << '\n';
125 }
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66

Member Data Documentation

iter arttest::ToySource::current_ {}
protected

Definition at line 47 of file ToySource.h.

std::string arttest::ToySource::currentFilename_ {}
protected

Definition at line 53 of file ToySource.h.

fhicl::ParameterSet arttest::ToySource::data_
protected

Definition at line 49 of file ToySource.h.

iter arttest::ToySource::end_ {}
protected

Definition at line 48 of file ToySource.h.

vv_t arttest::ToySource::fileData_ {}
protected

Definition at line 50 of file ToySource.h.

art::SourceHelper const& arttest::ToySource::sHelper_
protected

Definition at line 52 of file ToySource.h.

bool const arttest::ToySource::throw_on_closeCurrentFile_
protected

Definition at line 55 of file ToySource.h.

bool const arttest::ToySource::throw_on_construction_
protected

Definition at line 54 of file ToySource.h.

bool const arttest::ToySource::throw_on_readFile_
protected

Definition at line 57 of file ToySource.h.

bool const arttest::ToySource::throw_on_readNext_
protected

Definition at line 56 of file ToySource.h.

art::TypeLabel arttest::ToySource::vtl_
protected

Definition at line 59 of file ToySource.h.


The documentation for this class was generated from the following files: