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

References m_client, m_close, m_offset, and m_stat.

Referenced by open().

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

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

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

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

188 {
189  if (! m_client)
190  {
191  edm::LogError("XrdFileError")
192  << "XrdFile::close(name='" << m_name
193  << "') called but the file is not open";
194  m_close = false;
195  return;
196  }
197 
198  if (! m_client->Close())
199  edm::LogWarning("XrdFileWarning")
200  << "XrdFile::close(name='" << m_name
201  << "') failed with error '" << m_client->LastServerError()->errmsg
202  << "' (errno=" << m_client->LastServerError()->errnum << ")";
203  delete m_client;
204  m_client = 0;
205 
206  m_close = false;
207  m_offset = 0;
208  memset(&m_stat, 0, sizeof (m_stat));
209  edm::LogInfo("XrdFileInfo") << "Closed " << m_name;
210 }
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  m_client->UseCache(false); // Hack from Prof. Bockelman
140 
141  if (! m_client->Open(perms, openflags)
142  || m_client->LastServerResp()->status != kXR_ok) {
144  ex << "XrdClient::Open(name='" << name
145  << "', flags=0x" << std::hex << openflags
146  << ", permissions=0" << std::oct << perms << std::dec
147  << ") => error '" << m_client->LastServerError()->errmsg
148  << "' (errno=" << m_client->LastServerError()->errnum << ")";
149  ex.addContext("Calling XrdFile::open()");
150  addConnection(ex);
151  throw ex;
152  }
153  if (! m_client->Stat(&m_stat)) {
155  ex << "XrdClient::Stat(name='" << name
156  << ") => error '" << m_client->LastServerError()->errmsg
157  << "' (errno=" << m_client->LastServerError()->errnum << ")";
158  ex.addContext("Calling XrdFile::open()");
159  addConnection(ex);
160  throw ex;
161  }
162  m_offset = 0;
163  m_close = true;
164 
165  // Send the monitoring info, if available.
166  // Note: getenv is not reentrant.
167  const char * crabJobId = edm::storage::StatisticsSenderService::getJobID();
168  if (crabJobId) {
169  kXR_unt32 dictId;
170  m_client->SendMonitoringInfo(crabJobId, &dictId);
171  edm::LogInfo("XrdFileInfo") << "Set monitoring ID to " << crabJobId << " with resulting dictId " << dictId << ".";
172  }
173 
174  edm::LogInfo("XrdFileInfo") << "Opened " << m_name;
175 
176  XrdClientConn *conn = m_client->GetClientConn();
177  edm::LogInfo("XrdFileInfo") << "Connection URL " << conn->GetCurrentUrl().GetUrl().c_str();
178 
179  std::string host = std::string(conn->GetCurrentUrl().Host.c_str());
181  if (statsService.isAvailable()) {
182  statsService->setCurrentServer(host);
183  }
184 }
virtual void close(void)
Definition: XrdFile.cc:187
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:405
tuple conn
Definition: results_mgr.py:53
virtual void abort(void)
Definition: XrdFile.cc:213
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 355 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.

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

Reimplemented from Storage.

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

331 {
332  // Detect a prefetch support probe, and claim we don't support it.
333  // This will make the default application-only mode, but allows us to still
334  // effectively support storage-only mode.
335  if (unlikely((n == 1) && (what[0].offset() == 0) && (what[0].size() == PREFETCH_PROBE_LENGTH))) {
336  return false;
337  }
338  std::vector<long long> offsets; offsets.resize(n);
339  std::vector<int> lens; lens.resize(n);
340  kXR_int64 total = 0;
341  for (IOSize i = 0; i < n; ++i) {
342  offsets[i] = what[i].offset();
343  lens[i] = what[i].size();
344  total += what[i].size();
345  }
346 
347  kXR_int64 r = m_client->ReadV(NULL, &offsets[0], &lens[0], n);
348  return r == total;
349 }
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 224 of file XrdFile.cc.

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

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

Reimplemented from Storage.

Definition at line 250 of file XrdFile.cc.

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

251 {
252  if (n > 0x7fffffff) {
254  ex << "XrdFile::read(name='" << m_name << "', n=" << n
255  << ") exceeds read size limit 0x7fffffff";
256  ex.addContext("Calling XrdFile::read()");
257  addConnection(ex);
258  throw ex;
259  }
260  int s = m_client->Read(into, pos, n);
261  if (s < 0) {
263  ex << "XrdClient::Read(name='" << m_name
264  << "', offset=" << m_offset << ", n=" << n
265  << ") failed with error '" << m_client->LastServerError()->errmsg
266  << "' (errno=" << m_client->LastServerError()->errnum << ")";
267  ex.addContext("Calling XrdFile::read()");
268  addConnection(ex);
269  throw ex;
270  }
271  return s;
272 }
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:405
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:405
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(), 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:405
void XrdFile::resize ( IOOffset  size)
virtual

Implements Storage.

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

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

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

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

Reimplemented from Storage.

Definition at line 303 of file XrdFile.cc.

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

304 {
305  if (n > 0x7fffffff) {
306  cms::Exception ex("FileWriteError");
307  ex << "XrdFile::write(name='" << m_name << "', n=" << n
308  << ") too many bytes, limit is 0x7fffffff";
309  ex.addContext("Calling XrdFile::write()");
310  addConnection(ex);
311  throw ex;
312  }
313  ssize_t s = m_client->Write(from, pos, n);
314  if (s < 0) {
315  cms::Exception ex("FileWriteError");
316  ex << "XrdFile::write(name='" << m_name << "', n=" << n
317  << ") failed with error '" << m_client->LastServerError()->errmsg
318  << "' (errno=" << m_client->LastServerError()->errnum << ")";
319  ex.addContext("Calling XrdFile::write()");
320  addConnection(ex);
321  throw ex;
322  }
323  if (pos + s > m_stat.size)
324  m_stat.size = pos + s;
325 
326  return s;
327 }
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:405

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