Jpp 19.3.0-rc.1
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
16#include "JSystem/JGlob.hh"
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 vector<string> 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 inputFile = getFilenames(inputFile);
90
91 set<JChain> buffer;
92
93 for (vector<string>::const_iterator file_name = inputFile.begin(); file_name != inputFile.end(); ++file_name) {
94
95 TFile* file = TFile::Open(file_name->c_str());
96
97 if (file != NULL) {
98
99 TIter iter(file->GetListOfKeys(), kIterBackward);
100
101 for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
102
103 TKey* p = dynamic_cast<TKey*>(file->GetListOfKeys()->Before(key));
104
105 if (p == NULL || strcmp(key->GetName(), p->GetName()) != 0) { // select last key
106
107 TTree* tree = dynamic_cast<TTree*>(key->ReadObj());
108
109 if (tree != NULL) {
110 buffer.insert(JChain(tree->GetName()));
111 }
112 }
113 }
114
115 file->Close();
116
117 delete file;
118 }
119 }
120
121 for (auto& chain : buffer) {
122
123 for (vector<string>::const_iterator file_name = inputFile.begin(); file_name != inputFile.end(); ++file_name) {
124 chain->Add(file_name->c_str());
125 }
126
127 cout << setw(24) << left << chain->GetName() << ' '
128 << setw(10) << right << chain->GetEntries() << endl;
129 }
130}
bool operator<(const Status_Item &first, const Status_Item &second)
comparator for Status item; earliest hit first
Definition Ars.hh:413
File list.
General purpose messaging.
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
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
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).