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
5//
6// Distributed under the Boost Software License, Version 1.0.
7// (See accompanying file LICENSE_1_0.txt or copy at
8// http://www.boost.org/LICENSE_1_0.txt)
9
10// Please feel free to contact me (krumnack@iastate.edu) for bug
11// reports, feature suggestions, praise and complaints.
12
13
14//
15// includes
16//
17
19
20#include <sstream>
21#include <vector>
26
27#include <iostream>
28
29//
30// method implementations
31//
32
33namespace SH
34{
35 void DiskListXRD ::
36 testInvariant () const
37 {
38 }
39
40
41
42 DiskListXRD ::
43 DiskListXRD (const std::string& val_server, const std::string& val_directory,
44 bool val_laxParser)
45 : m_server (val_server), m_directory (val_directory),
46 m_laxParser (val_laxParser), m_isRead (false)
47 {
48 RCU_NEW_INVARIANT (this);
49 }
50
51
52
53 bool DiskListXRD ::
54 getNext ()
55 {
57 using namespace msgScanDir;
58
59 if (!m_isRead)
60 {
61 std::string command = "xrdfs " + m_server + " ls -l " + m_directory;
62 ANA_MSG_DEBUG ("trying XRD command: " << command);
63 m_list = RCU::Shell::exec_read (command);
64 ANA_MSG_DEBUG ("XRD command output:\n" << command);
65 m_context = "command: " + command + "\n" + m_list;
66 m_isRead = true;
67 }
68
69 while (!m_list.empty())
70 {
71 std::string::size_type split1 = m_list.find ('\n');
72 if (split1 == std::string::npos)
73 split1 = m_list.size();
74
75 const std::string line (m_list.substr (0, split1));
76 ANA_MSG_DEBUG ("next XRD list line: " << line);
77 m_list = m_list.substr (split1 + 1);
78
79 std::string::size_type split2 = line.find ('/');
80 if (split2 != std::string::npos &&
81 (line[0] == '-' || line[0] == 'd'))
82 {
83 m_isDir = line[0] == 'd';
84 m_file = line.substr (split2);
85 ANA_MSG_DEBUG ("next XRD file found: " << m_file);
86 ANA_MSG_DEBUG ("XRD file isDir: " << m_isDir);
87 return true;
88 }
89
90 if (!line.empty())
91 {
92 std::string message = "failed to parse line: \"" + line + "\"\n" + m_context;
93
94 ANA_MSG_WARNING (message);
95 if (!m_laxParser)
96 throw std::runtime_error (message);
97 }
98 }
99 return false;
100 }
101
102
103
104 std::string DiskListXRD ::
105 getPath () const
106 {
107 RCU_READ_INVARIANT (this);
108 return "root://" + m_server + "/" + m_file;
109 }
110
111
112
113 DiskList *DiskListXRD ::
114 doOpenDir () const
115 {
116 RCU_READ_INVARIANT (this);
117
118 if (m_file.empty() || !m_isDir)
119 return 0;
120
121 return new DiskListXRD (m_server, m_file, m_laxParser);
122 }
123
124
125
126 std::string DiskListXRD ::
127 getDirname () const
128 {
129 RCU_READ_INVARIANT (this);
130 return m_directory;
131 }
132}
#define RCU_CHANGE_INVARIANT(x)
Definition Assert.h:231
#define RCU_NEW_INVARIANT(x)
Definition Assert.h:233
#define RCU_READ_INVARIANT(x)
Definition Assert.h:229
#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:92
std::string m_context
the context (for error reporting)
bool m_laxParser
whether we employ lax parsing
std::string m_directory
the directory we are reading
Definition DiskListXRD.h:96
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:45
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:37
This module provides a lot of global definitions, forward declarations and includes that are used by ...
Definition PrunDriver.h:15