ATLAS Offline Software
Loading...
Searching...
No Matches
EL::UnitTestFixture Class Reference

#include <UnitTestFixture.h>

Inheritance diagram for EL::UnitTestFixture:
Collaboration diagram for EL::UnitTestFixture:

Public Member Functions

std::string getJob ()
SH::SamplePtr getSample (const std::string &sameName)
SH::SampleHandler getSH ()
unsigned eventCount (const std::string &sampleName)
TObject * getTObject (const std::string &sampleName, const std::string &objectName, bool isMandatory)
template<typename T>
T * getHist (const std::string &sampleName, const std::string &objectName, bool isMandatory)
TH1 * getCallbacks (const std::string &sampleName)
void checkFileExecuted (const std::string &sampleName)

Private Member Functions

std::string makeFile (const std::vector< unsigned > &entries)

Static Private Attributes

static std::map< std::shared_ptr< Driver >, std::string > m_jobs

Detailed Description

Definition at line 22 of file UnitTestFixture.h.

Member Function Documentation

◆ checkFileExecuted()

void EL::UnitTestFixture::checkFileExecuted ( const std::string & sampleName)

Definition at line 210 of file UnitTestFixture.cxx.

212 {
213 std::set<std::string> filesOut;
214 {
215 SH::SampleHandler sh;
216 sh.load (getJob() + "/hist");
217 SH::Sample *sample = sh.get (sampleName);
218 if (sample == nullptr)
219 RCU_THROW_MSG ("couldn't find sample: " + sampleName);
220 auto vec = readVectorFromTree (sample, "EventLoop_FileExecuted", "file");
221 filesOut.insert (vec.begin(), vec.end());
222 }
223 std::set<std::string> filesIn;
224 for (auto& file : getSample (sampleName)->makeFileList())
225 {
226 auto split = file.rfind ('/');
227 if (split == std::string::npos)
228 split = 0;
229 else
230 ++ split;
231 std::string fileName = file.substr (split);
232 ASSERT_TRUE (filesIn.find (fileName) == filesIn.end());
233 filesIn.insert (fileName);
234 }
235 ASSERT_EQ (filesIn, filesOut);
236 }
std::vector< size_t > vec
#define RCU_THROW_MSG(message)
Definition PrintMsg.h:58
SH::SamplePtr getSample(const std::string &sameName)
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:177
TFile * file

◆ eventCount()

unsigned EL::UnitTestFixture::eventCount ( const std::string & sampleName)

Definition at line 193 of file UnitTestFixture.cxx.

195 {
196 TH1 *hist = getHist<TH1> (sampleName, "EventLoop_EventCount", true);
197 return hist->GetBinContent (1);
198 }
T * getHist(const std::string &sampleName, const std::string &objectName, bool isMandatory)

◆ getCallbacks()

TH1 * EL::UnitTestFixture::getCallbacks ( const std::string & sampleName)

Definition at line 202 of file UnitTestFixture.cxx.

204 {
205 return getHist<TH1> (sampleName, "callbacks", true);
206 }

◆ getHist()

template<typename T>
T * EL::UnitTestFixture::getHist ( const std::string & sampleName,
const std::string & objectName,
bool isMandatory )

◆ getJob()

std::string EL::UnitTestFixture::getJob ( )

Definition at line 138 of file UnitTestFixture.cxx.

140 {
141 using namespace asg::msgUserCode;
142 ANA_MSG_INFO ("in EventLoopTest");
143
144 std::shared_ptr<Driver> driver = GetParam().m_driver;
145 auto iter = m_jobs.find (driver);
146 if (iter != m_jobs.end())
147 return iter->second;
148
149 Job job;
150 job.sampleHandler (getSH());
151 GetParam().setupJob (job);
152 {
153 EL::AnaAlgorithmConfig config;
154 config.setType ("EL::UnitTestAlg2");
155 config.setName ("newAlg");
156 config.setUseXAODs (false);
157 ANA_CHECK_THROW (config.setProperty ("property", 42));
158 job.algsAdd (config);
159 }
160 {
161 std::unique_ptr<UnitTestAlg1> alg (new UnitTestAlg1);
162 job.algsAdd (alg.release());
163 }
164
165 std::ostringstream submit;
166 submit << "submit-" << driver.get();
167 driver->submit (job, submit.str());
168 driver->wait (submit.str());
169 m_jobs[driver] = submit.str();
170 return submit.str();
171 }
#define ANA_MSG_INFO(xmsg)
Macro printing info messages.
#define ANA_CHECK_THROW(EXP)
check whether the given expression was successful, throwing an exception on failure
static std::map< std::shared_ptr< Driver >, std::string > m_jobs
SH::SampleHandler getSH()

◆ getSample()

SH::SamplePtr EL::UnitTestFixture::getSample ( const std::string & sameName)

Definition at line 75 of file UnitTestFixture.cxx.

77 {
78 if (sampleName == "empty")
79 {
80 static SH::SamplePtr result;
81 if (result.empty())
82 {
83 std::unique_ptr<SH::SampleLocal> myresult (new SH::SampleLocal ("empty"));
84 myresult->add (makeFile ({}));
85 result = myresult.release();
86 }
87 return result;
88 }
89 if (sampleName == "single")
90 {
91 static SH::SamplePtr result;
92 if (result.empty())
93 {
94 std::unique_ptr<SH::SampleLocal> myresult (new SH::SampleLocal ("single"));
95 std::vector<unsigned> entries;
96 for (unsigned iter = 0; iter != 10000; ++ iter)
97 entries.push_back (iter % 10);
98 myresult->add (makeFile (entries));
99 result = myresult.release();
100 }
101 return result;
102 }
103 if (sampleName == "multi")
104 {
105 static SH::SamplePtr result;
106 if (result.empty())
107 {
108 std::unique_ptr<SH::SampleLocal> myresult (new SH::SampleLocal ("multi"));
109 for (unsigned jter = 0; jter != 10; ++ jter)
110 {
111 std::vector<unsigned> entries;
112 for (unsigned iter = 0; iter != 10000; ++ iter)
113 entries.push_back (iter % 10);
114 myresult->add (makeFile (entries));
115 }
116 result = myresult.release();
117 }
118 return result;
119 }
120 RCU_THROW_MSG ("unknown sample: " + sampleName);
121 }
std::string makeFile(const std::vector< unsigned > &entries)
double entries
Definition listroot.cxx:49

◆ getSH()

SH::SampleHandler EL::UnitTestFixture::getSH ( )

Definition at line 125 of file UnitTestFixture.cxx.

127 {
128 SH::SampleHandler sh;
129 sh.add (getSample ("empty"));
130 sh.add (getSample ("single"));
131 sh.add (getSample ("multi"));
132 sh.setMetaString (SH::MetaFields::treeName, "physics");
133 return sh;
134 }
static const std::string treeName
the name of the tree in the sample
Definition MetaFields.h:52

◆ getTObject()

TObject * EL::UnitTestFixture::getTObject ( const std::string & sampleName,
const std::string & objectName,
bool isMandatory )

Definition at line 175 of file UnitTestFixture.cxx.

179 {
180 SH::SampleHandler sh;
181 sh.load (getJob() + "/hist");
182 SH::Sample *sample = sh.get (sampleName);
183 if (sample == nullptr)
184 RCU_THROW_MSG ("couldn't find sample: " + sampleName);
185 TObject *object = sample->readHist (objectName);
186 if (isMandatory && object == nullptr)
187 RCU_THROW_MSG ("couldn't find object: " + objectName);
188 return object;
189 }

◆ makeFile()

std::string EL::UnitTestFixture::makeFile ( const std::vector< unsigned > & entries)
private

Definition at line 240 of file UnitTestFixture.cxx.

242 {
243 static unsigned index = 0;
244 std::ostringstream fileName;
245 fileName << "file-" << ++ index << ".root";
246
247 std::unique_ptr<SH::DiskWriter> file
248 = GetParam().make_file_writer (fileName.str());
249 {
250 if (!entries.empty())
251 {
252 TTree *tree = new TTree ("physics", "physics");
253 Int_t el_n = 0;
254 tree->Branch ("el_n", &el_n, "el_n/I");
255 for (auto entry : entries)
256 {
257 el_n = entry;
258 tree->Fill ();
259 }
260 }
261 file->file()->Write ();
262 file->close ();
263 }
264 return file->path();
265 }
str index
Definition DeMoScan.py:362
TChain * tree

Member Data Documentation

◆ m_jobs

std::map< std::shared_ptr< Driver >, std::string > EL::UnitTestFixture::m_jobs
staticprivate

Definition at line 47 of file UnitTestFixture.h.


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