ToyRawProductAnalyzer_module.cc
Go to the documentation of this file.
6 
7 #include <cassert>
8 #include <iostream>
9 
10 namespace arttest {
11  class ToyRawProductAnalyzer;
12 }
13 
14 using namespace fhicl;
15 
17 public:
18  struct Config {
19  Atom<bool> beginRun{Name{"beginRun"}, true};
20  Atom<bool> beginSubRun{Name{"beginSubRun"}, true};
21  };
23  explicit ToyRawProductAnalyzer(Parameters const& p);
24 
25 private:
26  void analyze(art::Event const& e) override;
27  void beginRun(art::Run const& r) override;
28  void beginSubRun(art::SubRun const& sr) override;
29 
30  bool const doBeginRun_;
31  bool const doBeginSubRun_;
32 };
33 
35  : art::EDAnalyzer{p}
36  , doBeginRun_{p().beginRun()}
37  , doBeginSubRun_{p().beginSubRun()}
38 {}
39 
40 void
42 {
43  e.getRun(); // Will throw if subRun or run are unavailable.
44  std::vector<art::Handle<int>> hv;
45  e.getManyByType(hv);
46  assert(hv.size() == 1u);
47  art::Handle<int>& h = hv[0];
48  std::cerr << e.id() << " int = " << (*h) << "\n";
49  art::Handle<bool> hb1, hb2;
50  assert(e.getByLabel("m2", "a", hb1));
51  std::cerr << e.id() << " bool a = " << (*hb1) << "\n";
52  assert(e.getByLabel(art::InputTag("m2", "b"), hb2));
53  std::cerr << e.id() << " bool b = " << (*hb2) << "\n";
54  auto ph = e.getValidHandle<art::Ptr<double>>("m3");
55  assert(**ph == 3.7);
56 }
57 
58 void
60 {
61  if (!doBeginRun_)
62  return;
63  std::vector<art::Handle<double>> hv;
64  r.getManyByType(hv);
65  assert(hv.size() == 1u);
66  art::Handle<double>& h = hv[0];
67  std::cerr << r.id() << " double = " << (*h) << "\n";
68 }
69 
70 void
72 {
73  if (!doBeginSubRun_)
74  return;
75  sr.getRun(); // Will throw if not available.
76  std::vector<art::Handle<double>> hv;
77  sr.getManyByType(hv);
78  assert(hv.size() == 1u);
79  art::Handle<double>& h = hv[0];
80  std::cerr << sr.id() << " double = " << (*h) << "\n";
81 }
82 
def analyze(root, level, gtrees, gbranches, doprint)
Definition: rootstat.py:67
RunID id() const
Definition: Run.cc:24
void beginSubRun(art::SubRun const &sr) override
Definition: Run.h:21
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:435
const double e
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:68
Run const & getRun() const
Definition: SubRun.cc:27
parameter set interface
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:480
void getManyByType(std::vector< Handle< PROD >> &results) const
Definition: DataViewImpl.h:518
Run const & getRun() const
Definition: Event.cc:53
void beginRun(art::Run const &r) override
p
Definition: test.py:228
void analyze(art::Event const &e) override
SubRunID id() const
Definition: SubRun.cc:21
static const double sr
Definition: Units.h:167
EventID id() const
Definition: Event.cc:37
h
training ###############################
Definition: train_cnn.py:186