Jpp 20.0.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
JPrintChain.cc
Go to the documentation of this file.
1
2#include <string>
3#include <iostream>
4#include <iomanip>
5#include <set>
6#include <memory>
7#include <string.h>
8
9#include "TError.h"
10#include "TROOT.h"
11#include "TFile.h"
12#include "TKey.h"
13#include "TTree.h"
14#include "TChain.h"
15
17
18#include "Jeep/JParser.hh"
19#include "Jeep/JMessage.hh"
20
21
22namespace {
23
24 /**
25 * Auxiliary data structure for TChain.
26 */
27 struct JChain :
28 public std::unique_ptr<TChain>
29 {
30 /**
31 * Default constructor.
32 */
33 JChain()
34 {}
35
36 /**
37 * Constructor.
38 *
39 * \param name name of TTree
40 */
41 JChain(const char* const name) :
42 std::unique_ptr<TChain>(new TChain(name))
43 {}
44
45 /**
46 * Less-than operator for TChain.
47 *
48 * \param first first TChain
49 * \param second second TChain
50 * \return true if name of first TChain is less than that of second; else false
51 */
52 friend inline bool operator<(const JChain& first, const JChain& second)
53 {
54 return strcmp(first->GetName(), second->GetName()) < 0;
55 }
56 };
57}
58
59
60/**
61 * \file
62 *
63 * Auxiliary program to print ROOT TChain information.
64 * \author mdejong
65 */
66int main(int argc, char **argv)
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}
General purpose messaging.
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
Scanning of objects from multiple files according a format that follows from the extension of each fi...
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
int main(int argc, char **argv)
Utility class to parse command line options.
Definition JParser.hh:1698
bool operator<(const Head &first, const Head &second)
Less than operator.
Definition JHead.hh:1835
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary base class for list of file names.