LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
Analyzer.h
Go to the documentation of this file.
1 #ifndef art_Framework_Core_detail_Analyzer_h
2 #define art_Framework_Core_detail_Analyzer_h
3 // vim: set sw=2 expandtab :
4 
5 //
6 // The base class for all analyzer modules.
7 //
8 
13 #include "art/Framework/Core/fwd.h"
17 #include "cetlib/exempt_ptr.h"
21 #include "fhiclcpp/types/Table.h"
23 
24 #include <atomic>
25 #include <cstddef>
26 #include <ostream>
27 #include <string>
28 
29 namespace art {
30  class SharedResources;
31 }
32 
33 namespace art::detail {
34  class Analyzer : public Observer {
35  public:
36  template <typename UserConfig, typename UserKeysToIgnore = void>
38  template <typename T>
39  struct FullConfig {
43  };
44 
45  using KeysToIgnore_t = std::conditional_t<
49 
50  public:
51  explicit Table(fhicl::Name&& name) : fullConfig_{std::move(name)} {}
52  Table(fhicl::ParameterSet const& pset) : fullConfig_{pset} {}
53 
54  auto const&
55  operator()() const
56  {
57  return fullConfig_().user();
58  }
59 
60  auto const&
61  eoFragment() const
62  {
63  return fullConfig_().eoConfig();
64  }
65 
66  auto const&
67  get_PSet() const
68  {
69  return fullConfig_.get_PSet();
70  }
71 
72  void
73  print_allowed_configuration(std::ostream& os,
74  std::string const& prefix) const
75  {
76  fullConfig_.print_allowed_configuration(os, prefix);
77  }
78 
79  private:
80  cet::exempt_ptr<fhicl::detail::ParameterBase const>
81  get_parameter_base() const override
82  {
83  return &fullConfig_;
84  }
85 
87  };
88 
89  public:
90  virtual ~Analyzer() noexcept;
91  explicit Analyzer(fhicl::ParameterSet const& pset);
92  template <typename Config>
93  explicit Analyzer(Table<Config> const& config)
94  : Observer{config.eoFragment().selectEvents(), config.get_PSet()}
95  {}
96 
97  void doBeginJob(SharedResources const& resources);
98  void doEndJob();
100  void doRespondToCloseInputFile(FileBlock const& fb);
101  void doRespondToOpenOutputFiles(FileBlock const& fb);
102  void doRespondToCloseOutputFiles(FileBlock const& fb);
103  bool doBeginRun(RunPrincipal& rp, ModuleContext const& mc);
104  bool doEndRun(RunPrincipal& rp, ModuleContext const& mc);
105  bool doBeginSubRun(SubRunPrincipal& srp, ModuleContext const& mc);
106  bool doEndSubRun(SubRunPrincipal& srp, ModuleContext const& mc);
107  bool doEvent(EventPrincipal& ep,
108  ModuleContext const& mc,
109  std::atomic<std::size_t>& counts_run,
110  std::atomic<std::size_t>& counts_passed,
111  std::atomic<std::size_t>& counts_failed);
112 
113  private:
114  virtual void setupQueues(SharedResources const&) = 0;
115  virtual void analyzeWithFrame(Event const&, ProcessingFrame const&) = 0;
116  virtual void beginJobWithFrame(ProcessingFrame const&) = 0;
117  virtual void endJobWithFrame(ProcessingFrame const&) = 0;
118  virtual void respondToOpenInputFileWithFrame(FileBlock const&,
119  ProcessingFrame const&) = 0;
120  virtual void respondToCloseInputFileWithFrame(FileBlock const&,
121  ProcessingFrame const&) = 0;
122  virtual void respondToOpenOutputFilesWithFrame(FileBlock const&,
123  ProcessingFrame const&) = 0;
124  virtual void respondToCloseOutputFilesWithFrame(FileBlock const&,
125  ProcessingFrame const&) = 0;
126  virtual void beginRunWithFrame(Run const&, ProcessingFrame const&) = 0;
127  virtual void endRunWithFrame(Run const&, ProcessingFrame const&) = 0;
128  virtual void beginSubRunWithFrame(SubRun const&,
129  ProcessingFrame const&) = 0;
130  virtual void endSubRunWithFrame(SubRun const&, ProcessingFrame const&) = 0;
131  };
132 
133  template <typename T>
134  inline std::ostream&
135  operator<<(std::ostream& os, Analyzer::Table<T> const& t)
136  {
137  std::ostringstream config;
138  t.print_allowed_configuration(config, std::string(3, ' '));
139  return os << config.str();
140  }
141 
142 } // namespace art::detail
143 
144 #endif /* art_Framework_Core_detail_Analyzer_h */
145 
146 // Local Variables:
147 // mode: c++
148 // End:
static fhicl::Name plugin_type()
void doRespondToOpenOutputFiles(FileBlock const &fb)
Definition: Analyzer.cc:54
fhicl::TableFragment< Observer::EOConfig > eoConfig
Definition: Analyzer.h:41
virtual void endSubRunWithFrame(SubRun const &, ProcessingFrame const &)=0
auto const & eoFragment() const
Definition: Analyzer.h:61
virtual void beginJobWithFrame(ProcessingFrame const &)=0
virtual void respondToOpenOutputFilesWithFrame(FileBlock const &, ProcessingFrame const &)=0
void print_allowed_configuration(std::ostream &os, std::string const &prefix) const
Definition: Analyzer.h:73
virtual void endRunWithFrame(Run const &, ProcessingFrame const &)=0
virtual void setupQueues(SharedResources const &)=0
void doBeginJob(SharedResources const &resources)
Definition: Analyzer.cc:25
bool doBeginRun(RunPrincipal &rp, ModuleContext const &mc)
Definition: Analyzer.cc:68
std::conditional_t< std::is_void< UserKeysToIgnore >::value, ModuleConfig::IgnoreKeys, fhicl::KeysToIgnore< ModuleConfig::IgnoreKeys, UserKeysToIgnore >> KeysToIgnore_t
Definition: Analyzer.h:48
auto const & operator()() const
Definition: Analyzer.h:55
void doRespondToOpenInputFile(FileBlock const &fb)
Definition: Analyzer.cc:40
Definition: Run.h:37
Table(fhicl::ParameterSet const &pset)
Definition: Analyzer.h:52
fhicl::Atom< std::string > module_type
Definition: Analyzer.h:40
cet::exempt_ptr< fhicl::detail::ParameterBase const > get_parameter_base() const override
Definition: Analyzer.h:81
Table(fhicl::Name &&name)
Definition: Analyzer.h:51
virtual void endJobWithFrame(ProcessingFrame const &)=0
parameter set interface
virtual void beginSubRunWithFrame(SubRun const &, ProcessingFrame const &)=0
virtual void respondToCloseOutputFilesWithFrame(FileBlock const &, ProcessingFrame const &)=0
fhicl::Table< FullConfig< UserConfig >, KeysToIgnore_t > fullConfig_
Definition: Analyzer.h:86
bool doBeginSubRun(SubRunPrincipal &srp, ModuleContext const &mc)
Definition: Analyzer.cc:84
auto const & get_PSet() const
Definition: Analyzer.h:67
double value
Definition: spectrum.C:18
virtual ~Analyzer() noexcept
TFile fb("Li6.root")
virtual void respondToCloseInputFileWithFrame(FileBlock const &, ProcessingFrame const &)=0
bool doEndRun(RunPrincipal &rp, ModuleContext const &mc)
Definition: Analyzer.cc:76
Definition: MVAAlg.h:12
fhicl::TableFragment< T > user
Definition: Analyzer.h:42
void doRespondToCloseInputFile(FileBlock const &fb)
Definition: Analyzer.cc:47
bool doEvent(EventPrincipal &ep, ModuleContext const &mc, std::atomic< std::size_t > &counts_run, std::atomic< std::size_t > &counts_passed, std::atomic< std::size_t > &counts_failed)
Definition: Analyzer.cc:100
virtual void respondToOpenInputFileWithFrame(FileBlock const &, ProcessingFrame const &)=0
void doRespondToCloseOutputFiles(FileBlock const &fb)
Definition: Analyzer.cc:61
virtual void beginRunWithFrame(Run const &, ProcessingFrame const &)=0
bool doEndSubRun(SubRunPrincipal &srp, ModuleContext const &mc)
Definition: Analyzer.cc:92
virtual void analyzeWithFrame(Event const &, ProcessingFrame const &)=0