#include #include #include #include #include #include "TROOT.h" #include "TFile.h" #include "TObject.h" #include "TH1.h" #include "TAxis.h" #include "TKey.h" #include "TString.h" #include "TRegexp.h" #include "JLang/JException.hh" #include "JGizmo/JRootObjectID.hh" #include "JGizmo/JGizmoToolkit.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" #include "Jeep/JPrint.hh" /** * \file * * Auxiliary program to print axis label of ROOT objects. * * The option -f corresponds to \:\. * \author mdejong, bjung */ int main(int argc, char **argv) { using namespace std; using namespace JPP; vector inputFile; char axis; int debug; try { JParser<> zap("Auxiliary program to print the axis label of a ROOT histogram."); zap['f'] = make_field(inputFile, ":"); zap['A'] = make_field(axis, "axis") = 'x', 'X', 'y', 'Y', 'z', 'Z'; zap['d'] = make_field(debug) = 0; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } for (vector::const_iterator input = inputFile.begin(); input != inputFile.end(); ++input) { DEBUG("Input: " << *input << endl); TDirectory* dir = getDirectory(*input); if (dir == NULL) { ERROR("File: " << input->getFullFilename() << " not opened." << endl); continue; } const TRegexp regexp(input->getObjectName()); TIter iter(dir->GetListOfKeys()); for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) { const TString tag(key->GetName()); DEBUG("Key: " << tag << " match = " << tag.Contains(regexp) << endl); // option match if (tag.Contains(regexp) && isTObject(key)) { TH1* h = (TH1*) key->ReadObj(); switch (axis) { case 'X': case 'x': { cout << h->GetXaxis()->GetTitle() << endl; break; } case 'Y': case 'y': { cout << h->GetYaxis()->GetTitle() << endl; break; } case 'Z': case 'z': { TAxis* Zaxis = h->GetZaxis(); if (Zaxis != NULL) { cout << h->GetZaxis()->GetTitle() << endl; } else { ERROR("Histogram " << h->GetName() << " does not have a Z-axis."); } break; } } } } } }