ATLAS Offline Software
Public Member Functions | Private Attributes | List of all members
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. More...
 
Int_t run ()
 
void addFile (const char *filename)
 
virtual void processKey (TDirectory &dir, TKey &key)
 Method called for every key. More...
 

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. More...
 
void addFailRegexp (const char *regexp)
 Skip keys that match this regexp. More...
 
void addPassRegexp (const char *regexp)
 Never skip keys that match this regexp. More...
 
void passBeforeFailRegexp (Bool_t passBeforeFail=kTRUE)
 Reverse pass/fail logic. First check on pass then on fail. More...
 
void setVerbose (Bool_t verbose=kTRUE)
 Set verbose mode. More...
 
Bool_t verbose () const
 Query verbose mode. More...
 
const TFile * file () const
 Current ROOT file. More...
 
TString rootDir () const
 Current directory. More...
 
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 }

◆ 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 }

◆ 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 }

◆ 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; }

◆ 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; }

◆ 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();
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 }

◆ 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();
66  afterFile();
67 
68  delete m_file; // calls Close()
69 }

◆ 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 
54  for (iter=m_fileList.begin(); iter!=m_fileList.end(); ++iter) {
55  processFile(*iter);
56  }
57 
58  endJob();
59  return m_errorCode;
60 }

◆ 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 }

◆ 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;}

◆ setVerbose()

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

Set verbose mode.

Definition at line 77 of file TFileLooper.h.

77 {m_verbose = verbose;}

◆ 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 }

◆ 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.

◆ 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.

◆ 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.

◆ 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.


The documentation for this class was generated from the following files:
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
TFileLooper::skipDir
Bool_t skipDir(const TDirectory &dir)
Definition: TFileLooper.cxx:118
TFileLooper::m_skipDirs
TString m_skipDirs
Definition: TFileLooper.h:91
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
get_generator_info.result
result
Definition: get_generator_info.py:21
TFileLooper::verbose
Bool_t verbose() const
Query verbose mode.
Definition: TFileLooper.h:80
TFileLooper::m_skippedObjects
std::vector< std::string > m_skippedObjects
Definition: TFileLooper.h:99
Data
@ Data
Definition: BaseObject.h:11
TMultiFileLooper::addFile
void addFile(const char *filename)
Definition: TMultiFileLooper.cxx:62
TFileLooper::processFile
void processFile(const char *filename, const char *rootDir=0)
Definition: TFileLooper.cxx:44
TFileLooper::m_errorCode
Int_t m_errorCode
Definition: TFileLooper.h:94
TFileLooper::endJob
virtual void endJob()
Definition: TFileLooper.h:55
JetTagCalibConfig.className
string className
Definition: JetTagCalibConfig.py:31
fillPileUpNoiseLumi.next
next
Definition: fillPileUpNoiseLumi.py:52
ParseInputs.gDirectory
gDirectory
Definition: Final2012/ParseInputs.py:133
TFileLooper::afterDir
virtual void afterDir()
Definition: TFileLooper.h:59
TFileLooper::beginJob
virtual void beginJob()
Definition: TFileLooper.h:54
TFileLooper::m_rootDir
TString m_rootDir
Definition: TFileLooper.h:90
beamspotman.dir
string dir
Definition: beamspotman.py:623
TMultiFileLooper::run
Int_t run()
Definition: TMultiFileLooper.cxx:48
TFileLooper::rootDir
TString rootDir() const
Current directory.
Definition: TFileLooper.h:86
TFileLooper::m_passBeforeFail
Bool_t m_passBeforeFail
Definition: TFileLooper.h:93
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
TFileLooper::m_file
TFile * m_file
Definition: TFileLooper.h:89
TFileLooper::m_verbose
Bool_t m_verbose
Definition: TFileLooper.h:92
TFileLooper::m_passRE
std::vector< TPRegexp > m_passRE
Definition: TFileLooper.h:97
TFileLooper::beforeFile
virtual void beforeFile()
Definition: TFileLooper.h:56
TFileLooper::getPathFromDir
TString getPathFromDir(const TDirectory &dir)
Definition: TFileLooper.cxx:178
TFileLooper::beforeDir
virtual void beforeDir()
Definition: TFileLooper.h:58
re
const boost::regex re(r_e)
TFileLooper::m_failRE
std::vector< TPRegexp > m_failRE
Definition: TFileLooper.h:96
TMultiFileLooper::m_fileList
std::vector< TString > m_fileList
Definition: TMultiFileLooper.h:39
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:24
TFileLooper::processDir
void processDir(TDirectory &dir)
Definition: TFileLooper.cxx:73
TFileLooper::getKeyPath
TString getKeyPath(const TDirectory &dir, const TKey &key)
Definition: TFileLooper.cxx:188
TFileLooper::processKey
virtual void processKey(TDirectory &dir, TKey &key)
Method called for every key.
Definition: TFileLooper.cxx:110
TFileLooper::afterFile
virtual void afterFile()
Definition: TFileLooper.h:57
TFileLooper::skipObject
Bool_t skipObject(const char *name)
Definition: TFileLooper.cxx:129
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37