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