CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
XrdFile Class Reference

#include <XrdFile.h>

Inheritance diagram for XrdFile:
Storage IOInput IOOutput

Public Member Functions

virtual void abort (void)
 
virtual void close (void)
 
virtual void create (const char *name, bool exclusive=false, int perms=0666)
 
virtual void create (const std::string &name, bool exclusive=false, int perms=0666)
 
virtual void open (const char *name, int flags=IOFlags::OpenRead, int perms=0666)
 
virtual void open (const std::string &name, int flags=IOFlags::OpenRead, int perms=0666)
 
virtual IOOffset position (IOOffset offset, Relative whence=SET)
 
virtual bool prefetch (const IOPosBuffer *what, IOSize n)
 
virtual IOSize read (void *into, IOSize n)
 
virtual IOSize read (void *into, IOSize n, IOOffset pos)
 
virtual IOSize readv (IOBuffer *into, IOSize n)
 
virtual IOSize readv (IOPosBuffer *into, IOSize n)
 
virtual void resize (IOOffset size)
 
virtual IOSize write (const void *from, IOSize n)
 
virtual IOSize write (const void *from, IOSize n, IOOffset pos)
 
 XrdFile (void)
 
 XrdFile (IOFD fd)
 
 XrdFile (const char *name, int flags=IOFlags::OpenRead, int perms=0666)
 
 XrdFile (const std::string &name, int flags=IOFlags::OpenRead, int perms=0666)
 
 ~XrdFile (void)
 
- Public Member Functions inherited from Storage
virtual bool eof (void) const
 
virtual void flush (void)
 
virtual IOOffset position (void) const
 
IOSize read (IOBuffer into, IOOffset pos)
 
virtual void rewind (void)
 
virtual IOOffset size (void) const
 
 Storage (void)
 
IOSize write (IOBuffer from, IOOffset pos)
 
virtual IOSize writev (const IOPosBuffer *from, IOSize buffers)
 
virtual ~Storage (void)
 
- Public Member Functions inherited from IOInput
int read (void)
 
IOSize read (IOBuffer into)
 
IOSize xread (IOBuffer into)
 
IOSize xread (void *into, IOSize n)
 
IOSize xreadv (IOBuffer *into, IOSize buffers)
 
virtual ~IOInput (void)
 Destruct the stream. A no-op. More...
 
- Public Member Functions inherited from IOOutput
IOSize write (unsigned char byte)
 
IOSize write (IOBuffer from)
 
virtual IOSize writev (const IOBuffer *from, IOSize buffers)
 
IOSize xwrite (const void *from, IOSize n)
 
IOSize xwrite (IOBuffer from)
 
IOSize xwritev (const IOBuffer *from, IOSize buffers)
 
virtual ~IOOutput (void)
 Destruct the stream. A no-op. More...
 

Private Member Functions

void addConnection (cms::Exception &)
 

Private Attributes

XrdClient * m_client
 
bool m_close
 
std::string m_name
 
IOOffset m_offset
 
XrdClientStatInfo m_stat
 

Additional Inherited Members

- Public Types inherited from Storage
enum  Relative { SET, CURRENT, END }
 

Detailed Description

Definition at line 10 of file XrdFile.h.

Constructor & Destructor Documentation

XrdFile::XrdFile ( void  )

Definition at line 7 of file XrdFile.cc.

References m_stat.

8  : m_client (0),
9  m_offset (0),
10  m_stat(),
11  m_close (false),
12  m_name()
13 {
14  memset(&m_stat, 0, sizeof (m_stat));
15 }
XrdClientStatInfo m_stat
Definition: XrdFile.h:57
bool m_close
Definition: XrdFile.h:58
IOOffset m_offset
Definition: XrdFile.h:56
XrdClient * m_client
Definition: XrdFile.h:55
std::string m_name
Definition: XrdFile.h:59
XrdFile::XrdFile ( IOFD  fd)
XrdFile::XrdFile ( const char *  name,
int  flags = IOFlags::OpenRead,
int  perms = 0666 
)

Definition at line 17 of file XrdFile.cc.

References m_stat, and open().

20  : m_client (0),
21  m_offset (0),
22  m_stat(),
23  m_close (false),
24  m_name()
25 {
26  memset(&m_stat, 0, sizeof (m_stat));
27  open (name, flags, perms);
28 }
XrdClientStatInfo m_stat
Definition: XrdFile.h:57
std::vector< Variable::Flags > flags
Definition: MVATrainer.cc:135
bool m_close
Definition: XrdFile.h:58
IOOffset m_offset
Definition: XrdFile.h:56
XrdClient * m_client
Definition: XrdFile.h:55
std::string m_name
Definition: XrdFile.h:59
virtual void open(const char *name, int flags=IOFlags::OpenRead, int perms=0666)
Definition: XrdFile.cc:81
XrdFile::XrdFile ( const std::string &  name,
int  flags = IOFlags::OpenRead,
int  perms = 0666 
)

Definition at line 30 of file XrdFile.cc.

References flags, m_stat, and open().

33  : m_client (0),
34  m_offset (0),
35  m_stat(),
36  m_close (false),
37  m_name()
38 {
39  memset(&m_stat, 0, sizeof (m_stat));
40  open (name.c_str (), flags, perms);
41 }
XrdClientStatInfo m_stat
Definition: XrdFile.h:57
std::vector< Variable::Flags > flags
Definition: MVATrainer.cc:135
bool m_close
Definition: XrdFile.h:58
IOOffset m_offset
Definition: XrdFile.h:56
XrdClient * m_client
Definition: XrdFile.h:55
std::string m_name
Definition: XrdFile.h:59
virtual void open(const char *name, int flags=IOFlags::OpenRead, int perms=0666)
Definition: XrdFile.cc:81
XrdFile::~XrdFile ( void  )

Definition at line 43 of file XrdFile.cc.

References m_close, and m_name.

44 {
45  if (m_close)
46  edm::LogError("XrdFileError")
47  << "Destructor called on XROOTD file '" << m_name
48  << "' but the file is still open";
49 }
bool m_close
Definition: XrdFile.h:58
std::string m_name
Definition: XrdFile.h:59

Member Function Documentation

void XrdFile::abort ( void  )
virtual

Definition at line 188 of file XrdFile.cc.

References m_client, m_close, m_offset, and m_stat.

Referenced by open().

189 {
190  delete m_client;
191  m_client = 0;
192  m_close = false;
193  m_offset = 0;
194  memset(&m_stat, 0, sizeof (m_stat));
195 }
XrdClientStatInfo m_stat
Definition: XrdFile.h:57
bool m_close
Definition: XrdFile.h:58
IOOffset m_offset
Definition: XrdFile.h:56
XrdClient * m_client
Definition: XrdFile.h:55
void XrdFile::addConnection ( cms::Exception ex)
private

Definition at line 494 of file XrdFile.cc.

References cms::Exception::addAdditionalInfo(), results_mgr::conn, and m_client.

Referenced by open(), position(), read(), readv(), resize(), and write().

495 {
496  XrdClientConn *conn = m_client->GetClientConn();
497  if (conn) {
498  std::stringstream ss;
499  ss << "Current server connection: " << conn->GetCurrentUrl().GetUrl().c_str();
500  ex.addAdditionalInfo(ss.str());
501  }
502 }
void addAdditionalInfo(std::string const &info)
Definition: Exception.cc:235
XrdClient * m_client
Definition: XrdFile.h:55
tuple conn
Definition: results_mgr.py:53
void XrdFile::close ( void  )
virtual

Reimplemented from Storage.

Definition at line 162 of file XrdFile.cc.

References m_client, m_close, m_name, m_offset, and m_stat.

Referenced by lumiQTWidget.ApplicationWindow::fileQuit(), Vispa.Gui.BoxContentDialog.BoxContentDialog::keyPressEvent(), Vispa.Gui.FindDialog.FindDialog::keyPressEvent(), and open().

163 {
164  if (! m_client)
165  {
166  edm::LogError("XrdFileError")
167  << "XrdFile::close(name='" << m_name
168  << "') called but the file is not open";
169  m_close = false;
170  return;
171  }
172 
173  if (! m_client->Close())
174  edm::LogWarning("XrdFileWarning")
175  << "XrdFile::close(name='" << m_name
176  << "') failed with error '" << m_client->LastServerError()->errmsg
177  << "' (errno=" << m_client->LastServerError()->errnum << ")";
178  delete m_client;
179  m_client = 0;
180 
181  m_close = false;
182  m_offset = 0;
183  memset(&m_stat, 0, sizeof (m_stat));
184  edm::LogInfo("XrdFileInfo") << "Closed " << m_name;
185 }
XrdClientStatInfo m_stat
Definition: XrdFile.h:57
bool m_close
Definition: XrdFile.h:58
IOOffset m_offset
Definition: XrdFile.h:56
XrdClient * m_client
Definition: XrdFile.h:55
std::string m_name
Definition: XrdFile.h:59
void XrdFile::create ( const char *  name,
bool  exclusive = false,
int  perms = 0666 
)
virtual

Definition at line 53 of file XrdFile.cc.

References open(), IOFlags::OpenCreate, IOFlags::OpenExclusive, IOFlags::OpenTruncate, and IOFlags::OpenWrite.

56 {
57  open (name,
59  | (exclusive ? IOFlags::OpenExclusive : 0)),
60  perms);
61 }
virtual void open(const char *name, int flags=IOFlags::OpenRead, int perms=0666)
Definition: XrdFile.cc:81
void XrdFile::create ( const std::string &  name,
bool  exclusive = false,
int  perms = 0666 
)
virtual

Definition at line 64 of file XrdFile.cc.

References open(), IOFlags::OpenCreate, IOFlags::OpenExclusive, IOFlags::OpenTruncate, and IOFlags::OpenWrite.

67 {
68  open (name.c_str (),
70  | (exclusive ? IOFlags::OpenExclusive : 0)),
71  perms);
72 }
virtual void open(const char *name, int flags=IOFlags::OpenRead, int perms=0666)
Definition: XrdFile.cc:81
void XrdFile::open ( const char *  name,
int  flags = IOFlags::OpenRead,
int  perms = 0666 
)
virtual

Definition at line 81 of file XrdFile.cc.

References abort(), addConnection(), cms::Exception::addContext(), close(), results_mgr::conn, edm::errors::FileOpenError, m_client, m_close, m_name, m_offset, m_stat, mergeVDriftHistosByStation::name, IOFlags::OpenAppend, IOFlags::OpenCreate, IOFlags::OpenExclusive, IOFlags::OpenRead, IOFlags::OpenTruncate, and IOFlags::OpenWrite.

Referenced by create(), open(), and XrdFile().

84 {
85  // Actual open
86  if ((name == 0) || (*name == 0)) {
88  ex << "Cannot open a file without a name";
89  ex.addContext("Calling XrdFile::open()");
90  throw ex;
91  }
92  if ((flags & (IOFlags::OpenRead | IOFlags::OpenWrite)) == 0) {
94  ex << "Must open file '" << name << "' at least for read or write";
95  ex.addContext("Calling XrdFile::open()");
96  throw ex;
97  }
98  // If I am already open, close old file first
99  if (m_client && m_close)
100  close();
101  else
102  abort();
103 
104  // Translate our flags to system flags
105  int openflags = 0;
106 
108  openflags |= kXR_open_updt;
109  else if (flags & IOFlags::OpenRead)
110  openflags |= kXR_open_read;
111 
112  if (flags & IOFlags::OpenAppend) {
114  ex << "Opening file '" << name << "' in append mode not supported";
115  ex.addContext("Calling XrdFile::open()");
116  throw ex;
117  }
118 
120  {
121  if (! (flags & IOFlags::OpenExclusive))
122  openflags |= kXR_delete;
123  openflags |= kXR_new;
124  openflags |= kXR_mkpath;
125  }
126 
127  if ((flags & IOFlags::OpenTruncate) && (flags & IOFlags::OpenWrite))
128  openflags |= kXR_delete;
129 
130  m_name = name;
131  m_client = new XrdClient(name);
132  if (! m_client->Open(perms, openflags)
133  || m_client->LastServerResp()->status != kXR_ok) {
135  ex << "XrdClient::Open(name='" << name
136  << "', flags=0x" << std::hex << openflags
137  << ", permissions=0" << std::oct << perms << std::dec
138  << ") => error '" << m_client->LastServerError()->errmsg
139  << "' (errno=" << m_client->LastServerError()->errnum << ")";
140  ex.addContext("Calling XrdFile::open()");
141  addConnection(ex);
142  throw ex;
143  }
144  if (! m_client->Stat(&m_stat)) {
146  ex << "XrdClient::Stat(name='" << name
147  << ") => error '" << m_client->LastServerError()->errmsg
148  << "' (errno=" << m_client->LastServerError()->errnum << ")";
149  ex.addContext("Calling XrdFile::open()");
150  addConnection(ex);
151  throw ex;
152  }
153  m_offset = 0;
154  m_close = true;
155  edm::LogInfo("XrdFileInfo") << "Opened " << m_name;
156 
157  XrdClientConn *conn = m_client->GetClientConn();
158  edm::LogInfo("XrdFileInfo") << "Connection URL " << conn->GetCurrentUrl().GetUrl().c_str();
159 }
virtual void close(void)
Definition: XrdFile.cc:162
XrdClientStatInfo m_stat
Definition: XrdFile.h:57
std::vector< Variable::Flags > flags
Definition: MVATrainer.cc:135
bool m_close
Definition: XrdFile.h:58
IOOffset m_offset
Definition: XrdFile.h:56
XrdClient * m_client
Definition: XrdFile.h:55
std::string m_name
Definition: XrdFile.h:59
void addConnection(cms::Exception &)
Definition: XrdFile.cc:494
tuple conn
Definition: results_mgr.py:53
virtual void abort(void)
Definition: XrdFile.cc:188
void XrdFile::open ( const std::string &  name,
int  flags = IOFlags::OpenRead,
int  perms = 0666 
)
virtual

Definition at line 75 of file XrdFile.cc.

References flags, and open().

78 { open (name.c_str (), flags, perms); }
std::vector< Variable::Flags > flags
Definition: MVATrainer.cc:135
virtual void open(const char *name, int flags=IOFlags::OpenRead, int perms=0666)
Definition: XrdFile.cc:81
IOOffset XrdFile::position ( IOOffset  offset,
Relative  whence = SET 
)
virtual

Implements Storage.

Definition at line 444 of file XrdFile.cc.

References addConnection(), cms::Exception::addContext(), Storage::CURRENT, Storage::END, m_client, m_offset, m_stat, evf::evtn::offset(), and Storage::SET.

445 {
446  if (! m_client) {
447  cms::Exception ex("FilePositionError");
448  ex << "XrdFile::position() called on a closed file";
449  ex.addContext("Calling XrdFile::position()");
450  addConnection(ex);
451  throw ex;
452  }
453  switch (whence)
454  {
455  case SET:
456  m_offset = offset;
457  break;
458 
459  case CURRENT:
460  m_offset += offset;
461  break;
462 
463  case END:
464  m_offset = m_stat.size + offset;
465  break;
466 
467  default:
468  cms::Exception ex("FilePositionError");
469  ex << "XrdFile::position() called with incorrect 'whence' parameter";
470  ex.addContext("Calling XrdFile::position()");
471  addConnection(ex);
472  throw ex;
473  }
474 
475  if (m_offset < 0)
476  m_offset = 0;
477  if (m_offset > m_stat.size)
478  m_stat.size = m_offset;
479 
480  return m_offset;
481 }
XrdClientStatInfo m_stat
Definition: XrdFile.h:57
IOOffset m_offset
Definition: XrdFile.h:56
unsigned int offset(bool)
XrdClient * m_client
Definition: XrdFile.h:55
void addConnection(cms::Exception &)
Definition: XrdFile.cc:494
bool XrdFile::prefetch ( const IOPosBuffer what,
IOSize  n 
)
virtual

Reimplemented from Storage.

Definition at line 425 of file XrdFile.cc.

References i, m_client, n, NULL, IOPosBuffer::offset(), alignCSCRings::r, IOPosBuffer::size(), and pileupDistInMC::total.

426 {
427  std::vector<long long> offsets; offsets.resize(n);
428  std::vector<int> lens; lens.resize(n);
429  kXR_int64 total = 0;
430  for (IOSize i = 0; i < n; ++i) {
431  offsets[i] = what[i].offset();
432  lens[i] = what[i].size();
433  total += what[i].size();
434  }
435 
436  kXR_int64 r = m_client->ReadV(NULL, &offsets[0], &lens[0], n);
437  return r == total;
438 }
int i
Definition: DBlmapReader.cc:9
#define NULL
Definition: scimark2.h:8
XrdClient * m_client
Definition: XrdFile.h:55
IOOffset offset(void) const
Definition: IOPosBuffer.h:54
IOSize size(void) const
Definition: IOPosBuffer.h:64
size_t IOSize
Definition: IOTypes.h:14
IOSize XrdFile::read ( void *  into,
IOSize  n 
)
virtual

Read into into at most n number of bytes.

If this is a blocking stream, the call will block until some data can be read, end of input is reached, or an exception is thrown. For a non-blocking stream the available input is returned. If none is available, an exception is thrown.

Returns
The number of bytes actually read. This is less or equal to the size of the buffer. Zero indicates that the end of the input has been reached: end of file, or remote end closing for a connected channel like a pipe or a socket. Otherwise the value can be less than requested if limited amount of input is currently available for platform or implementation reasons.
Exceptions
Incase of error, a #IOError exception is thrown. This includes the situation where the input stream is in non-blocking mode and no input is currently available (FIXME: make this simpler; clarify which exception).

Implements IOInput.

Definition at line 199 of file XrdFile.cc.

References addConnection(), cms::Exception::addContext(), edm::errors::FileReadError, m_client, m_name, m_offset, and alignCSCRings::s.

200 {
201  if (n > 0x7fffffff) {
203  ex << "XrdFile::read(name='" << m_name << "', n=" << n
204  << ") too many bytes, limit is 0x7fffffff";
205  ex.addContext("Calling XrdFile::read()");
206  addConnection(ex);
207  throw ex;
208  }
209  int s = m_client->Read(into, m_offset, n);
210  if (s < 0) {
212  ex << "XrdClient::Read(name='" << m_name
213  << "', offset=" << m_offset << ", n=" << n
214  << ") failed with error '" << m_client->LastServerError()->errmsg
215  << "' (errno=" << m_client->LastServerError()->errnum << ")";
216  ex.addContext("Calling XrdFile::read()");
217  addConnection(ex);
218  throw ex;
219  }
220  m_offset += s;
221  return s;
222 }
IOOffset m_offset
Definition: XrdFile.h:56
XrdClient * m_client
Definition: XrdFile.h:55
std::string m_name
Definition: XrdFile.h:59
void addConnection(cms::Exception &)
Definition: XrdFile.cc:494
IOSize XrdFile::read ( void *  into,
IOSize  n,
IOOffset  pos 
)
virtual

Reimplemented from Storage.

Definition at line 225 of file XrdFile.cc.

References addConnection(), cms::Exception::addContext(), edm::errors::FileReadError, m_client, m_name, m_offset, and alignCSCRings::s.

226 {
227  if (n > 0x7fffffff) {
229  ex << "XrdFile::read(name='" << m_name << "', n=" << n
230  << ") exceeds read size limit 0x7fffffff";
231  ex.addContext("Calling XrdFile::read()");
232  addConnection(ex);
233  throw ex;
234  }
235  int s = m_client->Read(into, pos, n);
236  if (s < 0) {
238  ex << "XrdClient::Read(name='" << m_name
239  << "', offset=" << m_offset << ", n=" << n
240  << ") failed with error '" << m_client->LastServerError()->errmsg
241  << "' (errno=" << m_client->LastServerError()->errnum << ")";
242  ex.addContext("Calling XrdFile::read()");
243  addConnection(ex);
244  throw ex;
245  }
246  return s;
247 }
IOOffset m_offset
Definition: XrdFile.h:56
XrdClient * m_client
Definition: XrdFile.h:55
std::string m_name
Definition: XrdFile.h:59
void addConnection(cms::Exception &)
Definition: XrdFile.cc:494
IOSize XrdFile::readv ( IOBuffer into,
IOSize  buffers 
)
virtual

Read from the input stream into multiple scattered buffers. There are buffers to fill in an array starting at into; the memory those buffers occupy does not need to be contiguous. The buffers are filled in the order given, eac buffer is filled fully before the subsequent buffers.

If this is a blocking stream, the call will block until some data can be read, end of input is reached, or an exception is thrown. For a non-blocking stream the available input is returned. If none is available, an exception is thrown.

The base class implementation uses read(void *, IOSize) method, but derived classes may implement a more efficient alternative.

Returns
The number of bytes actually read. This is less or equal to the size of the buffer. Zero indicates that the end of the input has been reached: end of file, or remote end closing for a connected channel like a pipe or a socket. Otherwise the value can be less than requested if limited amount of input is currently available for platform or implementation reasons. Note that the return value indicates the number of bytes read, not the number of buffers; it is the sum total of bytes filled into all the buffers.
Exceptions
Incase of error, a #IOError exception is thrown. However if some data has already been read, the error is swallowed and the method returns the data read so far. It is assumed that persistent errors will occur anyway on the next read and sporadic errors like stream becoming unvailable can be ignored. Use xread() if a different policy is desirable.

Reimplemented from IOInput.

Definition at line 250 of file XrdFile.cc.

References addConnection(), cms::Exception::addContext(), data, edm::errors::FileReadError, i, l1GtPatternGenerator_cfi::lengths, m_client, m_name, m_offset, n, pos, alignCSCRings::s, IOBuffer::size(), and pileupDistInMC::total.

251 {
252  // Note that the XROOTD and our interfaces do not match.
253  // XROOTD expects readv() into a single monolithic buffer
254  // from multiple file locations, whereas we expect scatter
255  // gather buffers read from a single file location.
256  //
257  // We work around this mismatch for now by issuing a cache
258  // read on the background, and then individual reads.
260  std::vector<long long> offsets (n);
261  std::vector<int> lengths (n);
262  for (IOSize i = 0; i < n; ++i)
263  {
264  IOSize len = into[i].size();
265  if (len > 0x7fffffff) {
267  ex << "XrdFile::readv(name='" << m_name << "')[" << i
268  << "].size=" << len << " exceeds read size limit 0x7fffffff";
269  ex.addContext("Calling XrdFile::readv()");
270  addConnection(ex);
271  throw ex;
272  }
273  offsets[i] = pos;
274  lengths[i] = len;
275  pos += len;
276  }
277 
278  // Prefetch into the cache (if any).
279  if (m_client->ReadV(0, &offsets[0], &lengths[0], n) < 0) {
281  ex << "XrdClient::ReadV(name='" << m_name
282  << "') failed with error '" << m_client->LastServerError()->errmsg
283  << "' (errno=" << m_client->LastServerError()->errnum << ")";
284  ex.addContext("Calling XrdFile::readv()");
285  addConnection(ex);
286  throw ex;
287  }
288 
289  // Issue actual reads.
290  IOSize total = 0;
291  for (IOSize i = 0; i < n; ++i)
292  {
293  int s = m_client->Read(into[i].data(), offsets[i], lengths[i]);
294  if (s < 0)
295  {
296  if (i > 0)
297  break;
299  ex << "XrdClient::Read(name='" << m_name
300  << "', offset=" << offsets[i] << ", n=" << lengths[i]
301  << ") failed with error '" << m_client->LastServerError()->errmsg
302  << "' (errno=" << m_client->LastServerError()->errnum << ")";
303  ex.addContext("Calling XrdFile::readv()");
304  addConnection(ex);
305  throw ex;
306  }
307  total += s;
308  m_offset += s;
309  }
310 
311  return total;
312 }
int i
Definition: DBlmapReader.cc:9
IOOffset m_offset
Definition: XrdFile.h:56
XrdClient * m_client
Definition: XrdFile.h:55
IOSize size(void) const
Definition: IOBuffer.h:50
std::string m_name
Definition: XrdFile.h:59
int64_t IOOffset
Definition: IOTypes.h:19
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
size_t IOSize
Definition: IOTypes.h:14
void addConnection(cms::Exception &)
Definition: XrdFile.cc:494
IOSize XrdFile::readv ( IOPosBuffer into,
IOSize  n 
)
virtual

Reimplemented from Storage.

Definition at line 315 of file XrdFile.cc.

References addConnection(), cms::Exception::addContext(), data, edm::errors::FileReadError, i, l1GtPatternGenerator_cfi::lengths, m_client, m_name, n, IOPosBuffer::offset(), alignCSCRings::s, IOPosBuffer::size(), and pileupDistInMC::total.

316 {
317  // See comments in readv() above.
318  std::vector<long long> offsets (n);
319  std::vector<int> lengths (n);
320  for (IOSize i = 0; i < n; ++i)
321  {
322  IOSize len = into[i].size();
323  if (len > 0x7fffffff) {
325  ex << "XrdFile::readv(name='" << m_name << "')[" << i
326  << "].size=" << len << " exceeds read size limit 0x7fffffff";
327  ex.addContext("Calling XrdFile::readv()");
328  addConnection(ex);
329  throw ex;
330  }
331  offsets[i] = into[i].offset();
332  lengths[i] = len;
333  }
334 
335  // Prefetch into the cache (if any).
336  if (m_client->ReadV(0, &offsets[0], &lengths[0], n) < 0) {
338  ex << "XrdClient::ReadV(name='" << m_name
339  << "') failed with error '" << m_client->LastServerError()->errmsg
340  << "' (errno=" << m_client->LastServerError()->errnum << ")";
341  ex.addContext("Calling XrdFile::readv()");
342  addConnection(ex);
343  throw ex;
344  }
345  // Issue actual reads.
346  IOSize total = 0;
347  for (IOSize i = 0; i < n; ++i)
348  {
349  int s = m_client->Read(into[i].data(), offsets[i], lengths[i]);
350  if (s < 0)
351  {
352  if (i > 0)
353  break;
355  ex << "XrdClient::Read(name='" << m_name
356  << "', offset=" << offsets[i] << ", n=" << lengths[i]
357  << ") failed with error '" << m_client->LastServerError()->errmsg
358  << "' (errno=" << m_client->LastServerError()->errnum << ")";
359  ex.addContext("Calling XrdFile::readv()");
360  addConnection(ex);
361  throw ex;
362  }
363  total += s;
364  }
365 
366  return total;
367 }
int i
Definition: DBlmapReader.cc:9
XrdClient * m_client
Definition: XrdFile.h:55
IOOffset offset(void) const
Definition: IOPosBuffer.h:54
std::string m_name
Definition: XrdFile.h:59
IOSize size(void) const
Definition: IOPosBuffer.h:64
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
size_t IOSize
Definition: IOTypes.h:14
void addConnection(cms::Exception &)
Definition: XrdFile.cc:494
void XrdFile::resize ( IOOffset  size)
virtual

Implements Storage.

Definition at line 484 of file XrdFile.cc.

References addConnection(), cms::Exception::addContext(), and m_name.

Referenced by Vispa.Gui.TextDialog.TextDialog::__init__(), Vispa.Plugins.ConfigEditor.ToolDialog.ToolDialog::__init__(), Vispa.Main.MainWindow.MainWindow::_loadIni(), and Vispa.Gui.PortConnection.PointToPointConnection::updateConnection().

485 {
486  cms::Exception ex("FileResizeError");
487  ex << "XrdFile::resize(name='" << m_name << "') not implemented";
488  ex.addContext("Calling XrdFile::resize()");
489  addConnection(ex);
490  throw ex;
491 }
std::string m_name
Definition: XrdFile.h:59
void addConnection(cms::Exception &)
Definition: XrdFile.cc:494
IOSize XrdFile::write ( const void *  from,
IOSize  n 
)
virtual

Write n bytes of data starting at address from.

Returns
The number of bytes written. Normally this will be n, but can be less, even zero, for example if the stream is non-blocking mode and cannot accept input at this time.
Exceptions
Incase of error, an exception is thrown. However if the stream is in non-blocking mode and cannot accept output, it will not throw an exception – the return value will be less than requested.

Implements IOOutput.

Definition at line 370 of file XrdFile.cc.

References addConnection(), cms::Exception::addContext(), m_client, m_name, m_offset, m_stat, and alignCSCRings::s.

371 {
372  if (n > 0x7fffffff) {
373  cms::Exception ex("FileWriteError");
374  ex << "XrdFile::write(name='" << m_name << "', n=" << n
375  << ") too many bytes, limit is 0x7fffffff";
376  ex.addContext("Calling XrdFile::write()");
377  addConnection(ex);
378  throw ex;
379  }
380  ssize_t s = m_client->Write(from, m_offset, n);
381  if (s < 0) {
382  cms::Exception ex("FileWriteError");
383  ex << "XrdFile::write(name='" << m_name << "', n=" << n
384  << ") failed with error '" << m_client->LastServerError()->errmsg
385  << "' (errno=" << m_client->LastServerError()->errnum << ")";
386  ex.addContext("Calling XrdFile::write()");
387  addConnection(ex);
388  throw ex;
389  }
390  m_offset += s;
391  if (m_offset > m_stat.size)
392  m_stat.size = m_offset;
393 
394  return s;
395 }
XrdClientStatInfo m_stat
Definition: XrdFile.h:57
IOOffset m_offset
Definition: XrdFile.h:56
XrdClient * m_client
Definition: XrdFile.h:55
std::string m_name
Definition: XrdFile.h:59
static std::string from(" from ")
void addConnection(cms::Exception &)
Definition: XrdFile.cc:494
IOSize XrdFile::write ( const void *  from,
IOSize  n,
IOOffset  pos 
)
virtual

Reimplemented from Storage.

Definition at line 398 of file XrdFile.cc.

References addConnection(), cms::Exception::addContext(), m_client, m_name, m_stat, and alignCSCRings::s.

399 {
400  if (n > 0x7fffffff) {
401  cms::Exception ex("FileWriteError");
402  ex << "XrdFile::write(name='" << m_name << "', n=" << n
403  << ") too many bytes, limit is 0x7fffffff";
404  ex.addContext("Calling XrdFile::write()");
405  addConnection(ex);
406  throw ex;
407  }
408  ssize_t s = m_client->Write(from, pos, n);
409  if (s < 0) {
410  cms::Exception ex("FileWriteError");
411  ex << "XrdFile::write(name='" << m_name << "', n=" << n
412  << ") failed with error '" << m_client->LastServerError()->errmsg
413  << "' (errno=" << m_client->LastServerError()->errnum << ")";
414  ex.addContext("Calling XrdFile::write()");
415  addConnection(ex);
416  throw ex;
417  }
418  if (pos + s > m_stat.size)
419  m_stat.size = pos + s;
420 
421  return s;
422 }
XrdClientStatInfo m_stat
Definition: XrdFile.h:57
XrdClient * m_client
Definition: XrdFile.h:55
std::string m_name
Definition: XrdFile.h:59
static std::string from(" from ")
void addConnection(cms::Exception &)
Definition: XrdFile.cc:494

Member Data Documentation

XrdClient* XrdFile::m_client
private

Definition at line 55 of file XrdFile.h.

Referenced by abort(), addConnection(), close(), open(), position(), prefetch(), read(), readv(), and write().

bool XrdFile::m_close
private

Definition at line 58 of file XrdFile.h.

Referenced by abort(), close(), open(), and ~XrdFile().

std::string XrdFile::m_name
private

Definition at line 59 of file XrdFile.h.

Referenced by close(), open(), read(), readv(), resize(), write(), and ~XrdFile().

IOOffset XrdFile::m_offset
private

Definition at line 56 of file XrdFile.h.

Referenced by abort(), close(), open(), position(), read(), readv(), and write().

XrdClientStatInfo XrdFile::m_stat
private

Definition at line 57 of file XrdFile.h.

Referenced by abort(), close(), open(), position(), write(), and XrdFile().