ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
D3PDTools
SampleHandler
Root
DiskListXRD.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3
*/
4
6
7
//
8
// includes
9
//
10
11
#include <
SampleHandler/DiskListXRD.h
>
12
13
#include <sstream>
14
#include <
RootCoreUtils/Assert.h
>
15
#include <
RootCoreUtils/ShellExec.h
>
16
#include <
SampleHandler/MessageCheck.h
>
17
18
//
19
// method implementations
20
//
21
22
namespace
SH
23
{
24
void
DiskListXRD ::
25
testInvariant ()
const
26
{
27
}
28
29
30
31
DiskListXRD ::
32
DiskListXRD (
const
std::string& val_server,
const
std::string& val_directory,
33
bool
val_laxParser)
34
:
m_server
(val_server),
m_directory
(val_directory),
35
m_laxParser
(val_laxParser),
m_isRead
(false)
36
{
37
RCU_NEW_INVARIANT
(
this
);
38
}
39
40
41
42
bool
DiskListXRD ::
43
getNext ()
44
{
45
RCU_CHANGE_INVARIANT
(
this
);
46
using namespace
msgScanDir;
47
48
if
(!
m_isRead
)
49
{
50
std::string command =
"xrdfs "
+
RCU::Shell::quote
(
m_server
) +
" ls -l "
+
RCU::Shell::quote
(
m_directory
);
51
ANA_MSG_DEBUG
(
"trying XRD command: "
<< command);
52
m_list
=
RCU::Shell::exec_read
(command);
53
ANA_MSG_DEBUG
(
"XRD command output:\n"
<<
m_list
);
54
m_context
=
"command: "
+ command +
"\n"
+
m_list
;
55
m_isRead
=
true
;
56
m_pos
= 0;
57
}
58
59
// rationale: we advance a running index through m_list rather than
60
// repeatedly copying its tail, so that listing N entries costs
61
// O(N) rather than O(N^2). a final line without a trailing
62
// newline is still processed.
63
while
(
m_pos
<
m_list
.size())
64
{
65
std::string::size_type split1 =
m_list
.find (
'\n'
,
m_pos
);
66
std::string line;
67
if
(split1 == std::string::npos)
68
{
69
line =
m_list
.substr (
m_pos
);
70
m_pos
=
m_list
.size();
71
}
else
72
{
73
line =
m_list
.substr (
m_pos
, split1 -
m_pos
);
74
m_pos
= split1 + 1;
75
}
76
ANA_MSG_DEBUG
(
"next XRD list line: "
<< line);
77
78
std::string::size_type split2 = line.find (
'/'
);
79
if
(split2 != std::string::npos &&
80
(line[0] ==
'-'
|| line[0] ==
'd'
))
81
{
82
m_isDir
= line[0] ==
'd'
;
83
m_file
= line.substr (split2);
84
ANA_MSG_DEBUG
(
"next XRD file found: "
<<
m_file
);
85
ANA_MSG_DEBUG
(
"XRD file isDir: "
<<
m_isDir
);
86
return
true
;
87
}
88
89
if
(!line.empty())
90
{
91
std::string message =
"failed to parse line: \""
+ line +
"\"\n"
+
m_context
;
92
93
ANA_MSG_WARNING
(message);
94
if
(!
m_laxParser
)
95
throw
std::runtime_error (message);
96
}
97
}
98
return
false
;
99
}
100
101
102
103
std::string DiskListXRD ::
104
getPath ()
const
105
{
106
RCU_READ_INVARIANT
(
this
);
107
return
"root://"
+
m_server
+
"/"
+
m_file
;
108
}
109
110
111
112
DiskList
*DiskListXRD ::
113
doOpenDir ()
const
114
{
115
RCU_READ_INVARIANT
(
this
);
116
117
if
(
m_file
.empty() || !
m_isDir
)
118
return
nullptr
;
119
120
return
new
DiskListXRD
(
m_server
,
m_file
,
m_laxParser
);
121
}
122
123
124
125
std::string DiskListXRD ::
126
getDirname ()
const
127
{
128
RCU_READ_INVARIANT
(
this
);
129
return
m_directory
;
130
}
131
}
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
ANA_MSG_DEBUG
#define ANA_MSG_DEBUG(xmsg,...)
Macro printing debug messages.
Definition
Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:289
ANA_MSG_WARNING
#define ANA_MSG_WARNING(xmsg,...)
Macro printing warning messages.
Definition
Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:293
DiskListXRD.h
MessageCheck.h
ShellExec.h
SH::DiskListXRD::m_server
std::string m_server
the server from which we are reading
Definition
DiskListXRD.h:84
SH::DiskListXRD::m_context
std::string m_context
the context (for error reporting)
Definition
DiskListXRD.h:96
SH::DiskListXRD::m_laxParser
bool m_laxParser
whether we employ lax parsing
Definition
DiskListXRD.h:92
SH::DiskListXRD::m_directory
std::string m_directory
the directory we are reading
Definition
DiskListXRD.h:88
SH::DiskListXRD::m_list
std::string m_list
the result of the directory listing
Definition
DiskListXRD.h:100
SH::DiskListXRD::m_pos
std::string::size_type m_pos
the current parse position within m_list
Definition
DiskListXRD.h:104
SH::DiskListXRD::m_isRead
bool m_isRead
whether the directory has been read
Definition
DiskListXRD.h:116
SH::DiskListXRD::DiskListXRD
DiskListXRD(const std::string &val_server, const std::string &val_dir, bool val_laxParsing=false)
make the listing for the given directory, but replacing the directory with prefix for the path
Definition
DiskListXRD.cxx:32
SH::DiskListXRD::m_isDir
bool m_isDir
whether this is a directory
Definition
DiskListXRD.h:112
SH::DiskListXRD::m_file
std::string m_file
the last file we read
Definition
DiskListXRD.h:108
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