ATLAS Offline Software
Loading...
Searching...
No Matches
TMultiFileLooper Class Reference

Base class to loop over all the keys in several ROOT files. More...

#include <TMultiFileLooper.h>

Inheritance diagram for TMultiFileLooper:
Collaboration diagram for TMultiFileLooper:

Public Member Functions

 TMultiFileLooper ()
virtual ~TMultiFileLooper ()=default
virtual Int_t run (const char *fileListName, const char *rootDir=0)
 Start processing.
Int_t run ()
void addFile (const char *filename)
virtual void processKey (TDirectory &dir, TKey &key)
 Method called for every key.

Private Attributes

std::vector< TString > m_fileList

Processing hooks

virtual void beginJob ()
virtual void endJob ()
virtual void beforeFile ()
virtual void afterFile ()
virtual void beforeDir ()
virtual void afterDir ()
virtual void beforeObj ()
virtual void afterObj ()
void setDirsToSkip (const char *skipDirs)
 Skip this comma separated list of directories.
void addFailRegexp (const char *regexp)
 Skip keys that match this regexp.
void addPassRegexp (const char *regexp)
 Never skip keys that match this regexp.
void passBeforeFailRegexp (Bool_t passBeforeFail=kTRUE)
 Reverse pass/fail logic. First check on pass then on fail.
void setVerbose (Bool_t verbose=kTRUE)
 Set verbose mode.
Bool_t verbose () const
 Query verbose mode.
const TFile * file () const
 Current ROOT file.
TString rootDir () const
 Current directory.
TFile * m_file {nullptr}
TString m_rootDir
TString m_skipDirs
Bool_t m_verbose {kFALSE}
Bool_t m_passBeforeFail {kFALSE}
Int_t m_errorCode {0}
std::vector< TPRegexp > m_failRE
std::vector< TPRegexp > m_passRE
std::vector< std::string > m_skippedObjects
TString getPathFromDir (const TDirectory &dir)
TString getKeyPath (const TDirectory &dir, const TKey &key)
void processDir (TDirectory &dir)
void processFile (const char *filename, const char *rootDir=0)
Bool_t skipDir (const TDirectory &dir)
Bool_t skipObject (const char *name)
TString getDrawOptions (const TH1 &h)

Detailed Description

Base class to loop over all the keys in several ROOT files.

Author
Frank Winklmeier

Same as TFileLooper but can loop over multiple ROOT files.

Definition at line 28 of file TMultiFileLooper.h.

Constructor & Destructor Documentation

◆ TMultiFileLooper()

TMultiFileLooper::TMultiFileLooper ( )
inline

Definition at line 30 of file TMultiFileLooper.h.

30{}

◆ ~TMultiFileLooper()

virtual TMultiFileLooper::~TMultiFileLooper ( )
virtualdefault

Member Function Documentation

◆ addFailRegexp()

void TFileLooper::addFailRegexp ( const char * regexp)
inherited

Skip keys that match this regexp.

Definition at line 160 of file TFileLooper.cxx.

161{
162 if (regexp) {
163 m_failRE.emplace_back(regexp);
164 }
165}
std::vector< TPRegexp > m_failRE
Definition TFileLooper.h:96

◆ addFile()

void TMultiFileLooper::addFile ( const char * filename)

Definition at line 62 of file TMultiFileLooper.cxx.

63{
64 if (filename) m_fileList.push_back(TString(filename));
65}
std::vector< TString > m_fileList

◆ addPassRegexp()

void TFileLooper::addPassRegexp ( const char * regexp)
inherited

Never skip keys that match this regexp.

Definition at line 169 of file TFileLooper.cxx.

170{
171 if (regexp) {
172 m_passRE.emplace_back(regexp);
173 }
174}
std::vector< TPRegexp > m_passRE
Definition TFileLooper.h:97

◆ afterDir()

virtual void TFileLooper::afterDir ( )
inlinevirtualinherited

Definition at line 59 of file TFileLooper.h.

59{}

◆ afterFile()

virtual void TFileLooper::afterFile ( )
inlinevirtualinherited

Definition at line 57 of file TFileLooper.h.

57{}

◆ afterObj()

virtual void TFileLooper::afterObj ( )
inlinevirtualinherited

Definition at line 61 of file TFileLooper.h.

61{}

◆ beforeDir()

virtual void TFileLooper::beforeDir ( )
inlinevirtualinherited

Definition at line 58 of file TFileLooper.h.

58{}

◆ beforeFile()

virtual void TFileLooper::beforeFile ( )
inlinevirtualinherited

Definition at line 56 of file TFileLooper.h.

56{}

◆ beforeObj()

virtual void TFileLooper::beforeObj ( )
inlinevirtualinherited

Definition at line 60 of file TFileLooper.h.

60{}

◆ beginJob()

virtual void TFileLooper::beginJob ( )
inlinevirtualinherited

Reimplemented in TRootCompare.

Definition at line 54 of file TFileLooper.h.

54{}

◆ endJob()

virtual void TFileLooper::endJob ( )
inlinevirtualinherited

Reimplemented in TRootCompare.

Definition at line 55 of file TFileLooper.h.

55{}

◆ file()

const TFile * TFileLooper::file ( ) const
inlineinherited

Current ROOT file.

Definition at line 83 of file TFileLooper.h.

83{ return m_file; }
TFile * m_file
Definition TFileLooper.h:89

◆ getDrawOptions()

TString TFileLooper::getDrawOptions ( const TH1 & h)
protectedinherited

◆ getKeyPath()

TString TFileLooper::getKeyPath ( const TDirectory & dir,
const TKey & key )
protectedinherited

Definition at line 188 of file TFileLooper.cxx.

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}

◆ getPathFromDir()

TString TFileLooper::getPathFromDir ( const TDirectory & dir)
protectedinherited

Definition at line 178 of file TFileLooper.cxx.

179{
180 TString s(dir.GetPath());
181 if (s.Index("../")==0) s.Remove(0,3);
182 s.ReplaceAll(":","");
183 return s;
184}

◆ passBeforeFailRegexp()

void TFileLooper::passBeforeFailRegexp ( Bool_t passBeforeFail = kTRUE)
inlineinherited

Reverse pass/fail logic. First check on pass then on fail.

Definition at line 74 of file TFileLooper.h.

74{ m_passBeforeFail = passBeforeFail; }
Bool_t m_passBeforeFail
Definition TFileLooper.h:93

◆ processDir()

void TFileLooper::processDir ( TDirectory & dir)
protectedinherited

Definition at line 73 of file TFileLooper.cxx.

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}
@ Data
Definition BaseObject.h:11
std::vector< std::string > m_skippedObjects
Definition TFileLooper.h:99
void processDir(TDirectory &dir)
TString getKeyPath(const TDirectory &dir, const TKey &key)
Bool_t m_verbose
Definition TFileLooper.h:92
virtual void beforeDir()
Definition TFileLooper.h:58
Bool_t skipObject(const char *name)
Bool_t skipDir(const TDirectory &dir)
TString getPathFromDir(const TDirectory &dir)
virtual void afterDir()
Definition TFileLooper.h:59
virtual void processKey(TDirectory &dir, TKey &key)
Method called for every key.

◆ processFile()

void TFileLooper::processFile ( const char * filename,
const char * rootDir = 0 )
protectedinherited

Definition at line 44 of file TFileLooper.cxx.

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 }
61 }
62 else m_file->cd();
63
64 beforeFile();
65 processDir(*gDirectory);
66 afterFile();
67
68 delete m_file; // calls Close()
69}
virtual void afterFile()
Definition TFileLooper.h:57
TString m_rootDir
Definition TFileLooper.h:90
TString rootDir() const
Current directory.
Definition TFileLooper.h:86
virtual void beforeFile()
Definition TFileLooper.h:56
Int_t m_errorCode
Definition TFileLooper.h:94

◆ processKey()

void TFileLooper::processKey ( TDirectory & dir,
TKey & key )
virtualinherited

Method called for every key.

Only dummy implementation. Needs to be implemented in derived classes.

Reimplemented in TRootCompare.

Definition at line 110 of file TFileLooper.cxx.

111{
112 cout << "--- processKey: " << key.GetName()
113 << " in directory " << dir.GetPath() << endl;
114}

◆ rootDir()

TString TFileLooper::rootDir ( ) const
inlineinherited

Current directory.

Definition at line 86 of file TFileLooper.h.

86{ return m_rootDir; }

◆ run() [1/2]

Int_t TMultiFileLooper::run ( )

Definition at line 48 of file TMultiFileLooper.cxx.

49{
50 m_errorCode = 0;
51 beginJob();
52
53 vector<TString>::iterator iter;
54 for (iter=m_fileList.begin(); iter!=m_fileList.end(); ++iter) {
55 processFile(*iter);
56 }
57
58 endJob();
59 return m_errorCode;
60}
virtual void beginJob()
Definition TFileLooper.h:54
virtual void endJob()
Definition TFileLooper.h:55
void processFile(const char *filename, const char *rootDir=0)

◆ run() [2/2]

Int_t TMultiFileLooper::run ( const char * filename,
const char * rootDir = 0 )
virtual

Start processing.

Reimplemented from TFileLooper.

Definition at line 20 of file TMultiFileLooper.cxx.

21{
22 m_errorCode = 0;
23
24 if (fileListName==0) {
25 cout << "Invalid file list (0)" << endl;
26 m_errorCode = 1;
27 return m_errorCode;
28 }
29
30 ifstream ifs;
31 ifs.open(fileListName);
32 if (!ifs) {
33 cout << "Cannot open file " << fileListName << endl;
34 m_errorCode = 1;
35 return m_errorCode;
36 }
37
38 while (!ifs.eof()) {
39 string filename;
40 ifs >> filename;
41 if (filename!="") addFile(filename.c_str());
42 }
43
44 return run();
45}
void addFile(const char *filename)

◆ setDirsToSkip()

void TFileLooper::setDirsToSkip ( const char * skipDirs)
inlineinherited

Skip this comma separated list of directories.

Definition at line 65 of file TFileLooper.h.

65{if (skipDirs) m_skipDirs = skipDirs;}
TString m_skipDirs
Definition TFileLooper.h:91

◆ setVerbose()

void TFileLooper::setVerbose ( Bool_t verbose = kTRUE)
inlineinherited

Set verbose mode.

Definition at line 77 of file TFileLooper.h.

Bool_t verbose() const
Query verbose mode.
Definition TFileLooper.h:80

◆ skipDir()

Bool_t TFileLooper::skipDir ( const TDirectory & dir)
protectedinherited

Definition at line 118 of file TFileLooper.cxx.

119{
120 if (m_skipDirs.Contains(dir.GetName())) return kTRUE;
121 else return kFALSE;
122}

◆ skipObject()

Bool_t TFileLooper::skipObject ( const char * name)
protectedinherited

Definition at line 129 of file TFileLooper.cxx.

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}
const boost::regex re(r_e)

◆ verbose()

Bool_t TFileLooper::verbose ( ) const
inlineinherited

Query verbose mode.

Definition at line 80 of file TFileLooper.h.

80{return m_verbose;}

Member Data Documentation

◆ m_errorCode

Int_t TFileLooper::m_errorCode {0}
protectedinherited

Definition at line 94 of file TFileLooper.h.

94{0};

◆ m_failRE

std::vector<TPRegexp> TFileLooper::m_failRE
protectedinherited

Definition at line 96 of file TFileLooper.h.

◆ m_file

TFile* TFileLooper::m_file {nullptr}
protectedinherited

Definition at line 89 of file TFileLooper.h.

89{nullptr};

◆ m_fileList

std::vector<TString> TMultiFileLooper::m_fileList
private

Definition at line 39 of file TMultiFileLooper.h.

◆ m_passBeforeFail

Bool_t TFileLooper::m_passBeforeFail {kFALSE}
protectedinherited

Definition at line 93 of file TFileLooper.h.

93{kFALSE};

◆ m_passRE

std::vector<TPRegexp> TFileLooper::m_passRE
protectedinherited

Definition at line 97 of file TFileLooper.h.

◆ m_rootDir

TString TFileLooper::m_rootDir
protectedinherited

Definition at line 90 of file TFileLooper.h.

◆ m_skipDirs

TString TFileLooper::m_skipDirs
protectedinherited

Definition at line 91 of file TFileLooper.h.

◆ m_skippedObjects

std::vector<std::string> TFileLooper::m_skippedObjects
protectedinherited

Definition at line 99 of file TFileLooper.h.

◆ m_verbose

Bool_t TFileLooper::m_verbose {kFALSE}
protectedinherited

Definition at line 92 of file TFileLooper.h.

92{kFALSE};

The documentation for this class was generated from the following files: