All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ProcessorBlock.cxx
Go to the documentation of this file.
1 #include <string>
2 #include <vector>
3 #include "fhiclcpp/ParameterSet.h"
4 #include "ProcessorBase.hh"
5 #include "ProcessorBlock.hh"
6 
7 namespace core {
8 
10 
11 
13 
14 
16  fhicl::ParameterSet* config) {
17  fProcessors.push_back({processor, config});
18 }
19 
20 
21 void ProcessorBlock::ProcessFiles(std::vector<std::string> filenames) {
22  // Setup
23  for (auto it : fProcessors) {
24  it.first->Setup(it.second);
25  it.first->Initialize(it.second);
26  }
27 
28  // Event loop
29  for (gallery::Event ev(filenames); !ev.atEnd(); ev.next()) {
30  for (auto it : fProcessors) {
31  ProcessorBase* p = it.first;
32  p->BuildEventTree(ev);
33  p->SetupServices(ev);
34 
35  bool accept = p->ProcessEvent(ev, p->fEvent->truth, *p->fReco);
36 
37  // Set reco index
38  for (size_t i=0; i<p->fReco->size(); i++) {
39  p->fReco->at(i).index = i;
40  }
41  p->fEvent->nreco = p->fReco->size();
42 
43  if (accept) {
44  p->FillTree();
45 
46  // For each reco event, fill the reco output tree
49 
50  for (auto const& reco : *p->fReco) {
51  p->fRecoEvent->reco = reco;
52 
53  // Copy the associated truth interaction, if any
54  p->fRecoEvent->truth.resize(0);
55  int truthidx = p->fRecoEvent->reco.truth_index;
56  if (truthidx >= 0 && truthidx < p->fEvent->truth.size()) {
57  p->fRecoEvent->truth.push_back(p->fEvent->truth.at(truthidx));
58  }
59 
60  p->FillRecoTree();
61  }
62  }
63 
64  p->EventCleanup();
65  }
66  }
67 
68  // Finalize
69  for (auto it : fProcessors) {
70  it.first->Finalize();
71  it.first->Teardown();
72  }
73 }
74 
75 
77  for (auto it : fProcessors) {
78  delete it.first;
79  }
80 }
81 
82 } // namespace core
83 
Metadata metadata
Event metadata.
Definition: Event.hh:230
void SetupServices(gallery::Event &ev)
std::vector< std::pair< ProcessorBase *, fhicl::ParameterSet * > > fProcessors
pdgs p
Definition: selectors.fcl:22
std::vector< event::RecoInteraction > * fReco
Reco interaction list.
RecoInteraction reco
Reconstructed interaction.
Definition: Event.hh:215
Experiment experiment
Experiment identifier.
Definition: Event.hh:217
event::Event * fEvent
The standard output event data structure.
event::RecoEvent * fRecoEvent
The standard output reco event data structure.
process_name standard_reco_uboone reco
virtual void DeleteProcessors()
A generic tree-writing event-by-event processor.
virtual void EventCleanup()
virtual void FillTree()
virtual void FillRecoTree()
std::vector< Interaction > truth
Associated truth interaction.
Definition: Event.hh:216
Metadata metadata
Event metadata.
Definition: Event.hh:214
Experiment experiment
Experiment identifier.
Definition: Event.hh:235
void BuildEventTree(gallery::Event &ev)
virtual bool ProcessEvent(const gallery::Event &ev, const std::vector< event::Interaction > &truth, std::vector< event::RecoInteraction > &reco)=0
virtual void ProcessFiles(std::vector< std::string > filenames)
virtual void AddProcessor(ProcessorBase *processor, fhicl::ParameterSet *config)
size_t nreco
Size of reco.
Definition: Event.hh:233
std::vector< Interaction > truth
All truth interactions.
Definition: Event.hh:232