#include #include #include #include #include #include #include #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/JGraph.hh" #include "JROOT/JRootToolkit.hh" #include "JTools/JRange.hh" #include "Jeep/JPrint.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" namespace { /** * Auxiliary data structure for book keeping of histograms. */ struct JKey_t { /** * Constuctor. * * \param string string * \param floor floor * \param parameter parameter */ JKey_t(const int string, const int floor, const std::string& parameter) : string (string), floor (floor), parameter(parameter) {} /** * Less-than operator. * * \param first first key * \param second second key * \return true if first key before second key; else false */ friend inline bool operator<(const JKey_t& first, const JKey_t& second) { if (first.string == second.string) { if (first.floor == second.floor) return first.parameter < second.parameter; else return first.floor < second.floor; } else { return first.string < second.string; } } /** * Convert to string. * * \return string */ std::string toString() const { std::ostringstream os; os << *this; return os.str(); } /** * Write key to output stream. * * \param output output stream * \param object key * \return output stream */ friend inline std::ostream& operator<<(std::ostream& out, const JKey_t& object) { using namespace std; return out << setw(3) << setfill('0') << object.string << '.' << setw(2) << setfill('0') << object.floor << '.' << setfill(' ') << object.parameter; } int string; int floor; std::string parameter; }; } /** * \file * * Auxiliary program to convert ROOT TTree with slow control data to ROOT TGraph's. * \author mdejong */ int main(int argc, char **argv) { using namespace std; using namespace JPP; JMultipleFileScanner inputFile; JLimit_t& numberOfEvents = inputFile.getLimit(); string outputFile; set filter; int debug; try { JParser<> zap("Auxiliary program to convert ROOT TTree with slow control data to ROOT TGraph's."); zap['f'] = make_field(inputFile, "ROOT input file (output file of JTuna)."); zap['n'] = make_field(numberOfEvents) = JLimit::max(); zap['o'] = make_field(outputFile, "ROOT output file"); zap['F'] = make_field(filter, "filter") = JPARSER::initialised(); zap['d'] = make_field(debug) = 2; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } map data; set strings; set floors; long long int counter = 0; for (inputFile.rewind(); inputFile.hasNext(); ++counter) { STATUS(setw(10) << counter << '\r'); DEBUG(endl); JDatalog* p = inputFile.next(); if (filter.count(p->parameter) == 0) { JGraph_t& g1 = data[JKey_t(p->string, p->floor, p->parameter)]; g1.put(p->getTime(), p->value); strings.insert(p->string); floors .insert(p->floor); } } STATUS(endl); TFile out(outputFile.c_str(), "recreate"); for (map::iterator i = data.begin(); i != data.end(); ++i) { JGraph g1(i->second, i->first.toString().c_str()); const JRange range(i->second.Y.begin(), i->second.Y.end()); g1.SetMinimum(range.getLowerLimit()); g1.SetMaximum(range.getUpperLimit()); out << g1; } ostringstream os; os << "set_variable NUMBER_OF_STRINGS " << setw(4) << strings.size() << ";" << endl; os << "set_variable NUMBER_OF_FLOORS " << setw(4) << floors. size() << ";" << endl; if (!strings.empty()) { os << "set_variable FIRST_STRING " << setw(4) << *strings. begin() << ";" << endl; os << "set_variable LAST_STRING " << setw(4) << *strings.rbegin() << ";" << endl; } if (!floors.empty()) { os << "set_variable FIRST_FLOOR " << setw(4) << *floors. begin() << ";" << endl; os << "set_variable LAST_FLOOR " << setw(4) << *floors. rbegin() << ";" << endl; } os << "set_array STRINGS "; copy(strings.begin(), strings.end(), ostream_iterator(os, " ")); os << endl; TNamed meta("TUNA", os.str().c_str()); out << meta; out.Write(); out.Close(); }