PODIO v00-16-03
An Event-Data-Model Toolkit for High Energy Physics Experiments
Loading...
Searching...
No Matches
check_benchmark_outputs.cpp File Reference
#include "TFile.h"
#include "TTree.h"
#include <iostream>
#include <string>
#include <vector>

Go to the source code of this file.

Typedefs

using StringVec = std::vector< std::string >
 

Functions

bool verifyTree (TTree *tree, int expectedEntries, const StringVec &expectedBranches)
 
void verifyBMFile (const char *fileName, const StringVec &setupBranches, const StringVec &eventBranches, int expectedEvents=nExpectedEvents)
 
int main (int, char *argv[])
 

Variables

constexpr int nExpectedEvents = 2000
 

Typedef Documentation

◆ StringVec

using StringVec = std::vector<std::string>

Definition at line 9 of file check_benchmark_outputs.cpp.

Function Documentation

◆ main()

int main ( int  ,
char *  argv[] 
)

We can't really make any checks on the actual execution times, but we can at least verify that the expected timing points are here.

Definition at line 68 of file check_benchmark_outputs.cpp.

68 {
69 const StringVec writeBMSetupBranches = {"constructor", "finish", "register_for_write"};
70 const StringVec writeBMEventBranches = {"write_event"};
71 verifyBMFile(argv[1], writeBMSetupBranches, writeBMEventBranches);
72
73 const StringVec readBMSetupBranches = {"constructor", "open_file", "close_file", "get_entries",
74 "read_collection_ids"};
75 const StringVec readBMEventBranches = {"read_collections", "read_ev_md", "read_run_md",
76 "read_coll_md", "end_of_event", "read_event"};
77 verifyBMFile(argv[2], readBMSetupBranches, readBMEventBranches);
78
79 return 0;
80}
void verifyBMFile(const char *fileName, const StringVec &setupBranches, const StringVec &eventBranches, int expectedEvents=nExpectedEvents)
std::vector< std::string > StringVec

◆ verifyBMFile()

void verifyBMFile ( const char *  fileName,
const StringVec setupBranches,
const StringVec eventBranches,
int  expectedEvents = nExpectedEvents 
)

Definition at line 43 of file check_benchmark_outputs.cpp.

44 {
45 TFile* bmFile = TFile::Open(fileName);
46 if (!bmFile) {
47 std::cerr << "Benchmark file \'" << fileName << "\' does not exist!" << std::endl;
48 std::exit(1);
49 }
50 if (!verifyTree(static_cast<TTree*>(bmFile->Get("setup_times")), 1, setupBranches)) {
51 std::cerr << "In file \'" << fileName << "\' setup_times Tree does not have the expected entries" << std::endl;
52 bmFile->Close();
53 std::exit(1);
54 }
55 if (!verifyTree(static_cast<TTree*>(bmFile->Get("event_times")), expectedEvents, eventBranches)) {
56 std::cerr << "In file \'" << fileName << "\' event_times Tree does not have the expected entries" << std::endl;
57 bmFile->Close();
58 std::exit(1);
59 }
60
61 bmFile->Close();
62}
bool verifyTree(TTree *tree, int expectedEntries, const StringVec &expectedBranches)

Referenced by main().

◆ verifyTree()

bool verifyTree ( TTree *  tree,
int  expectedEntries,
const StringVec expectedBranches 
)

Definition at line 11 of file check_benchmark_outputs.cpp.

11 {
12 const std::string treeName = tree->GetName();
13 if (tree->GetEntries() != expectedEntries) {
14 std::cerr << "Tree \'" << treeName << "\' should have " << expectedEntries << " but has " << tree->GetEntries()
15 << std::endl;
16 return false;
17 }
18
19 const auto* branches = tree->GetListOfBranches();
20 for (const auto& branch : expectedBranches) {
21 bool found = false;
22 for (int i = 0; i < branches->GetEntries(); ++i) {
23 if (branch == branches->At(i)->GetName()) {
24 found = true;
25 break;
26 }
27 }
28 if (!found) {
29 std::cerr << "Branch \'" << branch << "\' was expected to be in Tree \'" << treeName
30 << "\' but could not be found" << std::endl;
31 return false;
32 }
33 }
34
35 if ((unsigned)branches->GetEntries() != expectedBranches.size()) {
36 std::cerr << "Tree \'" << treeName << "\' has additional, unexpected branches" << std::endl;
37 return false;
38 }
39
40 return true;
41}

Referenced by verifyBMFile().

Variable Documentation

◆ nExpectedEvents

constexpr int nExpectedEvents = 2000
constexpr

Definition at line 8 of file check_benchmark_outputs.cpp.