ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Trigger
TrigValidation
TrigValTools
src
TFileLooper.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3
*/
4
11
12
#include "
TrigValTools/TFileLooper.h
"
13
14
#include <iostream>
15
#include <sstream>
16
#include "TError.h"
17
#include "TH1.h"
18
#include "TFile.h"
19
#include "TCanvas.h"
20
#include "TSystem.h"
21
#include "TKey.h"
22
#include "TPRegexp.h"
23
24
using namespace
std
;
25
26
Int_t
TFileLooper::run
(
const
char
* filename,
const
char
*
rootDir
)
27
{
28
m_errorCode
= 0;
29
30
if
(filename==0) {
31
cout <<
"Invalid file name (0)"
<< endl;
32
m_errorCode
= 1;
33
return
m_errorCode
;
34
}
35
36
beginJob
();
37
processFile
(filename,
rootDir
);
38
endJob
();
39
return
m_errorCode
;
40
}
41
42
43
// Convert one file into html
44
void
TFileLooper::processFile
(
const
char
* filename,
const
char
*
rootDir
)
45
{
46
m_file
=
new
TFile(filename);
47
if
(
m_file
->IsZombie()) {
48
cout <<
"Cannot open "
<<filename << endl;
49
m_errorCode
= 1;
50
delete
m_file
;
51
return
;
52
}
53
54
if
(
rootDir
) {
55
if
(!
m_file
->cd(
rootDir
)) {
56
cout <<
"Cannot change to directory "
<<
rootDir
<< endl;
57
m_errorCode
= 1;
58
return
;
59
}
60
m_rootDir
=
rootDir
;
61
}
62
else
m_file
->cd();
63
64
beforeFile
();
65
processDir
(*gDirectory);
66
afterFile
();
67
68
delete
m_file
;
// calls Close()
69
}
70
71
72
// Save all histograms in dir into png files
73
void
TFileLooper::processDir
(TDirectory& dir)
74
{
75
TString s(
getPathFromDir
(dir));
76
77
if
(
skipDir
(dir)) {
78
cout <<
"Skipping "
<< s << endl;
79
return
;
80
}
81
82
if
(
m_verbose
) cout <<
"Reading directory "
<< dir.GetPath() << endl;
83
84
// Sort directory content
85
TList* dirList = dir.GetListOfKeys();
86
dirList->Sort();
87
88
TIter next(dirList);
89
TKey* key;
90
while
((key = (TKey*)next())) {
91
// if (skipObject(getKeyPath(dir,*key))) continue;
92
93
TString className(key->GetClassName());
94
if
(className==
"TDirectoryFile"
|| className==
"TDirectory"
) {
95
dir.cd(key->GetName());
96
beforeDir
();
97
processDir
(*gDirectory);
98
afterDir
();
99
}
100
else
{
101
if
(
skipObject
(
getKeyPath
(dir,*key))) {
102
m_skippedObjects
.push_back(
getKeyPath
(dir,*key).
Data
());
103
continue
;
104
}
105
processKey
(dir, *key);
106
}
107
}
108
}
109
110
void
TFileLooper::processKey
(TDirectory& dir, TKey& key)
111
{
112
cout <<
"--- processKey: "
<< key.GetName()
113
<<
" in directory "
<< dir.GetPath() << endl;
114
}
115
116
117
// Check if we have to skip this directory
118
Bool_t
TFileLooper::skipDir
(
const
TDirectory& dir)
119
{
120
if
(
m_skipDirs
.Contains(dir.GetName()))
return
kTRUE;
121
else
return
kFALSE;
122
}
123
124
125
// Check if we have to skip this object
126
// Logic: 1) check if name matches any of the m_failRE
127
// 2) check if name matches any of the m_passRE
128
// 3) Return true if 1)=true and 2)=false
129
Bool_t
TFileLooper::skipObject
(
const
char
* name)
130
{
131
Bool_t failMatch(kFALSE);
132
Bool_t passMatch(kFALSE);
133
134
for
(
auto
&
re
:
m_failRE
) {
135
if
(
re
.Match(name)>0) {
136
failMatch = kTRUE;
137
break
;
138
}
139
}
140
141
// give object another chance to match any of the m_passRE
142
for
(
auto
&
re
:
m_passRE
) {
143
if
(
re
.Match(name)>0) {
144
passMatch = kTRUE;
145
break
;
146
}
147
}
148
149
bool
result;
150
if
(
m_passBeforeFail
) result = (!passMatch || failMatch);
151
else
result = (failMatch && !passMatch);
152
153
if
(
m_verbose
&& result) cout <<
"Skipping "
<< name << endl;
154
return
result;
155
156
}
157
158
159
// Skip keys that match this regexp...
160
void
TFileLooper::addFailRegexp
(
const
char
* regexp)
161
{
162
if
(regexp) {
163
m_failRE
.emplace_back(regexp);
164
}
165
}
166
167
168
// ...and do not match this regexp.
169
void
TFileLooper::addPassRegexp
(
const
char
* regexp)
170
{
171
if
(regexp) {
172
m_passRE
.emplace_back(regexp);
173
}
174
}
175
176
// Create file system path from TDirectory path
177
// Example: "../Tau-monitoring.root:/TrigSteering" -> "Tau-monitoring.root/TrigSteering"
178
TString
TFileLooper::getPathFromDir
(
const
TDirectory& dir)
179
{
180
TString s(dir.GetPath());
181
if
(s.Index(
"../"
)==0) s.Remove(0,3);
182
s.ReplaceAll(
":"
,
""
);
183
return
s;
184
}
185
186
// return key name with path
187
// Example: myHist in directory myDir -> "myDir/myHist"
188
TString
TFileLooper::getKeyPath
(
const
TDirectory& dir,
const
TKey& key)
189
{
190
TString s(dir.GetPath()+TString(
"/"
)+key.GetName());
191
// Remove all chars from beginning including ":/"
192
s.Replace(0,s.First(
":"
)+2,0);
193
194
return
s;
195
}
re
const std::regex re(r_e)
Data
@ Data
Definition
BaseObject.h:11
TFileLooper.h
TFileLooper class.
TFileLooper::afterFile
virtual void afterFile()
Definition
TFileLooper.h:57
TFileLooper::addFailRegexp
void addFailRegexp(const char *regexp)
Skip keys that match this regexp.
Definition
TFileLooper.cxx:160
TFileLooper::addPassRegexp
void addPassRegexp(const char *regexp)
Never skip keys that match this regexp.
Definition
TFileLooper.cxx:169
TFileLooper::m_rootDir
TString m_rootDir
Definition
TFileLooper.h:90
TFileLooper::rootDir
TString rootDir() const
Current directory.
Definition
TFileLooper.h:86
TFileLooper::m_skippedObjects
std::vector< std::string > m_skippedObjects
Definition
TFileLooper.h:99
TFileLooper::processDir
void processDir(TDirectory &dir)
Definition
TFileLooper.cxx:73
TFileLooper::m_file
TFile * m_file
Definition
TFileLooper.h:89
TFileLooper::m_failRE
std::vector< TPRegexp > m_failRE
Definition
TFileLooper.h:96
TFileLooper::getKeyPath
TString getKeyPath(const TDirectory &dir, const TKey &key)
Definition
TFileLooper.cxx:188
TFileLooper::beforeFile
virtual void beforeFile()
Definition
TFileLooper.h:56
TFileLooper::run
virtual Int_t run(const char *filename, const char *rootDir=0)
Start processing.
Definition
TFileLooper.cxx:26
TFileLooper::beginJob
virtual void beginJob()
Definition
TFileLooper.h:54
TFileLooper::m_verbose
Bool_t m_verbose
Definition
TFileLooper.h:92
TFileLooper::endJob
virtual void endJob()
Definition
TFileLooper.h:55
TFileLooper::beforeDir
virtual void beforeDir()
Definition
TFileLooper.h:58
TFileLooper::m_passRE
std::vector< TPRegexp > m_passRE
Definition
TFileLooper.h:97
TFileLooper::skipObject
Bool_t skipObject(const char *name)
Definition
TFileLooper.cxx:129
TFileLooper::m_passBeforeFail
Bool_t m_passBeforeFail
Definition
TFileLooper.h:93
TFileLooper::skipDir
Bool_t skipDir(const TDirectory &dir)
Definition
TFileLooper.cxx:118
TFileLooper::getPathFromDir
TString getPathFromDir(const TDirectory &dir)
Definition
TFileLooper.cxx:178
TFileLooper::m_errorCode
Int_t m_errorCode
Definition
TFileLooper.h:94
TFileLooper::processFile
void processFile(const char *filename, const char *rootDir=0)
Definition
TFileLooper.cxx:44
TFileLooper::m_skipDirs
TString m_skipDirs
Definition
TFileLooper.h:91
TFileLooper::afterDir
virtual void afterDir()
Definition
TFileLooper.h:59
TFileLooper::processKey
virtual void processKey(TDirectory &dir, TKey &key)
Method called for every key.
Definition
TFileLooper.cxx:110
std
STL namespace.
Generated on
for ATLAS Offline Software by
1.17.0