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