Jpp  18.5.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 "JSystem/JGlob.hh"
13 
14 #include "Jeep/JParser.hh"
15 #include "Jeep/JMessage.hh"
16 
17 
18 /**
19  * \file
20  *
21  * Auxiliary program to print ROOT TTree information.
22  * \author mdejong
23  */
24 int main(int argc, char **argv)
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
int main(int argc, char *argv[])
Definition: Main.cc:15
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:123
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Utility class to parse command line options.
int debug
debug level
File list.