ATLAS Offline Software
Loading...
Searching...
No Matches
EL::UnitTest Struct Reference

#include <UnitTest.h>

Collaboration diagram for EL::UnitTest:

Public Member Functions

 UnitTest (const std::string &val_name, std::string base_path="")
 effects: standard constructor guarantee: storng failures: out of memory II
int run (const Driver &driver) const
 effects: perform a unit test with the given driver returns: EXIT_SUCCESS on success, EXIT_FAILURE on failure guarantee: basic failures: unit test failures requires: !sample.empty()

Public Attributes

std::string name
 description: the name of the unit test
std::string base_path
 description: the base path for the data files
bool scanNEvents {false}
 whether to scan for number of events
bool gridInput {false}
 whether to use the inputs from the grid dataset
bool cleanup
 description: whether we clean up the submit directory afterwards
bool testOutput
 description: whether to test creating output n-tuples
std::string location
 description: the location for the unit test
SH::DiskOutputoutputDisk
 description: the output disk
bool testFileExecute
 whether to test the fileExecute method

Detailed Description

Constructor & Destructor Documentation

◆ UnitTest()

EL::UnitTest::UnitTest ( const std::string & val_name,
std::string base_path = "" )

effects: standard constructor guarantee: storng failures: out of memory II

Definition at line 42 of file PhysicsAnalysis/D3PDTools/EventLoopTest/Root/UnitTest.cxx.

44 : name (val_name), base_path (val_base_path), cleanup (true), testOutput (true), outputDisk (0),
45 testFileExecute (true)
46 {
47 if (base_path.empty())
48 base_path = "$ROOTCOREBIN/data/EventLoop/";
49 }
std::string base_path
description: the base path for the data files
bool testOutput
description: whether to test creating output n-tuples
bool testFileExecute
whether to test the fileExecute method
SH::DiskOutput * outputDisk
description: the output disk
bool cleanup
description: whether we clean up the submit directory afterwards
std::string name
description: the name of the unit test

Member Function Documentation

◆ run()

int EL::UnitTest::run ( const Driver & driver) const

effects: perform a unit test with the given driver returns: EXIT_SUCCESS on success, EXIT_FAILURE on failure guarantee: basic failures: unit test failures requires: !sample.empty()

Definition at line 53 of file PhysicsAnalysis/D3PDTools/EventLoopTest/Root/UnitTest.cxx.

55 {
56 std::vector<std::string> files;
57 std::vector<TH1*> histos;
58
59 for (unsigned iter = 0, end = 3; iter != end; ++ iter)
60 {
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"));
67 RCU_ASSERT_SOFT (file.get() != 0);
68 TH1 *hist = dynamic_cast<TH1*>(file->Get ("hist_n"));
69 RCU_ASSERT_SOFT (hist != 0);
70 histos.push_back(hist);
71 hist->SetDirectory (0);
72 };
73 std::string tree ("physics");
74
75
76 SH::SampleHandler samples;
77
78 std::vector<std::unique_ptr<SH::Sample> > mysamples;
79 if (gridInput)
80 {
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));
90 } else
91 {
92 std::unique_ptr<SH::SampleLocal> mysample;
93 mysample.reset (new SH::SampleLocal ("dataset0"));
94 mysample->add (files[0]);
95 mysamples.push_back (std::move (mysample));
96 mysample.reset (new SH::SampleLocal ("dataset1"));
97 mysample->add (files[1]);
98 mysample->add (files[2]);
99 mysamples.push_back (std::move (mysample));
100 }
101 {
102 TH1 *hist = 0;
103 hist = dynamic_cast<TH1*>(histos[0]->Clone ("hist"));
104 mysamples[0]->meta()->addReplace (hist);
105
106 hist = dynamic_cast<TH1*>(histos[1]->Clone ("hist"));
107 hist->Add (histos[2]);
108 mysamples[1]->meta()->addReplace (hist);
109 }
110 for (auto& mysample : mysamples)
111 samples.add (std::move (mysample));
112
114
115 samples.print ();
116
117 for (unsigned iter = 0, end = histos.size(); iter != end; ++ iter)
118 delete histos[iter];
119
120 RCU_ASSERT (samples.size() > 0);
121
122 if (scanNEvents)
123 SH::scanNEvents (samples);
124
125 TString submitDir;
126 if (location.empty())
127 {
128 submitDir = "EventLoopTest-" + name;
129 } else submitDir = location;
130 gSystem->ExpandPathName (submitDir);
131
132 try
133 {
134 UnitTestAlg alg;
135 alg.makeOutput = testOutput;
136
137 EL::Job job;
138 // job.options()->setDouble (Job::optD3PDPerfStats, 1);
139 job.options()->setDouble ("jobOpt", 42);
140 // job.options()->setDouble (Job::optPerfTree, 1);
141 // job.options()->setDouble (EL::Job::optCacheSize, 10*1024*1024);
142 // job.options()->setDouble (Job::optPrintPerFileStats, 1);
143 {
144 SH::SampleHandler sh = samples;
145 sh.setMetaString ("mymeta", "test");
146 job.sampleHandler (sh);
147 }
148 job.algsAdd (new UnitTestAlg (alg));
149 bool outputDone = outputDisk == 0;
150 for (Job::outputMIter outputStream = job.outputBegin(),
151 end = job.outputEnd(); outputStream != end; ++ outputStream)
152 {
153 if (!outputDone)
154 {
155 outputStream->output (outputDisk);
156 outputDone = true;
157 }
158 }
159
160 if (!cleanup)
161 ANA_MSG_INFO ("placing temporary files in: " << submitDir);
162 job.options()->setString (Job::optSubmitDirMode, "unique");
163 std::string output = driver.submit (job, submitDir.Data());
164
165 for (std::size_t iter = 0, end = samples.size(); iter != end; ++ iter)
166 {
167 ANA_MSG_INFO ("looking at sample " << samples[iter]->name());
168 TH1 *ref_hist = dynamic_cast<TH1*>(samples[iter]->meta()->get ("hist"));
169 if (ref_hist != 0)
170 {
171 SH::SampleHandler sh;
172 sh.load ((output + "/hist").c_str());
173 SH::Sample *sample = sh.get (samples[iter]->name());
174 if (sample == nullptr)
175 RCU_THROW_MSG ("could not find histogram sample " + samples[iter]->name());
176
177 if (testFileExecute)
178 {
179 TH1 *file_executes = dynamic_cast<TH1*>(sample->readHist ("file_executes"));
180 RCU_ASSERT_SOFT (file_executes != 0);
181 ANA_MSG_INFO ("file executes: " << file_executes->GetEntries() << " " << samples[iter]->makeFileList().size());
182 RCU_ASSERT_SOFT (file_executes->GetEntries() == samples[iter]->makeFileList().size());
183 }
184
185 TH1 *hist = dynamic_cast<TH1*>(sample->readHist ("el_n"));
186 if (samples[iter]->getNumEntries() == 0)
187 {
188 RCU_ASSERT_SOFT (hist == 0);
189 } else
190 {
191 RCU_ASSERT_SOFT (dynamic_cast<TH1*>(sample->readHist ("el_n2")));
192 RCU_ASSERT_SOFT (dynamic_cast<TList*>(sample->readHist ("alpha")));
193 RCU_ASSERT_SOFT (sample->readHist ("beta/dir/hist"));
194 if (hist == 0)
195 RCU_THROW_MSG ("didn't find histogram el_n in sample " + sample->name());
196 if (hist->GetNbinsX() != ref_hist->GetNbinsX())
197 RCU_THROW_MSG ("bin missmatch between histograms");
198 for (int bin = 0, end = hist->GetNbinsX()+2; bin != end; ++ bin)
199 {
200 if (hist->GetBinContent (bin) != ref_hist->GetBinContent (bin))
201 {
202 std::ostringstream str;
203 str << "bin content missmatch in bin " << bin
204 << " found " << hist->GetBinContent (bin)
205 << " expected " << ref_hist->GetBinContent (bin);
206 RCU_THROW_MSG (str.str());
207 }
208 }
209 }
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");
213 }
214 if (testOutput && samples[iter]->getNumEntries() > 0)
215 {
216 SH::SampleHandler sh;
217 sh.load ((output + "/output-out").c_str());
218 SH::Sample *const sample = sh.get (samples[iter]->name());
219 if (!sample)
220 RCU_THROW_MSG ("output dataset not found for " + samples[iter]->name());
221 sample->meta()->setString (SH::MetaFields::treeName, "tree");
222 if (ref_hist && samples[iter]->getNumEntries() != ref_hist->GetEntries())
223 {
224 std::ostringstream str;
225 str << "tree entries missmatch found " << samples[iter]->getNumEntries()
226 << " expected " << ref_hist->GetEntries();
227 RCU_THROW_MSG (str.str());
228 }
229 }
230 }
231 if (cleanup)
232 gSystem->Exec (("rm -rf " + output).c_str());
233 return EXIT_SUCCESS;
234 } catch (std::exception& e)
235 {
236 std::cout << "exception caught in unit test: " << e.what() << std::endl;
237 return EXIT_FAILURE;
238 } catch (std::string& e)
239 {
240 std::cout << "exception caught in unit test: " << e << std::endl;
241 return EXIT_FAILURE;
242 } catch (...)
243 {
244 std::cout << "unknown exception caught in unit test" << std::endl;
245 return EXIT_FAILURE;
246 }
247 }
#define RCU_ASSERT(x)
Definition Assert.h:217
#define RCU_ASSERT_SOFT(x)
Definition Assert.h:162
#define ANA_MSG_INFO(xmsg)
Macro printing info messages.
#define RCU_THROW_MSG(message)
Definition PrintMsg.h:53
static const std::string optSubmitDirMode
the submit-dir mode (allowed values: "no-clobber", "overwrite", "unique", "unique-link")
Definition Job.h:191
OutputStream * outputMIter
description: the list of output datasets used guarantee: no-fail / strong failures(3): out of memory ...
Definition Job.h:138
void add(const Sample &sample)
add a copy of the sample to the handler
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
void print() const
print the debugging output to the screen
std::vector< std::string > files
file names and file pointers
Definition hcg.cxx:52
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition hcg.cxx:132
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:148
void scanNEvents(SampleHandler &sh)
effects: scan each sample in the sample handler and store the number of entries per file in the meta-...
path
python interpreter configuration --------------------------------------—
Definition athena.py:130
output
Definition merge.py:16
bool gridInput
whether to use the inputs from the grid dataset
std::string location
description: the location for the unit test
bool scanNEvents
whether to scan for number of events
static const std::string gridFilter
the field containing the file filter for the dataset on the grid
Definition MetaFields.h:30
static const std::string gridName
the field containing the name of the dataset on the grid
Definition MetaFields.h:26
static const std::string treeName
the name of the tree in the sample
Definition MetaFields.h:44
static const std::string gridFilter_default
the default value for gridFilter
Definition MetaFields.h:33
TChain * tree
TFile * file

Member Data Documentation

◆ base_path

std::string EL::UnitTest::base_path

description: the base path for the data files

Definition at line 22 of file PhysicsAnalysis/D3PDTools/EventLoopTest/EventLoopTest/UnitTest.h.

◆ cleanup

bool EL::UnitTest::cleanup

description: whether we clean up the submit directory afterwards

Definition at line 32 of file PhysicsAnalysis/D3PDTools/EventLoopTest/EventLoopTest/UnitTest.h.

◆ gridInput

bool EL::UnitTest::gridInput {false}

whether to use the inputs from the grid dataset

Definition at line 28 of file PhysicsAnalysis/D3PDTools/EventLoopTest/EventLoopTest/UnitTest.h.

28{false};

◆ location

std::string EL::UnitTest::location

description: the location for the unit test

Definition at line 38 of file PhysicsAnalysis/D3PDTools/EventLoopTest/EventLoopTest/UnitTest.h.

◆ name

std::string EL::UnitTest::name

description: the name of the unit test

Definition at line 19 of file PhysicsAnalysis/D3PDTools/EventLoopTest/EventLoopTest/UnitTest.h.

◆ outputDisk

SH::DiskOutput* EL::UnitTest::outputDisk

description: the output disk

Definition at line 41 of file PhysicsAnalysis/D3PDTools/EventLoopTest/EventLoopTest/UnitTest.h.

◆ scanNEvents

bool EL::UnitTest::scanNEvents {false}

whether to scan for number of events

Definition at line 25 of file PhysicsAnalysis/D3PDTools/EventLoopTest/EventLoopTest/UnitTest.h.

25{false};

◆ testFileExecute

bool EL::UnitTest::testFileExecute

whether to test the fileExecute method

Definition at line 44 of file PhysicsAnalysis/D3PDTools/EventLoopTest/EventLoopTest/UnitTest.h.

◆ testOutput

bool EL::UnitTest::testOutput

description: whether to test creating output n-tuples

Definition at line 35 of file PhysicsAnalysis/D3PDTools/EventLoopTest/EventLoopTest/UnitTest.h.


The documentation for this struct was generated from the following files: