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 265 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 288 of file FunctionalCoreTest.cxx.

290 : pass_(pass),
291 entries_(entries),
292 runs_(runs),
293 exist_collection_(existColl),
294 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 388 of file FunctionalCoreTest.cxx.

388 {
389 std::ostringstream ss;
390 ss << "can be opened and has the correct number of entries in the event "
391 "tree and the run tree.";
392
393 ss << " TestCollection_" << pass_ << " was verified to ";
395 ss << " be the correct pattern.";
396 else
397 ss << " not be in the file.";
398
399 ss << " TestObject_" << pass_ << " was verified to ";
400 if (exist_object_)
401 ss << " be the correct pattern.";
402 else
403 ss << " not be in the file.";
404
405 return ss.str();
406 }

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 304 of file FunctionalCoreTest.cxx.

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

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 271 of file FunctionalCoreTest.cxx.

Referenced by match().

◆ exist_collection_

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

collection should exist in file

Definition at line 277 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 280 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 268 of file FunctionalCoreTest.cxx.

Referenced by describe(), and match().

◆ runs_

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

correct number of runs

Definition at line 274 of file FunctionalCoreTest.cxx.

Referenced by match().


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