Jpp  18.0.1-rc.1
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  gErrorIgnoreLevel = kFatal;
43 
44  int number_of_errors = 0;
45 
46  for (vector<string>::const_iterator file_name = inputFile.begin(); file_name != inputFile.end(); ++file_name) {
47 
48  TFile* file = TFile::Open(file_name->c_str());
49 
50  cout << *file_name << flush;
51 
52  if (file != NULL) {
53 
54  cout << endl;
55 
56  TIter iter(file->GetListOfKeys(), kIterBackward);
57 
58  for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
59 
60  TKey* p = dynamic_cast<TKey*>(file->GetListOfKeys()->Before(key));
61 
62  if (p == NULL || strcmp(key->GetName(), p->GetName()) != 0) { // select last key
63 
64  TTree* tree = dynamic_cast<TTree*>(key->ReadObj());
65 
66  if (tree != NULL) {
67 
68  TBranch* branch = dynamic_cast<TBranch*>(tree->GetListOfBranches()->At(0)); // KM3NeT policy
69 
70  if (branch != NULL) {
71  cout << setw(24) << left << key->GetName() << ' '
72  << setw(32) << left << branch->GetClassName() << ' '
73  << setw(10) << right << tree->GetEntries() << ' '
74  << setw( 6) << right << (tree->GetTotBytes() >> 20) << " [MB]" << endl;
75  }
76  }
77  }
78  }
79 
80  } else {
81 
82  ++number_of_errors;
83 
84  cout << " not opened." << endl;
85  }
86  }
87 
88  return (number_of_errors == 0 ? 0 : 1);
89 }
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
#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