#include #include #include #include #include #include #include "TROOT.h" #include "TFile.h" #include "TObject.h" #include "TKey.h" #include "TString.h" #include "TRegexp.h" #include "TGraph.h" #include "JGizmo/JRootObjectID.hh" #include "JGizmo/JGizmoToolkit.hh" #include "JTools/JRange.hh" #include "JLang/JLangToolkit.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" #include "Jeep/JPrint.hh" namespace { /** * Type definition of lookup table. */ typedef std::vector< std::pair > map_type; /** * Get value from lookup table. * * The return value is obtained in order of appearance in the lookup table using TRegexp. * * \param zmap lookup table * \param parameter parameter * \param value default value * \return value */ inline double getValue(const map_type& zmap, const TString& parameter, const double value) { for (map_type::const_iterator i = zmap.begin(); i != zmap.end(); ++i) { if (parameter.Contains(TRegexp(i->first.c_str()))) { return i->second; } } return value; } } /** * \file * * Auxiliary program to write test criteria to file. * The option -f corresponds to \:\. */ int main(int argc, char **argv) { using namespace std; using namespace JPP; JRootObjectID inputFile; string outputFile; int numberOfEntries; int numberOfOutliers; map_type y_expand; map_type y_margin; int debug; try { JParser<> zap("Auxiliary program to write test criteria to file."); zap['f'] = make_field(inputFile, ":"); zap['P'] = make_field(outputFile, "ASCII formatted output file with test criteria"); zap['N'] = make_field(numberOfEntries, "Minimal number of entries"); zap['O'] = make_field(numberOfOutliers, "Maximal number of outliers"); zap['Y'] = make_field(y_expand, "Expand range of values") = JPARSER::initialised(); zap['D'] = make_field(y_margin, "Margin range of values") = JPARSER::initialised(); zap['d'] = make_field(debug) = 1; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } ofstream out(outputFile.c_str()); if (out) { TDirectory* dir = getDirectory(inputFile); if (dir == NULL) { FATAL("File: " << inputFile.getFullFilename() << " not opened." << endl); } const TRegexp regexp(inputFile.getObjectName()); TIter iter(dir->GetListOfKeys()); for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) { const TString tag(key->GetName()); DEBUG("Key: " << tag << " match = " << tag.Contains(regexp) << endl); // option match if (tag.Contains(regexp) && isTObject(key)) { TGraph* g1 = dynamic_cast(key->ReadObj()); if (g1 != NULL) { const JRange range(g1->GetY(), g1->GetY() + g1->GetN()); const double extra = (getValue(y_expand, tag, 0.0) * (range.getUpperLimit() - range.getLowerLimit()) + getValue(y_margin, tag, 0.0)); out << setw(64) << left << g1->GetName() << right << ' ' << setw(5) << numberOfEntries << ' ' << setw(3) << numberOfOutliers << ' ' << FIXED(15,3) << range.getLowerLimit() - extra << ' ' << FIXED(15,3) << range.getUpperLimit() + extra << endl; } } } } else { FATAL("Error opening file: " << outputFile << endl); } }