Jpp - the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JMantisShrimp.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <fstream>
3 
4 #include "TString.h"
5 #include "TRegexp.h"
6 #include "TFile.h"
7 
8 #include "Jeep/JParser.hh"
9 #include "JTest_t.hh"
10 #include "JTestDictionary.hh"
11 #include "JGizmo/JRootObjectID.hh"
12 #include "JGizmo/JGizmoToolkit.hh"
13 #include "JSupport/JMeta.hh"
14 
15 using namespace JPP;
16 using namespace std;
17 
18 /*
19  * Reads a list of JRootObjectID and returns a list of pointers to the corresponding objects.
20  *
21  * \param listOfPatterns The list of root object identifiers.
22  * \return vector with TObject*
23  */
25 
26  vector<TObject*> listOfObjects;
27 
28  for (vector<JRootObjectID>::const_iterator pattern = listOfPatterns.begin(); pattern != listOfPatterns.end(); ++pattern) {
29 
30  TDirectory* dir = getDirectory(*pattern);
31 
32  if (dir == NULL) {
33  ERROR("File: " << pattern->getFullFilename() << " not opened." << endl);
34  continue;
35  }
36 
37  const TRegexp regexp(pattern->getObjectName());
38 
39  TIter iter(dir->GetListOfKeys());
40 
41  for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
42 
43  const TString tag(key->GetName());
44 
45  if (tag.Contains(regexp)) {
46 
47  TObject* p = key->ReadObj();
48  p->SetUniqueID(dir->GetUUID().GetUUIDNumber());
49  listOfObjects.push_back(p);
50  }
51  }
52  }
53  return listOfObjects;
54 }
55 
56 /**
57  * \file
58  *
59  * Program to compare root histograms.\n
60  * The input histograms and the test to be applied for each histogram are specified\n
61  * through the command line.\n\n
62  *
63  * The histogram names are treated as regular expressions. Therefore, multiple histograms could be tested on one shot.\n
64  *
65  * The command line argument specifies the test to be performed, and the corresponding parameters. See JTestDictionary()\n
66  *
67  * \author rgruiz
68  */
69 int main(int argc, char** argv) {
70 
71  string steeringFile;
72 
73  vector<JRootObjectID> input_a;
74  vector<JRootObjectID> input_b;
75  string test;
76  string output;
77  string ascii;
78  bool onlyFailures;
79 
80  try {
81  JParser<> zap("\nProgram to compare root histograms. See the link below this usage for further details.\n");
82  zap['a'] = make_field(input_a, "Histogram a");
83  zap['b'] = make_field(input_b, "Histogram b");
84  zap['t'] = make_field(test, "Test parameters");
85  zap['o'] = make_field(output, "output file") = "out.root";
86  zap['t'] = make_field(ascii , "output file txt" ) = " ";
87  zap['w'] = make_field(onlyFailures , "write only failed tests" );
88 
89  zap(argc,argv);
90  }
91  catch(const exception &error) {
92  ERROR(error.what() << endl);
93  }
94 
96 
97  int testID;
98 
99  istringstream iss(test);
100  iss >> testID;
101  d[testID]->read(iss);
102 
103  vector<TObject*> listOfObjects_a = getListOfObjects(input_a);
104  vector<TObject*> listOfObjects_b = getListOfObjects(input_b);
105 
106  for(vector<TObject*>::const_iterator object_a = listOfObjects_a.begin() ; object_a != listOfObjects_a.end() ; ++object_a){
107  for(vector<TObject*>::const_iterator object_b = listOfObjects_b.begin() ; object_b != listOfObjects_b.end() ; ++object_b){
108 
109  d[testID]->test(*object_a,*object_b);
110  }
111  }
112 
113  TFile out(output.c_str(),"recreate");
114  out.cd();
115 
116  d[testID]->write(cout);
117  d[testID]->save(&out, "", onlyFailures);
118 
119  if(ascii != " "){
120  ofstream results;
121  results.open (ascii);
122  d[testID]->write(results, ";", onlyFailures);
123  results.close();
124  }
125 
126  putObject(&out, JMeta(argc, argv));
127 
128  out.Close();
129 
130  return 0;
131 }
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:70
Utility class to parse command line options.
Definition: JParser.hh:1500
int main(int argc, char *argv[])
Definition: Main.cc:15
vector< TObject * > getListOfObjects(vector< JRootObjectID > listOfPatterns)
Definition: JRoot.hh:19
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
ROOT I/O of application specific meta data.
#define ERROR(A)
Definition: JMessage.hh:66
then JMuonMCEvt f $INPUT_FILE o $INTERMEDIATE_FILE d
Definition: JMuonPath.sh:45
Utility class to parse command line options.
TDirectory * getDirectory(const JRootObjectID &id)
Get TDirectory pointer.
bool putObject(TDirectory *dir, const T &object)
Write object to ROOT directory.