ATLAS Offline Software
Loading...
Searching...
No Matches
SH::DiskListLocal Class Reference

a DiskList implementation for local directories More...

#include <DiskListLocal.h>

Inheritance diagram for SH::DiskListLocal:
Collaboration diagram for SH::DiskListLocal:

Public Member Functions

void testInvariant () const
 test the invariant of this object
 DiskListLocal (const std::string &val_dir)
 make the listing for the given directory
 DiskListLocal (const std::string &val_dir, const std::string &val_prefix)
 make the listing for the given directory, but replacing the directory with prefix for the path
virtual ~DiskListLocal ()
 standard destructor
bool next ()
 get the next list entry
std::string path () const
 the path for the current entry.
std::string fileName () const
 the filename for the current entry
DiskListopenDir () const
 make a new list object for the sub-directory
std::string dirname () const
 the base path for the directory listed

Protected Member Functions

virtual bool getNext ()
 get the next list entry
virtual std::string getPath () const
 the path for the current entry.
virtual DiskListdoOpenDir () const
 make a new list object for the sub-directory
virtual std::string getDirname () const
 the base path for the directory listed

Private Types

enum  State { S_BLANK , S_VALID , S_DONE , S_BROKEN }
 the current state More...

Private Attributes

std::string m_dir
 the directory we are reading
std::string m_prefix
 the directory from with to read actual files
void * m_dirp
 the directory pointer used
std::string m_file
 the file we last fetched
State m_state
 the current state

Detailed Description

a DiskList implementation for local directories

Definition at line 26 of file DiskListLocal.h.

Member Enumeration Documentation

◆ State

enum SH::DiskList::State
privateinherited

the current state

Enumerator
S_BLANK 

just initialized

S_VALID 

holding a valid entry

S_DONE 

finished reading entries

S_BROKEN 

an error occured

Definition at line 166 of file DiskList.h.

167 {
168 S_BLANK,
169 S_VALID,
170 S_DONE,
171 S_BROKEN
172 };
@ S_VALID
holding a valid entry
Definition DiskList.h:169
@ S_DONE
finished reading entries
Definition DiskList.h:170
@ S_BROKEN
an error occured
Definition DiskList.h:171
@ S_BLANK
just initialized
Definition DiskList.h:168

Constructor & Destructor Documentation

◆ DiskListLocal() [1/2]

SH::DiskListLocal::DiskListLocal ( const std::string & val_dir)

make the listing for the given directory

Parameters
val_dirthe directory to list
Guarantee
strong
Failures
out of memory II

Definition at line 38 of file DiskListLocal.cxx.

40 : m_dir (val_dir), m_prefix (val_dir), m_dirp (0)
41 {
42 RCU_NEW_INVARIANT (this);
43 }
#define RCU_NEW_INVARIANT(x)
Definition Assert.h:233
std::string m_prefix
the directory from with to read actual files
std::string m_dir
the directory we are reading
void * m_dirp
the directory pointer used

◆ DiskListLocal() [2/2]

SH::DiskListLocal::DiskListLocal ( const std::string & val_dir,
const std::string & val_prefix )

make the listing for the given directory, but replacing the directory with prefix for the path

Parameters
val_dirthe directory to list
val_prefixthe prefix with which val_dir will be replaced in the reported paths
Guarantee
strong
Failures
out of memory II
Rationale
this mechanism is meant to allow scanning file servers using one protocol, but then accessing them using another

Definition at line 47 of file DiskListLocal.cxx.

49 : m_dir (val_dir), m_prefix (val_prefix), m_dirp (0)
50 {
51 RCU_NEW_INVARIANT (this);
52 }

◆ ~DiskListLocal()

SH::DiskListLocal::~DiskListLocal ( )
virtual

standard destructor

Guarantee
no-fail

Definition at line 56 of file DiskListLocal.cxx.

58 {
60
61 if (m_dirp)
62 {
63 gSystem->FreeDirectory (m_dirp);
64 m_dirp = 0;
65 }
66 }
#define RCU_DESTROY_INVARIANT(x)
Definition Assert.h:235

Member Function Documentation

◆ dirname()

std::string SH::DiskList::dirname ( ) const
inherited

the base path for the directory listed

Guarantee
strong
Failures
out of memory II

Definition at line 110 of file DiskList.cxx.

112 {
113 RCU_READ_INVARIANT (this);
114 return getDirname ();
115 }
#define RCU_READ_INVARIANT(x)
Definition Assert.h:229
virtual std::string getDirname() const =0
the base path for the directory listed

◆ doOpenDir()

DiskList * SH::DiskListLocal::doOpenDir ( ) const
protectedvirtual

make a new list object for the sub-directory

Returns
a new list object for the sub-directory, or NULL if it is not a directory
Precondition
(soft) next() has been called successfully
Guarantee
strong
Failures
out of memory III
Rationale
the virtual part of DiskList::openDir()

Implements SH::DiskList.

Definition at line 109 of file DiskListLocal.cxx.

111 {
112 RCU_READ_INVARIANT (this);
113
114 std::unique_ptr<DiskListLocal> result
115 (new DiskListLocal (m_dir + "/" + m_file, m_prefix + "/" + m_file));
116 result->m_dirp = gSystem->OpenDirectory (result->m_dir.c_str());
117 if (result->m_dirp)
118 return result.release();
119 return 0;
120 }
DiskListLocal(const std::string &val_dir)
make the listing for the given directory
std::string m_file
the file we last fetched

◆ fileName()

std::string SH::DiskList::fileName ( ) const
inherited

the filename for the current entry

Returns
the filename for the current entry
Precondition
(soft) next() has been called successfully
Guarantee
strong
Failures
out of memory III

Definition at line 87 of file DiskList.cxx.

89 {
90 // no invariant used
91 std::string result = path();
92 std::string::size_type split = result.rfind ('/');
93 if (split != std::string::npos)
94 result = result.substr (split + 1);
95 return result;
96 }
std::string path() const
the path for the current entry.
Definition DiskList.cxx:78
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:177

◆ getDirname()

std::string SH::DiskListLocal::getDirname ( ) const
protectedvirtual

the base path for the directory listed

Guarantee
strong
Failures
out of memory II
Rationale
the virtual part of DiskList::dirname()

Implements SH::DiskList.

Definition at line 124 of file DiskListLocal.cxx.

126 {
127 RCU_READ_INVARIANT (this);
128 return m_dir;
129 }

◆ getNext()

bool SH::DiskListLocal::getNext ( )
protectedvirtual

get the next list entry

Returns
whether we found another entry
Guarantee
basic
Failures
i/o errors
Rationale
the virtual part of DiskList::next()

Implements SH::DiskList.

Definition at line 70 of file DiskListLocal.cxx.

72 {
74
75 if (!m_dirp)
76 {
77 m_dirp = gSystem->OpenDirectory (m_dir.c_str());
78 if (!m_dirp)
79 RCU_THROW_MSG ("could not open directory " + m_dir);
80 }
81
82 const char *subresult = 0;
83 do
84 {
85 subresult = gSystem->GetDirEntry (m_dirp);
86 if (subresult == 0)
87 {
88 gSystem->FreeDirectory (m_dirp);
89 m_dirp = 0;
90 m_file.clear ();
91 return false;
92 }
93 } while (strcmp (subresult, ".") == 0 || strcmp (subresult, "..") == 0);
94 m_file = subresult;
95 return subresult;
96 }
#define RCU_CHANGE_INVARIANT(x)
Definition Assert.h:231
#define RCU_THROW_MSG(message)
Definition PrintMsg.h:58

◆ getPath()

std::string SH::DiskListLocal::getPath ( ) const
protectedvirtual

the path for the current entry.

Returns
the path for the current entry
Precondition
(soft) next() has been called successfully
Guarantee
strong failures: out of memory III
Rationale
the virtual part of DiskList::path()

Implements SH::DiskList.

Definition at line 100 of file DiskListLocal.cxx.

102 {
103 RCU_READ_INVARIANT (this);
104 return m_prefix + "/" + m_file;
105 }

◆ next()

bool SH::DiskList::next ( )
inherited

get the next list entry

Returns
whether we found another entry
Guarantee
basic
Failures
i/o errors

Definition at line 53 of file DiskList.cxx.

55 {
57 switch (m_state)
58 {
59 case S_BLANK:
60 case S_VALID:
62 if (getNext())
64 else
66 return m_state == S_VALID;
67 case S_DONE:
68 RCU_THROW_MSG ("already finished processing list");
69 case S_BROKEN:
70 RCU_THROW_MSG ("list is in error state");
71 };
72 return false; // compiler dummy
73 }
State m_state
the current state
Definition DiskList.h:174
virtual bool getNext()=0
get the next list entry

◆ openDir()

DiskList * SH::DiskList::openDir ( ) const
inherited

make a new list object for the sub-directory

Returns
a new list object for the sub-directory, or NULL if it is not a directory
Precondition
(soft) next() has been called successfully
Guarantee
strong
Failures
out of memory III

Definition at line 100 of file DiskList.cxx.

102 {
103 RCU_READ_INVARIANT (this);
104 RCU_REQUIRE2_SOFT (m_state == S_VALID, "getNext() has not been called successfully");
105 return doOpenDir();
106 }
#define RCU_REQUIRE2_SOFT(x, y)
Definition Assert.h:155
virtual DiskList * doOpenDir() const =0
make a new list object for the sub-directory

◆ path()

std::string SH::DiskList::path ( ) const
inherited

the path for the current entry.

Returns
the path for the current entry
Precondition
(soft) next() has been called successfully
Guarantee
strong failures: out of memory III

Definition at line 77 of file DiskList.cxx.

79 {
80 RCU_READ_INVARIANT (this);
81 RCU_REQUIRE2_SOFT (m_state == S_VALID, "getNext() has not been called successfully");
82 return getPath();
83 }
virtual std::string getPath() const =0
the path for the current entry.

◆ testInvariant()

void SH::DiskListLocal::testInvariant ( ) const

test the invariant of this object

Guarantee
no-fail

Definition at line 31 of file DiskListLocal.cxx.

33 {
34 }

Member Data Documentation

◆ m_dir

std::string SH::DiskListLocal::m_dir
private

the directory we are reading

Definition at line 109 of file DiskListLocal.h.

◆ m_dirp

void* SH::DiskListLocal::m_dirp
private

the directory pointer used

Definition at line 117 of file DiskListLocal.h.

◆ m_file

std::string SH::DiskListLocal::m_file
private

the file we last fetched

Definition at line 121 of file DiskListLocal.h.

◆ m_prefix

std::string SH::DiskListLocal::m_prefix
private

the directory from with to read actual files

Definition at line 113 of file DiskListLocal.h.

◆ m_state

State SH::DiskList::m_state
privateinherited

the current state

Definition at line 174 of file DiskList.h.


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