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

Auxiliary program to print ROOT TTree information. More...

#include <string>
#include <iostream>
#include <iomanip>
#include "TError.h"
#include "TROOT.h"
#include "TFile.h"
#include "TKey.h"
#include "TTree.h"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Auxiliary program to print ROOT TTree information.

Author
mdejong

Definition in file JPrintTree.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 22 of file JPrintTree.cc.

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
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
int debug
debug level
Definition: JSirene.cc:66
#define FATAL(A)
Definition: JMessage.hh:67