Jpp  master_rocky-43-ge265d140c
the software that should make you happy
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 "JLang/JEquals.hh"
#include "JLang/JVectorize.hh"
#include "Jeep/JeepToolkit.hh"
#include "Jeep/JProperties.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

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 157 of file JPrintTree.cc.

158 {
159  using namespace std;
160  using namespace JPP;
161 
162  vector<string> inputFile;
163  tree_info ta; // selection
164  tree_info tb; // actual
165  string key; // format
166  int debug;
167 
168  JProperties format;
169 
170  format.insert(gmake_property(tb.name));
171  format.insert(gmake_property(tb.type));
172  format.insert(gmake_property(tb.number_of_entries));
173  format.insert(gmake_property(tb.number_of_bytes));
174  format.insert(gmake_property(tb.number_of_bytes_zipped));
175  format.insert(gmake_property(tb.compression_factor));
176 
177  try {
178 
179  JProperties properties;
180 
181  properties.insert(gmake_property(ta.name));
182  properties.insert(gmake_property(ta.type));
183 
184  JParser<> zap("Auxiliary program to print ROOT TTree information.");
185 
186  zap['f'] = make_field(inputFile);
187  zap['@'] = make_field(properties) = JPARSER::initialised();
188  zap['k'] = make_field(key) = "", get_keys(format);
189  zap['d'] = make_field(debug) = 1;
190 
191  zap(argc, argv);
192  }
193  catch(const exception &error) {
194  FATAL(error.what() << endl);
195  }
196 
197  gErrorIgnoreLevel = kFatal;
198 
199  inputFile = getFilenames(inputFile);
200 
201  int number_of_errors = 0;
202 
203  for (vector<string>::const_iterator file_name = inputFile.begin(); file_name != inputFile.end(); ++file_name) {
204 
205  TFile* file = TFile::Open(file_name->c_str());
206 
207  if (file == NULL) {
208 
209  ++number_of_errors;
210 
211  cerr << *file_name << " not opened." << endl;
212 
213  continue;
214  }
215 
216  if (key == "") {
217  cout << *file_name << endl;
218  }
219 
220  TIter iter(file->GetListOfKeys(), kIterBackward);
221 
222  for (TKey* _key; (_key = (TKey*) iter.Next()) != NULL; ) {
223 
224  TKey* p = dynamic_cast<TKey*>(file->GetListOfKeys()->Before(_key));
225 
226  if (p == NULL || strcmp(_key->GetName(), p->GetName()) != 0) { // select last key
227 
228  tb = tree_info(dynamic_cast<TTree*>(_key->ReadObj()));
229 
230  if (tb.is_valid() && ta == tb) {
231 
232  if (key == "")
233  cout << tb << endl;
234  else
235  format.write(cout, key) << ' ';
236  }
237  }
238  }
239 
240  file->Close();
241 
242  delete file;
243  }
244 
245  return (number_of_errors == 0 ? 0 : 1);
246 }
#define FATAL(A)
Definition: JMessage.hh:67
int debug
debug level
Definition: JSirene.cc:69
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2142
#define gmake_property(A)
macros to convert (template) parameter to JPropertiesElement object
Utility class to parse parameter values.
Definition: JProperties.hh:501
std::ostream & write(std::ostream &out) const
Write the current parameter values.
Definition: JProperties.hh:847
Utility class to parse command line options.
Definition: JParser.hh:1698
const array_type< JKey_t > & get_keys(const std::map< JKey_t, JValue_t, JComparator_t, JAllocator_t > &data)
Method to create array of keys of map.
Definition: JVectorize.hh:139
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
static JGlob getFilenames
Function object to get list of files for given pattern.
Definition: JGlob.hh:123
Definition: JSTDTypes.hh:14
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:68