ATLAS Offline Software
TFileLooper.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef TRIGVALTOOLS_TFILELOOPER_H
6 #define TRIGVALTOOLS_TFILELOOPER_H
7 
15 #include <fstream>
16 #include <vector>
17 
18 #include "TDirectory.h"
19 #include "TFile.h"
20 #include "TString.h"
21 #include "TH1.h"
22 #include "TPRegexp.h"
23 
24 
35 class TFileLooper {
36  public:
37  TFileLooper() = default;
38  virtual ~TFileLooper() = default;
39 
40  TFileLooper (const TFileLooper& other) = delete;
42 
44  virtual Int_t run(const char* filename, const char* rootDir = 0);
45 
50  virtual void processKey(TDirectory& dir, TKey& key);
51 
53 
54  virtual void beginJob() {}
55  virtual void endJob() {}
56  virtual void beforeFile() {}
57  virtual void afterFile() {}
58  virtual void beforeDir() {}
59  virtual void afterDir() {}
60  virtual void beforeObj() {}
61  virtual void afterObj() {}
63 
65  void setDirsToSkip(const char* skipDirs) {if (skipDirs) m_skipDirs = skipDirs;}
66 
68  void addFailRegexp(const char* regexp);
69 
71  void addPassRegexp(const char* regexp);
72 
74  void passBeforeFailRegexp(Bool_t passBeforeFail = kTRUE) { m_passBeforeFail = passBeforeFail; }
75 
77  void setVerbose(Bool_t verbose = kTRUE) {m_verbose = verbose;}
78 
80  Bool_t verbose() const {return m_verbose;}
81 
83  const TFile* file() const { return m_file; }
84 
86  TString rootDir() const { return m_rootDir; }
87 
88 protected:
89  TFile* m_file{nullptr};
90  TString m_rootDir;
91  TString m_skipDirs;
92  Bool_t m_verbose{kFALSE};
93  Bool_t m_passBeforeFail{kFALSE};
94  Int_t m_errorCode{0};
95 
96  std::vector<TPRegexp> m_failRE;
97  std::vector<TPRegexp> m_passRE;
98 
99  std::vector<std::string> m_skippedObjects;
100 
101  TString getPathFromDir(const TDirectory& dir);
102  TString getKeyPath(const TDirectory& dir, const TKey& key);
103 
104  void processDir(TDirectory& dir);
105  void processFile(const char* filename, const char* rootDir = 0);
106  Bool_t skipDir(const TDirectory& dir);
107  Bool_t skipObject(const char* name);
108  TString getDrawOptions(const TH1& h);
109 };
110 
111 #endif
TFileLooper::skipDir
Bool_t skipDir(const TDirectory &dir)
Definition: TFileLooper.cxx:118
TFileLooper::m_skipDirs
TString m_skipDirs
Definition: TFileLooper.h:91
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
TFileLooper::addFailRegexp
void addFailRegexp(const char *regexp)
Skip keys that match this regexp.
Definition: TFileLooper.cxx:160
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::run
virtual Int_t run(const char *filename, const char *rootDir=0)
Start processing.
Definition: TFileLooper.cxx:26
TFileLooper::endJob
virtual void endJob()
Definition: TFileLooper.h:55
TFileLooper::afterObj
virtual void afterObj()
Definition: TFileLooper.h:61
TFileLooper::file
const TFile * file() const
Current ROOT file.
Definition: TFileLooper.h:83
TFileLooper::beforeObj
virtual void beforeObj()
Definition: TFileLooper.h:60
TFileLooper::~TFileLooper
virtual ~TFileLooper()=default
TFileLooper::afterDir
virtual void afterDir()
Definition: TFileLooper.h:59
TFileLooper::setVerbose
void setVerbose(Bool_t verbose=kTRUE)
Set verbose mode.
Definition: TFileLooper.h:77
TFileLooper::getDrawOptions
TString getDrawOptions(const TH1 &h)
TFileLooper::operator=
TFileLooper & operator=(const TFileLooper &other)=delete
TFileLooper::addPassRegexp
void addPassRegexp(const char *regexp)
Never skip keys that match this regexp.
Definition: TFileLooper.cxx:169
TFileLooper::beginJob
virtual void beginJob()
Definition: TFileLooper.h:54
TFileLooper::TFileLooper
TFileLooper(const TFileLooper &other)=delete
TFileLooper::m_rootDir
TString m_rootDir
Definition: TFileLooper.h:90
beamspotman.dir
string dir
Definition: beamspotman.py:623
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:228
TFileLooper::m_file
TFile * m_file
Definition: TFileLooper.h:89
TFileLooper::m_verbose
Bool_t m_verbose
Definition: TFileLooper.h:92
TFileLooper::passBeforeFailRegexp
void passBeforeFailRegexp(Bool_t passBeforeFail=kTRUE)
Reverse pass/fail logic. First check on pass then on fail.
Definition: TFileLooper.h:74
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
TFileLooper
Base class to loop over all the keys in a ROOT file.
Definition: TFileLooper.h:35
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
h
TFileLooper::m_failRE
std::vector< TPRegexp > m_failRE
Definition: TFileLooper.h:96
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
TFileLooper::setDirsToSkip
void setDirsToSkip(const char *skipDirs)
Skip this comma separated list of directories.
Definition: TFileLooper.h:65
TFileLooper::TFileLooper
TFileLooper()=default
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37