test_dropAllEventsSubruns_verify.cxx
Go to the documentation of this file.
1 #include <cassert>
2 #include <iostream>
3 #include <string>
4 
5 #include "TH1F.h"
6 #include "TFile.h"
7 #include "TTree.h"
8 
9 using namespace std;
10 
11 int
12 check_ttree(TFile const* f, char const* name, bool const empty)
13 {
14  TTree* tree = nullptr;
15  const_cast<TFile*>(f)->GetObject(name, tree);
16  assert(tree != nullptr);
17  if ((tree->GetEntries() == 0) && !empty) {
18  cerr << "Tree " << name << " from " << f->GetName() << " not supposed to be empty.\n";
19  return 1;
20  }
21  if ((tree->GetEntries() != 0) && empty) {
22  cerr << "Tree " << name << " from " << f->GetName() << " supposed to be empty.\n"
23  << " it has " << tree->GetEntries() << " entries.\n";
24  return 1;
25  }
26  return 0;
27 }
28 
29 int
30 test_dropAllEventsSubruns_verify(string const& suffix = "")
31 {
32  bool const empty = true;
33  bool const not_empty = false;
34  string qual = suffix.empty() ? "" : string("_") + suffix;
35  string filename = string("out_dropAllEvents") + qual + string(".root");
36  TFile* f = TFile::Open(filename.c_str());
37  if (f == nullptr) {
38  return 1;
39  }
40  int passed = 0;
41  passed += check_ttree(f, "Events", empty);
42  passed += check_ttree(f, "EventMetaData", empty);
43  passed += check_ttree(f, "SubRuns", not_empty);
44  passed += check_ttree(f, "SubRunMetaData", not_empty);
45  passed += check_ttree(f, "Runs", not_empty);
46  passed += check_ttree(f, "RunMetaData", not_empty);
47  filename = string("out_dropAllEventsSubruns1") + qual + string(".root");
48  f = TFile::Open(filename.c_str());
49  if (f == nullptr) {
50  return 2;
51  }
52  passed += check_ttree(f, "Events", empty);
53  passed += check_ttree(f, "EventMetaData", empty);
54  passed += check_ttree(f, "SubRuns", empty);
55  passed += check_ttree(f, "SubRunMetaData", empty);
56  passed += check_ttree(f, "Runs", not_empty);
57  passed += check_ttree(f, "RunMetaData", not_empty);
58  filename = string("out_dropAllEventsSubruns2") + qual + string(".root");
59  f = TFile::Open(filename.c_str());
60  if (f == nullptr) {
61  return 3;
62  }
63  passed += check_ttree(f, "Events", empty);
64  passed += check_ttree(f, "EventMetaData", empty);
65  passed += check_ttree(f, "SubRuns", empty);
66  passed += check_ttree(f, "SubRunMetaData", empty);
67  passed += check_ttree(f, "Runs", not_empty);
68  passed += check_ttree(f, "RunMetaData", not_empty);
69  return passed;
70 }
71 
72 int
73 main(int argc, char** argv)
74 {
75  if (argc > 1) {
76  test_dropAllEventsSubruns_verify(string(argv[1]));
77  }
78  else {
80  }
81 }
82 
std::string string
Definition: nybbler.cc:12
STL namespace.
int check_ttree(TFile const *f, char const *name, bool const empty)
int main(int argc, char **argv)
int test_dropAllEventsSubruns_verify(string const &suffix="")