Jpp 20.0.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
JPrintChain.cc File Reference

Auxiliary program to print ROOT TChain information. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <set>
#include <memory>
#include <string.h>
#include "TError.h"
#include "TROOT.h"
#include "TFile.h"
#include "TKey.h"
#include "TTree.h"
#include "TChain.h"
#include "JSupport/JMultipleFileScanner.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 TChain information.

Author
mdejong

Definition in file JPrintChain.cc.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 66 of file JPrintChain.cc.

67{
68 using namespace std;
69 using namespace JPP;
70
71 JMultipleFileScanner_t inputFile;
72 int debug;
73
74 try {
75
76 JParser<> zap("Auxiliary program to print ROOT TChain information.");
77
78 zap['f'] = make_field(inputFile);
79 zap['d'] = make_field(debug) = 1;
80
81 zap(argc, argv);
82 }
83 catch(const exception &error) {
84 FATAL(error.what() << endl);
85 }
86
87 gErrorIgnoreLevel = kFatal;
88
89 set<JChain> buffer;
90
91 for (vector<string>::const_iterator file_name = inputFile.begin(); file_name != inputFile.end(); ++file_name) {
92
93 TFile* file = TFile::Open(file_name->c_str());
94
95 if (file != NULL) {
96
97 TIter iter(file->GetListOfKeys(), kIterBackward);
98
99 for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
100
101 TKey* p = dynamic_cast<TKey*>(file->GetListOfKeys()->Before(key));
102
103 if (p == NULL || strcmp(key->GetName(), p->GetName()) != 0) { // select last key
104
105 TTree* tree = dynamic_cast<TTree*>(key->ReadObj());
106
107 if (tree != NULL) {
108 buffer.insert(JChain(tree->GetName()));
109 }
110 }
111 }
112
113 file->Close();
114
115 delete file;
116 }
117 }
118
119 for (auto& chain : buffer) {
120
121 for (vector<string>::const_iterator file_name = inputFile.begin(); file_name != inputFile.end(); ++file_name) {
122 chain->Add(file_name->c_str());
123 }
124
125 cout << setw(24) << left << chain->GetName() << ' '
126 << setw(10) << right << chain->GetEntries() << endl;
127 }
128}
#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
Utility class to parse command line options.
Definition JParser.hh:1698
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary base class for list of file names.