#include #include #include "TFile.h" #include "TString.h" #include "TRegexp.h" #include "Jeep/JParser.hh" #include "JSupport/JMeta.hh" #include "JGizmo/JRootObjectID.hh" #include "JGizmo/JGizmoToolkit.hh" #include "JCompareHistograms/JTest_t.hh" #include "JCompareHistograms/JTestDictionary.hh" namespace { /* * Reads a list of JRootObjectID and returns a list of pointers to the corresponding objects. * * \param listOfPatterns The list of root object identifiers. * \return vector with TObject* */ inline std::vector getListOfObjects(std::vector listOfPatterns) { using namespace std; using namespace JPP; vector listOfObjects; for (vector::const_iterator pattern = listOfPatterns.begin(); pattern != listOfPatterns.end(); ++pattern) { TDirectory* dir = getDirectory(*pattern); if (dir == NULL) { ERROR("File: " << pattern->getFullFilename() << " not opened." << endl); continue; } const TRegexp regexp(pattern->getObjectName()); TIter iter(dir->GetListOfKeys()); for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) { const TString tag(key->GetName()); if (tag.Contains(regexp) && isTObject(key)) { TObject* p = key->ReadObj(); p->SetUniqueID(dir->GetUUID().GetUUIDNumber()); listOfObjects.push_back(p); } } } return listOfObjects; } } /** * \file * * Program to compare root histograms.\n * The input histograms and the test to be applied for each histogram are specified\n * through the command line.\n\n * * The histogram names are treated as regular expressions. Therefore, multiple histograms could be tested on one shot.\n * * The command line argument specifies the test to be performed, and the corresponding parameters. See JTestDictionary()\n * * \author rgruiz */ int main(int argc, char** argv) { using namespace JPP; using namespace std; string steeringFile; vector input_a; vector input_b; string test; string output; string ascii; bool onlyFailures; try { JParser<> zap("\nProgram to compare root histograms. See the link below this usage for further details.\n"); zap['a'] = make_field(input_a, "Histogram a"); zap['b'] = make_field(input_b, "Histogram b"); zap['T'] = make_field(test, "Test parameters"); zap['o'] = make_field(output, "output file") = "out.root"; zap['t'] = make_field(ascii , "output file txt" ) = ""; zap['w'] = make_field(onlyFailures , "write only failed tests" ); zap(argc,argv); } catch(const exception &error) { ERROR(error.what() << endl); } JTestDictionary d; int testID; istringstream iss(test); iss >> testID; d[testID]->read(iss); vector listOfObjects_a = getListOfObjects(input_a); vector listOfObjects_b = getListOfObjects(input_b); for(vector::const_iterator object_a = listOfObjects_a.begin() ; object_a != listOfObjects_a.end() ; ++object_a){ for(vector::const_iterator object_b = listOfObjects_b.begin() ; object_b != listOfObjects_b.end() ; ++object_b){ d[testID]->test(*object_a,*object_b); } } TFile out(output.c_str(),"recreate"); out.cd(); d[testID]->write(cout); d[testID]->save(&out, "", onlyFailures); if(!ascii.empty()){ ofstream results; results.open (ascii); d[testID]->write(results, ';', onlyFailures); results.close(); } putObject(&out, JMeta(argc, argv)); out.Close(); return 0; }