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 211 of file XrdFile.cc.

References m_client, m_close, m_offset, and m_stat.

Referenced by open().

212 {
213  delete m_client;
214  m_client = 0;
215  m_close = false;
216  m_offset = 0;
217  memset(&m_stat, 0, sizeof (m_stat));
218 }
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 387 of file XrdFile.cc.

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

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

388 {
389  XrdClientConn *conn = m_client->GetClientConn();
390  if (conn) {
391  std::stringstream ss;
392  ss << "Current server connection: " << conn->GetCurrentUrl().GetUrl().c_str();
393  ex.addAdditionalInfo(ss.str());
394  }
395 }
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 185 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().

186 {
187  if (! m_client)
188  {
189  edm::LogError("XrdFileError")
190  << "XrdFile::close(name='" << m_name
191  << "') called but the file is not open";
192  m_close = false;
193  return;
194  }
195 
196  if (! m_client->Close())
197  edm::LogWarning("XrdFileWarning")
198  << "XrdFile::close(name='" << m_name
199  << "') failed with error '" << m_client->LastServerError()->errmsg
200  << "' (errno=" << m_client->LastServerError()->errnum << ")";
201  delete m_client;
202  m_client = 0;
203 
204  m_close = false;
205  m_offset = 0;
206  memset(&m_stat, 0, sizeof (m_stat));
207  edm::LogInfo("XrdFileInfo") << "Closed " << m_name;
208 }
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, edm::errors::FileOpenError, JOB_UNIQUE_ID_ENV, JOB_UNIQUE_ID_ENV_V2, 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().

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 = getenv(JOB_UNIQUE_ID_ENV);
170  // Dashboard developers requested that we migrate to this environment variable.
171  if (!crabJobId) { crabJobId = getenv(JOB_UNIQUE_ID_ENV_V2); }
172  if (crabJobId) {
173  kXR_unt32 dictId;
174  m_client->SendMonitoringInfo(crabJobId, &dictId);
175  edm::LogInfo("XrdFileInfo") << "Set monitoring ID to " << crabJobId << " with resulting dictId " << dictId << ".";
176  }
177 
178  edm::LogInfo("XrdFileInfo") << "Opened " << m_name;
179 
180  XrdClientConn *conn = m_client->GetClientConn();
181  edm::LogInfo("XrdFileInfo") << "Connection URL " << conn->GetCurrentUrl().GetUrl().c_str();
182 }
virtual void close(void)
Definition: XrdFile.cc:185
XrdClientStatInfo m_stat
Definition: XrdFile.h:63
std::vector< Variable::Flags > flags
Definition: MVATrainer.cc:135
bool m_close
Definition: XrdFile.h:64
#define JOB_UNIQUE_ID_ENV_V2
Definition: XrdFile.cc:10
IOOffset m_offset
Definition: XrdFile.h:62
XrdClient * m_client
Definition: XrdFile.h:61
std::string m_name
Definition: XrdFile.h:65
#define JOB_UNIQUE_ID_ENV
Definition: XrdFile.cc:9
void addConnection(cms::Exception &)
Definition: XrdFile.cc:387
tuple conn
Definition: results_mgr.py:53
virtual void abort(void)
Definition: XrdFile.cc:211
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 337 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.

338 {
339  if (! m_client) {
340  cms::Exception ex("FilePositionError");
341  ex << "XrdFile::position() called on a closed file";
342  ex.addContext("Calling XrdFile::position()");
343  addConnection(ex);
344  throw ex;
345  }
346  switch (whence)
347  {
348  case SET:
349  m_offset = offset;
350  break;
351 
352  case CURRENT:
353  m_offset += offset;
354  break;
355 
356  case END:
357  m_offset = m_stat.size + offset;
358  break;
359 
360  default:
361  cms::Exception ex("FilePositionError");
362  ex << "XrdFile::position() called with incorrect 'whence' parameter";
363  ex.addContext("Calling XrdFile::position()");
364  addConnection(ex);
365  throw ex;
366  }
367 
368  if (m_offset < 0)
369  m_offset = 0;
370  if (m_offset > m_stat.size)
371  m_stat.size = m_offset;
372 
373  return m_offset;
374 }
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:387
bool XrdFile::prefetch ( const IOPosBuffer what,
IOSize  n 
)
virtual

Reimplemented from Storage.

Definition at line 328 of file XrdFile.cc.

329 {
330  return false;
331 }
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 222 of file XrdFile.cc.

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

223 {
224  if (n > 0x7fffffff) {
226  ex << "XrdFile::read(name='" << m_name << "', n=" << n
227  << ") too many bytes, limit is 0x7fffffff";
228  ex.addContext("Calling XrdFile::read()");
229  addConnection(ex);
230  throw ex;
231  }
232  int s = m_client->Read(into, m_offset, n);
233  if (s < 0) {
235  ex << "XrdClient::Read(name='" << m_name
236  << "', offset=" << m_offset << ", n=" << n
237  << ") failed with error '" << m_client->LastServerError()->errmsg
238  << "' (errno=" << m_client->LastServerError()->errnum << ")";
239  ex.addContext("Calling XrdFile::read()");
240  addConnection(ex);
241  throw ex;
242  }
243  m_offset += s;
244  return s;
245 }
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:387
IOSize XrdFile::read ( void *  into,
IOSize  n,
IOOffset  pos 
)
virtual

Reimplemented from Storage.

Definition at line 248 of file XrdFile.cc.

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

249 {
250  if (n > 0x7fffffff) {
252  ex << "XrdFile::read(name='" << m_name << "', n=" << n
253  << ") exceeds read size limit 0x7fffffff";
254  ex.addContext("Calling XrdFile::read()");
255  addConnection(ex);
256  throw ex;
257  }
258  int s = m_client->Read(into, pos, n);
259  if (s < 0) {
261  ex << "XrdClient::Read(name='" << m_name
262  << "', offset=" << m_offset << ", n=" << n
263  << ") failed with error '" << m_client->LastServerError()->errmsg
264  << "' (errno=" << m_client->LastServerError()->errnum << ")";
265  ex.addContext("Calling XrdFile::read()");
266  addConnection(ex);
267  throw ex;
268  }
269  return s;
270 }
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:387
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 41 of file XrdReadv.cc.

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

42 {
43  vector<IOPosBuffer> new_buf;
44  new_buf.reserve(n);
45  IOOffset off = 0;
46  for (IOSize i=0; i<n; i++) {
47  IOSize size = into[i].size();
48  new_buf[i] = IOPosBuffer(off, into[i].data(), size);
49  off += size;
50  }
51  return readv(&(new_buf[0]), n);
52 }
int i
Definition: DBlmapReader.cc:9
virtual IOSize readv(IOBuffer *into, IOSize n)
Definition: XrdReadv.cc:41
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 60 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.

61 {
62  assert(m_client);
63 
64  // A trivial vector read - unlikely, considering ROOT data format.
65  if (unlikely(n == 0)) {
66  return 0;
67  }
68  if (unlikely(n == 1)) {
69  return read(into[0].data(), into[0].size(), into[0].offset());
70  }
71 
72  // The main challenge here is to turn the request into a form that can be
73  // fed to the Xrootd connection. In particular, Xrootd has a limit on the
74  // maximum number of chunks and the maximum size of each chunk. Hence, the
75  // loop unrolling.
76  //
77  IOSize total_len = 0;
78  readahead_list read_chunk_list[READV_MAXCHUNKS];
79  char *result_list[READV_MAXCHUNKS];
80  IOSize chunk_off = 0;
81  IOSize readv_total_len = 0;
82  const char * handle = m_client->GetHandle(); // also - 16 bytes offset from the location of m_client.
83  for (IOSize i = 0; i < n; ++i) {
84 
85  IOSize len = into[i].size();
86  if (unlikely(len > 0x7fffffff)) {
88  ex << "XrdFile::readv(name='" << m_name << "')[" << i
89  << "].size=" << len << " exceeds read size limit 0x7fffffff";
90  ex.addContext("Calling XrdFile::readv()");
91  addConnection(ex);
92  throw ex;
93  }
94 
95  IOOffset off = into[i].offset();
96  char *chunk_data = static_cast<char *>(into[i].data());
97  while (len > 0) { // Iterate as long as there is additional data to read.
98  // Each iteration will read up to READV_MAXCHUNKSIZE of this request.
99  IOSize chunk_size = len > READV_MAXCHUNKSIZE ? READV_MAXCHUNKSIZE : len;
100  len -= chunk_size;
101  readv_total_len += chunk_size;
102  read_chunk_list[chunk_off].rlen = chunk_size;
103  read_chunk_list[chunk_off].offset = off;
104  result_list[chunk_off] = chunk_data;
105  chunk_data += chunk_size;
106  off += chunk_size;
107  memcpy(&(read_chunk_list[chunk_off].fhandle), handle, 4);
108  chunk_off++;
109  if (chunk_off == READV_MAXCHUNKS) {
110  // Now that we have broken the readv into Xrootd-sized chunks, send the actual command.
111  // readv_send will also parse the response and place the data into the result_list buffers.
112  IOSize tmp_total_len = readv_send(result_list, *read_chunk_list, chunk_off, readv_total_len);
113  total_len += tmp_total_len;
114  if (tmp_total_len != readv_total_len)
115  return total_len;
116  readv_total_len = 0;
117  chunk_off = 0;
118  }
119  }
120  }
121  // Do the actual readv for all remaining chunks.
122  if (chunk_off) {
123  total_len += readv_send(result_list, *read_chunk_list, chunk_off, readv_total_len);
124  }
125  return total_len;
126 }
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:136
#define unlikely(x)
Definition: Likely.h:21
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:387
IOSize XrdFile::readv_send ( char **  result_buffer,
readahead_list &  read_chunk_list,
IOSize  n,
IOSize  total_len 
)
private

Definition at line 136 of file XrdReadv.cc.

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

Referenced by readv().

137 {
138  // Per the xrootd protocol document:
139  // Sending requests using the same streamid when a kXR_oksofar status code has been
140  // returned may produced unpredictable results. A client must serialize all requests
141  // using the streamid in the presence of partial results.
142 
143  XrdClientConn *xrdc = m_client->GetClientConn();
144  ClientRequest readvFileRequest;
145  memset( &readvFileRequest, 0, sizeof(readvFileRequest) );
146 
147  kXR_unt16 sid = ConnectionManager->SidManager()->GetNewSid();
148  memcpy(readvFileRequest.header.streamid, &sid, sizeof(kXR_unt16));
149  readvFileRequest.header.requestid = kXR_readv;
150  readvFileRequest.readv.dlen = n * sizeof(struct readahead_list);
151 
152  std::vector<char> res_buf;
153  res_buf.reserve( total_len + (n * sizeof(struct readahead_list)) );
154 
155  // Encode, then send the command.
156  clientMarshallReadAheadList(&read_chunk_list, readvFileRequest.readv.dlen);
157  bool success;
158  IOSize data_length;
159  {
160  MutexSentry sentry(m_readv_mutex);
161  success = xrdc->SendGenCommand(&readvFileRequest, &read_chunk_list, 0,
162  (void *)&(res_buf[0]), FALSE, (char *)"ReadV");
163  data_length = xrdc->LastServerResp.dlen;
164  }
165  clientUnMarshallReadAheadList(&read_chunk_list, readvFileRequest.readv.dlen);
166 
167  ConnectionManager->SidManager()->ReleaseSid(sid);
168 
169  if (success) {
170  return readv_unpack(result_list, res_buf, data_length, read_chunk_list, n);
171  } else {
172  return 0;
173  }
174 
175 }
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:181
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 181 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().

182 {
183  IOSize response_offset = 0;
184  IOSize total_len = 0;
185  for (IOSize i = 0; i < n; i++) {
186 
187  if (unlikely(response_offset + sizeof(struct readahead_list) > response_length)) {
189  ex << "XrdFile::readv(name='" << m_name << "')[" << i
190  << "] returned an incorrectly-sized response (short header)";
191  ex.addContext("Calling XrdFile::readv()");
192  addConnection(ex);
193  }
194 
195  kXR_int64 offset;
196  kXR_int32 rlen;
197  { // Done as a separate block so response is not used later - as it is all in network order!
198  const readahead_list *response = reinterpret_cast<struct readahead_list*>(&result_buf[response_offset]);
199  offset = ntohll(response->offset);
200  rlen = ntohl(response->rlen);
201  }
202 
203  // Sanity / consistency checks; verify the results correspond to the requested chunk
204  // Also check that the response buffer is sufficient large to read from.
205  if (unlikely((&read_chunk_list)[i].offset != offset)) {
207  ex << "XrdFile::readv(name='" << m_name << "')[" << i
208  << "] returned offset " << offset << " does not match requested offset "
209  << (&read_chunk_list)[i].offset;
210  ex.addContext("Calling XrdFile::readv()");
211  addConnection(ex);
212  throw ex;
213  }
214  if (unlikely((&read_chunk_list)[i].rlen != rlen)) {
216  ex << "XrdFile::readv(name='" << m_name << "')[" << i
217  << "] returned size " << rlen << " does not match requested size "
218  << (&read_chunk_list)[i].rlen;
219  ex.addContext("Calling XrdFile::readv()");
220  addConnection(ex);
221  throw ex;
222  }
223  if (unlikely(response_offset + rlen > response_length)) {
225  ex << "XrdFile::readv(name='" << m_name << "')[" << i
226  << "] returned an incorrectly-sized response (short data)";
227  ex.addContext("Calling XrdFile::readv()");
228  addConnection(ex);
229  }
230 
231  response_offset += sizeof(struct readahead_list); // Data is stored after header.
232  total_len += rlen;
233  // Copy the data into place; increase the offset.
234  memcpy(result_list[i], &result_buf[response_offset], rlen);
235  response_offset += rlen;
236  }
237 
238  return total_len;
239 }
int i
Definition: DBlmapReader.cc:9
std::pair< double, double > response
Definition: HCALResponse.h:20
#define unlikely(x)
Definition: Likely.h:21
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:387
void XrdFile::resize ( IOOffset  size)
virtual

Implements Storage.

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

378 {
379  cms::Exception ex("FileResizeError");
380  ex << "XrdFile::resize(name='" << m_name << "') not implemented";
381  ex.addContext("Calling XrdFile::resize()");
382  addConnection(ex);
383  throw ex;
384 }
std::string m_name
Definition: XrdFile.h:65
void addConnection(cms::Exception &)
Definition: XrdFile.cc:387
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 273 of file XrdFile.cc.

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

274 {
275  if (n > 0x7fffffff) {
276  cms::Exception ex("FileWriteError");
277  ex << "XrdFile::write(name='" << m_name << "', n=" << n
278  << ") too many bytes, limit is 0x7fffffff";
279  ex.addContext("Calling XrdFile::write()");
280  addConnection(ex);
281  throw ex;
282  }
283  ssize_t s = m_client->Write(from, m_offset, n);
284  if (s < 0) {
285  cms::Exception ex("FileWriteError");
286  ex << "XrdFile::write(name='" << m_name << "', n=" << n
287  << ") failed with error '" << m_client->LastServerError()->errmsg
288  << "' (errno=" << m_client->LastServerError()->errnum << ")";
289  ex.addContext("Calling XrdFile::write()");
290  addConnection(ex);
291  throw ex;
292  }
293  m_offset += s;
294  if (m_offset > m_stat.size)
295  m_stat.size = m_offset;
296 
297  return s;
298 }
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
static std::string from(" from ")
void addConnection(cms::Exception &)
Definition: XrdFile.cc:387
IOSize XrdFile::write ( const void *  from,
IOSize  n,
IOOffset  pos 
)
virtual

Reimplemented from Storage.

Definition at line 301 of file XrdFile.cc.

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

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

Member Data Documentation

XrdClient* XrdFile::m_client
private

Definition at line 61 of file XrdFile.h.

Referenced by abort(), addConnection(), close(), open(), position(), 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().