Jpp 20.0.0-rc.2
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 "JLang/JEquals.hh"
#include "JLang/JVectorize.hh"
#include "JSupport/JMultipleFileScanner.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 172 of file JPrintTree.cc.

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