Jpp  18.0.0-rc.4
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JPrintAxisLabel.cc File Reference

Auxiliary program to print axis label of ROOT objects. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cmath>
#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"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Auxiliary program to print axis label of ROOT objects.

The option -f corresponds to <file name>:<object name>.

Author
mdejong, bjung

Definition in file JPrintAxisLabel.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 34 of file JPrintAxisLabel.cc.

35 {
36  using namespace std;
37  using namespace JPP;
38 
39  vector<JRootObjectID> inputFile;
40  char axis;
41  int debug;
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';
49  zap['d'] = make_field(debug) = 0;
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 
61  TDirectory* dir = getDirectory(*input);
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  // option match
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 }
Utility class to parse command line options.
Definition: JParser.hh:1514
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
#define ERROR(A)
Definition: JMessage.hh:66
#define FATAL(A)
Definition: JMessage.hh:67
bool isTObject(const TKey *key)
Check if given key corresponds to a TObject.
TDirectory * getDirectory(const JRootObjectID &id)
Get TDirectory pointer.
int debug
debug level
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62