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 &)
 
IOSize readv_send (char **result_buffer, readahead_list &read_chunk_list, IOSize n, IOSize total_len)
 
IOSize readv_unpack (char **result_buffer, std::vector< char > &res_buf, IOSize datalen, readahead_list &read_chunk_list, IOSize n)
 

Private Attributes

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

Additional Inherited Members

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

Detailed Description

Definition at line 11 of file XrdFile.h.

Constructor & Destructor Documentation

XrdFile::XrdFile ( void  )

Definition at line 12 of file XrdFile.cc.

References m_readv_mutex, and m_stat.

13  : m_client (0),
14  m_offset (0),
15  m_stat(),
16  m_close (false),
17  m_name()
18 {
19  memset(&m_stat, 0, sizeof (m_stat));
20  pthread_mutex_init(&m_readv_mutex, 0);
21 }
XrdClientStatInfo m_stat
Definition: XrdFile.h:63
bool m_close
Definition: XrdFile.h:64
IOOffset m_offset
Definition: XrdFile.h:62
XrdClient * m_client
Definition: XrdFile.h:61
std::string m_name
Definition: XrdFile.h:65
pthread_mutex_t m_readv_mutex
Definition: XrdFile.h:68
XrdFile::XrdFile ( IOFD  fd)
XrdFile::XrdFile ( const char *  name,
int  flags = IOFlags::OpenRead,
int  perms = 0666 
)

Definition at line 23 of file XrdFile.cc.

References m_readv_mutex, m_stat, and open().

26  : m_client (0),
27  m_offset (0),
28  m_stat(),
29  m_close (false),
30  m_name()
31 {
32  memset(&m_stat, 0, sizeof (m_stat));
33  pthread_mutex_init(&m_readv_mutex, 0);
34  open (name, flags, perms);
35 }
XrdClientStatInfo m_stat
Definition: XrdFile.h:63
std::vector< Variable::Flags > flags
Definition: MVATrainer.cc:135
bool m_close
Definition: XrdFile.h:64
IOOffset m_offset
Definition: XrdFile.h:62
XrdClient * m_client
Definition: XrdFile.h:61
std::string m_name
Definition: XrdFile.h:65
pthread_mutex_t m_readv_mutex
Definition: XrdFile.h:68
virtual void open(const char *name, int flags=IOFlags::OpenRead, int perms=0666)
Definition: XrdFile.cc:90
XrdFile::XrdFile ( const std::string &  name,
int  flags = IOFlags::OpenRead,
int  perms = 0666 
)

Definition at line 37 of file XrdFile.cc.

References flags, m_readv_mutex, m_stat, and open().

40  : m_client (0),
41  m_offset (0),
42  m_stat(),
43  m_close (false),
44  m_name()
45 {
46  memset(&m_stat, 0, sizeof (m_stat));
47  pthread_mutex_init(&m_readv_mutex, 0);
48  open (name.c_str (), flags, perms);
49 }
XrdClientStatInfo m_stat
Definition: XrdFile.h:63
std::vector< Variable::Flags > flags
Definition: MVATrainer.cc:135
bool m_close
Definition: XrdFile.h:64
IOOffset m_offset
Definition: XrdFile.h:62
XrdClient * m_client
Definition: XrdFile.h:61
std::string m_name
Definition: XrdFile.h:65
pthread_mutex_t m_readv_mutex
Definition: XrdFile.h:68
virtual void open(const char *name, int flags=IOFlags::OpenRead, int perms=0666)
Definition: XrdFile.cc:90
XrdFile::~XrdFile ( void  )

Definition at line 51 of file XrdFile.cc.

References m_close, m_name, and m_readv_mutex.

52 {
53  if (m_close)
54  edm::LogError("XrdFileError")
55  << "Destructor called on XROOTD file '" << m_name
56  << "' but the file is still open";
57  pthread_mutex_destroy(&m_readv_mutex);
58 }
bool m_close
Definition: XrdFile.h:64
std::string m_name
Definition: XrdFile.h:65
pthread_mutex_t m_readv_mutex
Definition: XrdFile.h:68

Member Function Documentation

void XrdFile::abort ( void  )
virtual

Definition at line 215 of file XrdFile.cc.

References m_client, m_close, m_offset, and m_stat.

Referenced by open().

216 {
217  delete m_client;
218  m_client = 0;
219  m_close = false;
220  m_offset = 0;
221  memset(&m_stat, 0, sizeof (m_stat));
222 }
XrdClientStatInfo m_stat
Definition: XrdFile.h:63
bool m_close
Definition: XrdFile.h:64
IOOffset m_offset
Definition: XrdFile.h:62
XrdClient * m_client
Definition: XrdFile.h:61
void XrdFile::addConnection ( cms::Exception ex)
private

Definition at line 407 of file XrdFile.cc.

References cms::Exception::addAdditionalInfo(), results_mgr::conn, m_client, NULL, contentValuesCheck::ss, and cond::rpcobgas::time.

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

408 {
409  XrdClientConn *conn = m_client->GetClientConn();
410  if (conn) {
411  std::stringstream ss;
412  ss << "Current server connection: " << conn->GetCurrentUrl().GetUrl().c_str();
413  ex.addAdditionalInfo(ss.str());
414  if (conn->IsOpTimeLimitElapsed(time(NULL)))
415  {
416  ex.addAdditionalInfo("Operation timeout expired. This is possibly a temporary issue which may go away on retry.");
417  }
418  }
419  struct ServerResponseBody_Error * lastError = m_client->LastServerError();
420  if (lastError && lastError->errnum != kXR_noErrorYet)
421  {
422  std::stringstream ss;
423  // Note: I see no guarantee that the errmsg from the server is null-terminated.
424  // Hence, I'm adding the extra guarantee below.
425  char errmsg[4097]; errmsg[4096] = '\0';
426  strncpy(errmsg, lastError->errmsg, 4096);
427  ss << "Last server error (code=" << lastError->errnum << ")";
428  if (strlen(errmsg)) {ss << ": " << errmsg;}
429  ex.addAdditionalInfo(ss.str());
430  }
431 }
#define NULL
Definition: scimark2.h:8
void addAdditionalInfo(std::string const &info)
Definition: Exception.cc:235
XrdClient * m_client
Definition: XrdFile.h:61
tuple conn
Definition: results_mgr.py:53
void XrdFile::close ( void  )
virtual

Reimplemented from Storage.

Definition at line 189 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().

190 {
191  if (! m_client)
192  {
193  edm::LogError("XrdFileError")
194  << "XrdFile::close(name='" << m_name
195  << "') called but the file is not open";
196  m_close = false;
197  return;
198  }
199 
200  if (! m_client->Close())
201  edm::LogWarning("XrdFileWarning")
202  << "XrdFile::close(name='" << m_name
203  << "') failed with error '" << m_client->LastServerError()->errmsg
204  << "' (errno=" << m_client->LastServerError()->errnum << ")";
205  delete m_client;
206  m_client = 0;
207 
208  m_close = false;
209  m_offset = 0;
210  memset(&m_stat, 0, sizeof (m_stat));
211  edm::LogInfo("XrdFileInfo") << "Closed " << m_name;
212 }
XrdClientStatInfo m_stat
Definition: XrdFile.h:63
bool m_close
Definition: XrdFile.h:64
IOOffset m_offset
Definition: XrdFile.h:62
XrdClient * m_client
Definition: XrdFile.h:61
std::string m_name
Definition: XrdFile.h:65
void XrdFile::create ( const char *  name,
bool  exclusive = false,
int  perms = 0666 
)
virtual

Definition at line 62 of file XrdFile.cc.

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

65 {
66  open (name,
68  | (exclusive ? IOFlags::OpenExclusive : 0)),
69  perms);
70 }
virtual void open(const char *name, int flags=IOFlags::OpenRead, int perms=0666)
Definition: XrdFile.cc:90
void XrdFile::create ( const std::string &  name,
bool  exclusive = false,
int  perms = 0666 
)
virtual

Definition at line 73 of file XrdFile.cc.

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

76 {
77  open (name.c_str (),
79  | (exclusive ? IOFlags::OpenExclusive : 0)),
80  perms);
81 }
virtual void open(const char *name, int flags=IOFlags::OpenRead, int perms=0666)
Definition: XrdFile.cc:90
void XrdFile::open ( const char *  name,
int  flags = IOFlags::OpenRead,
int  perms = 0666 
)
virtual

Definition at line 90 of file XrdFile.cc.

References abort(), addConnection(), cms::Exception::addContext(), close(), results_mgr::conn, TauDecayModes::dec, edm::errors::FileOpenError, edm::storage::StatisticsSenderService::getJobID(), query::host, m_client, m_close, m_name, m_offset, m_stat, mergeVDriftHistosByStation::name, IOFlags::OpenAppend, IOFlags::OpenCreate, IOFlags::OpenExclusive, IOFlags::OpenRead, IOFlags::OpenTruncate, IOFlags::OpenWrite, and AlCaHLTBitMon_QueryRunRegistry::string.

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

93 {
94  // Actual open
95  if ((name == 0) || (*name == 0)) {
97  ex << "Cannot open a file without a name";
98  ex.addContext("Calling XrdFile::open()");
99  throw ex;
100  }
101  if ((flags & (IOFlags::OpenRead | IOFlags::OpenWrite)) == 0) {
103  ex << "Must open file '" << name << "' at least for read or write";
104  ex.addContext("Calling XrdFile::open()");
105  throw ex;
106  }
107  // If I am already open, close old file first
108  if (m_client && m_close)
109  close();
110  else
111  abort();
112 
113  // Translate our flags to system flags
114  int openflags = 0;
115 
117  openflags |= kXR_open_updt;
118  else if (flags & IOFlags::OpenRead)
119  openflags |= kXR_open_read;
120 
121  if (flags & IOFlags::OpenAppend) {
123  ex << "Opening file '" << name << "' in append mode not supported";
124  ex.addContext("Calling XrdFile::open()");
125  throw ex;
126  }
127 
129  {
130  if (! (flags & IOFlags::OpenExclusive))
131  openflags |= kXR_delete;
132  openflags |= kXR_new;
133  openflags |= kXR_mkpath;
134  }
135 
136  if ((flags & IOFlags::OpenTruncate) && (flags & IOFlags::OpenWrite))
137  openflags |= kXR_delete;
138 
139  m_name = name;
140  m_client = new XrdClient(name);
141  m_client->UseCache(false); // Hack from Prof. Bockelman
142 
143  if (! m_client->Open(perms, openflags)
144  || m_client->LastServerResp()->status != kXR_ok) {
146  ex << "XrdClient::Open(name='" << name
147  << "', flags=0x" << std::hex << openflags
148  << ", permissions=0" << std::oct << perms << std::dec
149  << ") => error '" << m_client->LastServerError()->errmsg
150  << "' (errno=" << m_client->LastServerError()->errnum << ")";
151  ex.addContext("Calling XrdFile::open()");
152  addConnection(ex);
153  throw ex;
154  }
155  if (! m_client->Stat(&m_stat)) {
157  ex << "XrdClient::Stat(name='" << name
158  << ") => error '" << m_client->LastServerError()->errmsg
159  << "' (errno=" << m_client->LastServerError()->errnum << ")";
160  ex.addContext("Calling XrdFile::open()");
161  addConnection(ex);
162  throw ex;
163  }
164  m_offset = 0;
165  m_close = true;
166 
167  // Send the monitoring info, if available.
168  // Note: getenv is not reentrant.
169  const char * crabJobId = edm::storage::StatisticsSenderService::getJobID();
170  if (crabJobId) {
171  kXR_unt32 dictId;
172  m_client->SendMonitoringInfo(crabJobId, &dictId);
173  edm::LogInfo("XrdFileInfo") << "Set monitoring ID to " << crabJobId << " with resulting dictId " << dictId << ".";
174  }
175 
176  edm::LogInfo("XrdFileInfo") << "Opened " << m_name;
177 
178  XrdClientConn *conn = m_client->GetClientConn();
179  edm::LogInfo("XrdFileInfo") << "Connection URL " << conn->GetCurrentUrl().GetUrl().c_str();
180 
181  std::string host = std::string(conn->GetCurrentUrl().Host.c_str());
183  if (statsService.isAvailable()) {
184  statsService->setCurrentServer(host);
185  }
186 }
virtual void close(void)
Definition: XrdFile.cc:189
XrdClientStatInfo m_stat
Definition: XrdFile.h:63
std::vector< Variable::Flags > flags
Definition: MVATrainer.cc:135
bool m_close
Definition: XrdFile.h:64
IOOffset m_offset
Definition: XrdFile.h:62
XrdClient * m_client
Definition: XrdFile.h:61
std::string m_name
Definition: XrdFile.h:65
string host
Definition: query.py:114
void addConnection(cms::Exception &)
Definition: XrdFile.cc:407
tuple conn
Definition: results_mgr.py:53
virtual void abort(void)
Definition: XrdFile.cc:215
void XrdFile::open ( const std::string &  name,
int  flags = IOFlags::OpenRead,
int  perms = 0666 
)
virtual

Definition at line 84 of file XrdFile.cc.

References flags, and open().

87 { 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:90
IOOffset XrdFile::position ( IOOffset  offset,
Relative  whence = SET 
)
virtual

Implements Storage.

Definition at line 357 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.

358 {
359  if (! m_client) {
360  cms::Exception ex("FilePositionError");
361  ex << "XrdFile::position() called on a closed file";
362  ex.addContext("Calling XrdFile::position()");
363  addConnection(ex);
364  throw ex;
365  }
366  switch (whence)
367  {
368  case SET:
369  m_offset = offset;
370  break;
371 
372  case CURRENT:
373  m_offset += offset;
374  break;
375 
376  case END:
377  m_offset = m_stat.size + offset;
378  break;
379 
380  default:
381  cms::Exception ex("FilePositionError");
382  ex << "XrdFile::position() called with incorrect 'whence' parameter";
383  ex.addContext("Calling XrdFile::position()");
384  addConnection(ex);
385  throw ex;
386  }
387 
388  if (m_offset < 0)
389  m_offset = 0;
390  if (m_offset > m_stat.size)
391  m_stat.size = m_offset;
392 
393  return m_offset;
394 }
XrdClientStatInfo m_stat
Definition: XrdFile.h:63
IOOffset m_offset
Definition: XrdFile.h:62
unsigned int offset(bool)
XrdClient * m_client
Definition: XrdFile.h:61
void addConnection(cms::Exception &)
Definition: XrdFile.cc:407
bool XrdFile::prefetch ( const IOPosBuffer what,
IOSize  n 
)
virtual

Reimplemented from Storage.

Definition at line 332 of file XrdFile.cc.

References i, m_client, n, NULL, IOPosBuffer::offset(), evf::evtn::offset(), PREFETCH_PROBE_LENGTH, alignCSCRings::r, IOPosBuffer::size(), Storage::size(), pileupDistInMC::total, and unlikely.

333 {
334  // Detect a prefetch support probe, and claim we don't support it.
335  // This will make the default application-only mode, but allows us to still
336  // effectively support storage-only mode.
337  if (unlikely((n == 1) && (what[0].offset() == 0) && (what[0].size() == PREFETCH_PROBE_LENGTH))) {
338  return false;
339  }
340  std::vector<long long> offsets; offsets.resize(n);
341  std::vector<int> lens; lens.resize(n);
342  kXR_int64 total = 0;
343  for (IOSize i = 0; i < n; ++i) {
344  offsets[i] = what[i].offset();
345  lens[i] = what[i].size();
346  total += what[i].size();
347  }
348 
349  kXR_int64 r = m_client->ReadV(NULL, &offsets[0], &lens[0], n);
350  return r == total;
351 }
int i
Definition: DBlmapReader.cc:9
#define PREFETCH_PROBE_LENGTH
Definition: Storage.h:18
#define NULL
Definition: scimark2.h:8
#define unlikely(x)
unsigned int offset(bool)
XrdClient * m_client
Definition: XrdFile.h:61
IOOffset offset(void) const
Definition: IOPosBuffer.h:54
IOSize size(void) const
Definition: IOPosBuffer.h:64
virtual IOOffset size(void) const
Definition: Storage.cc:102
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 226 of file XrdFile.cc.

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

227 {
228  if (n > 0x7fffffff) {
230  ex << "XrdFile::read(name='" << m_name << "', n=" << n
231  << ") too many bytes, limit is 0x7fffffff";
232  ex.addContext("Calling XrdFile::read()");
233  addConnection(ex);
234  throw ex;
235  }
236  int s = m_client->Read(into, m_offset, n);
237  if (s < 0) {
239  ex << "XrdClient::Read(name='" << m_name
240  << "', offset=" << m_offset << ", n=" << n
241  << ") failed with error '" << m_client->LastServerError()->errmsg
242  << "' (errno=" << m_client->LastServerError()->errnum << ")";
243  ex.addContext("Calling XrdFile::read()");
244  addConnection(ex);
245  throw ex;
246  }
247  m_offset += s;
248  return s;
249 }
IOOffset m_offset
Definition: XrdFile.h:62
XrdClient * m_client
Definition: XrdFile.h:61
std::string m_name
Definition: XrdFile.h:65
void addConnection(cms::Exception &)
Definition: XrdFile.cc:407
IOSize XrdFile::read ( void *  into,
IOSize  n,
IOOffset  pos 
)
virtual

Reimplemented from Storage.

Definition at line 252 of file XrdFile.cc.

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

253 {
254  if (n > 0x7fffffff) {
256  ex << "XrdFile::read(name='" << m_name << "', n=" << n
257  << ") exceeds read size limit 0x7fffffff";
258  ex.addContext("Calling XrdFile::read()");
259  addConnection(ex);
260  throw ex;
261  }
262  int s = m_client->Read(into, pos, n);
263  if (s < 0) {
265  ex << "XrdClient::Read(name='" << m_name
266  << "', offset=" << m_offset << ", n=" << n
267  << ") failed with error '" << m_client->LastServerError()->errmsg
268  << "' (errno=" << m_client->LastServerError()->errnum << ")";
269  ex.addContext("Calling XrdFile::read()");
270  addConnection(ex);
271  throw ex;
272  }
273  return s;
274 }
IOOffset m_offset
Definition: XrdFile.h:62
XrdClient * m_client
Definition: XrdFile.h:61
std::string m_name
Definition: XrdFile.h:65
void addConnection(cms::Exception &)
Definition: XrdFile.cc:407
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 43 of file XrdReadv.cc.

References data, i, n, IOBuffer::size(), and Storage::size().

44 {
45  vector<IOPosBuffer> new_buf;
46  new_buf.reserve(n);
47  IOOffset off = 0;
48  for (IOSize i=0; i<n; i++) {
49  IOSize size = into[i].size();
50  new_buf[i] = IOPosBuffer(off, into[i].data(), size);
51  off += size;
52  }
53  return readv(&(new_buf[0]), n);
54 }
int i
Definition: DBlmapReader.cc:9
virtual IOSize readv(IOBuffer *into, IOSize n)
Definition: XrdReadv.cc:43
IOSize size(void) const
Definition: IOBuffer.h:50
virtual IOOffset size(void) const
Definition: Storage.cc:102
int64_t IOOffset
Definition: IOTypes.h:19
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
size_t IOSize
Definition: IOTypes.h:14
IOSize XrdFile::readv ( IOPosBuffer into,
IOSize  n 
)
virtual

Reimplemented from Storage.

Definition at line 62 of file XrdReadv.cc.

References addConnection(), cms::Exception::addContext(), IOPosBuffer::data(), data, edm::errors::FileReadError, patZpeak::handle, i, m_client, m_name, n, IOPosBuffer::offset(), evf::evtn::offset(), IOInput::read(), readv_send(), IOPosBuffer::size(), Storage::size(), and unlikely.

63 {
64  assert(m_client);
65 
66  // A trivial vector read - unlikely, considering ROOT data format.
67  if (unlikely(n == 0)) {
68  return 0;
69  }
70  if (unlikely(n == 1)) {
71  return read(into[0].data(), into[0].size(), into[0].offset());
72  }
73 
74  XrdClientConn *xrdc = m_client->GetClientConn();
75  if (xrdc) {xrdc->SetOpTimeLimit(EnvGetLong(NAME_TRANSACTIONTIMEOUT));}
76 
77  // The main challenge here is to turn the request into a form that can be
78  // fed to the Xrootd connection. In particular, Xrootd has a limit on the
79  // maximum number of chunks and the maximum size of each chunk. Hence, the
80  // loop unrolling.
81  //
82  IOSize total_len = 0;
83  readahead_list read_chunk_list[READV_MAXCHUNKS];
84  char *result_list[READV_MAXCHUNKS];
85  IOSize chunk_off = 0;
86  IOSize readv_total_len = 0;
87  const char * handle = m_client->GetHandle(); // also - 16 bytes offset from the location of m_client.
88  for (IOSize i = 0; i < n; ++i) {
89 
90  IOSize len = into[i].size();
91  if (unlikely(len > 0x7fffffff)) {
93  ex << "XrdFile::readv(name='" << m_name << "')[" << i
94  << "].size=" << len << " exceeds read size limit 0x7fffffff";
95  ex.addContext("Calling XrdFile::readv()");
96  addConnection(ex);
97  throw ex;
98  }
99 
100  IOOffset off = into[i].offset();
101  char *chunk_data = static_cast<char *>(into[i].data());
102  while (len > 0) { // Iterate as long as there is additional data to read.
103  // Each iteration will read up to READV_MAXCHUNKSIZE of this request.
104  IOSize chunk_size = len > READV_MAXCHUNKSIZE ? READV_MAXCHUNKSIZE : len;
105  len -= chunk_size;
106  readv_total_len += chunk_size;
107  read_chunk_list[chunk_off].rlen = chunk_size;
108  read_chunk_list[chunk_off].offset = off;
109  result_list[chunk_off] = chunk_data;
110  chunk_data += chunk_size;
111  off += chunk_size;
112  memcpy(&(read_chunk_list[chunk_off].fhandle), handle, 4);
113  chunk_off++;
114  if (chunk_off == READV_MAXCHUNKS) {
115  // Now that we have broken the readv into Xrootd-sized chunks, send the actual command.
116  // readv_send will also parse the response and place the data into the result_list buffers.
117  IOSize tmp_total_len = readv_send(result_list, *read_chunk_list, chunk_off, readv_total_len);
118  total_len += tmp_total_len;
119  if (unlikely(tmp_total_len != readv_total_len))
120  {
122  ex << "XrdFile::readv(name='" << m_name << "')"
123  << ".size=" << n << " Chunk of " << readv_total_len << " requested but "
124  << tmp_total_len << " bytes returned by server.";
125  ex.addContext("Calling XrdFile::readv()");
126  addConnection(ex);
127  throw ex;
128  }
129  readv_total_len = 0;
130  chunk_off = 0;
131  }
132  }
133  }
134  // Do the actual readv for all remaining chunks.
135  if (chunk_off) {
136  IOSize tmp_total_len = readv_send(result_list, *read_chunk_list, chunk_off, readv_total_len);
137  if (unlikely(tmp_total_len != readv_total_len))
138  {
140  ex << "XrdFile::readv(name='" << m_name << "')"
141  << ".size=" << n << " Chunk of " << readv_total_len << " requested but "
142  << tmp_total_len << " bytes returned by server.";
143  ex.addContext("Calling XrdFile::readv()");
144  addConnection(ex);
145  throw ex;
146  }
147  total_len += tmp_total_len;
148  }
149  return total_len;
150 }
int i
Definition: DBlmapReader.cc:9
IOSize readv_send(char **result_buffer, readahead_list &read_chunk_list, IOSize n, IOSize total_len)
Definition: XrdReadv.cc:160
#define unlikely(x)
tuple handle
Definition: patZpeak.py:22
int read(void)
Definition: IOInput.cc:54
unsigned int offset(bool)
XrdClient * m_client
Definition: XrdFile.h:61
IOOffset offset(void) const
Definition: IOPosBuffer.h:54
void * data(void) const
Definition: IOPosBuffer.h:59
std::string m_name
Definition: XrdFile.h:65
IOSize size(void) const
Definition: IOPosBuffer.h:64
virtual IOOffset size(void) const
Definition: Storage.cc:102
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:407
IOSize XrdFile::readv_send ( char **  result_buffer,
readahead_list &  read_chunk_list,
IOSize  n,
IOSize  total_len 
)
private

Definition at line 160 of file XrdReadv.cc.

References FALSE, m_client, m_readv_mutex, readv_unpack(), and summarizeEdmComparisonLogfiles::success.

Referenced by readv().

161 {
162  // Per the xrootd protocol document:
163  // Sending requests using the same streamid when a kXR_oksofar status code has been
164  // returned may produced unpredictable results. A client must serialize all requests
165  // using the streamid in the presence of partial results.
166 
167  XrdClientConn *xrdc = m_client->GetClientConn();
168  ClientRequest readvFileRequest;
169  memset( &readvFileRequest, 0, sizeof(readvFileRequest) );
170 
171  kXR_unt16 sid = ConnectionManager->SidManager()->GetNewSid();
172  memcpy(readvFileRequest.header.streamid, &sid, sizeof(kXR_unt16));
173  readvFileRequest.header.requestid = kXR_readv;
174  readvFileRequest.readv.dlen = n * sizeof(struct readahead_list);
175 
176  std::vector<char> res_buf;
177  res_buf.reserve( total_len + (n * sizeof(struct readahead_list)) );
178 
179  // Encode, then send the command.
180  clientMarshallReadAheadList(&read_chunk_list, readvFileRequest.readv.dlen);
181  bool success;
182  IOSize data_length;
183  {
184  MutexSentry sentry(m_readv_mutex);
185  success = xrdc->SendGenCommand(&readvFileRequest, &read_chunk_list, 0,
186  (void *)&(res_buf[0]), FALSE, (char *)"ReadV");
187  data_length = xrdc->LastServerResp.dlen;
188  }
189  clientUnMarshallReadAheadList(&read_chunk_list, readvFileRequest.readv.dlen);
190 
191  ConnectionManager->SidManager()->ReleaseSid(sid);
192 
193  if (success) {
194  return readv_unpack(result_list, res_buf, data_length, read_chunk_list, n);
195  } else {
196  return 0;
197  }
198 
199 }
XrdClient * m_client
Definition: XrdFile.h:61
pthread_mutex_t m_readv_mutex
Definition: XrdFile.h:68
IOSize readv_unpack(char **result_buffer, std::vector< char > &res_buf, IOSize datalen, readahead_list &read_chunk_list, IOSize n)
Definition: XrdReadv.cc:205
size_t IOSize
Definition: IOTypes.h:14
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of FALSE
IOSize XrdFile::readv_unpack ( char **  result_buffer,
std::vector< char > &  res_buf,
IOSize  datalen,
readahead_list &  read_chunk_list,
IOSize  n 
)
private

Definition at line 205 of file XrdReadv.cc.

References addConnection(), cms::Exception::addContext(), edm::errors::FileReadError, i, m_name, n, evf::evtn::offset(), and unlikely.

Referenced by readv_send().

206 {
207  IOSize response_offset = 0;
208  IOSize total_len = 0;
209  for (IOSize i = 0; i < n; i++) {
210 
211  if (unlikely(response_offset + sizeof(struct readahead_list) > response_length)) {
213  ex << "XrdFile::readv(name='" << m_name << "')[" << i
214  << "] returned an incorrectly-sized response (short header)";
215  ex.addContext("Calling XrdFile::readv()");
216  addConnection(ex);
217  }
218 
219  kXR_int64 offset;
220  kXR_int32 rlen;
221  { // Done as a separate block so response is not used later - as it is all in network order!
222  const readahead_list *response = reinterpret_cast<struct readahead_list*>(&result_buf[response_offset]);
223  offset = ntohll(response->offset);
224  rlen = ntohl(response->rlen);
225  }
226 
227  // Sanity / consistency checks; verify the results correspond to the requested chunk
228  // Also check that the response buffer is sufficient large to read from.
229  if (unlikely((&read_chunk_list)[i].offset != offset)) {
231  ex << "XrdFile::readv(name='" << m_name << "')[" << i
232  << "] returned offset " << offset << " does not match requested offset "
233  << (&read_chunk_list)[i].offset;
234  ex.addContext("Calling XrdFile::readv()");
235  addConnection(ex);
236  throw ex;
237  }
238  if (unlikely((&read_chunk_list)[i].rlen != rlen)) {
240  ex << "XrdFile::readv(name='" << m_name << "')[" << i
241  << "] returned size " << rlen << " does not match requested size "
242  << (&read_chunk_list)[i].rlen;
243  ex.addContext("Calling XrdFile::readv()");
244  addConnection(ex);
245  throw ex;
246  }
247  if (unlikely(response_offset + rlen > response_length)) {
249  ex << "XrdFile::readv(name='" << m_name << "')[" << i
250  << "] returned an incorrectly-sized response (short data)";
251  ex.addContext("Calling XrdFile::readv()");
252  addConnection(ex);
253  }
254 
255  response_offset += sizeof(struct readahead_list); // Data is stored after header.
256  total_len += rlen;
257  // Copy the data into place; increase the offset.
258  memcpy(result_list[i], &result_buf[response_offset], rlen);
259  response_offset += rlen;
260  }
261 
262  return total_len;
263 }
int i
Definition: DBlmapReader.cc:9
#define unlikely(x)
unsigned int offset(bool)
std::string m_name
Definition: XrdFile.h:65
size_t IOSize
Definition: IOTypes.h:14
void addConnection(cms::Exception &)
Definition: XrdFile.cc:407
void XrdFile::resize ( IOOffset  size)
virtual

Implements Storage.

Definition at line 397 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().

398 {
399  cms::Exception ex("FileResizeError");
400  ex << "XrdFile::resize(name='" << m_name << "') not implemented";
401  ex.addContext("Calling XrdFile::resize()");
402  addConnection(ex);
403  throw ex;
404 }
std::string m_name
Definition: XrdFile.h:65
void addConnection(cms::Exception &)
Definition: XrdFile.cc:407
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 277 of file XrdFile.cc.

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

278 {
279  if (n > 0x7fffffff) {
280  cms::Exception ex("FileWriteError");
281  ex << "XrdFile::write(name='" << m_name << "', n=" << n
282  << ") too many bytes, limit is 0x7fffffff";
283  ex.addContext("Calling XrdFile::write()");
284  addConnection(ex);
285  throw ex;
286  }
287  ssize_t s = m_client->Write(from, m_offset, n);
288  if (s < 0) {
289  cms::Exception ex("FileWriteError");
290  ex << "XrdFile::write(name='" << m_name << "', n=" << n
291  << ") failed with error '" << m_client->LastServerError()->errmsg
292  << "' (errno=" << m_client->LastServerError()->errnum << ")";
293  ex.addContext("Calling XrdFile::write()");
294  addConnection(ex);
295  throw ex;
296  }
297  m_offset += s;
298  if (m_offset > m_stat.size)
299  m_stat.size = m_offset;
300 
301  return s;
302 }
XrdClientStatInfo m_stat
Definition: XrdFile.h:63
IOOffset m_offset
Definition: XrdFile.h:62
XrdClient * m_client
Definition: XrdFile.h:61
std::string m_name
Definition: XrdFile.h:65
void addConnection(cms::Exception &)
Definition: XrdFile.cc:407
IOSize XrdFile::write ( const void *  from,
IOSize  n,
IOOffset  pos 
)
virtual

Reimplemented from Storage.

Definition at line 305 of file XrdFile.cc.

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

306 {
307  if (n > 0x7fffffff) {
308  cms::Exception ex("FileWriteError");
309  ex << "XrdFile::write(name='" << m_name << "', n=" << n
310  << ") too many bytes, limit is 0x7fffffff";
311  ex.addContext("Calling XrdFile::write()");
312  addConnection(ex);
313  throw ex;
314  }
315  ssize_t s = m_client->Write(from, pos, n);
316  if (s < 0) {
317  cms::Exception ex("FileWriteError");
318  ex << "XrdFile::write(name='" << m_name << "', n=" << n
319  << ") failed with error '" << m_client->LastServerError()->errmsg
320  << "' (errno=" << m_client->LastServerError()->errnum << ")";
321  ex.addContext("Calling XrdFile::write()");
322  addConnection(ex);
323  throw ex;
324  }
325  if (pos + s > m_stat.size)
326  m_stat.size = pos + s;
327 
328  return s;
329 }
XrdClientStatInfo m_stat
Definition: XrdFile.h:63
XrdClient * m_client
Definition: XrdFile.h:61
std::string m_name
Definition: XrdFile.h:65
void addConnection(cms::Exception &)
Definition: XrdFile.cc:407

Member Data Documentation

XrdClient* XrdFile::m_client
private

Definition at line 61 of file XrdFile.h.

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

bool XrdFile::m_close
private

Definition at line 64 of file XrdFile.h.

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

std::string XrdFile::m_name
private

Definition at line 65 of file XrdFile.h.

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

IOOffset XrdFile::m_offset
private

Definition at line 62 of file XrdFile.h.

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

pthread_mutex_t XrdFile::m_readv_mutex
private

Definition at line 68 of file XrdFile.h.

Referenced by readv_send(), XrdFile(), and ~XrdFile().

XrdClientStatInfo XrdFile::m_stat
private

Definition at line 63 of file XrdFile.h.

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