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
6
7//
8// includes
9//
10
12
13#include <vector>
17
18//
19// method implementations
20//
21
22namespace SH
23{
24 void DiskListSRM ::
25 testInvariant () const
26 {
27 }
28
29
30
31 DiskListSRM ::
32 DiskListSRM (const std::string& val_dir)
33 : m_dir (val_dir), m_prefix (val_dir)
34 {
35 RCU_NEW_INVARIANT (this);
36 }
37
38
39
40 DiskListSRM ::
41 DiskListSRM (const std::string& val_dir, const std::string& val_prefix)
42 : m_dir (val_dir), m_prefix (val_prefix)
43 {
44 RCU_NEW_INVARIANT (this);
45 }
46
47
48
49 bool DiskListSRM ::
50 getNext ()
51 {
53
54 if (m_list.empty())
55 {
56 m_list = RCU::Shell::exec_read ("srmls " + m_dir);
57 std::string::size_type split1 = m_list.find ('\n');
58 if (split1 == std::string::npos)
59 return false;
60 m_list = m_list.substr (split1 + 1);
61 }
62
63 while (!m_list.empty())
64 {
65 std::string::size_type split1 = m_list.find ('\n');
66 if (split1 == std::string::npos)
67 return false;
68
69 const std::string line = m_list.substr (0, split1);
70 m_list = m_list.substr (split1 + 1);
71 if (line.size() > 2)
72 {
73 std::string::size_type split2 = line.rfind ('/', line.size()-2);
74 if (split2 != std::string::npos)
75 {
76 m_file = line.substr (split2 + 1);
77 if (m_file[m_file.size()-1] == '/')
78 {
79 m_isDir = true;
80 m_file.resize (m_file.size()-1);
81 } else
82 m_isDir = false;
83 return true;
84 }
85 }
86 }
87 return false;
88 }
89
90
91
92 std::string DiskListSRM ::
93 getPath () const
94 {
95 RCU_READ_INVARIANT (this);
96 return m_prefix + "/" + m_file;
97 }
98
99
100
101 DiskList *DiskListSRM ::
102 doOpenDir () const
103 {
104 RCU_READ_INVARIANT (this);
105
106 if (m_file.empty() || !m_isDir)
107 return 0;
108
109 return new DiskListSRM (m_dir + "/" + m_file, m_prefix + "/" + m_file);
110 }
111
112
113
114 std::string DiskListSRM ::
115 getDirname () const
116 {
117 RCU_READ_INVARIANT (this);
118 return m_dir;
119 }
120}
#define RCU_CHANGE_INVARIANT(x)
Definition Assert.h:226
#define RCU_NEW_INVARIANT(x)
Definition Assert.h:228
#define RCU_READ_INVARIANT(x)
Definition Assert.h:224
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
Definition DiskListSRM.h:92
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
Definition DiskListSRM.h:96
DiskList()
standard constructor
Definition DiskList.cxx:38
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:34
This module provides a lot of global definitions, forward declarations and includes that are used by ...
Definition PrunDriver.h:15