ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
D3PDTools
SampleHandler
Root
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
11
#include <
SampleHandler/DiskListSRM.h
>
12
13
#include <
RootCoreUtils/Assert.h
>
14
#include <
RootCoreUtils/ShellExec.h
>
15
16
//
17
// method implementations
18
//
19
20
namespace
SH
21
{
22
void
DiskListSRM ::
23
testInvariant ()
const
24
{
25
}
26
27
28
29
DiskListSRM ::
30
DiskListSRM (
const
std::string& val_dir)
31
:
m_dir
(val_dir),
m_prefix
(val_dir)
32
{
33
RCU_NEW_INVARIANT
(
this
);
34
}
35
36
37
38
DiskListSRM ::
39
DiskListSRM (
const
std::string& val_dir,
const
std::string& val_prefix)
40
:
m_dir
(val_dir),
m_prefix
(val_prefix)
41
{
42
RCU_NEW_INVARIANT
(
this
);
43
}
44
45
46
47
bool
DiskListSRM ::
48
getNext ()
49
{
50
RCU_CHANGE_INVARIANT
(
this
);
51
52
if
(!
m_isRead
)
53
{
54
m_list
=
RCU::Shell::exec_read
(
"srmls "
+
RCU::Shell::quote
(
m_dir
));
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
}
98
99
100
101
std::string DiskListSRM ::
102
getPath ()
const
103
{
104
RCU_READ_INVARIANT
(
this
);
105
return
m_prefix
+
"/"
+
m_file
;
106
}
107
108
109
110
DiskList
*DiskListSRM ::
111
doOpenDir ()
const
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
}
120
121
122
123
std::string DiskListSRM ::
124
getDirname ()
const
125
{
126
RCU_READ_INVARIANT
(
this
);
127
return
m_dir
;
128
}
129
}
Assert.h
RCU_CHANGE_INVARIANT
#define RCU_CHANGE_INVARIANT(x)
Definition
Assert.h:219
RCU_NEW_INVARIANT
#define RCU_NEW_INVARIANT(x)
Definition
Assert.h:221
RCU_READ_INVARIANT
#define RCU_READ_INVARIANT(x)
Definition
Assert.h:217
DiskListSRM.h
ShellExec.h
SH::DiskListSRM::DiskListSRM
DiskListSRM(const std::string &val_dir)
make the listing for the given directory
Definition
DiskListSRM.cxx:30
SH::DiskListSRM::m_isDir
bool m_isDir
whether this is a directory
Definition
DiskListSRM.h:112
SH::DiskListSRM::m_dir
std::string m_dir
the directory we are reading
Definition
DiskListSRM.h:92
SH::DiskListSRM::m_file
std::string m_file
the last file we read
Definition
DiskListSRM.h:108
SH::DiskListSRM::m_pos
std::string::size_type m_pos
the current parse position within m_list
Definition
DiskListSRM.h:104
SH::DiskListSRM::m_isRead
bool m_isRead
whether the directory has been read
Definition
DiskListSRM.h:116
SH::DiskListSRM::m_list
std::string m_list
the result of the directory listing
Definition
DiskListSRM.h:100
SH::DiskListSRM::m_prefix
std::string m_prefix
the directory from with to read actual files
Definition
DiskListSRM.h:96
SH::DiskList::DiskList
DiskList()
standard constructor
Definition
DiskList.cxx:38
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:35
RCU::Shell::quote
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
SH
This module provides a lot of global definitions, forward declarations and includes that are used by ...
Definition
DiskList.cxx:21
Generated on
for ATLAS Offline Software by
1.17.0