ATLAS Offline Software
Loading...
Searching...
No Matches
DiskListSRM.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 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>
24
25//
26// method implementations
27//
28
29namespace SH
30{
31 void DiskListSRM ::
32 testInvariant () const
33 {
34 }
35
36
37
38 DiskListSRM ::
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
47 DiskListSRM ::
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
56 bool DiskListSRM ::
57 getNext ()
58 {
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.resize (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
108 DiskList *DiskListSRM ::
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}
#define RCU_CHANGE_INVARIANT(x)
Definition Assert.h:231
#define RCU_NEW_INVARIANT(x)
Definition Assert.h:233
#define RCU_READ_INVARIANT(x)
Definition Assert.h:229
DiskListSRM(const std::string &val_dir)
make the listing for the given directory
bool m_isDir
whether this is a directory
std::string m_dir
the directory we are reading
std::string m_file
the last file we read
std::string m_list
the result of the directory listing
std::string m_prefix
the directory from with to read actual files
DiskList()
standard constructor
Definition DiskList.cxx:45
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
This module provides a lot of global definitions, forward declarations and includes that are used by ...
Definition PrunDriver.h:15