Jpp  16.0.2
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 
12 
13 #include "JDAQ/JDAQEventIO.hh"
14 #include "JDAQ/JDAQTimesliceIO.hh"
16 
19 
20 #include "JROOT/JTreeParameters.hh"
21 #include "JROOT/JTreeReader.hh"
22 #include "JSupport/JSupport.hh"
23 
24 #include "JLang/JSinglePointer.hh"
25 #include "JLang/JBool.hh"
26 #include "JLang/JType.hh"
27 #include "JLang/JTypeList.hh"
28 #include "JLang/JNullType.hh"
29 
30 #include "Jeep/JParser.hh"
31 #include "Jeep/JMessage.hh"
32 
33 
34 namespace {
35 
36  using namespace JPP;
37 
38 
39  /**
40  * Auxiliary class to build list of valid TreeReader pointers.
41  */
42  class JTreeList :
43  public std::vector< JSinglePointer<JAbstractTreeReader> >
44  {
45  public:
46  /**
47  * Constructor.
48  *
49  * \param typelist type list
50  */
51  template<class T>
52  JTreeList(JType<T> typelist)
53  {
54  for_each(*this, typelist);
55  }
56 
57 
58  /**
59  * Addition of class.
60  *
61  * \param type type
62  */
63  template<class T>
64  void operator()(JType<T> type)
65  {
67  }
68 
69  private:
70  /**
71  * Addition of TTree compatible class.
72  */
73  template<class T>
74  void add(JType<T>, JBool<true>)
75  {
76  this->push_back(new JTreeReader<T>());
77  }
78 
79 
80  /**
81  * No addition of TTree incompatible class.
82  */
83  template<class T>
84  void add(JType<T>, JBool<false>)
85  {}
86  };
87 }
88 
89 
90 /**
91  * \file
92  *
93  * Auxiliary program to print ROOT TTree information.
94  * \author mdejong
95  */
96 int main(int argc, char **argv)
97 {
98  using namespace std;
99 
100  vector<string> inputFile;
101  int debug;
102 
103  try {
104 
105  JParser<> zap("Auxiliary program to print ROOT TTree information.");
106 
107  zap['f'] = make_field(inputFile);
108  zap['d'] = make_field(debug) = 1;
109 
110  zap(argc, argv);
111  }
112  catch(const exception &error) {
113  FATAL(error.what() << endl);
114  }
115 
116  cout.tie(&cerr);
117 
118  gErrorIgnoreLevel = kFatal;
119 
121 
122  JTreeList inspector(typelist);
123 
124  int number_of_errors = 0;
125 
126  for (vector<string>::const_iterator file_name = inputFile.begin(); file_name != inputFile.end(); ++file_name) {
127 
128  TFile* fp = TFile::Open(file_name->c_str());
129 
130  cout << *file_name << flush;
131 
132  if (fp != NULL) {
133 
134  cout << endl;
135 
136  for (JTreeList::iterator i = inspector.begin(); i != inspector.end(); ++i) {
137 
138  if ((*i)->load(fp)) {
139  cout << setw(24) << left << (**i)->GetName() << ' '
140  << setw(32) << left << (*i)->getDictionary()->GetName() << ' '
141  << setw(10) << right << (**i)->GetEntries() << ' '
142  << setw( 6) << right << ((**i)->GetTotBytes() >> 20) << " [MB]" << endl;
143  }
144  }
145 
146  } else {
147 
148  ++number_of_errors;
149 
150  cout << " not opened." << endl;
151  }
152  }
153 
154  return (number_of_errors == 0 ? 0 : 1);
155 }
Utility class to parse command line options.
Definition: JParser.hh:1500
int main(int argc, char *argv[])
Definition: Main.cc:15
ROOT TTree parameter settings of various packages.
Test availability of TTree parameters for given class.
Auxiliary class for a type holder.
Definition: JType.hh:19
TTree reading for template data type.
Auxiliary template class for type bool.
Definition: JBool.hh:20
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
int debug
debug level
Definition: JSirene.cc:63
General purpose messaging.
Auxiliary class for template TTree reading.
Definition: JTreeReader.hh:54
JObject_t & for_each(JObject_t &object, JType< JTypeList< JHead_t, JTail_t > > typelist)
For each data type method.
Definition: JTypeList.hh:415
#define FATAL(A)
Definition: JMessage.hh:67
Utility class to parse command line options.