40 std::vector<std::string>
41 readVectorFromTree (SH::Sample *sample,
const std::string& treeName,
42 const std::string& branchName)
44 std::vector<std::string>
result;
46 TString *
var =
nullptr;
47 for (
auto& fileName : fileNames)
49 std::unique_ptr<TFile>
file (TFile::Open (
fileName.c_str(),
"READ"));
54 if (
tree !=
nullptr && (nentries =
tree->GetEntries()) > 0)
56 TBranch *branch =
nullptr;
57 tree->SetBranchAddress (branchName.c_str(), &var, &branch);
60 if (branch->GetEntry(entry) <= 0)
76 getSample (
const std::string& sampleName)
78 if (sampleName ==
"empty")
83 std::unique_ptr<SH::SampleLocal> myresult (
new SH::SampleLocal (
"empty"));
85 result = myresult.release();
89 if (sampleName ==
"single")
94 std::unique_ptr<SH::SampleLocal> myresult (
new SH::SampleLocal (
"single"));
96 for (
unsigned iter = 0; iter != 10000; ++ iter)
99 result = myresult.release();
103 if (sampleName ==
"multi")
108 std::unique_ptr<SH::SampleLocal> myresult (
new SH::SampleLocal (
"multi"));
109 for (
unsigned jter = 0; jter != 10; ++ jter)
112 for (
unsigned iter = 0; iter != 10000; ++ iter)
116 result = myresult.release();
138 std::string UnitTestFixture ::
141 using namespace asg::msgUserCode;
144 std::shared_ptr<Driver> driver = GetParam().m_driver;
145 auto iter =
m_jobs.find (driver);
150 job.sampleHandler (
getSH());
151 GetParam().setupJob (job);
154 config.setType (
"EL::UnitTestAlg2");
155 config.setName (
"newAlg");
156 config.setUseXAODs (
false);
162 job.algsAdd (alg.release());
165 std::ostringstream
submit;
166 submit <<
"submit-" << driver.get();
167 driver->submit (job,
submit.str());
168 driver->wait (
submit.str());
175 TObject *UnitTestFixture ::
176 getTObject (
const std::string& sampleName,
177 const std::string& objectName,
183 if (sample ==
nullptr)
185 TObject *
object = sample->readHist (objectName);
186 if (isMandatory &&
object ==
nullptr)
193 unsigned UnitTestFixture ::
194 eventCount (
const std::string& sampleName)
196 TH1 *hist =
getHist<TH1> (sampleName,
"EventLoop_EventCount",
true);
197 return hist->GetBinContent (1);
202 TH1 *UnitTestFixture ::
203 getCallbacks (
const std::string& sampleName)
210 void UnitTestFixture ::
211 checkFileExecuted (
const std::string& sampleName)
213 std::set<std::string> filesOut;
218 if (sample ==
nullptr)
220 auto vec = readVectorFromTree (sample,
"EventLoop_FileExecuted",
"file");
221 filesOut.insert (
vec.begin(),
vec.end());
223 std::set<std::string> filesIn;
227 if (
split == std::string::npos)
231 std::string fileName =
file.substr (
split);
232 ASSERT_TRUE (filesIn.find (fileName) == filesIn.end());
233 filesIn.insert (fileName);
235 ASSERT_EQ (filesIn, filesOut);
240 std::string UnitTestFixture ::
241 makeFile (
const std::vector<unsigned>&
entries)
243 static unsigned index = 0;
244 std::ostringstream fileName;
245 fileName <<
"file-" << ++
index <<
".root";
247 std::unique_ptr<SH::DiskWriter>
file
248 = GetParam().make_file_writer (fileName.str());
252 TTree *
tree =
new TTree (
"physics",
"physics");
254 tree->Branch (
"el_n", &el_n,
"el_n/I");
261 file->file()->Write ();
271 EXPECT_EQ (eventCount (
"empty"), 0u);
278 TH1 *callbacks = getCallbacks (
"empty");
293 checkFileExecuted (
"empty");
300 EXPECT_EQ (eventCount (
"single"), 10000u);
307 TH1 *callbacks = getCallbacks (
"single");
322 checkFileExecuted (
"single");
329 EXPECT_EQ (eventCount (
"multi"), 100000u);
336 TH1 *callbacks = getCallbacks (
"multi");
351 checkFileExecuted (
"multi");
359 sh.load (getJob() +
"/output-out_empty");
361 ASSERT_TRUE (sample !=
nullptr);
363 for (
auto fileName : sample->makeFileList())
365 std::unique_ptr<TFile>
file (TFile::Open (fileName.c_str(),
"READ"));
std::vector< size_t > vec
#define RCU_THROW_MSG(message)
an object that can create a AnaAlgorithm
static std::map< std::shared_ptr< Driver >, std::string > m_jobs
SH::SamplePtr getSample(const std::string &sameName)
SH::SampleHandler getSH()
T * getHist(const std::string &sampleName, const std::string &objectName, bool isMandatory)
std::string makeFile(const std::vector< unsigned > &entries)
A class that manages a list of Sample objects.
A Sample based on a simple file list.
A smart pointer class that holds a single Sample object.
a base class that manages a set of files belonging to a particular data set and the associated meta-d...
std::vector< std::string > split(const std::string &s, const std::string &t=":")
This module defines the arguments passed from the BATCH driver to the BATCH worker.
TEST_P(UnitTestFixture, empty_eventCount)