LDMX Software
framework::test::IsGoodEventFile Class Reference

Public Member Functions

 IsGoodEventFile (const std::string &pass, const int &entries, const int &runs, bool existColl=true, bool existObj=true)
 Constructor.
 
bool match (const std::string &filename) const override
 Actually do the matching.
 
virtual std::string describe () const override
 Human-readable statement for any match that is true.
 

Private Attributes

std::string pass_
 pass name to check the collection and/or object for
 
int entries_
 correct number of entries in the event ttree
 
int runs_
 correct number of runs
 
bool exist_collection_
 collection should exist in file
 
bool exist_object_
 object should exist in file
 

Detailed Description

Definition at line 256 of file FunctionalCoreTest.cxx.

Constructor & Destructor Documentation

◆ IsGoodEventFile()

framework::test::IsGoodEventFile::IsGoodEventFile ( const std::string & pass,
const int & entries,
const int & runs,
bool existColl = true,
bool existObj = true )
inline

Constructor.

Sets the correct number of entries and the other checking parameters

Definition at line 279 of file FunctionalCoreTest.cxx.

281 : pass_(pass),
282 entries_(entries),
283 runs_(runs),
284 exist_collection_(existColl),
285 exist_object_(existObj) {}
int entries_
correct number of entries in the event ttree
bool exist_object_
object should exist in file
std::string pass_
pass name to check the collection and/or object for
bool exist_collection_
collection should exist in file

Member Function Documentation

◆ describe()

virtual std::string framework::test::IsGoodEventFile::describe ( ) const
inlineoverridevirtual

Human-readable statement for any match that is true.

Definition at line 379 of file FunctionalCoreTest.cxx.

379 {
380 std::ostringstream ss;
381 ss << "can be opened and has the correct number of entries in the event "
382 "tree and the run tree.";
383
384 ss << " test_collection_" << pass_ << " was verified to ";
386 ss << " be the correct pattern.";
387 else
388 ss << " not be in the file.";
389
390 ss << " test_object_" << pass_ << " was verified to ";
391 if (exist_object_)
392 ss << " be the correct pattern.";
393 else
394 ss << " not be in the file.";
395
396 return ss.str();
397 }

References exist_collection_, exist_object_, and pass_.

◆ match()

bool framework::test::IsGoodEventFile::match ( const std::string & filename) const
inlineoverride

Actually do the matching.

The event and run tree names are hardcoded. The branchnames are also hardcoded.

Parameters
[in]filenamename of event file to check

Definition at line 295 of file FunctionalCoreTest.cxx.

295 {
296 TFile* f = TFile::Open(filename.c_str());
297 if (!f) return false;
298
299 TTreeReader events("LDMX_Events", f);
300
301 if (events.GetEntries(true) != entries_) {
302 f->Close();
303 return false;
304 }
305
306 // Event tree should _always_ have the ldmx::EventHeader
307 TTreeReaderValue<ldmx::EventHeader> header(events, "EventHeader");
308
309 if (exist_collection_) {
310 // make sure collection matches pattern
311 TTreeReaderValue<std::vector<ldmx::CalorimeterHit>> collection(
312 events, ("test_collection_" + pass_).c_str());
313 while (events.Next()) {
314 if (collection->size() != header->getEventNumber()) {
315 f->Close();
316 return false;
317 }
318 for (unsigned int i = 0; i < collection->size(); i++)
319 if (collection->at(i).getID() != header->getEventNumber() * 10 + i) {
320 f->Close();
321 return false;
322 }
323 }
324 // restart in case checking object as well
325 events.Restart();
326 } else {
327 // check to make sure collection is NOT there
328 auto t{(TTree*)f->Get("LDMX_Events")};
329 if (t and t->GetBranch(("test_collection_" + pass_).c_str())) {
330 f->Close();
331 return false;
332 }
333 }
334
335 if (exist_object_) {
336 // make sure object matches pattern
337 TTreeReaderValue<ldmx::HcalVetoResult> object(
338 events, ("test_object_" + pass_).c_str());
339 while (events.Next()) {
340 if (object->getMaxPEHit().getID() != header->getEventNumber()) {
341 f->Close();
342 return false;
343 }
344 }
345 } else {
346 // check to make sure object is NOT there
347 auto t{(TTree*)f->Get("LDMX_Events")};
348 if (t and t->GetBranch(("test_object_" + pass_).c_str())) {
349 f->Close();
350 return false;
351 }
352 }
353
354 TTreeReader runs("LDMX_Run", f);
355
356 if (runs.GetEntries(true) != runs_) {
357 f->Close();
358 return false;
359 }
360
361 TTreeReaderValue<ldmx::RunHeader> run_header(runs, "RunHeader");
362
363 while (runs.Next()) {
364 if (run_header->getRunNumber() !=
365 run_header->getIntParameter("Should Be Run Number")) {
366 f->Close();
367 return false;
368 }
369 }
370
371 f->Close();
372
373 return true;
374 }

References entries_, exist_collection_, exist_object_, pass_, and runs_.

Member Data Documentation

◆ entries_

int framework::test::IsGoodEventFile::entries_
private

correct number of entries in the event ttree

Definition at line 262 of file FunctionalCoreTest.cxx.

Referenced by match().

◆ exist_collection_

bool framework::test::IsGoodEventFile::exist_collection_
private

collection should exist in file

Definition at line 268 of file FunctionalCoreTest.cxx.

Referenced by describe(), and match().

◆ exist_object_

bool framework::test::IsGoodEventFile::exist_object_
private

object should exist in file

Definition at line 271 of file FunctionalCoreTest.cxx.

Referenced by describe(), and match().

◆ pass_

std::string framework::test::IsGoodEventFile::pass_
private

pass name to check the collection and/or object for

Definition at line 259 of file FunctionalCoreTest.cxx.

Referenced by describe(), and match().

◆ runs_

int framework::test::IsGoodEventFile::runs_
private

correct number of runs

Definition at line 265 of file FunctionalCoreTest.cxx.

Referenced by match().


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