35{
38
40 char axis;
42
43 try {
44
45 JParser<> zap(
"Auxiliary program to print the axis label of a ROOT histogram.");
46
47 zap[
'f'] =
make_field(inputFile,
"<input file>:<object name>");
48 zap[
'A'] =
make_field(axis,
"axis") =
'x',
'X',
'y',
'Y',
'z',
'Z';
50
51 zap(argc, argv);
52 }
53 catch(const exception &error) {
54 FATAL(error.what() << endl);
55 }
56
57 for (vector<JRootObjectID>::const_iterator input = inputFile.begin(); input != inputFile.end(); ++input) {
58
59 DEBUG(
"Input: " << *input << endl);
60
62
63 if (dir == NULL) {
64 ERROR(
"File: " << input->getFullFilename() <<
" not opened." << endl);
65 continue;
66 }
67
68 const TRegexp regexp(input->getObjectName());
69
70 TIter iter(dir->GetListOfKeys());
71
72 for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
73
74 const TString tag(key->GetName());
75
76 DEBUG(
"Key: " << tag <<
" match = " << tag.Contains(regexp) << endl);
77
78
79
80 if (tag.Contains(regexp) &&
isTObject(key)) {
81
82 TH1* h = (TH1*) key->ReadObj();
83
84 switch (axis) {
85
86 case 'X':
87 case 'x': {
88 cout << h->GetXaxis()->GetTitle() << endl;
89 break;
90 }
91
92 case 'Y':
93 case 'y': {
94 cout << h->GetYaxis()->GetTitle() << endl;
95 break;
96 }
97
98 case 'Z':
99 case 'z': {
100
101 TAxis* Zaxis = h->GetZaxis();
102
103 if (Zaxis != NULL) {
104 cout << h->GetZaxis()->GetTitle() << endl;
105 } else {
106 ERROR(
"Histogram " << h->GetName() <<
" does not have a Z-axis.");
107 }
108
109 break;
110 }
111 }
112 }
113 }
114 }
115}
#define DEBUG(A)
Message macros.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Utility class to parse command line options.
TDirectory * getDirectory(const JRootObjectID &id)
Get TDirectory pointer.
bool isTObject(const TKey *key)
Check if given key corresponds to a TObject.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).