Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
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
27namespace {
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 */
116int main(int argc, char **argv)
117{
118 using namespace std;
119 using namespace JPP;
120
122 JLimit_t& numberOfEvents = inputFile.getLimit();
123 string outputFile;
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
146 set<int> strings;
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}
string outputFile
ROOT TTree parameter settings.
General purpose messaging.
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define STATUS(A)
Definition JMessage.hh:63
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
Scanning of objects from multiple files according a format that follows from the extension of each fi...
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
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.
int main(int argc, char **argv)
Utility class to parse command line options.
Definition JParser.hh:1698
General purpose class for object reading from a list of file names.
virtual void rewind() override
Rewind.
virtual bool hasNext() override
Check availability of next element.
virtual const pointer_type & next() override
Get next element.
Range of values.
Definition JRange.hh:42
T getLowerLimit() const
Get lower limit.
Definition JRange.hh:202
T getUpperLimit() const
Get upper limit.
Definition JRange.hh:213
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition JHead.cc:163
bool operator<(const Head &first, const Head &second)
Less than operator.
Definition JHead.hh:1817
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
bool filter(const JDAQEvent &tev, const JEvt &evt, const Evt *const pE)
Event selection.
JWriter & operator<<(JWriter &out, const JDAQChronometer &chronometer)
Write DAQ chronometer to output.
double getTime() const
Get time.
Definition JDatalog.hh:65
std::string parameter
Definition JDatalog.hh:74
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition JParser.hh:68
Auxiliary data structure to build TGraph.
Definition JGraph.hh:44
Auxiliary class for defining the range of iterations of objects.
Definition JLimit.hh:45
static counter_type max()
Get maximum counter value.
Definition JLimit.hh:128