LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
EDAnalyzer.h
Go to the documentation of this file.
1 #ifndef art_Framework_Core_EDAnalyzer_h
2 #define art_Framework_Core_EDAnalyzer_h
3 
4 // ======================================================================
5 //
6 // EDAnalyzer - the base class for all analyzer "modules".
7 //
8 // ======================================================================
9 
17 #include "fhiclcpp/ParameterSet.h"
21 #include "fhiclcpp/types/Table.h"
23 
24 #include <memory>
25 #include <ostream>
26 #include <string>
27 
28 // ----------------------------------------------------------------------
29 
30 namespace art {
31  class EDAnalyzer : public EventObserverBase,
32  public Consumer,
33  public EngineCreator {
34  public:
35  template <typename T>
36  friend class WorkerT;
37 
40 
41  //---------------------------------------------------------------------------
42  // Configuration
43 
44  template <typename UserConfig, typename UserKeysToIgnore = void>
46  public:
47  template <typename T>
48  struct FullConfig {
53  };
54 
55  using KeysToIgnore_t =
58  fhicl::KeysToIgnore<detail::ModuleConfig::IgnoreKeys,
59  UserKeysToIgnore>>;
60 
61  public:
62  explicit Table(fhicl::Name&& name) : fullConfig_{std::move(name)} {}
63  Table(fhicl::ParameterSet const& pset) : fullConfig_{pset} {}
64 
65  auto const&
66  operator()() const
67  {
68  return fullConfig_().user();
69  }
70  auto const&
71  eoFragment() const
72  {
73  return fullConfig_().eoConfig();
74  }
75  auto const&
76  get_PSet() const
77  {
78  return fullConfig_.get_PSet();
79  }
80 
81  void
82  print_allowed_configuration(std::ostream& os,
83  std::string const& prefix) const
84  {
85  fullConfig_.print_allowed_configuration(os, prefix);
86  }
87 
88  private:
90  cet::exempt_ptr<fhicl::detail::ParameterBase const>
91  get_parameter_base() const override
92  {
93  return &fullConfig_;
94  }
95  };
96 
97  //---------------------------------------------------------------------------
98 
99  template <typename Config>
100  explicit EDAnalyzer(Table<Config> const& config)
101  : EventObserverBase{config.eoFragment().selectEvents(), config.get_PSet()}
102  {}
103 
104  explicit EDAnalyzer(fhicl::ParameterSet const& pset);
105 
106  virtual ~EDAnalyzer() = default;
107 
108  std::string
109  workerType() const
110  {
111  return "WorkerT<EDAnalyzer>";
112  }
113 
114  protected:
115  // The returned pointer will be null unless the this is currently
116  // executing its event loop function ('analyze').
118 
119  private:
120  using CPC_exempt_ptr = cet::exempt_ptr<CurrentProcessingContext const>;
121 
122  bool doEvent(EventPrincipal const& ep,
123  CPC_exempt_ptr cpc,
125  void doBeginJob();
126  void doEndJob();
127  bool doBeginRun(RunPrincipal const& rp, CPC_exempt_ptr cpc);
128  bool doEndRun(RunPrincipal const& rp, CPC_exempt_ptr cpc);
129  bool doBeginSubRun(SubRunPrincipal const& srp, CPC_exempt_ptr cpc);
130  bool doEndSubRun(SubRunPrincipal const& srp, CPC_exempt_ptr cpc);
135 
136  virtual void analyze(Event const&) = 0;
137  virtual void
139  {}
140  virtual void
142  {}
143  virtual void
144  beginRun(Run const&)
145  {}
146  virtual void
147  endRun(Run const&)
148  {}
149  virtual void
151  {}
152  virtual void
154  {}
155  virtual void
157  {}
158  virtual void
160  {}
161  virtual void
163  {}
164  virtual void
166  {}
167 
168  void
170  {
171  moduleDescription_ = md;
172  // Since the module description in the Consumer base class is
173  // owned by pointer, we must give it the owned object of this
174  // class--i.e. moduleDescription_, not md.
176  }
177 
180  }; // EDAnalyzer
181 
182  template <typename T>
183  inline std::ostream&
184  operator<<(std::ostream& os, EDAnalyzer::Table<T> const& t)
185  {
186  std::ostringstream config;
187  t.print_allowed_configuration(config, std::string(3, ' '));
188  return os << config.str();
189  }
190 
191 } // art
192 
193  // ======================================================================
194 
195 #endif /* art_Framework_Core_EDAnalyzer_h */
196 
197 // Local Variables:
198 // mode: c++
199 // End:
static fhicl::Name plugin_type()
void doBeginJob()
Definition: EDAnalyzer.cc:36
void doRespondToCloseInputFile(FileBlock const &fb)
Definition: EDAnalyzer.cc:96
bool doBeginRun(RunPrincipal const &rp, CPC_exempt_ptr cpc)
Definition: EDAnalyzer.cc:54
virtual void beginRun(Run const &)
Definition: EDAnalyzer.h:144
virtual void analyze(Event const &)=0
void doRespondToCloseOutputFiles(FileBlock const &fb)
Definition: EDAnalyzer.cc:108
void doRespondToOpenOutputFiles(FileBlock const &fb)
Definition: EDAnalyzer.cc:102
virtual void respondToCloseInputFile(FileBlock const &)
Definition: EDAnalyzer.h:159
std::conditional_t< std::is_void< UserKeysToIgnore >::value, detail::ModuleConfig::IgnoreKeys, fhicl::KeysToIgnore< detail::ModuleConfig::IgnoreKeys, UserKeysToIgnore >> KeysToIgnore_t
Definition: EDAnalyzer.h:59
auto const & operator()() const
Definition: EDAnalyzer.h:66
virtual void endRun(Run const &)
Definition: EDAnalyzer.h:147
bool doEvent(EventPrincipal const &ep, CPC_exempt_ptr cpc, CountingStatistics &)
Definition: EDAnalyzer.cc:18
bool doEndSubRun(SubRunPrincipal const &srp, CPC_exempt_ptr cpc)
Definition: EDAnalyzer.cc:81
auto const & eoFragment() const
Definition: EDAnalyzer.h:71
bool doEndRun(RunPrincipal const &rp, CPC_exempt_ptr cpc)
Definition: EDAnalyzer.cc:63
bool doBeginSubRun(SubRunPrincipal const &srp, CPC_exempt_ptr cpc)
Definition: EDAnalyzer.cc:72
fhicl::TableFragment< EventObserverBase::EOConfig > eoConfig
Definition: EDAnalyzer.h:51
Definition: Run.h:30
cet::exempt_ptr< fhicl::detail::ParameterBase const > get_parameter_base() const override
Definition: EDAnalyzer.h:91
Table(fhicl::Name &&name)
Definition: EDAnalyzer.h:62
void doRespondToOpenInputFile(FileBlock const &fb)
Definition: EDAnalyzer.cc:90
fhicl::Table< FullConfig< UserConfig >, KeysToIgnore_t > fullConfig_
Definition: EDAnalyzer.h:89
virtual void respondToOpenInputFile(FileBlock const &)
Definition: EDAnalyzer.h:156
virtual void beginSubRun(SubRun const &)
Definition: EDAnalyzer.h:150
cet::exempt_ptr< CurrentProcessingContext const > CPC_exempt_ptr
Definition: EDAnalyzer.h:120
virtual void respondToOpenOutputFiles(FileBlock const &)
Definition: EDAnalyzer.h:162
std::string workerType() const
Definition: EDAnalyzer.h:109
TFile fb("Li6.root")
void setModuleDescription(ModuleDescription const &md)
Definition: Consumer.cc:83
CurrentProcessingContext const * currentContext() const
Definition: EDAnalyzer.cc:114
EDAnalyzer(Table< Config > const &config)
Definition: EDAnalyzer.h:100
virtual void endJob()
Definition: EDAnalyzer.h:141
CPC_exempt_ptr current_context_
Definition: EDAnalyzer.h:179
fhicl::TableFragment< T > user
Definition: EDAnalyzer.h:52
virtual ~EDAnalyzer()=default
std::string value(boost::any const &)
virtual void endSubRun(SubRun const &)
Definition: EDAnalyzer.h:153
auto const & get_PSet() const
Definition: EDAnalyzer.h:76
virtual void respondToCloseOutputFiles(FileBlock const &)
Definition: EDAnalyzer.h:165
virtual void beginJob()
Definition: EDAnalyzer.h:138
void print_allowed_configuration(std::ostream &os, std::string const &prefix) const
Definition: EDAnalyzer.h:82
ModuleDescription moduleDescription_
Definition: EDAnalyzer.h:178
HLT enums.
void setModuleDescription(ModuleDescription const &md)
Definition: EDAnalyzer.h:169
fhicl::Atom< std::string > module_type
Definition: EDAnalyzer.h:49
Table(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:63