ATLAS Offline Software
Loading...
Searching...
No Matches
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
12
13#include <sstream>
14#include <vector>
19
20#include <iostream>
21
22//
23// method implementations
24//
25
26namespace 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 {
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}
#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
#define ANA_MSG_WARNING(xmsg)
Macro printing warning messages.
#define ANA_MSG_DEBUG(xmsg)
Macro printing debug messages.
std::string m_server
the server from which we are reading
Definition DiskListXRD.h:84
std::string m_context
the context (for error reporting)
Definition DiskListXRD.h:96
bool m_laxParser
whether we employ lax parsing
Definition DiskListXRD.h:92
std::string m_directory
the directory we are reading
Definition DiskListXRD.h:88
std::string m_list
the result of the directory listing
bool m_isRead
whether the directory has been read
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
bool m_isDir
whether this is a directory
std::string m_file
the last file we read
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