Jpp  17.0.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JPrintTree.cc
Go to the documentation of this file.
1 
2 #include <string>
3 #include <iostream>
4 #include <iomanip>
5 
6 #include "TError.h"
7 #include "TROOT.h"
8 #include "TFile.h"
9 #include "TKey.h"
10 #include "TTree.h"
11 
12 #include "Jeep/JParser.hh"
13 #include "Jeep/JMessage.hh"
14 
15 
16 /**
17  * \file
18  *
19  * Auxiliary program to print ROOT TTree information.
20  * \author mdejong
21  */
22 int main(int argc, char **argv)
23 {
24  using namespace std;
25 
26  vector<string> inputFile;
27  int debug;
28 
29  try {
30 
31  JParser<> zap("Auxiliary program to print ROOT TTree information.");
32 
33  zap['f'] = make_field(inputFile);
34  zap['d'] = make_field(debug) = 1;
35 
36  zap(argc, argv);
37  }
38  catch(const exception &error) {
39  FATAL(error.what() << endl);
40  }
41 
42  cout.tie(&cerr);
43 
44  gErrorIgnoreLevel = kFatal;
45 
46  int number_of_errors = 0;
47 
48  for (vector<string>::const_iterator file_name = inputFile.begin(); file_name != inputFile.end(); ++file_name) {
49 
50  TFile* file = TFile::Open(file_name->c_str());
51 
52  cout << *file_name << flush;
53 
54  if (file != NULL) {
55 
56  cout << endl;
57 
58  TIter iter(file->GetListOfKeys(), kIterBackward);
59 
60  for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
61 
62  TKey* p = dynamic_cast<TKey*>(file->GetListOfKeys()->Before(key));
63 
64  if (p == NULL || strcmp(key->GetName(), p->GetName()) != 0) { // select last key
65 
66  TTree* tree = dynamic_cast<TTree*>(key->ReadObj());
67 
68  if (tree != NULL) {
69 
70  TBranch* branch = dynamic_cast<TBranch*>(tree->GetListOfBranches()->At(0)); // KM3NeT policy
71 
72  if (branch != NULL) {
73  cout << setw(24) << left << key->GetName() << ' '
74  << setw(32) << left << branch->GetClassName() << ' '
75  << setw(10) << right << tree->GetEntries() << ' '
76  << setw( 6) << right << (tree->GetTotBytes() >> 20) << " [MB]" << endl;
77  }
78  }
79  }
80  }
81 
82  } else {
83 
84  ++number_of_errors;
85 
86  cout << " not opened." << endl;
87  }
88  }
89 
90  return (number_of_errors == 0 ? 0 : 1);
91 }
Utility class to parse command line options.
Definition: JParser.hh:1500
int main(int argc, char *argv[])
Definition: Main.cc:15
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
int debug
debug level
Definition: JSirene.cc:66
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Utility class to parse command line options.