All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ProcessorBase.hh
Go to the documentation of this file.
1 #ifndef __sbnanalysis_core_ProcessorBase__
2 #define __sbnanalysis_core_ProcessorBase__
3 
4 /**
5  * \file ProcessorBase.hh
6  *
7  * A generic processor that writes an sbnanalysis tree.
8  *
9  * Author: A. Mastbaum <mastbaum@uchicago.edu>, 2018/01/25
10  */
11 
12 #include <string>
13 #include <vector>
14 #include "gallery/Event.h"
15 #include "Loader.hh"
16 #include "Event.hh"
17 #include "FileMeta.hh"
18 
19 class TBranch;
20 class TFile;
21 class TTree;
22 class SubRun;
23 template<class AParamType>
24 class TParameter;
25 
26 namespace event {
27  class Event;
28 }
29 
30 namespace fhicl {
31  class ParameterSet;
32 }
33 
34 namespace geo {
35  class BoxBoundedGeo;
36 }
37 
38 /** Core framework functionality. */
39 namespace core {
40 
41 class ProviderManager;
42 
43 /**
44  * \class core::ProcessorBase
45  * \brief A generic tree-writing event-by-event processor.
46  */
48 friend class ProcessorBlock;
49 public:
50  /** Constructor */
51  ProcessorBase();
52 
53  /** Destructor */
54  virtual ~ProcessorBase();
55 
56  /**
57  * Fill the tree and increment the event index.
58  */
59  virtual void FillTree();
60 
61  /**
62  * Fill the reco tree.
63  */
64  virtual void FillRecoTree();
65 
66  /**
67  * Cleanup any objects that were filled per event
68  */
69  virtual void EventCleanup();
70 
71  /**
72  * Add a branch to the output tree.
73  *
74  * Called in user subclasses to augment the default event tree.
75  * This mirrors the TTree::Branch API.
76  *
77  * \param name The branch name
78  * \param obj A pointer to the object
79  * \returns A pointer to the created TBranch (we retain ownership)
80  */
81  template<class T>
82  TBranch* AddBranch(std::string name, T* obj) {
83  return fTree->Branch(name.c_str(), obj);
84  }
85 
86  /**
87  * Add a branch to the output reco tree.
88  *
89  * Called in user subclasses to augment the default event tree.
90  * This mirrors the TTree::Branch API.
91  *
92  * \param name The branch name
93  * \param obj A pointer to the object
94  * \returns A pointer to the created TBranch (we retain ownership)
95  */
96  template<class T>
97  TBranch* AddRecoBranch(std::string name, T* obj) {
98  return fRecoTree->Branch(name.c_str(), obj);
99  }
100 
101  /**
102  * Process one event.
103  *
104  * This also serves as a filter: if the function results false, it acts as a
105  * filter and the event is not written out.
106  *
107  * \param ev The event, as a gallery::Event
108  * \param reco Reco interactions, to be populated by the user
109  * \returns True if event passes filter
110  */
111  virtual bool ProcessEvent(const gallery::Event& ev,
112  const std::vector<event::Interaction> &truth,
113  std::vector<event::RecoInteraction>& reco) = 0;
114 
115  /** Pointer to reco event information */
116  std::vector<event::RecoInteraction>* fReco; //!< Reco interaction list
117 
118 protected:
119  /**
120  * Perform user-level initialization.
121  *
122  * \param config A configuration, as a JSON filename.
123  */
124  virtual void Initialize(char* config=NULL);
125 
126  /**
127  * Perform user-level initialization.
128  *
129  * \param config A configuration, as a JSON object.
130  */
131  virtual void Initialize(fhicl::ParameterSet* config=NULL) = 0;
132 
133  /** Perform user-level finalization. */
134  virtual void Finalize() = 0;
135 
136  /**
137  * Perform framework-level initialization.
138  *
139  * \param config A configuration as a JSON filename.
140  */
141  virtual void Setup(char* config=NULL);
142 
143  /**
144  * Perform framework-level initialization.
145  *
146  * \param config A configuration as a JSON object
147  */
148  virtual void Setup(fhicl::ParameterSet* config=NULL);
149 
150  /** Perform framework-level finalization. */
151  virtual void Teardown();
152 
153  /**
154  * Populate the default event tree variables.
155  *
156  * \param ev The current gallery event
157  */
158  void BuildEventTree(gallery::Event& ev);
159 
160  void SetupServices(gallery::Event& ev);
161 
162  /**
163  * Update subrun list to include subruns for this event's file.
164  *
165  * \param ev The current gallery event
166  */
167  void UpdateSubRuns(gallery::Event& ev);
168 
169  void UpdateFileMeta(gallery::Event& ev);
170 
171  unsigned long fEventIndex; //!< An incrementing index
172  Experiment fExperimentID; //!< Experiment identifier
173  ProviderManager* fProviderManager; //!< Interface for provider access
174  std::string fOutputFilename; //!< The output filename
175  std::string fProviderConfig; //!< A custom provider config fcl file
176  std::vector<geo::BoxBoundedGeo> fActiveVolumes; //!< List of active volumes in configured detector
177  bool fWriteTree; //!< Enable writing of the main tree
178  TFile* fOutputFile; //!< The output ROOT file
179  TTree* fTree; //!< The output ROOT tree
180  event::Event* fEvent; //!< The standard output event data structure
181  bool fWriteRecoTree; //!< Enable writing of the reco tree
182  TTree* fRecoTree; //!< The output reco ROOT tree
183  event::RecoEvent* fRecoEvent; //!< The standard output reco event data structure
184  TTree* fSubRunTree; //!< Subrun output tree
185  SubRun* fSubRun; //!< Standard output subrun structure
186  TTree* fFileMetaTree; //!< File metadata output tree
187  FileMeta *fFileMeta; //!< standard output file metadata structure
188  TParameter<int>* fExperimentParameter; //!< Saves value of experiment enum
189  std::set<std::pair<int, int> > fSubRunCache; //!< Cache stored subruns
190  art::InputTag fTruthTag; //!< art tag for MCTruth information
191  art::InputTag fFluxTag; //!< art tag for MCFlux information
192  std::vector<art::InputTag> fWeightTags; //!< art tag(s) for MCEventWeight information
193  art::InputTag fMCTrackTag; //!< art tag for MCTrack
194  art::InputTag fMCShowerTag; //!< art tag for MCShower
195  art::InputTag fMCParticleTag; //!< art tag for MCParticle
196  std::string fGeneratorProcess; //!< process_name of process used to run genie. Used to extract subrun/POT information
197 };
198 
199 } // namespace core
200 
201 
202 /** Macro to create plugin library for user-defined Processors. */
203 #define DECLARE_SBN_PROCESSOR(classname) extern "C" { \
204 core::ProcessorBase* CreateProcessorObject() { return new classname; } \
205 void DestroyProcessorObject(core::ProcessorBase* o) { delete o; } \
206 struct core::export_table exports = { CreateProcessorObject, DestroyProcessorObject };}
207 
208 #endif // __sbnanalysis_core_ProcessorBase__
209 
TTree * fSubRunTree
Subrun output tree.
Experiment
Definition: Experiment.hh:13
TParameter< int > * fExperimentParameter
Saves value of experiment enum.
void SetupServices(gallery::Event &ev)
art::InputTag fTruthTag
art tag for MCTruth information
TTree * fTree
The output ROOT tree.
std::vector< event::RecoInteraction > * fReco
Reco interaction list.
virtual void Finalize()=0
TFile * fOutputFile
The output ROOT file.
std::vector< geo::BoxBoundedGeo > fActiveVolumes
List of active volumes in configured detector.
std::vector< art::InputTag > fWeightTags
art tag(s) for MCEventWeight information
The reconstructed event data definition.
Definition: Event.hh:208
event::Event * fEvent
The standard output event data structure.
event::RecoEvent * fRecoEvent
The standard output reco event data structure.
Interface to LArSoft services.
void UpdateSubRuns(gallery::Event &ev)
virtual void Initialize(char *config=NULL)
process_name standard_reco_uboone reco
std::string fProviderConfig
A custom provider config fcl file.
A set of Processors.
unsigned long fEventIndex
An incrementing index.
bool fWriteTree
Enable writing of the main tree.
SubRun * fSubRun
Standard output subrun structure.
A generic tree-writing event-by-event processor.
virtual void EventCleanup()
Experiment fExperimentID
Experiment identifier.
art::InputTag fFluxTag
art tag for MCFlux information
FileMeta * fFileMeta
standard output file metadata structure
art::InputTag fMCShowerTag
art tag for MCShower
The standard subrun data definition.
Definition: SubRun.hh:23
virtual void FillTree()
virtual void FillRecoTree()
void BuildEventTree(gallery::Event &ev)
The standard event data definition.
Definition: Event.hh:228
virtual void Teardown()
std::string fGeneratorProcess
process_name of process used to run genie. Used to extract subrun/POT information ...
virtual bool ProcessEvent(const gallery::Event &ev, const std::vector< event::Interaction > &truth, std::vector< event::RecoInteraction > &reco)=0
TTree * fRecoTree
The output reco ROOT tree.
ProviderManager * fProviderManager
Interface for provider access.
bool fWriteRecoTree
Enable writing of the reco tree.
art::InputTag fMCParticleTag
art tag for MCParticle
then echo fcl name
std::string fOutputFilename
The output filename.
TTree * fFileMetaTree
File metadata output tree.
TBranch * AddRecoBranch(std::string name, T *obj)
std::set< std::pair< int, int > > fSubRunCache
Cache stored subruns.
art::InputTag fMCTrackTag
art tag for MCTrack
TBranch * AddBranch(std::string name, T *obj)
Metadata for each input file.
Definition: FileMeta.hh:16
void UpdateFileMeta(gallery::Event &ev)
virtual void Setup(char *config=NULL)