Jpp  pmt_effective_area_update_2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JZebraMantis.cc File Reference

Program to compare histograms in root files that have same directory structure,
and where the histograms have the same names. 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 that have same directory structure,
and where the histograms have the same names.

The input histograms and the test to be applied for each histogram are specified
in an ASCII formatted steering file which is passed by the command line.

Each row of the steering file should have multiple columns.

Column 1 is the name of the histogram to be compared (including the full path inside the root file)
Column 2 is an integer value that indicates the test to be performed. See JTestDictionary()
Columns 3..n are reserved for the different parameters of the test.

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 63 of file JZebraMantis.cc.

63  {
64 
65  string steeringFile;
66  string file1;
67  string file2;
68  string output;
69  string ascii;
70  bool onlyFailures;
71 
72 
73  try {
74  JParser<> zap("\nProgram to compare histograms in root files that have the same directory structure. See the link below this usage for further details.\n");
75  zap['s'] = make_field(steeringFile , "ASCII steering file with list of histograms and tests");
76  zap['a'] = make_field(file1 , "input file 1");
77  zap['b'] = make_field(file2 , "input file 2");
78  zap['o'] = make_field(output , "output file root") = "zebramantis.root";
79  zap['t'] = make_field(ascii , "output file txt" ) = "zebramantis.txt";
80  zap['w'] = make_field(onlyFailures , "write only failed tests" );
81  zap(argc,argv);
82  }
83  catch(const exception &error) {
84  ERROR(error.what() << endl);
85  }
86 
87  TFile* f1 = TFile::Open(file1.c_str());
88  TFile* f2 = TFile::Open(file2.c_str());
89 
90  TFile out(output.c_str(),"recreate");
91  out.cd();
92 
93  ofstream results;
94  results.open (ascii);
95 
96  vector<TString> keys;
97  readDir(f1,keys);
98 
99  std::ifstream infile(steeringFile);
100 
102 
103  TString name;
104  int testID;
105  string rest;
106 
107  int npassed = 0;
108  int nfailed = 0;
109 
110  for (vector<TString>::const_iterator key = keys.begin() ; key != keys.end() ; ++key) {
111 
112  string line;
113  while (getline(infile, line)) {
114  while (line.length()==0)
115  getline(infile, line);
116 
117  istringstream iss(line);
118  iss >> name >> testID;
119 
120  const TRegexp regexp(name);
121 
122  if (((*key).Index(regexp) != -1) && (f2->Get(*key))) {
123 
124  TObject* obj1 = (TObject*)f1->Get(*key);
125  TObject* obj2 = (TObject*)f2->Get(*key);
126 
127  d[testID]->read(iss);
128  d[testID]->test(obj1,obj2);
129 
130  for (vector<JTestResult>::const_iterator r = d[testID]->results.begin() ; r != d[testID]->results.end() ; ++r) {
131  (r->passed ? npassed++ : nfailed++);
132  }
133 
134  string Key = MAKE_STRING(*key);
135  string path = MAKE_STRING(Key.substr (Key.find ('/') + 1 , Key.rfind ('/')));
136 
137  d[testID]->write(cout);
138  d[testID]->write(results, ";", onlyFailures);
139  d[testID]->save (&out, path, onlyFailures);
140  d[testID]->clear();
141  }
142  }
143  infile.clear();
144  infile.seekg(0, ios::beg);
145  }
146 
147  results << WHITE << "PASSED: " << npassed << " " << " FAILED: " << nfailed << " FAILURE FRACTION: " << float (nfailed)/(nfailed+npassed) << endl;
148 
149  putObject(&out, JMeta(argc, argv));
150  JMeta::copy(file1.c_str(), out);
151  JMeta::copy(file2.c_str(), out);
152 
153  results.close();
154  out .Close();
155  return 0;
156 }
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
then echo Enter input within $TIMEOUT_S seconds echo n User name
Definition: JCookie.sh:42
bool putObject(TDirectory *dir, const TObject &object)
Write object to ROOT directory.
Definition: JRoot.hh:19
data_type r[M+1]
Definition: JPolint.hh:742
#define MAKE_STRING(A)
Make string.
Definition: JPrint.hh:142
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:1961
#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 JMuonMCEvt f $INPUT_FILE o $INTERMEDIATE_FILE d
Definition: JMuonPath.sh:47
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:139
void readDir(TDirectory *dir, vector< TString > &v)
Definition: JZebraMantis.cc:26