Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JPrintResult.cc File Reference

Auxiliary program to print result from ROOT histograms. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cmath>
#include "TROOT.h"
#include "TFile.h"
#include "TObject.h"
#include "TKey.h"
#include "TH1.h"
#include "TString.h"
#include "TRegexp.h"
#include "JGizmo/JRootObjectID.hh"
#include "JGizmo/JGizmoToolkit.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Auxiliary program to print result from ROOT histograms.

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

The formula (option -F <formula>) refers to a ROOT TFormula. The expression may contain member methods of the corresponding object.

Author
mdejong

Definition in file JPrintResult.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 32 of file JPrintResult.cc.

33 {
34  using namespace std;
35  using namespace JPP;
36 
37  vector<JRootObjectID> inputFile;
38  TString formula;
39  int debug;
40 
41  try {
42 
43  JParser<> zap("Auxiliary program to print result from ROOT histograms."\
44  "\nNote that the formula may contain method names of the specified object.");
45 
46  zap['f'] = make_field(inputFile, "<input file>:<object name>");
47  zap['F'] = make_field(formula, "ROOT TFormula (may contain method names of object)");
48  zap['d'] = make_field(debug) = 0;
49 
50  zap(argc, argv);
51  }
52  catch(const exception &error) {
53  FATAL(error.what() << endl);
54  }
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.Index(regexp) << " (-1 /= OK)" << endl);
77 
78  // option match
79 
80  if (tag.Index(regexp) != -1) {
81 
82  TObject* object = key->ReadObj();
83 
84  try {
85 
86  TH1& h1 = dynamic_cast<TH1&>(*object);
87 
88  double factor = getResult(formula, object);
89 
90  cout << factor << flush;
91  }
92  catch(exception&) {}
93  }
94  }
95  }
96 }
Utility class to parse command line options.
Definition: JParser.hh:1410
Definition: JRoot.hh:19
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1836
Double_t getResult(const TString &text, TObject *object=NULL)
Get result of given textual formula.
#define ERROR(A)
Definition: JMessage.hh:64
int debug
debug level
Definition: JSirene.cc:59
#define FATAL(A)
Definition: JMessage.hh:65
TDirectory * getDirectory(const JRootObjectID &id)
Get TDirectory pointer.
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:60