ATLAS Offline Software
TIDDirectory.h
Go to the documentation of this file.
1 /* emacs: this is -*- c++ -*- */
17 #ifndef TIDA_TIDDIRECTORY_H
18 #define TIDA_TIDDIRECTORY_H
19 
20 #include "TDirectory.h"
21 #include "TH1.h"
22 
23 // #include "utils.h"
24 
25 class TIDDirectory {
26 
27 public:
28 
29  // TIDDirectory() : mHAddState(true), mDAddState(true), mPop(0), mDir(0) { }
30 
31  TIDDirectory(const std::string& n="") :
32  mname(n), mPop(gDirectory), mDir(0) {
33 
34  if ( n=="" ) {
35  mDir = gDirectory;
36  return;
37  }
38 
39 
40 
41  if ( n.find("/")==std::string::npos ) {
43  mDir = gDirectory->GetDirectory(n.c_str());
44  if ( mDir==0 ) mDir = gDirectory->mkdir(n.c_str());
45  return;
46  }
47 
48  std::string _dir = n;
49 
50  if ( _dir.find("/")!=std::string::npos ) {
51 
52  std::string dir = chop( _dir, "/" );
53 
54  if ( _dir == "" ) {
56  mDir = gDirectory->GetDirectory( dir.c_str());
57  if ( mDir==0 ) mDir = gDirectory->mkdir( dir.c_str() );
58  return;
59  }
60 
62  mDir = gDirectory->GetDirectory( dir.c_str());
63  if ( mDir==0 ) mDir = gDirectory->mkdir( dir.c_str() );
64  push();
65 
67  TIDDirectory d(_dir);
68  mDir = d.cwd();
69  pop();
70  }
71 
72  // push();
73  }
74 
75 
76  virtual ~TIDDirectory() { }
77 
78  void push() { mPop = gDirectory; if (mDir) mDir->cd(); }
79  void pop() { if (mPop) mPop->cd(); }
80 
81  void Write() { push(); mDir->Write(); pop(); }
82 
83  void pwd() const { mDir->pwd(); }
84  TDirectory* cwd() { return mDir; }
85 
86  void disable() { }
87  void restore() { }
88 
89  const std::string& name() const { return mname; }
90 
91  protected:
92 
93  std::string chop( std::string& s1, const std::string& s2="/" ) {
94  std::string s3 = "";
95  std::string::size_type pos = s1.find(s2);
96  if ( pos != std::string::npos ) {
97  s3 = s1.substr(0, pos+s2.size());
98  s1.erase(0, pos+s2.size());
99  }
100  return s3;
101  }
102 
103  protected:
104 
105  // bool mHAddState;
106  // bool mDAddState;
107 
108  std::string mname;
109 
110  TDirectory* mPop;
111  TDirectory* mDir;
112 
113 };
114 
115 
116 
117 #endif /* TIDA_TIDDIRECTORY_H */
118 
119 
ReadCellNoiseFromCoolCompare.s1
s1
Definition: ReadCellNoiseFromCoolCompare.py:378
TIDDirectory::chop
std::string chop(std::string &s1, const std::string &s2="/")
Definition: TIDDirectory.h:93
TIDDirectory::pop
void pop()
Definition: TIDDirectory.h:79
TIDDirectory::Write
void Write()
Definition: TIDDirectory.h:81
hist_file_dump.d
d
Definition: hist_file_dump.py:137
TIDDirectory
Definition: TIDDirectory.h:25
ParseInputs.gDirectory
gDirectory
Definition: Final2012/ParseInputs.py:133
beamspotman.n
n
Definition: beamspotman.py:731
TIDDirectory::pwd
void pwd() const
Definition: TIDDirectory.h:83
TIDDirectory::cwd
TDirectory * cwd()
Definition: TIDDirectory.h:84
TIDDirectory::disable
void disable()
Definition: TIDDirectory.h:86
TIDDirectory::mPop
TDirectory * mPop
Definition: TIDDirectory.h:110
TIDDirectory::name
const std::string & name() const
Definition: TIDDirectory.h:89
beamspotman.dir
string dir
Definition: beamspotman.py:623
TIDDirectory::mDir
TDirectory * mDir
Definition: TIDDirectory.h:111
ReadCellNoiseFromCoolCompare.s3
s3
Definition: ReadCellNoiseFromCoolCompare.py:380
TIDDirectory::push
void push()
Definition: TIDDirectory.h:78
TIDDirectory::restore
void restore()
Definition: TIDDirectory.h:87
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
ReadCellNoiseFromCoolCompare.s2
s2
Definition: ReadCellNoiseFromCoolCompare.py:379
TIDDirectory::mname
std::string mname
Definition: TIDDirectory.h:108
TIDDirectory::~TIDDirectory
virtual ~TIDDirectory()
Definition: TIDDirectory.h:76
TIDDirectory::TIDDirectory
TIDDirectory(const std::string &n="")
Definition: TIDDirectory.h:31