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 <vector>
15
#include <
RootCoreUtils/Assert.h
>
16
#include <
RootCoreUtils/ShellExec.h
>
17
#include <
RootCoreUtils/ThrowMsg.h
>
18
#include <
SampleHandler/MessageCheck.h
>
19
20
#include <iostream>
21
22
//
23
// method implementations
24
//
25
26
namespace
SH
27
{
28
void
DiskListXRD ::
29
testInvariant ()
const
30
{
31
}
32
33
34
35
DiskListXRD ::
36
DiskListXRD (
const
std::string& val_server,
const
std::string& val_directory,
37
bool
val_laxParser)
38
:
m_server
(val_server),
m_directory
(val_directory),
39
m_laxParser
(val_laxParser),
m_isRead
(false)
40
{
41
RCU_NEW_INVARIANT
(
this
);
42
}
43
44
45
46
bool
DiskListXRD ::
47
getNext ()
48
{
49
RCU_CHANGE_INVARIANT
(
this
);
50
using namespace
msgScanDir;
51
52
if
(!
m_isRead
)
53
{
54
std::string command =
"xrdfs "
+
m_server
+
" ls -l "
+
m_directory
;
55
ANA_MSG_DEBUG
(
"trying XRD command: "
<< command);
56
m_list
=
RCU::Shell::exec_read
(command);
57
ANA_MSG_DEBUG
(
"XRD command output:\n"
<< command);
58
m_context
=
"command: "
+ command +
"\n"
+
m_list
;
59
m_isRead
=
true
;
60
}
61
62
while
(!
m_list
.empty())
63
{
64
std::string::size_type split1 =
m_list
.find (
'\n'
);
65
if
(split1 == std::string::npos)
66
split1 =
m_list
.size();
67
68
const
std::string line (
m_list
.substr (0, split1));
69
ANA_MSG_DEBUG
(
"next XRD list line: "
<< line);
70
m_list
=
m_list
.substr (split1 + 1);
71
72
std::string::size_type split2 = line.find (
'/'
);
73
if
(split2 != std::string::npos &&
74
(line[0] ==
'-'
|| line[0] ==
'd'
))
75
{
76
m_isDir
= line[0] ==
'd'
;
77
m_file
= line.substr (split2);
78
ANA_MSG_DEBUG
(
"next XRD file found: "
<<
m_file
);
79
ANA_MSG_DEBUG
(
"XRD file isDir: "
<<
m_isDir
);
80
return
true
;
81
}
82
83
if
(!line.empty())
84
{
85
std::string message =
"failed to parse line: \""
+ line +
"\"\n"
+
m_context
;
86
87
ANA_MSG_WARNING
(message);
88
if
(!
m_laxParser
)
89
throw
std::runtime_error (message);
90
}
91
}
92
return
false
;
93
}
94
95
96
97
std::string DiskListXRD ::
98
getPath ()
const
99
{
100
RCU_READ_INVARIANT
(
this
);
101
return
"root://"
+
m_server
+
"/"
+
m_file
;
102
}
103
104
105
106
DiskList
*DiskListXRD ::
107
doOpenDir ()
const
108
{
109
RCU_READ_INVARIANT
(
this
);
110
111
if
(
m_file
.empty() || !
m_isDir
)
112
return
0;
113
114
return
new
DiskListXRD
(
m_server
,
m_file
,
m_laxParser
);
115
}
116
117
118
119
std::string DiskListXRD ::
120
getDirname ()
const
121
{
122
RCU_READ_INVARIANT
(
this
);
123
return
m_directory
;
124
}
125
}
Assert.h
RCU_CHANGE_INVARIANT
#define RCU_CHANGE_INVARIANT(x)
Definition
Assert.h:226
RCU_NEW_INVARIANT
#define RCU_NEW_INVARIANT(x)
Definition
Assert.h:228
RCU_READ_INVARIANT
#define RCU_READ_INVARIANT(x)
Definition
Assert.h:224
ANA_MSG_WARNING
#define ANA_MSG_WARNING(xmsg)
Macro printing warning messages.
Definition
Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:292
ANA_MSG_DEBUG
#define ANA_MSG_DEBUG(xmsg)
Macro printing debug messages.
Definition
Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:288
DiskListXRD.h
MessageCheck.h
ShellExec.h
ThrowMsg.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_isRead
bool m_isRead
whether the directory has been read
Definition
DiskListXRD.h:112
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:36
SH::DiskListXRD::m_isDir
bool m_isDir
whether this is a directory
Definition
DiskListXRD.h:108
SH::DiskListXRD::m_file
std::string m_file
the last file we read
Definition
DiskListXRD.h:104
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:34
SH
This module provides a lot of global definitions, forward declarations and includes that are used by ...
Definition
PrunDriver.h:15
Generated on
for ATLAS Offline Software by
1.17.0