55 run (
const Driver& driver)
const
57 std::vector<std::string>
files;
58 std::vector<TH1*> histos;
60 for (
unsigned iter = 0, end = 3; iter != end; ++ iter)
62 std::ostringstream path;
63 path <<
base_path <<
"test_ntuple" << iter <<
".root";
64 TString input = path.str();
65 gSystem->ExpandPathName (input);
66 files.push_back (input.Data());
67 std::unique_ptr<TFile>
file (TFile::Open (input.Data(),
"READ"));
69 TH1 *hist =
dynamic_cast<TH1*
>(
file->Get (
"hist_n"));
71 histos.push_back(hist);
72 hist->SetDirectory (0);
74 std::string
tree (
"physics");
79 std::vector<std::unique_ptr<SH::Sample> > mysamples;
82 std::unique_ptr<SH::SampleGrid> mysample;
83 mysample.reset (
new SH::SampleGrid (
"user.krumnack:user.krumnack.EventLoopTest.2019-03-25.dataset0"));
84 mysample->meta()->setString (
SH::MetaFields::gridName,
"user.krumnack:user.krumnack.EventLoopTest.2019-03-25.dataset0");
86 mysamples.push_back (std::move (mysample));
87 mysample.reset (
new SH::SampleGrid (
"user.krumnack:user.krumnack.EventLoopTest.2019-03-25.dataset1"));
88 mysample->meta()->setString (
SH::MetaFields::gridName,
"user.krumnack:user.krumnack.EventLoopTest.2019-03-25.dataset1");
90 mysamples.push_back (std::move (mysample));
93 std::unique_ptr<SH::SampleLocal> mysample;
95 mysample->add (
files[0]);
96 mysamples.push_back (std::move (mysample));
98 mysample->add (
files[1]);
99 mysample->add (
files[2]);
100 mysamples.push_back (std::move (mysample));
104 hist =
dynamic_cast<TH1*
>(histos[0]->Clone (
"hist"));
105 mysamples[0]->meta()->addReplace (hist);
107 hist =
dynamic_cast<TH1*
>(histos[1]->Clone (
"hist"));
108 hist->Add (histos[2]);
109 mysamples[1]->meta()->addReplace (hist);
111 for (
auto& mysample : mysamples)
112 samples.
add (mysample.release());
118 for (
unsigned iter = 0, end = histos.size(); iter != end; ++ iter)
129 submitDir =
"EventLoopTest-" +
name;
131 gSystem->ExpandPathName (submitDir);
140 job.options()->setDouble (
"jobOpt", 42);
146 sh.setMetaString (
"mymeta",
"test");
147 job.sampleHandler (
sh);
152 end = job.outputEnd(); outputStream != end; ++ outputStream)
162 ANA_MSG_INFO (
"placing temporary files in: " << submitDir);
164 std::string output = driver.submit (job, submitDir.Data());
166 for (std::size_t iter = 0, end = samples.
size(); iter != end; ++ iter)
169 TH1 *ref_hist =
dynamic_cast<TH1*
>(samples[iter]->meta()->
get (
"hist"));
173 sh.load ((output +
"/hist").c_str());
180 TH1 *file_executes =
dynamic_cast<TH1*
>(sample->readHist (
"file_executes"));
182 ANA_MSG_INFO (
"file executes: " << file_executes->GetEntries() <<
" " << samples[iter]->makeFileList().
size());
186 TH1 *hist =
dynamic_cast<TH1*
>(sample->readHist (
"el_n"));
187 if (samples[iter]->getNumEntries() == 0)
196 RCU_THROW_MSG (
"didn't find histogram el_n in sample " + sample->name());
197 if (hist->GetNbinsX() != ref_hist->GetNbinsX())
199 for (
int bin = 0, end = hist->GetNbinsX()+2;
bin != end; ++
bin)
201 if (hist->GetBinContent (
bin) != ref_hist->GetBinContent (
bin))
203 std::ostringstream
str;
204 str <<
"bin content missmatch in bin " <<
bin
205 <<
" found " << hist->GetBinContent (
bin)
206 <<
" expected " << ref_hist->GetBinContent (
bin);
211 TH1 *
count =
dynamic_cast<TH1*
>(sample->readHist (
"EventLoop_EventCount"));
212 if (samples[iter]->getNumEntries() > 0 &&
count == 0)
213 RCU_THROW_MSG (
"didn't find histogram EventLoop_EventCount");
215 if (
testOutput && samples[iter]->getNumEntries() > 0)
218 sh.load ((output +
"/output-out").c_str());
223 if (ref_hist && samples[iter]->getNumEntries() != ref_hist->GetEntries())
225 std::ostringstream
str;
226 str <<
"tree entries missmatch found " << samples[iter]->getNumEntries()
227 <<
" expected " << ref_hist->GetEntries();
233 gSystem->Exec ((
"rm -rf " + output).c_str());
235 }
catch (std::exception& e)
237 std::cout <<
"exception caught in unit test: " << e.what() << std::endl;
239 }
catch (std::string& e)
241 std::cout <<
"exception caught in unit test: " << e << std::endl;
245 std::cout <<
"unknown exception caught in unit test" << std::endl;
static const std::string optSubmitDirMode
the submit-dir mode (allowed values: "no-clobber", "overwrite", "unique", "unique-link")