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

a DiskList implementation for the SRM protocol More...

#include <DiskListSRM.h>

Inheritance diagram for SH::DiskListSRM:
Collaboration diagram for SH::DiskListSRM:

Public Member Functions

void testInvariant () const
 test the invariant of this object
 DiskListSRM (const std::string &val_dir)
 make the listing for the given directory
 DiskListSRM (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
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::unique_ptr< DiskListopenDirUnique () 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 () override
 get the next list entry
virtual std::string getPath () const override
 the path for the current entry.
virtual DiskListdoOpenDir () const override
 make a new list object for the sub-directory
virtual std::string getDirname () const override
 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
std::string m_list
 the result of the directory listing
std::string::size_type m_pos = 0
 the current parse position within m_list
std::string m_file
 the last file we read
bool m_isDir = false
 whether this is a directory
bool m_isRead = false
 whether the directory has been read
State m_state
 the current state

Detailed Description

a DiskList implementation for the SRM protocol

Definition at line 17 of file DiskListSRM.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 173 of file DiskList.h.

174 {
175 S_BLANK,
176 S_VALID,
177 S_DONE,
178 S_BROKEN
179 };
@ S_VALID
holding a valid entry
Definition DiskList.h:176
@ S_DONE
finished reading entries
Definition DiskList.h:177
@ S_BROKEN
an error occured
Definition DiskList.h:178
@ S_BLANK
just initialized
Definition DiskList.h:175

Constructor & Destructor Documentation

◆ DiskListSRM() [1/2]

SH::DiskListSRM::DiskListSRM ( 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 29 of file DiskListSRM.cxx.

31 : m_dir (val_dir), m_prefix (val_dir)
32 {
33 RCU_NEW_INVARIANT (this);
34 }
#define RCU_NEW_INVARIANT(x)
Definition Assert.h:221
std::string m_dir
the directory we are reading
Definition DiskListSRM.h:92
std::string m_prefix
the directory from with to read actual files
Definition DiskListSRM.h:96

◆ DiskListSRM() [2/2]

SH::DiskListSRM::DiskListSRM ( 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 38 of file DiskListSRM.cxx.

40 : m_dir (val_dir), m_prefix (val_prefix)
41 {
42 RCU_NEW_INVARIANT (this);
43 }

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 113 of file DiskList.cxx.

115 {
116 RCU_READ_INVARIANT (this);
117 return getDirname ();
118 }
#define RCU_READ_INVARIANT(x)
Definition Assert.h:217
virtual std::string getDirname() const =0
the base path for the directory listed

◆ doOpenDir()

DiskList * SH::DiskListSRM::doOpenDir ( ) const
overrideprotectedvirtual

make a new list object for the sub-directory

Returns
a new list object for the sub-directory, or nullptr 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 110 of file DiskListSRM.cxx.

112 {
113 RCU_READ_INVARIANT (this);
114
115 if (m_file.empty() || !m_isDir)
116 return nullptr;
117
118 return new DiskListSRM (m_dir + "/" + m_file, m_prefix + "/" + m_file);
119 }
DiskListSRM(const std::string &val_dir)
make the listing for the given directory
bool m_isDir
whether this is a directory
std::string m_file
the last file we read

◆ 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 80 of file DiskList.cxx.

82 {
83 // no invariant used
84 std::string result = path();
85 std::string::size_type split = result.rfind ('/');
86 if (split != std::string::npos)
87 result = result.substr (split + 1);
88 return result;
89 }
std::string path() const
the path for the current entry.
Definition DiskList.cxx:71
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:179

◆ getDirname()

std::string SH::DiskListSRM::getDirname ( ) const
overrideprotectedvirtual

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 123 of file DiskListSRM.cxx.

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

◆ getNext()

bool SH::DiskListSRM::getNext ( )
overrideprotectedvirtual

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 47 of file DiskListSRM.cxx.

49 {
51
52 if (!m_isRead)
53 {
55 m_isRead = true;
56 m_pos = 0;
57 // rationale: skip the header line of the srmls output
58 std::string::size_type split1 = m_list.find ('\n');
59 if (split1 == std::string::npos)
60 return false;
61 m_pos = split1 + 1;
62 }
63
64 // rationale: we advance a running index through m_list rather than
65 // repeatedly copying its tail, so that listing N entries costs
66 // O(N) rather than O(N^2).
67 while (m_pos < m_list.size())
68 {
69 std::string::size_type split1 = m_list.find ('\n', m_pos);
70 std::string line;
71 if (split1 == std::string::npos)
72 {
73 line = m_list.substr (m_pos);
74 m_pos = m_list.size();
75 } else
76 {
77 line = m_list.substr (m_pos, split1 - m_pos);
78 m_pos = split1 + 1;
79 }
80 if (line.size() > 2)
81 {
82 std::string::size_type split2 = line.rfind ('/', line.size()-2);
83 if (split2 != std::string::npos)
84 {
85 m_file = line.substr (split2 + 1);
86 if (m_file[m_file.size()-1] == '/')
87 {
88 m_isDir = true;
89 m_file.resize (m_file.size()-1);
90 } else
91 m_isDir = false;
92 return true;
93 }
94 }
95 }
96 return false;
97 }
#define RCU_CHANGE_INVARIANT(x)
Definition Assert.h:219
std::string::size_type m_pos
the current parse position within m_list
bool m_isRead
whether the directory has been read
std::string m_list
the result of the directory listing
std::string exec_read(const std::string &cmd)
effects: execute the given command and return the output returns: the output of the command guarantee...
Definition ShellExec.cxx:35
std::string quote(const std::string &name)
effects: quote the given name to protect it from the shell returns: the quoted name guarantee: strong...
Definition ShellExec.cxx:65

◆ getPath()

std::string SH::DiskListSRM::getPath ( ) const
overrideprotectedvirtual

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 101 of file DiskListSRM.cxx.

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

◆ 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 46 of file DiskList.cxx.

48 {
50 switch (m_state)
51 {
52 case S_BLANK:
53 case S_VALID:
55 if (getNext())
57 else
59 return m_state == S_VALID;
60 case S_DONE:
61 throw std::runtime_error ("DiskList::next: already finished processing list");
62 case S_BROKEN:
63 throw std::runtime_error ("DiskList::next: list is in error state");
64 };
65 return false; // compiler dummy
66 }
State m_state
the current state
Definition DiskList.h:181
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 nullptr if it is not a directory
Precondition
(soft) next() has been called successfully
Guarantee
strong
Failures
out of memory III

Definition at line 93 of file DiskList.cxx.

95 {
96 RCU_READ_INVARIANT (this);
97 RCU_REQUIRE2_SOFT (m_state == S_VALID, "getNext() has not been called successfully");
98 return doOpenDir();
99 }
#define RCU_REQUIRE2_SOFT(x, y)
Definition Assert.h:143
virtual DiskList * doOpenDir() const =0
make a new list object for the sub-directory

◆ openDirUnique()

std::unique_ptr< DiskList > SH::DiskList::openDirUnique ( ) const
inherited

make a new list object for the sub-directory

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

Definition at line 103 of file DiskList.cxx.

105 {
106 RCU_READ_INVARIANT (this);
107 RCU_REQUIRE2_SOFT (m_state == S_VALID, "getNext() has not been called successfully");
108 return std::unique_ptr<DiskList> (doOpenDir());
109 }

◆ 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 70 of file DiskList.cxx.

72 {
73 RCU_READ_INVARIANT (this);
74 RCU_REQUIRE2_SOFT (m_state == S_VALID, "getNext() has not been called successfully");
75 return getPath();
76 }
virtual std::string getPath() const =0
the path for the current entry.

◆ testInvariant()

void SH::DiskListSRM::testInvariant ( ) const

test the invariant of this object

Guarantee
no-fail

Definition at line 22 of file DiskListSRM.cxx.

24 {
25 }

Member Data Documentation

◆ m_dir

std::string SH::DiskListSRM::m_dir
private

the directory we are reading

Definition at line 92 of file DiskListSRM.h.

◆ m_file

std::string SH::DiskListSRM::m_file
private

the last file we read

Definition at line 108 of file DiskListSRM.h.

◆ m_isDir

bool SH::DiskListSRM::m_isDir = false
private

whether this is a directory

Definition at line 112 of file DiskListSRM.h.

◆ m_isRead

bool SH::DiskListSRM::m_isRead = false
private

whether the directory has been read

Definition at line 116 of file DiskListSRM.h.

◆ m_list

std::string SH::DiskListSRM::m_list
private

the result of the directory listing

Definition at line 100 of file DiskListSRM.h.

◆ m_pos

std::string::size_type SH::DiskListSRM::m_pos = 0
private

the current parse position within m_list

Definition at line 104 of file DiskListSRM.h.

◆ m_prefix

std::string SH::DiskListSRM::m_prefix
private

the directory from with to read actual files

Definition at line 96 of file DiskListSRM.h.

◆ m_state

State SH::DiskList::m_state
privateinherited

the current state

Definition at line 181 of file DiskList.h.


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