ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Trigger
TrigAnalysis
TrigInDetAnalysisUser
Analysis
src
chains.cxx
Go to the documentation of this file.
1
/* emacs: this is -*- c++ -*- */
10
11
12
#include <iostream>
13
#include <string>
14
15
16
#include "TFile.h"
17
#include "TDirectory.h"
18
#include "TList.h"
19
#include "TKey.h"
20
#include "TH1D.h"
21
22
23
24
void
descend
( TDirectory* d,
int
level,
int
maxdepth
,
const
std::vector<std::string>& labels );
25
26
27
28
29
int
usage
(std::ostream& s,
int
argc,
char
** argv) {
30
if
( argc<1 )
return
-1;
31
s <<
"Usage: "
<< argv[0] <<
" [OPTIONS] <file1> <file2> ... \n\n"
;
32
s <<
" writes names of chains from files\n\n"
;
33
s <<
"Options: \n"
;
34
s <<
" -a, --always \t always descend, \n"
;
35
s <<
" -d, --depth maxdepth \t maximum depth to descend, \n"
;
36
s <<
" -c, --contents histogram \t display number of entries in histogram, \n"
;
37
s <<
" -f, --fast \t bomb out as soon as a single chain has been found, \n"
;
38
s <<
" -v, --verbose \t verbose output, \n"
;
39
s <<
" -h, --help \t this help,\n"
;
40
// s << "\nSee " << PACKAGE_URL << " for more details\n";
41
// s << "\nReport bugs to <" << PACKAGE_BUGREPORT << ">";
42
s << std::endl;
43
return
0;
44
}
45
46
49
50
bool
verbose
=
false
;
51
bool
always_descend
=
false
;
52
std::string
histogram
=
""
;
53
bool
fast
=
false
;
54
55
int
main
(
int
argc,
char
** argv ) {
56
57
std::vector<std::string> args;
58
59
int
maxdepth
= 2;
60
61
62
for
(
int
i=1 ; i<argc ; i++ ) {
63
std::string arg = argv[i];
64
if
( arg==
"-h"
|| arg==
"--help"
)
return
usage
( std::cout, argc, argv );
65
else
if
( arg==
"-v"
|| arg==
"--verbose"
)
verbose
=
true
;
66
else
if
( arg==
"-f"
|| arg==
"--fast"
)
fast
=
true
;
67
else
if
( arg==
"-a"
|| arg==
"--always"
)
always_descend
=
true
;
68
else
if
( arg==
"-d"
|| arg==
"--depth"
) {
69
if
( ++i<argc )
maxdepth
= std::atoi(argv[i]);
70
else
return
usage
( std::cout, argc, argv );
71
}
72
else
if
( arg==
"-c"
|| arg==
"--contents"
) {
73
if
( ++i<argc )
histogram
= argv[i];
74
else
return
usage
( std::cout, argc, argv );
75
}
76
77
else
args.push_back(std::move(arg));
78
}
79
80
std::vector<std::string> labels;
81
labels.push_back(
"L2_"
);
82
labels.push_back(
"EF_"
);
83
labels.push_back(
"HLT_"
);
84
85
for
(
unsigned
i=0 ; i<args.size() ; i++ ) {
86
TFile f( args[i].c_str() );
87
88
if
( !f.IsOpen() || f.IsZombie() ) {
89
std::cerr <<
"Error: could not open input file: "
<< args[i] << std::endl;
90
std::exit(1);
91
}
92
93
// gDirectory->ls();
94
descend
( gDirectory, 0,
maxdepth
, labels );
95
}
96
97
return
0;
98
}
99
101
double
hsum
( TH1*
h
) {
102
double
d=0;
103
for
(
int
i=0 ; i<=
h
->GetNbinsX()+1 ; i++ ) d +=
h
->GetBinContent(i);
104
return
d;
105
}
106
107
void
descend
( TDirectory* d,
int
level,
int
maxdepth
,
const
std::vector<std::string>& labels ) {
108
109
if
(
verbose
) std::cout <<
"level "
<< level <<
"\tmaxdepth "
<<
maxdepth
<< std::endl;
110
111
if
( d==0 )
return
;
112
113
TList* tl = d->GetListOfKeys();
114
115
if
(
verbose
) std::cout <<
"list of keys "
<< tl <<
" "
<< ( tl ? tl->Capacity() : 0 ) << std::endl;
116
117
if
( tl==0 )
return
;
118
119
std::string name = d->GetName();
120
121
int
plevel = level;
122
123
if
( !
verbose
)
if
( plevel>0 ) plevel--;
124
125
for
(
int
ip=plevel ; ip-- ; ) std::cout <<
"\t"
;
126
127
bool
displayed =
false
;
128
129
int
dsize = 0;
130
131
if
(
verbose
) std::cout <<
"Directory: "
;
132
if
(
verbose
|| level>0 ) {
133
std::cout<< name;
134
displayed =
true
;
135
dsize = name.size();
136
if
( dsize<60 ) std::cout <<
"\t"
;
137
}
138
139
// struct timeval tv = simpletimer_start();
140
141
if
(
verbose
) std::cout <<
"level "
<< level <<
"\tmaxdepth "
<<
maxdepth
<< std::endl;
142
143
for
(
int
i=tl->GetSize() ; i-- ; ) {
144
145
TKey* tobj = (TKey*)tl->At(i);
146
147
if
( tobj==0 )
continue
;
148
149
150
// for ( int ip=level+1 ; ip-- ; ) std::cout << "\t";
151
// std::cout << "tobj " << tobj << " : \t" << tobj->GetName() << std::endl;
152
153
if
( std::string(tobj->GetClassName()).find(
"TDirectory"
)!=std::string::npos ) {
154
// std::cout << ns << "Directory " << tobj->GetName() << std::endl;
155
TDirectory* tnd = (TDirectory*)tobj->ReadObj();
156
157
if
( tnd==0 )
continue
;
158
159
std::string dname = tnd->GetName();
160
161
162
// if ( dname.find("L2_")!=std::string::npos ||
163
// dname.find("EF_")!=std::string::npos ||
164
// dname.find("HLT_")!=std::string::npos )
165
if
( level<
maxdepth
) {
166
bool
dscnd =
true
;
167
if
( !
always_descend
&& labels.size() ) {
168
dscnd =
false
;
169
for
(
unsigned
il=labels.size() ; il-- ; ) {
170
if
( dname.find(labels[il])!=std::string::npos) dscnd =
true
;
171
}
172
}
173
if
( dscnd )
descend
( tnd, level+1,
maxdepth
, labels );
174
}
175
}
176
else
{
177
if
(
histogram
!=
""
){
178
if
( std::string(tobj->GetClassName()).find(
"TH1"
)!=std::string::npos ||
179
// std::string(tobj->GetClassName()).find("TH2")!=std::string::npos ||
180
std::string(tobj->GetClassName()).find(
"TProfile"
)!=std::string::npos ) {
181
182
TH1* th = (TH1*)tobj->ReadObj();
183
184
if
( th && std::string(th->GetName()) ==
histogram
) {
185
186
double
ddd =
hsum
( th );
187
188
std::cout <<
"\t"
<< ddd << std::endl;
189
190
displayed =
false
;
191
192
}
193
}
194
}
195
}
196
}
197
if
( displayed ) std::cout << std::endl;
198
}
199
fast
bool fast
Definition
TrigGlobEffCorrValidation.cxx:190
histogram
std::string histogram
Definition
chains.cxx:52
descend
void descend(TDirectory *d, int level, int maxdepth, const std::vector< std::string > &labels)
Definition
chains.cxx:107
hsum
double hsum(TH1 *h)
sum the bin contents including the over and underflow bins
Definition
chains.cxx:101
always_descend
bool always_descend
Definition
chains.cxx:51
h
Header file for AthHistogramAlgorithm.
usage
StatusCode usage()
Definition
fbtTestToyMC.cxx:1168
verbose
bool verbose
Definition
hcg.cxx:75
main
int main()
Definition
hello.cxx:18
maxdepth
int maxdepth
Definition
listroot.cxx:202
Generated on
for ATLAS Offline Software by
1.17.0