28#include <TObjString.h>
41 std::vector<std::string>
42 readVectorFromTree (SH::Sample *sample,
const std::string& treeName,
43 const std::string& branchName)
45 std::vector<std::string>
result;
47 TString *
var =
nullptr;
48 for (
auto& fileName : fileNames)
50 std::unique_ptr<TFile>
file (TFile::Open (
fileName.c_str(),
"READ"));
55 if (
tree !=
nullptr && (nentries =
tree->GetEntries()) > 0)
58 tree->SetBranchAddress (branchName.c_str(), &var, &branch);
61 if (
branch->GetEntry(entry) <= 0)
72 SH::SampleHandler makeReprocessSamples (
const std::string& submitdir)
75 SH::SampleHandler shInput;
76 shInput.
load (submitdir +
"/input");
79 SH::SampleHandler shHist;
80 shHist.
load (submitdir +
"/hist");
84 SH::SampleHandler shReprocess;
86 for (SH::Sample *sampleInput : shInput)
88 SH::Sample *sampleHist = shHist.
get (sampleInput->name());
90 std::vector<std::string> filesUsedVector
91 = readVectorFromTree (sampleHist,
"EventLoop_FileExecuted",
"file");
92 std::set<std::string> filesUsed
93 (filesUsedVector.begin(), filesUsedVector.end());
94 RCU_ASSERT (filesUsed.size() == filesUsedVector.size());
96 std::unique_ptr<SH::SampleLocal> sampleReprocess;
97 std::vector<std::string>
filesInput (sampleInput->makeFileList ());
99 for (
auto fileInput : filesInput)
103 if (
split != std::string::npos)
106 if (filesUsed.find (fileName) == filesUsed.end())
108 if (sampleReprocess ==
nullptr)
110 sampleReprocess.reset (
new SH::SampleLocal (sampleInput->name()));
111 *sampleReprocess->meta() = *sampleInput->meta();
113 sampleReprocess->add (fileInput);
118 sampleReprocess.reset (
new SH::SampleLocal (sampleInput->name()));
119 *sampleReprocess->meta() = *sampleInput->meta();
121 if (sampleReprocess !=
nullptr)
124 shReprocess.
add (sampleReprocess.release());
132 void mergeHists (
const std::string& mainDir,
133 const std::string& extraDir,
134 const SH::SampleHandler& samples)
136 for (
auto& sample : samples)
138 std::string
tmp = extraDir +
"/hist2-" +
sample->name() +
".root";
139 std::string
target = mainDir +
"/hist-" +
sample->name() +
".root";
148 void mergeNtuple (
const std::string& mainDir,
149 const std::string& extraDir)
151 SH::SampleHandler mainSH;
152 mainSH.
load (mainDir);
153 SH::SampleHandler extraSH;
154 extraSH.
load (extraDir);
155 SH::SampleHandler newSH;
157 for (SH::Sample *extraSample : extraSH)
159 SH::Sample *mainSample = mainSH.
get (extraSample->name());
161 std::unique_ptr<SH::SampleLocal> newSample
162 (
new SH::SampleLocal (extraSample->name()));
163 *newSample->meta() = *mainSample->
meta();
166 newSample->add (
file);
167 for (
auto&
file : extraSample->makeFileList())
168 newSample->add (
file);
169 newSH.
add (newSample.release());
172 for (SH::Sample *mainSample : mainSH)
174 if (newSH.
get (mainSample->
name()) ==
nullptr)
175 newSH.
add (mainSample);
178 mainSH.save (mainDir);
187 if (shReprocess.
size() > 0)
189 std::string mysubmitdir = submitdir +
"/emptyFiles";
194 driver.submit (myjob, mysubmitdir);
196 mergeHists (submitdir, mysubmitdir, shReprocess);
197 for (
auto output = job.outputBegin(),
198 end = job.outputEnd(); output != end; ++ output)
200 mergeNtuple (submitdir +
"/output-" + output->label(),
201 mysubmitdir +
"/output-" + output->label());
#define RCU_THROW_MSG(message)
a Driver that runs directly inside the submission job itself
const SH::SampleHandler & sampleHandler() const
description: the sample handler used guarantee: no-fail / strong failures: out of memory II
A class that manages a list of Sample objects.
void setMetaString(const std::string &name, const std::string &value)
set the meta-data string with the given name for all samples.
std::size_t size() const
the number of samples contained
Sample * get(const std::string &name)
get the sample with the given name
void add(Sample *sample)
add a sample to the handler
void load(const std::string &directory)
load all the samples from the given directory
MetaObject * meta()
the meta-information for this sample
std::vector< std::string > makeFileList() const
make a list of all files, prestaging them if necessary
const std::string & name() const
the name of the sample we are using
std::vector< std::string > split(const std::string &s, const std::string &t=":")
This module defines the arguments passed from the BATCH driver to the BATCH worker.
void processEmptyFiles(const std::string &submitdir, const Job &job)
check the output of the given (completed) job, rerun all (empty) files that did not get a fileExecute...
void exec(const std::string &cmd)
effects: execute the given command guarantee: strong failures: out of memory II failures: system fail...
std::string quote(const std::string &name)
effects: quote the given name to protect it from the shell returns: the quoted name guarantee: strong...
void hadd(const std::string &output_file, const std::vector< std::string > &input_files, unsigned max_files)
effects: perform the hadd functionality guarantee: basic failures: out of memory III failures: i/o er...