Jpp  15.0.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JFileTuna.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <fstream>
4 #include <iomanip>
5 #include <vector>
6 #include <utility>
7 
8 #include "TROOT.h"
9 #include "TFile.h"
10 #include "TObject.h"
11 #include "TKey.h"
12 #include "TString.h"
13 #include "TRegexp.h"
14 #include "TGraph.h"
15 
16 #include "JGizmo/JRootObjectID.hh"
17 #include "JGizmo/JGizmoToolkit.hh"
18 #include "JTools/JRange.hh"
19 #include "JLang/JLangToolkit.hh"
20 
21 #include "Jeep/JParser.hh"
22 #include "Jeep/JMessage.hh"
23 #include "Jeep/JPrint.hh"
24 
25 
26 namespace {
27 
28  /**
29  * Type definition of lookup table.
30  */
32 
33  /**
34  * Get value from lookup table.
35  *
36  * The return value is obtained in order of appearance in the lookup table using TRegexp.
37  *
38  * \param zmap lookup table
39  * \param parameter parameter
40  * \param value default value
41  * \return value
42  */
43  inline double getValue(const map_type& zmap, const TString& parameter, const double value)
44  {
45  for (map_type::const_iterator i = zmap.begin(); i != zmap.end(); ++i) {
46  if (parameter.Contains(TRegexp(i->first.c_str()))) {
47  return i->second;
48  }
49  }
50 
51  return value;
52  }
53 }
54 
55 /**
56  * \file
57  *
58  * Auxiliary program to write test criteria to file.
59  * The option <tt>-f</tt> corresponds to <tt><file name>:<object name></tt>.
60  */
61 int main(int argc, char **argv)
62 {
63  using namespace std;
64  using namespace JPP;
65 
66  JRootObjectID inputFile;
67  string outputFile;
68  int numberOfEntries;
69  int numberOfOutliers;
70  map_type y_expand;
71  map_type y_margin;
72  int debug;
73 
74  try {
75 
76  JParser<> zap("Auxiliary program to write test criteria to file.");
77 
78  zap['f'] = make_field(inputFile, "<input file>:<object name>");
79  zap['P'] = make_field(outputFile, "ASCII formatted output file with test criteria");
80  zap['N'] = make_field(numberOfEntries, "Minimal number of entries");
81  zap['O'] = make_field(numberOfOutliers, "Maximal number of outliers");
82  zap['Y'] = make_field(y_expand, "Expand range of values") = JPARSER::initialised();
83  zap['D'] = make_field(y_margin, "Margin range of values") = JPARSER::initialised();
84  zap['d'] = make_field(debug) = 1;
85 
86  zap(argc, argv);
87  }
88  catch(const exception &error) {
89  FATAL(error.what() << endl);
90  }
91 
92 
93  ofstream out(outputFile.c_str());
94 
95  if (out) {
96 
97  TDirectory* dir = getDirectory(inputFile);
98 
99  if (dir == NULL) {
100  FATAL("File: " << inputFile.getFullFilename() << " not opened." << endl);
101  }
102 
103  const TRegexp regexp(inputFile.getObjectName());
104 
105  TIter iter(dir->GetListOfKeys());
106 
107  for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
108 
109  const TString tag(key->GetName());
110 
111  DEBUG("Key: " << tag << " match = " << tag.Contains(regexp) << endl);
112 
113  // option match
114 
115  if (tag.Contains(regexp)) {
116 
117  TGraph* g1 = dynamic_cast<TGraph*>(key->ReadObj());
118 
119  if (g1 != NULL) {
120 
121  const JRange<double> range(g1->GetY(), g1->GetY() + g1->GetN());
122 
123  const double extra = (getValue(y_expand, tag, 0.0) * (range.getUpperLimit() - range.getLowerLimit()) +
124  getValue(y_margin, tag, 0.0));
125 
126  out << setw(64) << left << g1->GetName() << right << ' '
127  << setw(5) << numberOfEntries << ' '
128  << setw(3) << numberOfOutliers << ' '
129  << FIXED(15,3) << range.getLowerLimit() - extra << ' '
130  << FIXED(15,3) << range.getUpperLimit() + extra << endl;
131  }
132  }
133  }
134  } else {
135  FATAL("Error opening file: " << outputFile << endl);
136  }
137 }
Utility class to parse command line options.
Definition: JParser.hh:1500
double getValue(const JScale_t scale)
Get numerical value corresponding to scale.
Definition: JScale.hh:47
int main(int argc, char *argv[])
Definition: Main.cc:15
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:66
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
string outputFile
I/O formatting auxiliaries.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
int debug
debug level
Definition: JSirene.cc:63
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
z range($ZMAX-$ZMIN)< $MINIMAL_DZ." fi fi typeset -Z 4 STRING typeset -Z 2 FLOOR JPlot1D -f $
Auxiliary class to define a range between two values.
Utility class to parse command line options.
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
TDirectory * getDirectory(const JRootObjectID &id)
Get TDirectory pointer.
Double_t g1(const Double_t x)
Function.
Definition: JQuantiles.cc:25