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 43 of file PhysicsAnalysis/D3PDTools/EventLoopTest/Root/UnitTest.cxx.

45 : name (val_name), base_path (val_base_path), cleanup (true), testOutput (true), outputDisk (0),
46 testFileExecute (true)
47 {
48 if (base_path.empty())
49 base_path = "$ROOTCOREBIN/data/EventLoop/";
50 }
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 54 of file PhysicsAnalysis/D3PDTools/EventLoopTest/Root/UnitTest.cxx.

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