Jpp 19.3.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
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 173 of file JPrintTree.cc.

174{
175 using namespace std;
176 using namespace JPP;
177
178 vector<string> inputFile;
179 tree_info ta; // selection
180 tree_info tb; // actual
181 string key; // format
182 int debug;
183
184 JProperties format;
185
186 format.insert(gmake_property(tb.name));
187 format.insert(gmake_property(tb.type));
188 format.insert(gmake_property(tb.number_of_entries));
189 format.insert(gmake_property(tb.number_of_bytes));
190 format.insert(gmake_property(tb.number_of_bytes_zipped));
191 format.insert(gmake_property(tb.compression_factor));
192
193 try {
194
195 JProperties properties;
196
197 properties.insert(gmake_property(ta.name));
198 properties.insert(gmake_property(ta.type));
199
200 JParser<> zap("Auxiliary program to print ROOT TTree information.");
201
202 zap['f'] = make_field(inputFile);
203 zap['@'] = make_field(properties) = JPARSER::initialised();
204 zap['k'] = make_field(key) = "", get_keys(format);
205 zap['d'] = make_field(debug) = 1;
206
207 zap(argc, argv);
208 }
209 catch(const exception &error) {
210 FATAL(error.what() << endl);
211 }
212
213 gErrorIgnoreLevel = kFatal;
214
215 inputFile = getFilenames(inputFile);
216
217 int number_of_errors = 0;
218
219 for (vector<string>::const_iterator file_name = inputFile.begin(); file_name != inputFile.end(); ++file_name) {
220
221 TFile* file = TFile::Open(file_name->c_str());
222
223 if (file == NULL) {
224
225 ++number_of_errors;
226
227 cerr << *file_name << " not opened." << endl;
228
229 continue;
230 }
231
232 if (key == "") {
233 cout << *file_name << endl;
234 }
235
236 TIter iter(file->GetListOfKeys(), kIterBackward);
237
238 for (TKey* _key; (_key = (TKey*) iter.Next()) != NULL; ) {
239
240 TKey* p = dynamic_cast<TKey*>(file->GetListOfKeys()->Before(_key));
241
242 DEBUG("Key: " << _key->GetName() << ' ' << (p == NULL || strcmp(_key->GetName(), p->GetName()) != 0) << endl);
243
244 if (p == NULL || strcmp(_key->GetName(), p->GetName()) != 0) { // select last key
245
246 tb = tree_info(dynamic_cast<TTree*>(_key->ReadObj()));
247
248 DEBUG(tb << endl);
249
250 if (tb.is_valid() && ta == tb) {
251
252 if (key == "")
253 cout << tb << endl;
254 else
255 format.write(cout, key) << ' ';
256 }
257 }
258 }
259
260 file->Close();
261
262 delete file;
263 }
264
265 return (number_of_errors == 0 ? 0 : 1);
266}
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
#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.
std::ostream & write(std::ostream &out) const
Write the current parameter values.
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.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition JParser.hh:68