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

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

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

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

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

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

Referenced by match().

◆ exist_collection_

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

collection should exist in file

Definition at line 275 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 278 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 266 of file FunctionalCoreTest.cxx.

Referenced by describe(), and match().

◆ runs_

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

correct number of runs

Definition at line 272 of file FunctionalCoreTest.cxx.

Referenced by match().


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