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 
16 #include "cetlib/exempt_ptr.h"
20 #include "fhiclcpp/types/Table.h"
22 
23 #include <atomic>
24 #include <cstddef>
25 #include <ostream>
26 #include <string>
27 
28 namespace art {
29  class SharedResources;
30 }
31 
32 namespace art::detail {
33  class Analyzer : public Observer {
34  public:
35  template <typename UserConfig, typename UserKeysToIgnore = void>
37  template <typename T>
38  struct FullConfig {
43  };
44 
45  using KeysToIgnore_t =
48  fhicl::KeysToIgnore<detail::ModuleConfig::IgnoreKeys,
49  UserKeysToIgnore>>;
50 
51  public:
53  Table(fhicl::ParameterSet const& pset) : fullConfig_{pset} {}
54 
55  auto const&
56  operator()() const
57  {
58  return fullConfig_().user();
59  }
60 
61  auto const&
62  eoFragment() const
63  {
64  return fullConfig_().eoConfig();
65  }
66 
67  auto const&
68  get_PSet() const
69  {
70  return fullConfig_.get_PSet();
71  }
72 
73  void
74  print_allowed_configuration(std::ostream& os,
75  std::string const& prefix) const
76  {
77  fullConfig_.print_allowed_configuration(os, prefix);
78  }
79 
80  private:
82  get_parameter_base() const override
83  {
84  return &fullConfig_;
85  }
86 
88  };
89 
90  public:
91  virtual ~Analyzer() noexcept;
92  explicit Analyzer(fhicl::ParameterSet const& pset);
93  template <typename Config>
95  : Observer{config.eoFragment().selectEvents(), config.get_PSet()}
96  {}
97 
98  void doBeginJob(SharedResources const& resources);
99  void doEndJob();
100  void doRespondToOpenInputFile(FileBlock const& fb);
101  void doRespondToCloseInputFile(FileBlock const& fb);
102  void doRespondToOpenOutputFiles(FileBlock const& fb);
103  void doRespondToCloseOutputFiles(FileBlock const& fb);
104  bool doBeginRun(RunPrincipal& rp, ModuleContext const& mc);
105  bool doEndRun(RunPrincipal& rp, ModuleContext const& mc);
106  bool doBeginSubRun(SubRunPrincipal& srp, ModuleContext const& mc);
107  bool doEndSubRun(SubRunPrincipal& srp, ModuleContext const& mc);
108  bool doEvent(EventPrincipal& ep,
109  ModuleContext const& mc,
110  std::atomic<std::size_t>& counts_run,
111  std::atomic<std::size_t>& counts_passed,
112  std::atomic<std::size_t>& counts_failed);
113 
114  private:
115  virtual void setupQueues(SharedResources const&) = 0;
116  virtual void analyzeWithFrame(Event const&, ProcessingFrame const&) = 0;
117  virtual void beginJobWithFrame(ProcessingFrame const&) = 0;
118  virtual void endJobWithFrame(ProcessingFrame const&) = 0;
119  virtual void respondToOpenInputFileWithFrame(FileBlock const&,
120  ProcessingFrame const&) = 0;
121  virtual void respondToCloseInputFileWithFrame(FileBlock const&,
122  ProcessingFrame const&) = 0;
123  virtual void respondToOpenOutputFilesWithFrame(FileBlock const&,
124  ProcessingFrame const&) = 0;
125  virtual void respondToCloseOutputFilesWithFrame(FileBlock const&,
126  ProcessingFrame const&) = 0;
127  virtual void beginRunWithFrame(Run const&, ProcessingFrame const&) = 0;
128  virtual void endRunWithFrame(Run const&, ProcessingFrame const&) = 0;
129  virtual void beginSubRunWithFrame(SubRun const&,
130  ProcessingFrame const&) = 0;
131  virtual void endSubRunWithFrame(SubRun const&, ProcessingFrame const&) = 0;
132  };
133 
134  template <typename T>
135  inline std::ostream&
136  operator<<(std::ostream& os, Analyzer::Table<T> const& t)
137  {
138  std::ostringstream config;
139  t.print_allowed_configuration(config, std::string(3, ' '));
140  return os << config.str();
141  }
142 
143 } // namespace art::detail
144 
145 #endif /* art_Framework_Core_detail_Analyzer_h */
146 
147 // Local Variables:
148 // mode: c++
149 // End:
static fhicl::Name plugin_type()
static QCString name
Definition: declinfo.cpp:673
void doRespondToOpenOutputFiles(FileBlock const &fb)
Definition: Analyzer.cc:53
fhicl::TableFragment< Observer::EOConfig > eoConfig
Definition: Analyzer.h:41
virtual void endSubRunWithFrame(SubRun const &, ProcessingFrame const &)=0
auto const & eoFragment() const
Definition: Analyzer.h:62
virtual void beginJobWithFrame(ProcessingFrame const &)=0
virtual void respondToOpenOutputFilesWithFrame(FileBlock const &, ProcessingFrame const &)=0
std::string string
Definition: nybbler.cc:12
void print_allowed_configuration(std::ostream &os, std::string const &prefix) const
Definition: Analyzer.h:74
virtual void endRunWithFrame(Run const &, ProcessingFrame const &)=0
virtual void setupQueues(SharedResources const &)=0
void doBeginJob(SharedResources const &resources)
Definition: Analyzer.cc:24
bool doBeginRun(RunPrincipal &rp, ModuleContext const &mc)
Definition: Analyzer.cc:67
auto const & operator()() const
Definition: Analyzer.h:56
void doRespondToOpenInputFile(FileBlock const &fb)
Definition: Analyzer.cc:39
Definition: config.h:291
Definition: Run.h:17
Table(fhicl::ParameterSet const &pset)
Definition: Analyzer.h:53
fhicl::Atom< std::string > module_type
Definition: Analyzer.h:39
cet::exempt_ptr< fhicl::detail::ParameterBase const > get_parameter_base() const override
Definition: Analyzer.h:82
Table(fhicl::Name &&name)
Definition: Analyzer.h:52
virtual void endJobWithFrame(ProcessingFrame const &)=0
static Config * config
Definition: config.cpp:1054
virtual void beginSubRunWithFrame(SubRun const &, ProcessingFrame const &)=0
def move(depos, offset)
Definition: depos.py:107
virtual void respondToCloseOutputFilesWithFrame(FileBlock const &, ProcessingFrame const &)=0
fhicl::Table< FullConfig< UserConfig >, KeysToIgnore_t > fullConfig_
Definition: Analyzer.h:87
bool doBeginSubRun(SubRunPrincipal &srp, ModuleContext const &mc)
Definition: Analyzer.cc:85
auto const & get_PSet() const
Definition: Analyzer.h:68
virtual ~Analyzer() noexcept
std::conditional_t< std::is_void< UserKeysToIgnore >::value, detail::ModuleConfig::IgnoreKeys, fhicl::KeysToIgnore< detail::ModuleConfig::IgnoreKeys, UserKeysToIgnore >> KeysToIgnore_t
Definition: Analyzer.h:49
virtual void respondToCloseInputFileWithFrame(FileBlock const &, ProcessingFrame const &)=0
bool doEndRun(RunPrincipal &rp, ModuleContext const &mc)
Definition: Analyzer.cc:76
fhicl::TableFragment< T > user
Definition: Analyzer.h:42
void doRespondToCloseInputFile(FileBlock const &fb)
Definition: Analyzer.cc:46
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:103
virtual void respondToOpenInputFileWithFrame(FileBlock const &, ProcessingFrame const &)=0
void doRespondToCloseOutputFiles(FileBlock const &fb)
Definition: Analyzer.cc:60
virtual void beginRunWithFrame(Run const &, ProcessingFrame const &)=0
bool doEndSubRun(SubRunPrincipal &srp, ModuleContext const &mc)
Definition: Analyzer.cc:94
virtual void analyzeWithFrame(Event const &, ProcessingFrame const &)=0