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

References m_readv_mutex, and m_stat.

11  : m_client (0),
12  m_offset (0),
13  m_stat(),
14  m_close (false),
15  m_name()
16 {
17  memset(&m_stat, 0, sizeof (m_stat));
18  pthread_mutex_init(&m_readv_mutex, 0);
19 }
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 21 of file XrdFile.cc.

References m_readv_mutex, m_stat, and open().

24  : m_client (0),
25  m_offset (0),
26  m_stat(),
27  m_close (false),
28  m_name()
29 {
30  memset(&m_stat, 0, sizeof (m_stat));
31  pthread_mutex_init(&m_readv_mutex, 0);
32  open (name, flags, perms);
33 }
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:88
XrdFile::XrdFile ( const std::string &  name,
int  flags = IOFlags::OpenRead,
int  perms = 0666 
)

Definition at line 35 of file XrdFile.cc.

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

38  : m_client (0),
39  m_offset (0),
40  m_stat(),
41  m_close (false),
42  m_name()
43 {
44  memset(&m_stat, 0, sizeof (m_stat));
45  pthread_mutex_init(&m_readv_mutex, 0);
46  open (name.c_str (), flags, perms);
47 }
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:88
XrdFile::~XrdFile ( void  )

Definition at line 49 of file XrdFile.cc.

References m_close, m_name, and m_readv_mutex.

50 {
51  if (m_close)
52  edm::LogError("XrdFileError")
53  << "Destructor called on XROOTD file '" << m_name
54  << "' but the file is still open";
55  pthread_mutex_destroy(&m_readv_mutex);
56 }
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 403 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().

404 {
405  XrdClientConn *conn = m_client->GetClientConn();
406  if (conn) {
407  std::stringstream ss;
408  ss << "Current server connection: " << conn->GetCurrentUrl().GetUrl().c_str();
409  ex.addAdditionalInfo(ss.str());
410  }
411 }
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 60 of file XrdFile.cc.

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

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

Definition at line 71 of file XrdFile.cc.

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

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

Definition at line 88 of file XrdFile.cc.

References abort(), addConnection(), cms::Exception::addContext(), close(), results_mgr::conn, 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().

91 {
92  // Actual open
93  if ((name == 0) || (*name == 0)) {
95  ex << "Cannot open a file without a name";
96  ex.addContext("Calling XrdFile::open()");
97  throw ex;
98  }
99  if ((flags & (IOFlags::OpenRead | IOFlags::OpenWrite)) == 0) {
101  ex << "Must open file '" << name << "' at least for read or write";
102  ex.addContext("Calling XrdFile::open()");
103  throw ex;
104  }
105  // If I am already open, close old file first
106  if (m_client && m_close)
107  close();
108  else
109  abort();
110 
111  // Translate our flags to system flags
112  int openflags = 0;
113 
115  openflags |= kXR_open_updt;
116  else if (flags & IOFlags::OpenRead)
117  openflags |= kXR_open_read;
118 
119  if (flags & IOFlags::OpenAppend) {
121  ex << "Opening file '" << name << "' in append mode not supported";
122  ex.addContext("Calling XrdFile::open()");
123  throw ex;
124  }
125 
127  {
128  if (! (flags & IOFlags::OpenExclusive))
129  openflags |= kXR_delete;
130  openflags |= kXR_new;
131  openflags |= kXR_mkpath;
132  }
133 
134  if ((flags & IOFlags::OpenTruncate) && (flags & IOFlags::OpenWrite))
135  openflags |= kXR_delete;
136 
137  m_name = name;
138  m_client = new XrdClient(name);
139  if (! m_client->Open(perms, openflags)
140  || m_client->LastServerResp()->status != kXR_ok) {
142  ex << "XrdClient::Open(name='" << name
143  << "', flags=0x" << std::hex << openflags
144  << ", permissions=0" << std::oct << perms << std::dec
145  << ") => error '" << m_client->LastServerError()->errmsg
146  << "' (errno=" << m_client->LastServerError()->errnum << ")";
147  ex.addContext("Calling XrdFile::open()");
148  addConnection(ex);
149  throw ex;
150  }
151  if (! m_client->Stat(&m_stat)) {
153  ex << "XrdClient::Stat(name='" << name
154  << ") => error '" << m_client->LastServerError()->errmsg
155  << "' (errno=" << m_client->LastServerError()->errnum << ")";
156  ex.addContext("Calling XrdFile::open()");
157  addConnection(ex);
158  throw ex;
159  }
160  m_offset = 0;
161  m_close = true;
162 
163  // Send the monitoring info, if available.
164  // Note: getenv is not reentrant.
165  const char * crabJobId = edm::storage::StatisticsSenderService::getJobID();
166  if (crabJobId) {
167  kXR_unt32 dictId;
168  m_client->SendMonitoringInfo(crabJobId, &dictId);
169  edm::LogInfo("XrdFileInfo") << "Set monitoring ID to " << crabJobId << " with resulting dictId " << dictId << ".";
170  }
171 
172  edm::LogInfo("XrdFileInfo") << "Opened " << m_name;
173 
174  XrdClientConn *conn = m_client->GetClientConn();
175  edm::LogInfo("XrdFileInfo") << "Connection URL " << conn->GetCurrentUrl().GetUrl().c_str();
176 
177  std::string host = std::string(conn->GetCurrentUrl().Host.c_str());
179  if (statsService.isAvailable()) {
180  statsService->setCurrentServer(host);
181  }
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
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:403
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 82 of file XrdFile.cc.

References flags, and open().

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

Implements Storage.

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

354 {
355  if (! m_client) {
356  cms::Exception ex("FilePositionError");
357  ex << "XrdFile::position() called on a closed file";
358  ex.addContext("Calling XrdFile::position()");
359  addConnection(ex);
360  throw ex;
361  }
362  switch (whence)
363  {
364  case SET:
365  m_offset = offset;
366  break;
367 
368  case CURRENT:
369  m_offset += offset;
370  break;
371 
372  case END:
373  m_offset = m_stat.size + offset;
374  break;
375 
376  default:
377  cms::Exception ex("FilePositionError");
378  ex << "XrdFile::position() called with incorrect 'whence' parameter";
379  ex.addContext("Calling XrdFile::position()");
380  addConnection(ex);
381  throw ex;
382  }
383 
384  if (m_offset < 0)
385  m_offset = 0;
386  if (m_offset > m_stat.size)
387  m_stat.size = m_offset;
388 
389  return m_offset;
390 }
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:403
bool XrdFile::prefetch ( const IOPosBuffer what,
IOSize  n 
)
virtual

Reimplemented from Storage.

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

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

Implements Storage.

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

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

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().