Jpp  18.3.1
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 "JSystem/JGlob.hh"
#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 24 of file JPrintTree.cc.

25 {
26  using namespace std;
27  using namespace JPP;
28 
29  vector<string> inputFile;
30  int debug;
31 
32  try {
33 
34  JParser<> zap("Auxiliary program to print ROOT TTree information.");
35 
36  zap['f'] = make_field(inputFile);
37  zap['d'] = make_field(debug) = 1;
38 
39  zap(argc, argv);
40  }
41  catch(const exception &error) {
42  FATAL(error.what() << endl);
43  }
44 
45  gErrorIgnoreLevel = kFatal;
46 
47  inputFile = getFilenames(inputFile);
48 
49  int number_of_errors = 0;
50 
51  for (vector<string>::const_iterator file_name = inputFile.begin(); file_name != inputFile.end(); ++file_name) {
52 
53  TFile* file = TFile::Open(file_name->c_str());
54 
55  cout << *file_name << flush;
56 
57  if (file != NULL) {
58 
59  cout << endl;
60 
61  TIter iter(file->GetListOfKeys(), kIterBackward);
62 
63  for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
64 
65  TKey* p = dynamic_cast<TKey*>(file->GetListOfKeys()->Before(key));
66 
67  if (p == NULL || strcmp(key->GetName(), p->GetName()) != 0) { // select last key
68 
69  TTree* tree = dynamic_cast<TTree*>(key->ReadObj());
70 
71  if (tree != NULL) {
72 
73  TBranch* branch = dynamic_cast<TBranch*>(tree->GetListOfBranches()->At(0)); // KM3NeT policy
74 
75  if (branch != NULL) {
76  cout << setw(24) << left << key->GetName() << ' '
77  << setw(32) << left << branch->GetClassName() << ' '
78  << setw(10) << right << tree->GetEntries() << ' '
79  << setw( 6) << right << (tree->GetTotBytes() >> 20) << " [MB]" << endl;
80  }
81  }
82  }
83  }
84 
85  file->Close();
86 
87  delete file;
88 
89  } else {
90 
91  ++number_of_errors;
92 
93  cout << " not opened." << endl;
94  }
95  }
96 
97  return (number_of_errors == 0 ? 0 : 1);
98 }
Utility class to parse command line options.
Definition: JParser.hh:1514
then usage $script[< detector identifier >< run range >]< QA/QCfile > nExample script to produce data quality plots nWhen a detector identifier and run range are data are downloaded from the database nand subsequently stored in the given QA QC file
Definition: JDataQuality.sh:19
static JGlob getFilenames
Function object to get list of files for given pattern.
Definition: JGlob.hh:127
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
#define FATAL(A)
Definition: JMessage.hh:67
int debug
debug level