ATLAS Offline Software
DiskListSRM.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 //
6 // Distributed under the Boost Software License, Version 1.0.
7 // (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
9 
10 // Please feel free to contact me (krumnack@iastate.edu) for bug
11 // reports, feature suggestions, praise and complaints.
12 
13 
14 //
15 // includes
16 //
17 
19 
20 #include <vector>
21 #include <RootCoreUtils/Assert.h>
23 #include <RootCoreUtils/ThrowMsg.h>
24 
25 //
26 // method implementations
27 //
28 
29 namespace SH
30 {
32  testInvariant () const
33  {
34  }
35 
36 
37 
39  DiskListSRM (const std::string& val_dir)
40  : m_dir (val_dir), m_prefix (val_dir)
41  {
42  RCU_NEW_INVARIANT (this);
43  }
44 
45 
46 
48  DiskListSRM (const std::string& val_dir, const std::string& val_prefix)
49  : m_dir (val_dir), m_prefix (val_prefix)
50  {
51  RCU_NEW_INVARIANT (this);
52  }
53 
54 
55 
57  getNext ()
58  {
59  RCU_CHANGE_INVARIANT (this);
60 
61  if (m_list.empty())
62  {
63  m_list = RCU::Shell::exec_read ("srmls " + m_dir);
64  std::string::size_type split1 = m_list.find ('\n');
65  if (split1 == std::string::npos)
66  return false;
67  m_list = m_list.substr (split1 + 1);
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  const std::string line = m_list.substr (0, split1);
77  m_list = m_list.substr (split1 + 1);
78  if (line.size() > 2)
79  {
80  std::string::size_type split2 = line.rfind ('/', line.size()-2);
81  if (split2 != std::string::npos)
82  {
83  m_file = line.substr (split2 + 1);
84  if (m_file[m_file.size()-1] == '/')
85  {
86  m_isDir = true;
87  m_file = m_file.substr (0, m_file.size()-1);
88  } else
89  m_isDir = false;
90  return true;
91  }
92  }
93  }
94  return false;
95  }
96 
97 
98 
99  std::string DiskListSRM ::
100  getPath () const
101  {
102  RCU_READ_INVARIANT (this);
103  return m_prefix + "/" + m_file;
104  }
105 
106 
107 
109  doOpenDir () const
110  {
111  RCU_READ_INVARIANT (this);
112 
113  if (m_file.empty() || !m_isDir)
114  return 0;
115 
116  return new DiskListSRM (m_dir + "/" + m_file, m_prefix + "/" + m_file);
117  }
118 
119 
120 
121  std::string DiskListSRM ::
122  getDirname () const
123  {
124  RCU_READ_INVARIANT (this);
125  return m_dir;
126  }
127 }
SH::DiskListSRM::m_dir
std::string m_dir
the directory we are reading
Definition: DiskListSRM.h:100
checkFileSG.line
line
Definition: checkFileSG.py:75
SH::DiskListSRM::getPath
virtual std::string getPath() const
the path for the current entry.
Definition: DiskListSRM.cxx:100
m_dir
TDirectory & m_dir
The directory we need to return to.
Definition: OutputStreamData.cxx:41
SH::DiskListSRM::m_list
std::string m_list
the result of the directory listing
Definition: DiskListSRM.h:108
SH::DiskListSRM::getDirname
virtual std::string getDirname() const
the base path for the directory listed
Definition: DiskListSRM.cxx:122
ShellExec.h
Assert.h
SH::DiskListSRM::m_isDir
bool m_isDir
whether this is a directory
Definition: DiskListSRM.h:116
SH::DiskListSRM::m_file
std::string m_file
the last file we read
Definition: DiskListSRM.h:112
DiskListSRM.h
SH::DiskList
an interface for listing directory contents, locally or on a file server
Definition: DiskList.h:32
SH::DiskListSRM::doOpenDir
virtual DiskList * doOpenDir() const
make a new list object for the sub-directory
Definition: DiskListSRM.cxx:109
SH::DiskListSRM::m_prefix
std::string m_prefix
the directory from with to read actual files
Definition: DiskListSRM.h:104
ThrowMsg.h
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
SH::DiskListSRM::getNext
virtual bool getNext()
get the next list entry
Definition: DiskListSRM.cxx:57
RCU_CHANGE_INVARIANT
#define RCU_CHANGE_INVARIANT(x)
Definition: Assert.h:231
SH
This module provides a lot of global definitions, forward declarations and includes that are used by ...
Definition: PrunDriver.h:15
RCU_READ_INVARIANT
#define RCU_READ_INVARIANT(x)
Definition: Assert.h:229
SH::DiskListSRM::DiskListSRM
DiskListSRM(const std::string &val_dir)
make the listing for the given directory
Definition: DiskListSRM.cxx:39
SH::DiskListSRM::testInvariant
void testInvariant() const
test the invariant of this object
Definition: DiskListSRM.cxx:32
RCU_NEW_INVARIANT
#define RCU_NEW_INVARIANT(x)
Definition: Assert.h:233