ATLAS Offline Software
Public Member Functions | Protected Member Functions | Private Types | Private Attributes | List of all members
SH::DiskListEOS Class Reference

a DiskList implementation for EOS More...

#include <DiskListEOS.h>

Inheritance diagram for SH::DiskListEOS:
Collaboration diagram for SH::DiskListEOS:

Public Member Functions

void testInvariant () const
 test the invariant of this object More...
 
 DiskListEOS (const std::string &val_dir)
 make the listing for the given directory More...
 
 DiskListEOS (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 More...
 
bool next ()
 get the next list entry More...
 
std::string path () const
 the path for the current entry. More...
 
std::string fileName () const
 the filename for the current entry More...
 
DiskListopenDir () const
 make a new list object for the sub-directory More...
 
std::string dirname () const
 the base path for the directory listed More...
 

Protected Member Functions

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

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 More...
 
std::string m_prefix
 the directory from with to read actual files More...
 
std::string m_list
 the result of the directory listing More...
 
std::string m_file
 the last file we read More...
 
bool m_isDir
 whether this is a directory More...
 
bool m_isRead
 whether the directory has been read More...
 
State m_state
 the current state More...
 

Detailed Description

a DiskList implementation for EOS

Definition at line 25 of file DiskListEOS.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  };

Constructor & Destructor Documentation

◆ DiskListEOS() [1/2]

SH::DiskListEOS::DiskListEOS ( 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 41 of file DiskListEOS.cxx.

43  : m_dir (val_dir), m_prefix ("root://eosatlas.cern.ch/" + val_dir), m_isRead (false)
44  {
45  RCU_NEW_INVARIANT (this);
46  }

◆ DiskListEOS() [2/2]

SH::DiskListEOS::DiskListEOS ( 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 50 of file DiskListEOS.cxx.

52  : m_dir (val_dir), m_prefix (val_prefix), m_isRead (false)
53  {
54  RCU_NEW_INVARIANT (this);
55  }

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  }

◆ doOpenDir()

DiskList * SH::DiskListEOS::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 111 of file DiskListEOS.cxx.

113  {
114  RCU_READ_INVARIANT (this);
115 
116  if (m_file.empty() || !m_isDir)
117  return 0;
118 
119  return new DiskListEOS (m_dir + "/" + m_file, m_prefix + "/" + m_file);
120  }

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

◆ getDirname()

std::string SH::DiskListEOS::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 DiskListEOS.cxx.

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

◆ getNext()

bool SH::DiskListEOS::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 59 of file DiskListEOS.cxx.

61  {
62  RCU_CHANGE_INVARIANT (this);
63 
64  if (!m_isRead)
65  {
66  m_list = RCU::Shell::exec_read ("eos ls -l " + m_dir);
67  m_isRead = true;
68  }
69 
70  while (!m_list.empty())
71  {
72  std::string::size_type split1 = m_list.find ('\n');
73  if (split1 == std::string::npos)
74  return false;
75 
76  std::string line (m_list.substr (0, split1));
77  m_list = m_list.substr (split1 + 1);
78 
79  // rationale: this should handle it correctly if there is a
80  // formatting escape sequence at the beginning of the line.
81  std::string::size_type split2 = line.find ("r");
82  m_isDir = line[split2-1] == 'd';
83  line = line.substr (split2);
84 
85  std::istringstream str (line);
86  std::string fields [9];
87  for (unsigned iter = 0, end = 9; iter != end; ++ iter)
88  {
89  if (!(str >> fields[iter]))
90  RCU_THROW_MSG ("failed to parse line: " + line);
91  }
92  if (fields[0].empty())
93  RCU_THROW_MSG ("failed to parse line: " + line);
94  m_file = fields[8];
95  return true;
96  }
97  return false;
98  }

◆ getPath()

std::string SH::DiskListEOS::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 102 of file DiskListEOS.cxx.

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

◆ 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  {
56  RCU_CHANGE_INVARIANT (this);
57  switch (m_state)
58  {
59  case S_BLANK:
60  case S_VALID:
61  m_state = S_BROKEN;
62  if (getNext())
63  m_state = S_VALID;
64  else
65  m_state = S_DONE;
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  }

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

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

◆ testInvariant()

void SH::DiskListEOS::testInvariant ( ) const

test the invariant of this object

Guarantee
no-fail

Definition at line 34 of file DiskListEOS.cxx.

36  {
37  }

Member Data Documentation

◆ m_dir

std::string SH::DiskListEOS::m_dir
private

the directory we are reading

Definition at line 100 of file DiskListEOS.h.

◆ m_file

std::string SH::DiskListEOS::m_file
private

the last file we read

Definition at line 112 of file DiskListEOS.h.

◆ m_isDir

bool SH::DiskListEOS::m_isDir
private

whether this is a directory

Definition at line 116 of file DiskListEOS.h.

◆ m_isRead

bool SH::DiskListEOS::m_isRead
private

whether the directory has been read

Definition at line 120 of file DiskListEOS.h.

◆ m_list

std::string SH::DiskListEOS::m_list
private

the result of the directory listing

Definition at line 108 of file DiskListEOS.h.

◆ m_prefix

std::string SH::DiskListEOS::m_prefix
private

the directory from with to read actual files

Definition at line 104 of file DiskListEOS.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:
checkFileSG.line
line
Definition: checkFileSG.py:75
SH::DiskListEOS::DiskListEOS
DiskListEOS(const std::string &val_dir)
make the listing for the given directory
Definition: DiskListEOS.cxx:42
get_generator_info.result
result
Definition: get_generator_info.py:21
SH::DiskListEOS::m_prefix
std::string m_prefix
the directory from with to read actual files
Definition: DiskListEOS.h:104
SH::DiskList::doOpenDir
virtual DiskList * doOpenDir() const =0
make a new list object for the sub-directory
SH::DiskList::getDirname
virtual std::string getDirname() const =0
the base path for the directory listed
SH::DiskList::getNext
virtual bool getNext()=0
get the next list entry
SH::DiskListEOS::m_file
std::string m_file
the last file we read
Definition: DiskListEOS.h:112
empty
bool empty(TH1 *h)
Definition: computils.cxx:294
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
SH::DiskList::S_VALID
@ S_VALID
holding a valid entry
Definition: DiskList.h:169
SH::DiskListEOS::m_isRead
bool m_isRead
whether the directory has been read
Definition: DiskListEOS.h:120
SH::DiskListEOS::m_list
std::string m_list
the result of the directory listing
Definition: DiskListEOS.h:108
SH::DiskListEOS::m_isDir
bool m_isDir
whether this is a directory
Definition: DiskListEOS.h:116
SH::DiskList::m_state
State m_state
the current state
Definition: DiskList.h:174
RCU_REQUIRE2_SOFT
#define RCU_REQUIRE2_SOFT(x, y)
Definition: Assert.h:155
RCU::Shell::exec_read
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:37
python.CaloScaleNoiseConfig.str
str
Definition: CaloScaleNoiseConfig.py:78
SH::DiskList::getPath
virtual std::string getPath() const =0
the path for the current entry.
SH::DiskList::S_BLANK
@ S_BLANK
just initialized
Definition: DiskList.h:168
RCU_CHANGE_INVARIANT
#define RCU_CHANGE_INVARIANT(x)
Definition: Assert.h:231
str
Definition: BTagTrackIpAccessor.cxx:11
RCU_THROW_MSG
#define RCU_THROW_MSG(message)
Definition: PrintMsg.h:58
SH::DiskList::path
std::string path() const
the path for the current entry.
Definition: DiskList.cxx:78
SH::DiskList::S_BROKEN
@ S_BROKEN
an error occured
Definition: DiskList.h:171
CaloCondBlobAlgs_fillNoiseFromASCII.fields
fields
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:106
RCU_READ_INVARIANT
#define RCU_READ_INVARIANT(x)
Definition: Assert.h:229
SH::DiskListEOS::m_dir
std::string m_dir
the directory we are reading
Definition: DiskListEOS.h:100
Trk::split
@ split
Definition: LayerMaterialProperties.h:38
SH::DiskList::S_DONE
@ S_DONE
finished reading entries
Definition: DiskList.h:170
RCU_NEW_INVARIANT
#define RCU_NEW_INVARIANT(x)
Definition: Assert.h:233