Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JPrintResult.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <iomanip>
4 #include <sstream>
5 #include <cmath>
6 
7 #include "TROOT.h"
8 #include "TFile.h"
9 #include "TObject.h"
10 #include "TKey.h"
11 #include "TH1.h"
12 #include "TString.h"
13 #include "TRegexp.h"
14 
15 #include "JGizmo/JRootObjectID.hh"
16 #include "JGizmo/JGizmoToolkit.hh"
17 
18 #include "Jeep/JParser.hh"
19 #include "Jeep/JMessage.hh"
20 
21 
22 /**
23  * \file
24  *
25  * Auxiliary program to print result from ROOT histograms.
26  * The option <tt>-f</tt> corresponds to <tt><file name>:<object name></tt>.
27  *
28  * The formula (option <tt>-F <formula></tt>) refers to a ROOT TFormula.
29  * The expression may contain member methods of the corresponding object.
30  * \author mdejong
31  */
32 int main(int argc, char **argv)
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
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:65
Utility class to parse command line options.
TDirectory * getDirectory(const JRootObjectID &id)
Get TDirectory pointer.
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:60
int main(int argc, char *argv[])
Definition: Main.cpp:15