Jpp  16.0.0-rc.1
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 "JLang/JPredicate.hh"
#include "JCompareHistograms/JTest_t.hh"
#include "JCompareHistograms/JTestDictionary.hh"
#include "JGizmo/JRootObjectID.hh"

Go to the source code of this file.

Functions

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, bjung

Definition in file JZebraMantis.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 73 of file JZebraMantis.cc.

73  {
74 
75  using namespace JPP;
76  using namespace std;
77 
78  string steeringFile;
79 
80  string file1;
81  string file2;
82 
83  string output;
84  string ascii;
85 
86  vector<string> keys;
87 
88  bool onlyFailures;
89 
90  int debug;
91 
92  const array_type<string>& listOfKeys = get_keys(JTestSummary().getProperties());
93 
94  try {
95 
96  const string& keysExplainer = MAKE_STRING("Terminal output:" << endl << listOfKeys);
97 
98  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");
99 
100  zap['s'] = make_field(steeringFile , "ASCII steering file with list of histograms and tests");
101  zap['a'] = make_field(file1 , "input file 1");
102  zap['b'] = make_field(file2 , "input file 2");
103  zap['o'] = make_field(output , "output file root") = "zebramantis.root";
104  zap['t'] = make_field(ascii , "output file txt" ) = "zebramantis.txt";
105  zap['k'] = make_field(keys , keysExplainer ) = JPARSER::initialised();
106  zap['w'] = make_field(onlyFailures , "write only failed tests" );
107  zap['d'] = make_field(debug) = 2;
108 
109  zap(argc,argv);
110  }
111  catch(const exception &error) {
112  ERROR(error.what() << endl);
113  }
114 
115  if (keys.empty()) {
116  keys = listOfKeys;
117  }
118 
119  TFile* f1 = TFile::Open(file1.c_str());
120  TFile* f2 = TFile::Open(file2.c_str());
121 
122  TFile out(output.c_str(),"recreate");
123 
124  ofstream results;
125  results.open (ascii);
126  results << "# " << listOfKeys << endl;
127 
128  vector<JRootObjectID> objectIDs;
129  readDir(f1,objectIDs);
130 
131  std::ifstream infile(steeringFile);
132 
133  JTestDictionary d;
134 
135  size_t npassed = 0;
136  size_t nfailed = 0;
137 
138  for (string line; getline(infile, line); ) {
139 
140  istringstream iss(line);
141 
142  TString name;
143  int testID;
144 
145  if (!(iss >> name >> testID)) {
146  continue;
147  }
148 
149  const TRegexp regexp(name);
150 
151  for (vector<JRootObjectID>::const_iterator objectID = objectIDs.cbegin() ; objectID != objectIDs.cend() ; ++objectID) {
152 
153  const TString& objectDir = objectID->getDirectory();
154  const TString& objectName = objectID->getFullObjectName();
155 
156  if ((objectName.Index(regexp) != -1) && (f2->Get(objectName))) {
157 
158  TObject* obj1 = (TObject*)f1->Get(objectName);
159  TObject* obj2 = (TObject*)f2->Get(objectName);
160 
161  d[testID]->read(iss);
162  d[testID]->test(obj1,obj2);
163 
164  if (out.GetDirectory(objectDir)==0) {
165  out.mkdir(objectDir);
166  }
167 
168  out.cd(objectDir);
169 
170  for (vector<JTestResult>::iterator r = d[testID]->results.begin() ; r != d[testID]->results.end() ; ++r) {
171 
172  if (onlyFailures && r->passed) {
173  continue;
174  }
175 
176  print(cout, *r, keys.cbegin(), keys.cend(), ' ', false);
177  print(results, *r, listOfKeys.cbegin(), listOfKeys.cend(), ' ', true);
178 
179  r->obj->Write();
180  }
181 
182  const size_t Npass = count_if(d[testID]->results.cbegin(), d[testID]->results.cend(),
184 
185  npassed += Npass;
186  nfailed += (d[testID]->results.size() - Npass);
187 
188  d[testID]->clear();
189  }
190  }
191  }
192 
193  infile.close();
194 
195  results << WHITE << "# PASSED: " << npassed << " " << " FAILED: " << nfailed << " FAILURE FRACTION: " << float (nfailed)/(nfailed+npassed) << endl;
196 
197  putObject(&out, JMeta(argc, argv));
198  JMeta::copy(file1.c_str(), out);
199  JMeta::copy(file2.c_str(), out);
200 
201  results.close();
202  out .Close();
203 
204  return 0;
205 }
Utility class to parse command line options.
Definition: JParser.hh:1500
JPredicate< JResult_t T::*, JComparison::eq > make_predicate(JResult_t T::*member, const JResult_t value)
Helper method to create predicate for data member.
Definition: JPredicate.hh:128
JProperties & getProperties(T &object, const JEquationParameters &parameters=JEquationParameters(), const int debug=1)
Get properties of a given object.
static void copy(const char *const file_name, TFile &out)
Copy meta data.
Definition: JMeta.hh:421
then echo Enter input within $TIMEOUT_S seconds echo n User name
Definition: JCookie.sh:42
Definition: JRoot.hh:19
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:66
data_type r[M+1]
Definition: JPolint.hh:758
#define MAKE_STRING(A)
Make string.
Definition: JPrint.hh:142
#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
int debug
debug level
Definition: JSirene.cc:63
bool putObject(TDirectory &dir, const TObject &object)
Write object to ROOT directory.
print
Definition: JConvertDusj.sh:44
then JMuonMCEvt f $INPUT_FILE o $INTERMEDIATE_FILE d
Definition: JMuonPath.sh:47
const array_type< JKey_t > & get_keys(const std::map< JKey_t, JValue_t, JComparator_t, JAllocator_t > &data)
Method to create array of keys of map.
Definition: JVectorize.hh:139
void readDir(TDirectory *dir, std::vector< TString > &v)