Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
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
14
17
18
19namespace {
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 */
78int main(int argc, char** argv) {
79
80 using namespace JPP;
81 using namespace std;
82
83 string steeringFile;
84
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
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}
int main(int argc, char **argv)
#define ERROR(A)
Definition JMessage.hh:66
ROOT I/O of application specific meta data.
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
Dictionary to map different tests to unique integer indices.
Utility class to parse command line options.
Definition JParser.hh:1698
TDirectory * getDirectory(const JRootObjectID &id)
Get TDirectory pointer.
bool isTObject(const TKey *key)
Check if given key corresponds to a TObject.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary class for ROOT I/O of application specific meta data.
Definition JMeta.hh:72