5 #include <TParameter.h>
6 #include "fhiclcpp/ParameterSet.h"
31 if (cfg == NULL) cfg =
new fhicl::ParameterSet;
32 if (output_fname.size() != 0) cfg->put(
"OutputFile", output_fname);
46 TFile f(fname.c_str());
48 std::cerr <<
"Failed openning file: " << fname <<
". "
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);
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;
107 fThreadIDs.push_back(std::this_thread::get_id());
108 for (
auto const&
fname: inputFiles) {
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);
126 while (file_index < inputFiles.size()) {
128 file_index = f_index.fetch_add(1);
132 for (std::thread &
w: workers)
w.join();
Service provider with utility LAr functions.
BEGIN_PROLOG could also be cerr
virtual void ProcessEvent(const event::Event *event)=0
Contains data associated to particles from detector simulation.
void Initialize(char *config=NULL, const std::string &output_fname="", unsigned n_workers=1)
virtual ~PostProcessorBase()
Access the description of auxiliary detector geometry.
Access the description of detector geometry.
Interface to LArSoft services.
virtual void ProcessSubRun(const SubRun *subrun)
std::vector< std::thread::id > fThreadIDs
virtual void FileSetup(TFile *f, TTree *eventTree)
virtual void FileCleanup(TTree *eventTree)
back track the reconstruction to the simulation
The standard subrun data definition.
void Run(std::vector< std::string > filelist)
The standard event data definition.
fhicl::ParameterSet * LoadConfig(char *configfile)
virtual void ProcessFileMeta(const FileMeta *filemeta)
virtual void InitializeThread()
void ProcessFile(const std::string &fname)
ProviderManager * fProviderManager
Interface for provider access.