ATLAS Offline Software
Public Member Functions | Private Member Functions | Static Private Attributes | List of all members
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  {
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  }

◆ 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  }

◆ 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  {
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  }

◆ 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  }

◆ getSH()

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

Definition at line 125 of file UnitTestFixture.cxx.

127  {
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  }

◆ getTObject()

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

Definition at line 175 of file UnitTestFixture.cxx.

179  {
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  }

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:
SGout2dot.alg
alg
Definition: SGout2dot.py:243
get_generator_info.result
result
Definition: get_generator_info.py:21
index
Definition: index.py:1
plotmaker.hist
hist
Definition: plotmaker.py:148
tree
TChain * tree
Definition: tile_monitor.h:30
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:12
EL::AnaAlgorithmConfig
an object that can create a AnaAlgorithm
Definition: AnaAlgorithmConfig.h:29
submit
Definition: submit.py:1
FullCPAlgorithmsTest_eljob.driver
driver
Definition: FullCPAlgorithmsTest_eljob.py:175
EL::UnitTestFixture::getJob
std::string getJob()
Definition: UnitTestFixture.cxx:139
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
ANA_CHECK_THROW
#define ANA_CHECK_THROW(EXP)
check whether the given expression was successful, throwing an exception on failure
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:339
EL::UnitTestFixture::m_jobs
static std::map< std::shared_ptr< Driver >, std::string > m_jobs
Definition: UnitTestFixture.h:47
FortranAlgorithmOptions.fileName
fileName
Definition: FortranAlgorithmOptions.py:13
FullCPAlgorithmsTest_eljob.sh
sh
Definition: FullCPAlgorithmsTest_eljob.py:114
FullCPAlgorithmsTest_eljob.sample
sample
Definition: FullCPAlgorithmsTest_eljob.py:116
RCU::Shell
Definition: ShellExec.cxx:28
ANA_MSG_INFO
#define ANA_MSG_INFO(xmsg)
Macro printing info messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:290
file
TFile * file
Definition: tile_monitor.h:29
EL::UnitTestFixture::getSH
SH::SampleHandler getSH()
Definition: UnitTestFixture.cxx:126
SH::MetaFields::treeName
static const std::string treeName
the name of the tree in the sample
Definition: MetaFields.h:52
SH::Sample
a base class that manages a set of files belonging to a particular data set and the associated meta-d...
Definition: Sample.h:54
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
EL::UnitTestFixture::makeFile
std::string makeFile(const std::vector< unsigned > &entries)
Definition: UnitTestFixture.cxx:241
SH::SamplePtr
A smart pointer class that holds a single Sample object.
Definition: SamplePtr.h:35
config
std::vector< std::string > config
Definition: fbtTestBasics.cxx:74
SH::SampleLocal
A Sample based on a simple file list.
Definition: SampleLocal.h:38
entries
double entries
Definition: listroot.cxx:49
pickleTool.object
object
Definition: pickleTool.py:30
SH::SampleHandler
A class that manages a list of Sample objects.
Definition: SampleHandler.h:60
RCU_THROW_MSG
#define RCU_THROW_MSG(message)
Definition: PrintMsg.h:58
test_interactive_athena.job
job
Definition: test_interactive_athena.py:6
Trk::split
@ split
Definition: LayerMaterialProperties.h:38
EL::UnitTestFixture::getSample
SH::SamplePtr getSample(const std::string &sameName)
Definition: UnitTestFixture.cxx:76