A generic tree-reading event-by-event processor.
More...
#include <PostProcessorBase.hh>
A generic tree-reading event-by-event processor.
Definition at line 43 of file PostProcessorBase.hh.
core::PostProcessorBase::PostProcessorBase |
( |
| ) |
|
Constructor
Definition at line 23 of file PostProcessorBase.cxx.
ProviderManager * fProviderManager
Interface for provider access.
core::PostProcessorBase::~PostProcessorBase |
( |
| ) |
|
|
virtual |
virtual void core::PostProcessorBase::FileCleanup |
( |
TTree * |
eventTree | ) |
|
|
inlineprotectedvirtual |
virtual void core::PostProcessorBase::FileSetup |
( |
TFile * |
f, |
|
|
TTree * |
eventTree |
|
) |
| |
|
inlineprotectedvirtual |
Setup anything needed per file
- Parameters
-
f | the TFile being opened |
eventTree | the TTree associated with the sbncode event. Use this TTree to set branch addresses for everything other than the sbncode event. |
Files are guaranteed to be processed in the order they are specified on the command line for sbn-postprocess
Reimplemented in ana::SBNOsc::Selection, and ana::SBNOsc::Flatten.
Definition at line 88 of file PostProcessorBase.hh.
virtual void core::PostProcessorBase::Finalize |
( |
| ) |
|
|
inlineprotectedvirtual |
void core::PostProcessorBase::Initialize |
( |
char * |
config = NULL , |
|
|
const std::string & |
output_fname = "" , |
|
|
unsigned |
n_workers = 1 |
|
) |
| |
Perform user-level initialization.
- Parameters
-
config | A configuration, as a JSON filename. |
Definition at line 29 of file PostProcessorBase.cxx.
31 if (cfg == NULL) cfg =
new fhicl::ParameterSet;
32 if (output_fname.size() != 0) cfg->put(
"OutputFile", output_fname);
void Initialize(char *config=NULL, const std::string &output_fname="", unsigned n_workers=1)
fhicl::ParameterSet * LoadConfig(char *configfile)
ProviderManager * fProviderManager
Interface for provider access.
virtual void core::PostProcessorBase::Initialize |
( |
fhicl::ParameterSet * |
config = NULL | ) |
|
|
protectedpure virtual |
virtual void core::PostProcessorBase::InitializeThread |
( |
| ) |
|
|
inlineprotectedvirtual |
unsigned core::PostProcessorBase::NWorkers |
( |
| ) |
|
|
inlineprotected |
virtual void core::PostProcessorBase::ProcessEvent |
( |
const event::Event * |
event | ) |
|
|
protectedpure virtual |
void core::PostProcessorBase::ProcessFile |
( |
const std::string & |
fname | ) |
|
|
private |
Definition at line 44 of file PostProcessorBase.cxx.
46 TFile f(
fname.c_str());
49 <<
"Cleaning up and exiting." << std::endl;
53 TTree *event_tree = 0;
56 TTree *subrun_tree = 0;
59 TTree *filemeta_tree = 0;
62 f.GetObject(
"sbnana", event_tree);
63 event_tree->SetBranchAddress(
"events", &event);
66 for (
int event_ind = 0; event_ind < event_tree->GetEntries(); event_ind++) {
67 event_tree->GetEntry(event_ind);
71 f.GetObject(
"sbnsubrun", subrun_tree);
72 if (subrun_tree == NULL) {
73 std::cerr <<
"Error: NULL subrun tree" << std::endl;
75 subrun_tree->SetBranchAddress(
"subruns", &subrun);
77 for (
int subrun_ind = 0; subrun_ind < subrun_tree->GetEntries(); subrun_ind++) {
78 subrun_tree->GetEntry(subrun_ind);
83 f.GetObject(
"sbnfilemeta", filemeta_tree);
84 if (filemeta_tree == NULL) {
85 std::cerr <<
"Error: NULL filemeta tree" << std::endl;
87 filemeta_tree->SetBranchAddress(
"filemeta", &filemeta);
88 for (
int filemeta_ind = 0; filemeta_ind < filemeta_tree->GetEntries(); filemeta_ind++) {
89 filemeta_tree->GetEntry(filemeta_ind);
BEGIN_PROLOG could also be cerr
virtual void ProcessEvent(const event::Event *event)=0
virtual void ProcessSubRun(const SubRun *subrun)
virtual void FileSetup(TFile *f, TTree *eventTree)
virtual void FileCleanup(TTree *eventTree)
The standard subrun data definition.
The standard event data definition.
virtual void ProcessFileMeta(const FileMeta *filemeta)
virtual void core::PostProcessorBase::ProcessFileMeta |
( |
const FileMeta * |
filemeta | ) |
|
|
inlineprotectedvirtual |
virtual void core::PostProcessorBase::ProcessSubRun |
( |
const SubRun * |
subrun | ) |
|
|
inlineprotectedvirtual |
void core::PostProcessorBase::Run |
( |
std::vector< std::string > |
filelist | ) |
|
Run
- Parameters
-
filelist | The list of files to be processed by this PostProcessor |
Definition at line 104 of file PostProcessorBase.cxx.
107 fThreadIDs.push_back(std::this_thread::get_id());
115 std::atomic<unsigned> f_index = 0;
116 std::atomic<unsigned> w_index = 0;
117 std::vector<std::thread> workers;
118 for (
unsigned i = 0; i <
fNWorkers; i++) {
119 workers.emplace_back([&]() {
121 unsigned this_index = w_index.fetch_add(1);
122 fThreadIDs[this_index] = std::this_thread::get_id();
125 unsigned file_index = f_index.fetch_add(1);
128 file_index = f_index.fetch_add(1);
132 for (std::thread &
w: workers)
w.join();
std::vector< std::thread::id > fThreadIDs
virtual void InitializeThread()
void ProcessFile(const std::string &fname)
ProviderManager * fProviderManager
Interface for provider access.
unsigned core::PostProcessorBase::WorkerID |
( |
| ) |
|
|
protected |
Definition at line 96 of file PostProcessorBase.cxx.
97 std::thread::id this_id = std::this_thread::get_id();
98 for (
unsigned index = 0; index <
fThreadIDs.size(); index++) {
99 if (this_id ==
fThreadIDs[index])
return index;
std::vector< std::thread::id > fThreadIDs
int core::PostProcessorBase::fConfigExperimentID |
|
protected |
unsigned core::PostProcessorBase::fNWorkers |
|
private |
std::vector<std::thread::id> core::PostProcessorBase::fThreadIDs |
|
private |
The documentation for this class was generated from the following files: