test_simple_01_verify.cxx
Go to the documentation of this file.
1 #include "TDirectory.h"
2 #include "TFile.h"
3 #include "TGraph.h"
4 #include "TGraphPolar.h"
5 #include "TH1F.h"
6 #include "TH2F.h"
7 
8 #include <iostream>
9 
10 using namespace std;
11 
12 int
14 {
15  TFile* f = TFile::Open("tfile_output.root");
16  if (f == nullptr) {
17  return 1;
18  }
19  // Having obtained 'f', we never use it again. We use the global
20  // variable gDirectory, because that's what the 'cd' calls
21  // manipulate. Really.
22  // Make sure we have a directory named by our module label, "hist".
23  bool rc = gDirectory->cd("hist");
24  if (!rc) {
25  return 1;
26  }
27  // Make sure we have the subdirectory "a", containing the TH1F
28  // histogram named "test1".
29  rc = gDirectory->cd("a");
30  if (!rc) {
31  return 2;
32  }
33  TH1F* h1 = nullptr;
34  TH2F* h2 = nullptr;
35  TH1F* h3 = nullptr;
36  gDirectory->GetObject("test1", h1);
37  if (h1 == nullptr) {
38  cerr << "test1 not found\n";
39  return 1;
40  }
41  h1 = nullptr;
42  gDirectory->GetObject("z", h1);
43  if (h1 != nullptr) {
44  cerr << "z incorrectly found\n";
45  return 1;
46  }
47  h2 = nullptr;
48  gDirectory->GetObject("test1", h2);
49  if (h2 != nullptr) {
50  cerr << "test1 incorrectly identified as a TH2F\n";
51  return 1;
52  }
53  // Make sure we have the subdirectory "b", containing the TH2F
54  // histogram named "test2".
55  rc = gDirectory->cd("../b");
56  if (!rc) {
57  return 3;
58  }
59  h2 = nullptr;
60  gDirectory->GetObject("test2", h2);
61  if (h2 == nullptr) {
62  cerr << "test2 not found\n";
63  return 3;
64  }
65  // Make sure we have the subdirectory "respondToOpenInputFile",
66  // containing the TH1F histogrm named "test3"
67  rc = gDirectory->cd("../respondToOpenInputFile");
68  if (!rc) {
69  return 4;
70  }
71  h3 = nullptr;
72  gDirectory->GetObject("test3", h3);
73  if (h3 == nullptr) {
74  cerr << "test3 not found\n";
75  return 4;
76  }
77  // Make sure the top-level directory contains a TGraph named
78  // "graphAtTopLevel".
79  rc = gDirectory->cd("/hist");
80  if (!rc) {
81  return 5;
82  }
83  TGraph* pgraph = nullptr;
84  gDirectory->GetObject("graphAtTopLevel", pgraph);
85  if (pgraph == nullptr) {
86  cerr << "graphAtTopLevel not found\n";
87  return 5;
88  }
89  string title = pgraph->GetTitle();
90  if (title != "graph at top level") {
91  cerr << "TGraph at top level not recovered with correct title\n";
92  return 5;
93  }
94  // Make sure the direcotyr "b" contains a TGraph named
95  // "graphInSubdirectory"
96  rc = gDirectory->cd("b");
97  if (!rc) {
98  return 6;
99  }
100  TGraphPolar* ppolar = nullptr;
101  gDirectory->GetObject("graphInSubdirectory", ppolar);
102  if (ppolar == nullptr) {
103  cerr << "graphInSubdirectory not found\n";
104  return 6;
105  }
106  title = ppolar->GetTitle();
107  if (title != "graph in subdirectory") {
108  cerr << "TGraph in subdirectory not recovered with correct title\n";
109  return 6;
110  }
111  return 0;
112 }
113 
114 int
116 {
117  return test_simple_01_verify();
118 }
119 
int main()
STL namespace.
int test_simple_01_verify()