LDMX Software
Public Member Functions | Private Attributes | List of all members
framework::test::isGoodEventFile Class Reference

Checks: More...

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 existCollection_
 collection should exist in file
 
bool existObject_
 object should exist in file
 

Detailed Description

Checks:

Definition at line 235 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 258 of file FunctionalCoreTest.cxx.

260 : pass_(pass),
261 entries_(entries),
262 runs_(runs),
263 existCollection_(existColl),
264 existObject_(existObj) {}
bool existCollection_
collection should exist in file
bool existObject_
object should exist in file
std::string pass_
pass name to check the collection and/or object for
int entries_
correct number of entries in the event ttree

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

358 {
359 std::ostringstream ss;
360 ss << "can be opened and has the correct number of entries in the event "
361 "tree and the run tree.";
362
363 ss << " TestCollection_" << pass_ << " was verified to ";
365 ss << " be the correct pattern.";
366 else
367 ss << " not be in the file.";
368
369 ss << " TestObject_" << pass_ << " was verified to ";
370 if (existObject_)
371 ss << " be the correct pattern.";
372 else
373 ss << " not be in the file.";
374
375 return ss.str();
376 }

References existCollection_, existObject_, 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 274 of file FunctionalCoreTest.cxx.

274 {
275 TFile* f = TFile::Open(filename.c_str());
276 if (!f) return false;
277
278 TTreeReader events("LDMX_Events", f);
279
280 if (events.GetEntries(true) != entries_) {
281 f->Close();
282 return false;
283 }
284
285 // Event tree should _always_ have the ldmx::EventHeader
286 TTreeReaderValue<ldmx::EventHeader> header(events, "EventHeader");
287
288 if (existCollection_) {
289 // make sure collection matches pattern
290 TTreeReaderValue<std::vector<ldmx::CalorimeterHit>> collection(
291 events, ("TestCollection_" + pass_).c_str());
292 while (events.Next()) {
293 if (collection->size() != header->getEventNumber()) {
294 f->Close();
295 return false;
296 }
297 for (unsigned int i = 0; i < collection->size(); i++)
298 if (collection->at(i).getID() != header->getEventNumber() * 10 + i) {
299 f->Close();
300 return false;
301 }
302 }
303 // restart in case checking object as well
304 events.Restart();
305 } else {
306 // check to make sure collection is NOT there
307 auto t{(TTree*)f->Get("LDMX_Events")};
308 if (t and t->GetBranch(("TestCollection_" + pass_).c_str())) {
309 f->Close();
310 return false;
311 }
312 }
313
314 if (existObject_) {
315 // make sure object matches pattern
316 TTreeReaderValue<ldmx::HcalVetoResult> object(
317 events, ("TestObject_" + pass_).c_str());
318 while (events.Next()) {
319 if (object->getMaxPEHit().getID() != header->getEventNumber()) {
320 f->Close();
321 return false;
322 }
323 }
324 } else {
325 // check to make sure object is NOT there
326 auto t{(TTree*)f->Get("LDMX_Events")};
327 if (t and t->GetBranch(("TestObject_" + pass_).c_str())) {
328 f->Close();
329 return false;
330 }
331 }
332
333 TTreeReader runs("LDMX_Run", f);
334
335 if (runs.GetEntries(true) != runs_) {
336 f->Close();
337 return false;
338 }
339
340 TTreeReaderValue<ldmx::RunHeader> runHeader(runs, "RunHeader");
341
342 while (runs.Next()) {
343 if (runHeader->getRunNumber() !=
344 runHeader->getIntParameter("Should Be Run Number")) {
345 f->Close();
346 return false;
347 }
348 }
349
350 f->Close();
351
352 return true;
353 }

References entries_, existCollection_, existObject_, pass_, and runs_.

Member Data Documentation

◆ entries_

int framework::test::isGoodEventFile::entries_
private

correct number of entries in the event ttree

Definition at line 241 of file FunctionalCoreTest.cxx.

Referenced by match().

◆ existCollection_

bool framework::test::isGoodEventFile::existCollection_
private

collection should exist in file

Definition at line 247 of file FunctionalCoreTest.cxx.

Referenced by describe(), and match().

◆ existObject_

bool framework::test::isGoodEventFile::existObject_
private

object should exist in file

Definition at line 250 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 238 of file FunctionalCoreTest.cxx.

Referenced by describe(), and match().

◆ runs_

int framework::test::isGoodEventFile::runs_
private

correct number of runs

Definition at line 244 of file FunctionalCoreTest.cxx.

Referenced by match().


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