Jpp
Functions
JTuna2Graph.cc File Reference
#include <string>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <iterator>
#include <set>
#include <map>
#include "TROOT.h"
#include "TFile.h"
#include "TGraph.h"
#include "TTimeStamp.h"
#include "TNamed.h"
#include "JDB/JDatalog.hh"
#include "JDB/JSupport.hh"
#include "JSupport/JMultipleFileScanner.hh"
#include "JROOT/JRootToolkit.hh"
#include "JTools/JRange.hh"
#include "Jeep/JPrint.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Auxiliary program to convert ROOT TTree with slow control data to ROOT TGraph's.

Author
mdejong

Definition in file JTuna2Graph.cc.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 115 of file JTuna2Graph.cc.

116 {
117  using namespace std;
118  using namespace JPP;
119 
121  JLimit_t& numberOfEvents = inputFile.getLimit();
122  string outputFile;
123  set<string> filter;
124  int debug;
125 
126  try {
127 
128  JParser<> zap("Auxiliary program to convert ROOT TTree with slow control data to ROOT TGraph's.");
129 
130  zap['f'] = make_field(inputFile, "ROOT input file (output file of JTuna).");
131  zap['n'] = make_field(numberOfEvents) = JLimit::max();
132  zap['o'] = make_field(outputFile, "ROOT output file");
133  zap['F'] = make_field(filter, "filter") = JPARSER::initialised();
134  zap['d'] = make_field(debug) = 2;
135 
136  zap(argc, argv);
137  }
138  catch(const exception &error) {
139  FATAL(error.what() << endl);
140  }
141 
142 
143  struct JGraph_t {
144 
145  void put(const Double_t x, const Double_t y)
146  {
147  X.push_back(x);
148  Y.push_back(y);
149  }
150 
151  vector<double> X;
152  vector<double> Y;
153  };
154 
155 
157 
158  set<int> strings;
159  set<int> floors;
160 
161  long long int counter = 0;
162 
163  for (inputFile.rewind(); inputFile.hasNext(); ++counter) {
164 
165  STATUS(setw(10) << counter << '\r'); DEBUG(endl);
166 
167  JDatalog* p = inputFile.next();
168 
169  if (filter.count(p->parameter) == 0) {
170 
171  JGraph_t& g1 = data[JKey_t(p->string, p->floor, p->parameter)];
172 
173  g1.put(p->getTime(), p->value);
174 
175  strings.insert(p->string);
176  floors .insert(p->floor);
177  }
178  }
179  STATUS(endl);
180 
181 
182  TFile out(outputFile.c_str(), "recreate");
183 
184  for (map<JKey_t, JGraph_t>::iterator i = data.begin(); i != data.end(); ++i) {
185 
186  TGraph g1(i->second.X.size(), i->second.X.data(), i->second.Y.data());
187 
188  g1.SetName(i->first.toString().c_str());
189 
190  const JRange<double> range(i->second.Y.begin(), i->second.Y.end());
191 
192  g1.SetMinimum(range.getLowerLimit());
193  g1.SetMaximum(range.getUpperLimit());
194 
195  out << g1;
196  }
197 
198  ostringstream os;
199 
200  os << "set_variable NUMBER_OF_STRINGS " << setw(4) << strings.size() << ";" << endl;
201  os << "set_variable NUMBER_OF_FLOORS " << setw(4) << floors. size() << ";" << endl;
202  if (!strings.empty()) {
203  os << "set_variable FIRST_STRING " << setw(4) << *strings. begin() << ";" << endl;
204  os << "set_variable LAST_STRING " << setw(4) << *strings.rbegin() << ";" << endl;
205  }
206  if (!floors.empty()) {
207  os << "set_variable FIRST_FLOOR " << setw(4) << *floors. begin() << ";" << endl;
208  os << "set_variable LAST_FLOOR " << setw(4) << *floors. rbegin() << ";" << endl;
209  }
210  os << "set_array STRINGS ";
211  copy(strings.begin(), strings.end(), ostream_iterator<int>(os, " "));
212  os << endl;
213 
214  TNamed meta("TUNA", os.str().c_str());
215 
216  out << meta;
217 
218  out.Write();
219  out.Close();
220 }
JSUPPORT::JLimit
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
g1
Double_t g1(const Double_t x)
Function.
Definition: JQuantiles.cc:25
JPARSER::initialised
Empty structure for specification of parser element that is initialised (i.e.
Definition: JParser.hh:63
JDATABASE::JDatalog::parameter
std::string parameter
Definition: JDatalog.hh:74
std::vector< double >
JTOOLS::JRange< double >
JPARSER::JParser
Utility class to parse command line options.
Definition: JParser.hh:1493
JAANET::copy
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:152
std::set
Definition: JSTDTypes.hh:13
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JDATABASE::JDatalog::value
double value
Definition: JDatalog.hh:76
debug
int debug
debug level
Definition: JSirene.cc:59
JSUPPORT::JMultipleFileScanner::next
virtual const pointer_type & next()
Get next element.
Definition: JMultipleFileScanner.hh:398
std::map
Definition: JSTDTypes.hh:16
JDATABASE::JDatalog::floor
int floor
Definition: JDatalog.hh:72
STATUS
#define STATUS(A)
Definition: JMessage.hh:63
JSUPPORT::JMultipleFileScanner::hasNext
virtual bool hasNext()
Check availability of next element.
Definition: JMultipleFileScanner.hh:350
JDATABASE::JDatalog::getTime
double getTime() const
Get time.
Definition: JDatalog.hh:65
JDATABASE::JDatalog
Definition: JDatalog.hh:17
JSUPPORT::JMultipleFileScanner::rewind
virtual void rewind()
Rewind.
Definition: JMultipleFileScanner.hh:332
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
JSUPPORT::JMultipleFileScanner
General purpose class for object reading from a list of file names.
Definition: JMultipleFileScanner.hh:167
DEBUG
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
std
Definition: jaanetDictionary.h:36
JDATABASE::JDatalog::string
int string
Definition: JDatalog.hh:71
FATAL
#define FATAL(A)
Definition: JMessage.hh:67
outputFile
string outputFile
Definition: JDAQTimesliceSelector.cc:37