Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JZebraMantis.cc File Reference

Program to compare histograms in root files with same directory structure. More...

#include <iostream>
#include <fstream>
#include "TString.h"
#include "TRegexp.h"
#include "TObjArray.h"
#include "TObjString.h"
#include "TFile.h"
#include "TKey.h"
#include "Jeep/JParser.hh"
#include "JSupport/JMeta.hh"
#include "JCompareHistograms/JTest_t.hh"
#include "JCompareHistograms/JTestDictionary.hh"

Go to the source code of this file.

Functions

void readDir (TDirectory *dir, vector< TString > &v)
 
int main (int argc, char **argv)
 

Detailed Description

Program to compare histograms in root files with same directory structure.

Author
rgruiz

Definition in file JZebraMantis.cc.

Function Documentation

void readDir ( TDirectory *  dir,
vector< TString > &  v 
)
inline

Definition at line 26 of file JZebraMantis.cc.

26  {
27 
28  TIter iter(dir->GetListOfKeys());
29 
30  for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
31 
32  if (key->IsFolder()){
33 
34  dir->cd(key->GetName());
35  TDirectory *subdir = gDirectory;
36  readDir(subdir,v);
37  dir->cd();
38  }else{
39 
40  const TString fullPath(dir->GetPath());
41  TObjArray* t = fullPath.Tokenize(":");
42  v.push_back(TString(((TObjString *)(t->At(1)))->String() + "/" + (TString)key->GetName()));
43  }
44  }
45 }
void readDir(TDirectory *dir, vector< TString > &v)
Definition: JZebraMantis.cc:26
int main ( int  argc,
char **  argv 
)

Definition at line 53 of file JZebraMantis.cc.

53  {
54 
55  string steeringFile;
56  string file1;
57  string file2;
58  string output;
59  string ascii;
60 
61  try {
62  JParser<> zap;
63  zap['s'] = make_field(steeringFile , "ASCII file with list of histograms and tests");
64  zap['a'] = make_field(file1 , "input file 1");
65  zap['b'] = make_field(file2 , "input file 2");
66  zap['o'] = make_field(output, "output file root") = "zebramantis.root";
67  zap['t'] = make_field(ascii , "output file txt" ) = "zebramantis.txt";
68  zap(argc,argv);
69  }
70  catch(const exception &error) {
71  ERROR(error.what() << endl);
72  }
73 
74  TFile* f1 = TFile::Open(file1.c_str());
75  TFile* f2 = TFile::Open(file2.c_str());
76 
77  TFile out(output.c_str(),"recreate");
78  out.cd();
79 
80  ofstream results;
81  results.open (ascii);
82 
83  vector<TString> keys;
84  readDir(f1,keys);
85 
86  TH1::AddDirectory(kFALSE);
87  TH2::AddDirectory(kFALSE);
88 
89  std::ifstream infile(steeringFile);
90 
91  JTestDictionary d;
92 
93  TString name;
94  int testID;
95  string rest;
96 
97  int npassed = 0;
98  int nfailed = 0;
99 
100  for (vector<TString>::const_iterator key = keys.begin() ; key != keys.end() ; ++key) {
101 
102  string line;
103  while (getline(infile, line)) {
104 
105  istringstream iss(line);
106  iss >> name >> testID;
107 
108  const TRegexp regexp(name);
109 
110  if (((*key).Index(regexp) != -1) && (f2->Get(*key))) {
111 
112  TObject* obj1 = (TObject*)f1->Get(*key);
113  TObject* obj2 = (TObject*)f2->Get(*key);
114 
115  d[testID]->read(iss);
116  d[testID]->test(obj1,obj2);
117 
118  for (vector<JTestResult>::const_iterator r = d[testID]->results.begin() ; r != d[testID]->results.end() ; ++r) {
119  (r->passed ? npassed++ : nfailed++);
120  }
121 
122  string Key = MAKE_STRING(*key);
123  string path = MAKE_STRING(Key.substr (Key.find ('/') + 1 , Key.rfind ('/')));
124 
125  d[testID]->write(cout);
126  d[testID]->write(results);
127  d[testID]->save(&out, path);
128  d[testID]->clear();
129  }
130  }
131  infile.clear();
132  infile.seekg(0, ios::beg);
133  }
134 
135  results << WHITE << "PASSED: " << npassed << " " << " FAILED: " << nfailed << " FAILURE FRACTION: " << float (nfailed)/(nfailed+npassed) << endl;
136 
137  putObject(&out, JMeta(argc, argv));
138  JMeta::copy(file1.c_str(), out);
139  JMeta::copy(file2.c_str(), out);
140 
141  results.close();
142  out .Close();
143  return 0;
144 }
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:71
Utility class to parse command line options.
Definition: JParser.hh:1493
Definition: JRoot.hh:19
data_type r[M+1]
Definition: JPolint.hh:709
#define MAKE_STRING(A)
Make string.
Definition: JPrint.hh:699
do cat driver txt<< EOFevent ev_configure{RC_EVT%< ev_configure.txt > RC_DWRT path
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
then print_variable DETECTOR INPUT_FILE INTERMEDIATE_FILE check_input_file $DETECTOR $INPUT_FILE check_output_file $INTERMEDIATE_FILE $OUTPUT_FILE JMCEvt f $INPUT_FILE o $INTERMEDIATE_FILE d
Definition: JPath.sh:52
#define ERROR(A)
Definition: JMessage.hh:66
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition: JString.hh:478
then echo n User name
Definition: JCookie.sh:45
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:153
void readDir(TDirectory *dir, vector< TString > &v)
Definition: JZebraMantis.cc:26
bool putObject(TDirectory *dir, const T &object)
Write object to ROOT directory.