Jpp  master_rocky-43-ge265d140c
the software that should make you happy
JPrintRange1D.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <iomanip>
4 
5 #include "TROOT.h"
6 #include "TFile.h"
7 #include "TClass.h"
8 #include "TApplication.h"
9 #include "TKey.h"
10 #include "TRegexp.h"
11 #include "TH1.h"
12 #include "TGraph.h"
13 #include "TProfile.h"
14 
15 #include "JTools/JRange.hh"
16 #include "JGizmo/JRootObjectID.hh"
17 #include "JGizmo/JGizmoToolkit.hh"
18 
19 #include "Jeep/JPrint.hh"
20 #include "Jeep/JParser.hh"
21 #include "Jeep/JMessage.hh"
22 
23 
24 /**
25  * \file
26  * Auxiliary program to print the ranges of x and y values of 1D ROOT objects.
27  * The option <tt>-f</tt> corresponds to <tt><file name>:<object name></tt>.
28  * \author mdejong
29  */
30 int main(int argc, char **argv)
31 {
32  using namespace std;
33  using namespace JPP;
34 
35  typedef JRange<double> JRange_t;
36 
37  vector<JRootObjectID> inputFile;
38  JRange_t x;
39  JRange_t y;
40  int debug;
41 
42  try {
43 
44  JParser<> zap("Auxiliary program to print the ranges of x and y values of 1D ROOT objects.");
45 
46  zap['f'] = make_field(inputFile, "<input file>:<object name>");
47  zap['x'] = make_field(x, "x range") = JRange_t();
48  zap['y'] = make_field(y, "y range") = JRange_t();
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 
58  JRange_t X = JRange_t::DEFAULT_RANGE();
59  JRange_t Y = JRange_t::DEFAULT_RANGE();
60 
61  for (vector<JRootObjectID>::const_iterator input = inputFile.begin(); input != inputFile.end(); ++input) {
62 
63  DEBUG("Input: " << *input << endl);
64 
65  TDirectory* dir = getDirectory(*input);
66 
67  if (dir == NULL) {
68  ERROR("File: " << input->getFullFilename() << " not opened." << endl);
69  continue;
70  }
71 
72  const TRegexp regexp(input->getObjectName());
73 
74  TIter iter(dir->GetListOfKeys());
75 
76  for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
77 
78  const TString tag(key->GetName());
79 
80  DEBUG("Key: " << tag << " match = " << tag.Contains(regexp) << endl);
81 
82  // option match
83 
84  if (tag.Contains(regexp) && isTObject(key)) {
85 
86  TObject* object = key->ReadObj();
87 
88  try {
89 
90  TH1& h1 = dynamic_cast<TH1&>(*object);
91 
92  X.combine(x.join(JRange_t(h1.GetXaxis()->GetXmin(), h1.GetXaxis()->GetXmax())));
93  Y.combine(y.join(JRange_t(h1.GetMinimum(), h1.GetMaximum())));
94  }
95  catch(exception&) {}
96 
97  try {
98 
99  TProfile& h1 = dynamic_cast<TProfile&>(*object);
100 
101  X.combine(x.join(JRange_t(h1.GetXaxis()->GetXmin(), h1.GetXaxis()->GetXmax())));
102  Y.combine(y.join(JRange_t(h1.GetMinimum(), h1.GetMaximum())));
103  }
104  catch(exception&) {}
105 
106  try {
107 
108  TGraph& g1 = dynamic_cast<TGraph&>(*object);
109 
110  for (Int_t i = 0; i != g1.GetN(); ++i) {
111  if (x(g1.GetX()[i]) &&
112  y(g1.GetY()[i])) {
113  X.include(g1.GetX()[i]);
114  Y.include(g1.GetY()[i]);
115  }
116  }
117  }
118  catch(exception&) {}
119  }
120  }
121  }
122 
123 
124  cout << SCIENTIFIC(15,5) << X.getLowerLimit() << ' '
125  << SCIENTIFIC(15,5) << Y.getLowerLimit() << ' '
126  << SCIENTIFIC(15,5) << X.getUpperLimit() << ' '
127  << SCIENTIFIC(15,5) << Y.getUpperLimit() << endl;
128 }
General purpose messaging.
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
#define ERROR(A)
Definition: JMessage.hh:66
#define FATAL(A)
Definition: JMessage.hh:67
int debug
debug level
Definition: JSirene.cc:69
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2142
int main(int argc, char **argv)
I/O formatting auxiliaries.
Double_t g1(const Double_t x)
Function.
Definition: JQuantiles.cc:25
Auxiliary class to define a range between two values.
Utility class to parse command line options.
Definition: JParser.hh:1698
range_type & include(argument_type x)
Include given value to range.
Definition: JRange.hh:397
T getLowerLimit() const
Get lower limit.
Definition: JRange.hh:202
range_type & combine(const range_type &range)
Combine ranges.
Definition: JRange.hh:432
T getUpperLimit() const
Get upper limit.
Definition: JRange.hh:213
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).
Definition: JSTDTypes.hh:14
Type definition of range.
Definition: JHead.hh:43
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:488
Definition: JRoot.hh:19