Jpp  18.0.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JTuna2Graph.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <sstream>
4 #include <iomanip>
5 #include <iterator>
6 #include <set>
7 #include <map>
8 
9 #include "TROOT.h"
10 #include "TFile.h"
11 #include "TGraph.h"
12 #include "TTimeStamp.h"
13 #include "TNamed.h"
14 
15 #include "JDB/JDatalog.hh"
16 #include "JDB/JSupport.hh"
18 #include "JROOT/JGraph.hh"
19 #include "JROOT/JRootToolkit.hh"
20 #include "JTools/JRange.hh"
21 
22 #include "Jeep/JPrint.hh"
23 #include "Jeep/JParser.hh"
24 #include "Jeep/JMessage.hh"
25 
26 
27 namespace {
28 
29  /**
30  * Auxiliary data structure for book keeping of histograms.
31  */
32  struct JKey_t {
33  /**
34  * Constuctor.
35  *
36  * \param string string
37  * \param floor floor
38  * \param parameter parameter
39  */
40  JKey_t(const int string,
41  const int floor,
42  const std::string& parameter) :
43  string (string),
44  floor (floor),
45  parameter(parameter)
46  {}
47 
48 
49  /**
50  * Less-than operator.
51  *
52  * \param first first key
53  * \param second second key
54  * \return true if first key before second key; else false
55  */
56  friend inline bool operator<(const JKey_t& first, const JKey_t& second)
57  {
58  if (first.string == second.string) {
59 
60  if (first.floor == second.floor)
61  return first.parameter < second.parameter;
62  else
63  return first.floor < second.floor;
64 
65  } else {
66 
67  return first.string < second.string;
68  }
69  }
70 
71 
72  /**
73  * Convert to string.
74  *
75  * \return string
76  */
77  std::string toString() const
78  {
79  std::ostringstream os;
80 
81  os << *this;
82 
83  return os.str();
84  }
85 
86 
87  /**
88  * Write key to output stream.
89  *
90  * \param output output stream
91  * \param object key
92  * \return output stream
93  */
94  friend inline std::ostream& operator<<(std::ostream& out, const JKey_t& object)
95  {
96  using namespace std;
97 
98  return out << setw(3) << setfill('0') << object.string << '.'
99  << setw(2) << setfill('0') << object.floor << '.'
100  << setfill(' ') << object.parameter;
101  }
102 
103  int string;
104  int floor;
105  std::string parameter;
106  };
107 }
108 
109 
110 /**
111  * \file
112  *
113  * Auxiliary program to convert ROOT TTree with slow control data to ROOT TGraph's.
114  * \author mdejong
115  */
116 int main(int argc, char **argv)
117 {
118  using namespace std;
119  using namespace JPP;
120 
122  JLimit_t& numberOfEvents = inputFile.getLimit();
123  string outputFile;
124  set<string> filter;
125  int debug;
126 
127  try {
128 
129  JParser<> zap("Auxiliary program to convert ROOT TTree with slow control data to ROOT TGraph's.");
130 
131  zap['f'] = make_field(inputFile, "ROOT input file (output file of JTuna).");
132  zap['n'] = make_field(numberOfEvents) = JLimit::max();
133  zap['o'] = make_field(outputFile, "ROOT output file");
134  zap['F'] = make_field(filter, "filter") = JPARSER::initialised();
135  zap['d'] = make_field(debug) = 2;
136 
137  zap(argc, argv);
138  }
139  catch(const exception &error) {
140  FATAL(error.what() << endl);
141  }
142 
143 
145 
147  set<int> floors;
148 
149  long long int counter = 0;
150 
151  for (inputFile.rewind(); inputFile.hasNext(); ++counter) {
152 
153  STATUS(setw(10) << counter << '\r'); DEBUG(endl);
154 
155  JDatalog* p = inputFile.next();
156 
157  if (filter.count(p->parameter) == 0) {
158 
159  JGraph_t& g1 = data[JKey_t(p->string, p->floor, p->parameter)];
160 
161  g1.put(p->getTime(), p->value);
162 
163  strings.insert(p->string);
164  floors .insert(p->floor);
165  }
166  }
167  STATUS(endl);
168 
169 
170  TFile out(outputFile.c_str(), "recreate");
171 
172  for (map<JKey_t, JGraph_t>::iterator i = data.begin(); i != data.end(); ++i) {
173 
174  JGraph g1(i->second, i->first.toString().c_str());
175 
176  const JRange<double> range(i->second.Y.begin(), i->second.Y.end());
177 
178  g1.SetMinimum(range.getLowerLimit());
179  g1.SetMaximum(range.getUpperLimit());
180 
181  out << g1;
182  }
183 
184  ostringstream os;
185 
186  os << "set_variable NUMBER_OF_STRINGS " << setw(4) << strings.size() << ";" << endl;
187  os << "set_variable NUMBER_OF_FLOORS " << setw(4) << floors. size() << ";" << endl;
188  if (!strings.empty()) {
189  os << "set_variable FIRST_STRING " << setw(4) << *strings. begin() << ";" << endl;
190  os << "set_variable LAST_STRING " << setw(4) << *strings.rbegin() << ";" << endl;
191  }
192  if (!floors.empty()) {
193  os << "set_variable FIRST_FLOOR " << setw(4) << *floors. begin() << ";" << endl;
194  os << "set_variable LAST_FLOOR " << setw(4) << *floors. rbegin() << ";" << endl;
195  }
196  os << "set_array STRINGS ";
197  copy(strings.begin(), strings.end(), ostream_iterator<int>(os, " "));
198  os << endl;
199 
200  TNamed meta("TUNA", os.str().c_str());
201 
202  out << meta;
203 
204  out.Write();
205  out.Close();
206 }
Utility class to parse command line options.
Definition: JParser.hh:1514
int main(int argc, char *argv[])
Definition: Main.cc:15
double getTime() const
Get time.
Definition: JDatalog.hh:65
void put(const Double_t x, const Double_t y)
Put data.
Definition: JGraph.hh:28
Data structure for graph data.
Definition: JGraph.hh:21
bool operator<(const Head &first, const Head &second)
Less than operator.
Definition: JHead.hh:1799
#define STATUS(A)
Definition: JMessage.hh:63
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:83
then usage $script< detector specific pre-calibration script >< option > nAuxiliary script to make scan of pre stretching of detector strings(see JEditDetector)." "\nPossible options
Auxiliary data structure to build TGraph.
Definition: JGraph.hh:42
string outputFile
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
I/O formatting auxiliaries.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
then awk string
ROOT TTree parameter settings.
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Scanning of objects from multiple files according a format that follows from the extension of each fi...
z range($ZMAX-$ZMIN)< $MINIMAL_DZ." fi fi typeset -Z 4 STRING typeset -Z 2 FLOOR JPlot1D -f $
std::string parameter
Definition: JDatalog.hh:74
Auxiliary class to define a range between two values.
General purpose class for object reading from a list of file names.
Utility class to parse command line options.
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:162
std::ostream & operator<<(std::ostream &stream, const CLBCommonHeader &header)
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:84
int debug
debug level
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
Double_t g1(const Double_t x)
Function.
Definition: JQuantiles.cc:25