54 run (
const Driver& driver)
const
56 std::vector<std::string>
files;
57 std::vector<TH1*> histos;
59 for (
unsigned iter = 0, end = 3; iter != end; ++ iter)
61 std::ostringstream path;
62 path <<
base_path <<
"test_ntuple" << iter <<
".root";
63 TString input = path.str();
64 gSystem->ExpandPathName (input);
65 files.push_back (input.Data());
66 std::unique_ptr<TFile>
file (TFile::Open (input.Data(),
"READ"));
68 TH1 *hist =
dynamic_cast<TH1*
>(
file->Get (
"hist_n"));
70 histos.push_back(hist);
71 hist->SetDirectory (0);
73 std::string
tree (
"physics");
78 std::vector<std::unique_ptr<SH::Sample> > mysamples;
81 std::unique_ptr<SH::SampleGrid> mysample;
82 mysample.reset (
new SH::SampleGrid (
"user.krumnack:user.krumnack.EventLoopTest.2019-03-25.dataset0"));
83 mysample->meta()->setString (
SH::MetaFields::gridName,
"user.krumnack:user.krumnack.EventLoopTest.2019-03-25.dataset0");
85 mysamples.push_back (std::move (mysample));
86 mysample.reset (
new SH::SampleGrid (
"user.krumnack:user.krumnack.EventLoopTest.2019-03-25.dataset1"));
87 mysample->meta()->setString (
SH::MetaFields::gridName,
"user.krumnack:user.krumnack.EventLoopTest.2019-03-25.dataset1");
89 mysamples.push_back (std::move (mysample));
92 std::unique_ptr<SH::SampleLocal> mysample;
94 mysample->add (
files[0]);
95 mysamples.push_back (std::move (mysample));
97 mysample->add (
files[1]);
98 mysample->add (
files[2]);
99 mysamples.push_back (std::move (mysample));
103 hist =
dynamic_cast<TH1*
>(histos[0]->Clone (
"hist"));
104 mysamples[0]->meta()->addReplace (hist);
106 hist =
dynamic_cast<TH1*
>(histos[1]->Clone (
"hist"));
107 hist->Add (histos[2]);
108 mysamples[1]->meta()->addReplace (hist);
110 for (
auto& mysample : mysamples)
111 samples.
add (std::move (mysample));
117 for (
unsigned iter = 0, end = histos.size(); iter != end; ++ iter)
128 submitDir =
"EventLoopTest-" +
name;
130 gSystem->ExpandPathName (submitDir);
139 job.options()->setDouble (
"jobOpt", 42);
145 sh.setMetaString (
"mymeta",
"test");
146 job.sampleHandler (
sh);
151 end = job.outputEnd(); outputStream != end; ++ outputStream)
161 ANA_MSG_INFO (
"placing temporary files in: " << submitDir);
163 std::string output = driver.submit (job, submitDir.Data());
165 for (std::size_t iter = 0, end = samples.
size(); iter != end; ++ iter)
168 TH1 *ref_hist =
dynamic_cast<TH1*
>(samples[iter]->meta()->
get (
"hist"));
172 sh.load ((output +
"/hist").c_str());
174 if (sample ==
nullptr)
179 TH1 *file_executes =
dynamic_cast<TH1*
>(sample->readHist (
"file_executes"));
181 ANA_MSG_INFO (
"file executes: " << file_executes->GetEntries() <<
" " << samples[iter]->makeFileList().
size());
185 TH1 *hist =
dynamic_cast<TH1*
>(sample->readHist (
"el_n"));
186 if (samples[iter]->getNumEntries() == 0)
195 RCU_THROW_MSG (
"didn't find histogram el_n in sample " + sample->name());
196 if (hist->GetNbinsX() != ref_hist->GetNbinsX())
198 for (
int bin = 0, end = hist->GetNbinsX()+2;
bin != end; ++
bin)
200 if (hist->GetBinContent (
bin) != ref_hist->GetBinContent (
bin))
202 std::ostringstream
str;
203 str <<
"bin content missmatch in bin " <<
bin
204 <<
" found " << hist->GetBinContent (
bin)
205 <<
" expected " << ref_hist->GetBinContent (
bin);
210 TH1 *
count =
dynamic_cast<TH1*
>(sample->readHist (
"EventLoop_EventCount"));
211 if (samples[iter]->getNumEntries() > 0 &&
count == 0)
212 RCU_THROW_MSG (
"didn't find histogram EventLoop_EventCount");
214 if (
testOutput && samples[iter]->getNumEntries() > 0)
217 sh.load ((output +
"/output-out").c_str());
222 if (ref_hist && samples[iter]->getNumEntries() != ref_hist->GetEntries())
224 std::ostringstream
str;
225 str <<
"tree entries missmatch found " << samples[iter]->getNumEntries()
226 <<
" expected " << ref_hist->GetEntries();
232 gSystem->Exec ((
"rm -rf " + output).c_str());
234 }
catch (std::exception& e)
236 std::cout <<
"exception caught in unit test: " << e.what() << std::endl;
238 }
catch (std::string& e)
240 std::cout <<
"exception caught in unit test: " << e << std::endl;
244 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")