PODIO v00-16-03
An Event-Data-Model Toolkit for High Energy Physics Experiments
Loading...
Searching...
No Matches
check_benchmark_outputs.cpp
Go to the documentation of this file.
1#include "TFile.h"
2#include "TTree.h"
3
4#include <iostream>
5#include <string>
6#include <vector>
7
8constexpr int nExpectedEvents = 2000;
9using StringVec = std::vector<std::string>;
10
11bool verifyTree(TTree* tree, int expectedEntries, const StringVec& expectedBranches) {
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}
42
43void verifyBMFile(const char* fileName, const StringVec& setupBranches, const StringVec& eventBranches,
44 int expectedEvents = nExpectedEvents) {
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}
63
64/**
65 * We can't really make any checks on the actual execution times, but we can at
66 * least verify that the expected timing points are here.
67 */
68int main(int, char* argv[]) {
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)
constexpr int nExpectedEvents
std::vector< std::string > StringVec
bool verifyTree(TTree *tree, int expectedEntries, const StringVec &expectedBranches)
int main()