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 &)
 
std::shared_ptr< XrdCl::File > getActiveFile ()
 

Private Attributes

bool m_close
 
std::string m_name
 
IOOffset m_offset
 
std::atomic< unsigned int > m_op_count
 
std::shared_ptr
< XrdAdaptor::RequestManager
m_requestmanager
 
IOOffset m_size
 

Additional Inherited Members

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

Detailed Description

Definition at line 16 of file XrdFile.h.

Constructor & Destructor Documentation

XrdFile::XrdFile ( void  )

Definition at line 20 of file XrdFile.cc.

21  : m_offset (0),
22  m_size(-1),
23  m_close (false),
24  m_name(),
25  m_op_count(0)
26 {
27 }
bool m_close
Definition: XrdFile.h:70
IOOffset m_offset
Definition: XrdFile.h:68
std::atomic< unsigned int > m_op_count
Definition: XrdFile.h:72
IOOffset m_size
Definition: XrdFile.h:69
std::string m_name
Definition: XrdFile.h:71
XrdFile::XrdFile ( IOFD  fd)
XrdFile::XrdFile ( const char *  name,
int  flags = IOFlags::OpenRead,
int  perms = 0666 
)

Definition at line 29 of file XrdFile.cc.

References open().

32  : m_offset (0),
33  m_size(-1),
34  m_close (false),
35  m_name(),
36  m_op_count(0)
37 {
38  open (name, flags, perms);
39 }
std::vector< Variable::Flags > flags
Definition: MVATrainer.cc:135
bool m_close
Definition: XrdFile.h:70
IOOffset m_offset
Definition: XrdFile.h:68
std::atomic< unsigned int > m_op_count
Definition: XrdFile.h:72
IOOffset m_size
Definition: XrdFile.h:69
std::string m_name
Definition: XrdFile.h:71
virtual void open(const char *name, int flags=IOFlags::OpenRead, int perms=0666)
Definition: XrdFile.cc:91
XrdFile::XrdFile ( const std::string &  name,
int  flags = IOFlags::OpenRead,
int  perms = 0666 
)

Definition at line 41 of file XrdFile.cc.

References flags, and open().

44  : m_offset (0),
45  m_size(-1),
46  m_close (false),
47  m_name(),
48  m_op_count(0)
49 {
50  open (name.c_str (), flags, perms);
51 }
std::vector< Variable::Flags > flags
Definition: MVATrainer.cc:135
bool m_close
Definition: XrdFile.h:70
IOOffset m_offset
Definition: XrdFile.h:68
std::atomic< unsigned int > m_op_count
Definition: XrdFile.h:72
IOOffset m_size
Definition: XrdFile.h:69
std::string m_name
Definition: XrdFile.h:71
virtual void open(const char *name, int flags=IOFlags::OpenRead, int perms=0666)
Definition: XrdFile.cc:91
XrdFile::~XrdFile ( void  )

Definition at line 53 of file XrdFile.cc.

References m_close, and m_name.

54 {
55  if (m_close)
56  edm::LogError("XrdFileError")
57  << "Destructor called on XROOTD file '" << m_name
58  << "' but the file is still open";
59 }
bool m_close
Definition: XrdFile.h:70
std::string m_name
Definition: XrdFile.h:71

Member Function Documentation

void XrdFile::abort ( void  )
virtual

Definition at line 214 of file XrdFile.cc.

References m_close, m_offset, m_requestmanager, and m_size.

215 {
216  m_requestmanager.reset();
217  m_close = false;
218  m_offset = 0;
219  m_size = -1;
220 }
std::shared_ptr< XrdAdaptor::RequestManager > m_requestmanager
Definition: XrdFile.h:67
bool m_close
Definition: XrdFile.h:70
IOOffset m_offset
Definition: XrdFile.h:68
IOOffset m_size
Definition: XrdFile.h:69
void XrdFile::addConnection ( cms::Exception ex)
private

Definition at line 564 of file XrdFile.cc.

References m_requestmanager.

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

565 {
566  if (m_requestmanager.get())
567  {
568  m_requestmanager->addConnections(ex);
569  }
570 }
std::shared_ptr< XrdAdaptor::RequestManager > m_requestmanager
Definition: XrdFile.h:67
void XrdFile::close ( void  )
virtual

Reimplemented from Storage.

Definition at line 194 of file XrdFile.cc.

References m_close, m_name, m_offset, m_requestmanager, and m_size.

Referenced by lumiQTWidget.ApplicationWindow::fileQuit(), esMonitoring.AsyncLineReaderMixin::handle_close(), esMonitoring.FDJsonServer::handle_close(), Vispa.Gui.BoxContentDialog.BoxContentDialog::keyPressEvent(), and Vispa.Gui.FindDialog.FindDialog::keyPressEvent().

195 {
196  if (! m_requestmanager.get())
197  {
198  edm::LogError("XrdFileError")
199  << "XrdFile::close(name='" << m_name
200  << "') called but the file is not open";
201  m_close = false;
202  return;
203  }
204 
205  m_requestmanager.reset();
206 
207  m_close = false;
208  m_offset = 0;
209  m_size = -1;
210  edm::LogInfo("XrdFileInfo") << "Closed " << m_name;
211 }
std::shared_ptr< XrdAdaptor::RequestManager > m_requestmanager
Definition: XrdFile.h:67
bool m_close
Definition: XrdFile.h:70
IOOffset m_offset
Definition: XrdFile.h:68
IOOffset m_size
Definition: XrdFile.h:69
std::string m_name
Definition: XrdFile.h:71
void XrdFile::create ( const char *  name,
bool  exclusive = false,
int  perms = 0666 
)
virtual

Definition at line 63 of file XrdFile.cc.

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

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

Definition at line 74 of file XrdFile.cc.

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

77 {
78  open (name.c_str (),
80  | (exclusive ? IOFlags::OpenExclusive : 0)),
81  perms);
82 }
virtual void open(const char *name, int flags=IOFlags::OpenRead, int perms=0666)
Definition: XrdFile.cc:91
std::shared_ptr< XrdCl::File > XrdFile::getActiveFile ( void  )
private

Returns a file handle from one of the active sources. Verifies the file is open and throws an exception as necessary.

Definition at line 549 of file XrdFile.cc.

References cms::Exception::addContext(), m_close, m_name, and m_requestmanager.

Referenced by open(), and write().

550 {
551  if (!m_requestmanager.get())
552  {
553  cms::Exception ex("XrdFileLogicError");
554  ex << "Xrd::getActiveFile(name='" << m_name << "') no active request manager";
555  ex.addContext("Calling XrdFile::getActiveFile()");
556  m_requestmanager->addConnections(ex);
557  m_close = false;
558  throw ex;
559  }
560  return m_requestmanager->getActiveFile();
561 }
std::shared_ptr< XrdAdaptor::RequestManager > m_requestmanager
Definition: XrdFile.h:67
bool m_close
Definition: XrdFile.h:70
std::string m_name
Definition: XrdFile.h:71
void XrdFile::open ( const char *  name,
int  flags = IOFlags::OpenRead,
int  perms = 0666 
)
virtual

Definition at line 91 of file XrdFile.cc.

References addConnection(), cms::Exception::addContext(), assert(), mergeVDriftHistosByStation::file, edm::errors::FileOpenError, getActiveFile(), m_close, m_name, m_offset, m_requestmanager, m_size, mergeVDriftHistosByStation::name, FSQ::None, NULL, IOFlags::OpenAppend, IOFlags::OpenCreate, IOFlags::OpenExclusive, IOFlags::OpenRead, IOFlags::OpenTruncate, IOFlags::OpenWrite, contentValuesCheck::ss, and ntuplemaker::status.

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

94 {
95  // Actual open
96  if ((name == 0) || (*name == 0)) {
98  ex << "Cannot open a file without a name";
99  ex.addContext("Calling XrdFile::open()");
100  throw ex;
101  }
102  if ((flags & (IOFlags::OpenRead | IOFlags::OpenWrite)) == 0) {
104  ex << "Must open file '" << name << "' at least for read or write";
105  ex.addContext("Calling XrdFile::open()");
106  throw ex;
107  }
108 
109  // Translate our flags to system flags
110  XrdCl::OpenFlags::Flags openflags = XrdCl::OpenFlags::None;
111 
113  openflags |= XrdCl::OpenFlags::Update;
114  else if (flags & IOFlags::OpenRead)
115  openflags |= XrdCl::OpenFlags::Read;
116 
117  if (flags & IOFlags::OpenAppend) {
119  ex << "Opening file '" << name << "' in append mode not supported";
120  ex.addContext("Calling XrdFile::open()");
121  throw ex;
122  }
123 
125  {
126  if (! (flags & IOFlags::OpenExclusive))
127  openflags |= XrdCl::OpenFlags::Delete;
128  openflags |= XrdCl::OpenFlags::New;
129  openflags |= XrdCl::OpenFlags::MakePath;
130  }
131 
132  if ((flags & IOFlags::OpenTruncate) && (flags & IOFlags::OpenWrite))
133  openflags |= XrdCl::OpenFlags::Delete;
134 
135  // Translate mode flags
137  modeflags |= (perms & S_IRUSR) ? XrdCl::Access::UR : XrdCl::Access::None;
138  modeflags |= (perms & S_IWUSR) ? XrdCl::Access::UW : XrdCl::Access::None;
139  modeflags |= (perms & S_IXUSR) ? XrdCl::Access::UX : XrdCl::Access::None;
140  modeflags |= (perms & S_IRGRP) ? XrdCl::Access::GR : XrdCl::Access::None;
141  modeflags |= (perms & S_IWGRP) ? XrdCl::Access::GW : XrdCl::Access::None;
142  modeflags |= (perms & S_IXGRP) ? XrdCl::Access::GX : XrdCl::Access::None;
143  modeflags |= (perms & S_IROTH) ? XrdCl::Access::GR : XrdCl::Access::None;
144  modeflags |= (perms & S_IWOTH) ? XrdCl::Access::GW : XrdCl::Access::None;
145  modeflags |= (perms & S_IXOTH) ? XrdCl::Access::GX : XrdCl::Access::None;
146 
147  m_requestmanager = RequestManager::getInstance(name, openflags, modeflags);
148  m_name = name;
149 
150  // Stat the file so we can keep track of the offset better.
151  auto file = getActiveFile();
152  XrdCl::XRootDStatus status;
153  XrdCl::StatInfo *statInfo = NULL;
154  if (! (status = file->Stat(false, statInfo)).IsOK()) {
156  ex << "XrdCl::File::Stat(name='" << name
157  << ") => error '" << status.ToStr()
158  << "' (errno=" << status.errNo << ", code=" << status.code << ")";
159  ex.addContext("Calling XrdFile::open()");
160  addConnection(ex);
161  throw ex;
162  }
163  assert(statInfo);
164  m_size = statInfo->GetSize();
165  delete(statInfo);
166 
167  m_offset = 0;
168  m_close = true;
169 
170  // Send the monitoring info, if available.
171  // Note: getenv is not reentrant.
172  // Commenting out until this is available in the new client.
173 /*
174  char * crabJobId = getenv(kCrabJobIdEnv);
175  if (crabJobId) {
176  kXR_unt32 dictId;
177  m_file->SendMonitoringInfo(crabJobId, &dictId);
178  edm::LogInfo("XrdFileInfo") << "Set monitoring ID to " << crabJobId << " with resulting dictId " << dictId << ".";
179  }
180 */
181 
182  edm::LogInfo("XrdFileInfo") << "Opened " << m_name;
183 
184  std::vector<std::string> sources;
185  m_requestmanager->getActiveSourceNames(sources);
186  std::stringstream ss;
187  ss << "Active sources: ";
188  for (auto const& it : sources)
189  ss << it << ", ";
190  edm::LogInfo("XrdFileInfo") << ss.str();
191 }
std::shared_ptr< XrdAdaptor::RequestManager > m_requestmanager
Definition: XrdFile.h:67
assert(m_qm.get())
std::vector< Variable::Flags > flags
Definition: MVATrainer.cc:135
#define NULL
Definition: scimark2.h:8
bool m_close
Definition: XrdFile.h:70
IOOffset m_offset
Definition: XrdFile.h:68
std::shared_ptr< XrdCl::File > getActiveFile()
Definition: XrdFile.cc:549
IOOffset m_size
Definition: XrdFile.h:69
std::string m_name
Definition: XrdFile.h:71
void addConnection(cms::Exception &)
Definition: XrdFile.cc:564
tuple status
Definition: ntuplemaker.py:245
void XrdFile::open ( const std::string &  name,
int  flags = IOFlags::OpenRead,
int  perms = 0666 
)
virtual

Definition at line 85 of file XrdFile.cc.

References flags, and open().

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

Implements Storage.

Definition at line 496 of file XrdFile.cc.

References addConnection(), cms::Exception::addContext(), assert(), Storage::CURRENT, Storage::END, m_offset, m_requestmanager, m_size, hltrates_dqm_sourceclient-live_cfg::offset, and Storage::SET.

497 {
498  if (! m_requestmanager.get()) {
499  cms::Exception ex("FilePositionError");
500  ex << "XrdFile::position() called on a closed file";
501  ex.addContext("Calling XrdFile::position()");
502  addConnection(ex);
503  throw ex;
504  }
505  switch (whence)
506  {
507  case SET:
508  m_offset = offset;
509  break;
510 
511  case CURRENT:
512  m_offset += offset;
513  break;
514 
515  // TODO: None of this works with concurrent writers to the file.
516  case END:
517  assert(m_size != -1);
518  m_offset = m_size + offset;
519  break;
520 
521  default:
522  cms::Exception ex("FilePositionError");
523  ex << "XrdFile::position() called with incorrect 'whence' parameter";
524  ex.addContext("Calling XrdFile::position()");
525  addConnection(ex);
526  throw ex;
527  }
528 
529  if (m_offset < 0)
530  m_offset = 0;
531  assert(m_size != -1);
532  if (m_offset > m_size)
533  m_size = m_offset;
534 
535  return m_offset;
536 }
std::shared_ptr< XrdAdaptor::RequestManager > m_requestmanager
Definition: XrdFile.h:67
assert(m_qm.get())
IOOffset m_offset
Definition: XrdFile.h:68
IOOffset m_size
Definition: XrdFile.h:69
void addConnection(cms::Exception &)
Definition: XrdFile.cc:564
bool XrdFile::prefetch ( const IOPosBuffer what,
IOSize  n 
)
virtual

Reimplemented from Storage.

Definition at line 485 of file XrdFile.cc.

486 {
487  // The new Xrootd client does not contain any internal buffers.
488  // Hence, prefetching is disabled completely.
489  return false;
490 }
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_name, m_offset, and m_requestmanager.

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 
235  uint32_t bytesRead = m_requestmanager->handle(into, n, m_offset).get();
236  m_offset += bytesRead;
237  return bytesRead;
238 }
std::shared_ptr< XrdAdaptor::RequestManager > m_requestmanager
Definition: XrdFile.h:67
IOOffset m_offset
Definition: XrdFile.h:68
std::string m_name
Definition: XrdFile.h:71
void addConnection(cms::Exception &)
Definition: XrdFile.cc:564
IOSize XrdFile::read ( void *  into,
IOSize  n,
IOOffset  pos 
)
virtual

Reimplemented from Storage.

Definition at line 241 of file XrdFile.cc.

References addConnection(), cms::Exception::addContext(), edm::errors::FileReadError, m_name, and m_requestmanager.

242 {
243  if (n > 0x7fffffff) {
245  ex << "XrdFile::read(name='" << m_name << "', n=" << n
246  << ") exceeds read size limit 0x7fffffff";
247  ex.addContext("Calling XrdFile::read()");
248  addConnection(ex);
249  throw ex;
250  }
251 
252  uint32_t bytesRead = m_requestmanager->handle(into, n, pos).get();
253 
254  return bytesRead;
255 }
std::shared_ptr< XrdAdaptor::RequestManager > m_requestmanager
Definition: XrdFile.h:67
std::string m_name
Definition: XrdFile.h:71
void addConnection(cms::Exception &)
Definition: XrdFile.cc:564
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 259 of file XrdFile.cc.

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

260 {
261  std::vector<IOPosBuffer> new_buf;
262  new_buf.reserve(n);
263  IOOffset off = 0;
264  for (IOSize i=0; i<n; i++) {
265  IOSize size = into[i].size();
266  new_buf[i] = IOPosBuffer(off, into[i].data(), size);
267  off += size;
268  }
269  return readv(&(new_buf[0]), n);
270 }
int i
Definition: DBlmapReader.cc:9
virtual IOSize readv(IOBuffer *into, IOSize n)
Definition: XrdFile.cc:259
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 277 of file XrdFile.cc.

References cms::Exception::addContext(), assert(), GetRecoTauVFromDQM_MC_cff::cl, prof2calltree::count, IOPosBuffer::data(), data, end, cppFunctionSkipper::exception, XrdAdaptor::XrootdException::getCode(), customizeTrackingMonitorSeedNumber::idx, m_op_count, m_requestmanager, fileCollector::now, IOPosBuffer::offset(), hltrates_dqm_sourceclient-live_cfg::offset, IOInput::read(), query::result, IOPosBuffer::set_data(), IOPosBuffer::set_offset(), IOPosBuffer::set_size(), IOPosBuffer::size(), Storage::size(), dqm_diff::start, edm::errors::StdException, unlikely, cms::Exception::what(), XRD_CL_MAX_CHUNK, and XRD_CL_MAX_SIZE.

278 {
279  // A trivial vector read - unlikely, considering ROOT data format.
280  if (unlikely(n == 0)) {
281  return 0;
282  }
283  if (unlikely(n == 1)) {
284  return read(into[0].data(), into[0].size(), into[0].offset());
285  }
286 
287  std::shared_ptr<std::vector<IOPosBuffer> >cl(new std::vector<IOPosBuffer>);
288 
289  // CMSSW may issue large readv's; Xrootd is only able to handle
290  // 1024. Further, the splitting algorithm may slightly increase
291  // the number of buffers.
292  IOSize adjust = XRD_CL_MAX_SIZE - 2;
293  cl->reserve(n > adjust ? adjust : n);
294  IOSize idx = 0, last_idx = 0;
295  IOSize final_result = 0;
296  std::vector<std::pair<std::future<IOSize>, IOSize>> readv_futures;
297  while (idx < n)
298  {
299  cl->clear();
300  IOSize size = 0;
301  while (idx < n) {
302  unsigned rollback_count = 1;
303  IOSize current_size = size;
304  IOOffset offset = into[idx].offset();
305  IOSize length = into[idx].size();
306  size += length;
307  char * buffer = static_cast<char *>(into[idx].data());
308  while (length > XRD_CL_MAX_CHUNK) {
309  IOPosBuffer ci;
311  length -= XRD_CL_MAX_CHUNK;
312  ci.set_offset(offset);
313  offset += XRD_CL_MAX_CHUNK;
314  ci.set_data(buffer);
315  buffer += XRD_CL_MAX_CHUNK;
316  cl->emplace_back(ci);
317  rollback_count ++;
318  }
319  IOPosBuffer ci;
320  ci.set_size(length);
321  ci.set_offset(offset);
322  ci.set_data(buffer);
323  cl->emplace_back(ci);
324 
325  if (cl->size() > adjust)
326  {
327  while (rollback_count--) cl->pop_back();
328  size = current_size;
329  break;
330  }
331  else
332  {
333  idx++;
334  }
335  }
336  try
337  {
338  readv_futures.emplace_back(m_requestmanager->handle(cl), size);
339  }
340  catch (edm::Exception& ex)
341  {
342  ex.addContext("Calling XrdFile::readv()");
343  throw;
344  }
345 
346  // Assure that we have made some progress.
347  assert(last_idx < idx);
348  last_idx = idx;
349 
350  }
351  std::chrono::time_point<std::chrono::high_resolution_clock> start, end;
353 
354  // If there are multiple readv calls, wait until all return until looking
355  // at the results of any. This guarantees that all readv's have finished
356  // by time we call .get() for the first time (in case one of the readv's
357  // result in an exception).
358  //
359  // We cannot have outstanding readv's on function exit as the XrdCl may
360  // write into the corresponding buffer at the same time as ROOT.
361  if (readv_futures.size() > 1)
362  {
363  for (auto & readv_result : readv_futures)
364  {
365  if (readv_result.first.valid())
366  {
367  readv_result.first.wait();
368  }
369  }
370  }
371 
372  for (auto & readv_result : readv_futures)
373  {
374  IOSize result = 0;
375  try
376  {
377  const int retry_count = 5;
378  for (int retries=0; retries<retry_count; retries++)
379  {
380  try
381  {
382  if (readv_result.first.valid())
383  {
384  result = readv_result.first.get();
385  }
386  }
387  catch (XrootdException& ex)
388  {
389  if ((retries != retry_count-1) && (ex.getCode() == XrdCl::errInvalidResponse))
390  {
391  edm::LogWarning("XrdAdaptorInternal") << "Got an invalid response from Xrootd server; retrying" << std::endl;
392  result = m_requestmanager->handle(cl).get();
393  }
394  else
395  {
396  throw;
397  }
398  }
399  assert(result == readv_result.second);
400  }
401  }
402  catch (edm::Exception& ex)
403  {
404  ex.addContext("Calling XrdFile::readv()");
405  throw;
406  }
407  catch (std::exception& ex)
408  {
410  newex << "A std::exception was thrown when processing an xrootd request: " << ex.what();
411  newex.addContext("Calling XrdFile::readv()");
412  throw newex;
413  }
414  final_result += result;
415  }
417 
418  edm::LogVerbatim("XrdAdaptorInternal") << "[" << m_op_count.fetch_add(1) << "] Time for readv: " << static_cast<int>(std::chrono::duration_cast<std::chrono::milliseconds>(end-start).count()) << " (sub-readv requests: " << readv_futures.size() << ")" << std::endl;
419 
420  return final_result;
421 }
std::shared_ptr< XrdAdaptor::RequestManager > m_requestmanager
Definition: XrdFile.h:67
tuple start
Check for commandline option errors.
Definition: dqm_diff.py:58
assert(m_qm.get())
void set_data(void *new_buffer)
Definition: IOPosBuffer.h:74
void set_size(IOSize new_size)
Definition: IOPosBuffer.h:79
#define unlikely(x)
void set_offset(IOOffset new_offset)
Definition: IOPosBuffer.h:69
tuple result
Definition: query.py:137
#define XRD_CL_MAX_CHUNK
Definition: XrdFile.cc:17
std::atomic< unsigned int > m_op_count
Definition: XrdFile.h:72
#define end
Definition: vmac.h:37
int read(void)
Definition: IOInput.cc:54
IOOffset offset(void) const
Definition: IOPosBuffer.h:54
void * data(void) const
Definition: IOPosBuffer.h:59
IOSize size(void) const
Definition: IOPosBuffer.h:64
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
virtual IOOffset size(void) const
Definition: Storage.cc:102
void addContext(std::string const &context)
Definition: Exception.cc:227
int64_t IOOffset
Definition: IOTypes.h:19
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
size_t IOSize
Definition: IOTypes.h:14
#define XRD_CL_MAX_SIZE
Definition: XrdFile.cc:18
void XrdFile::resize ( IOOffset  size)
virtual

Implements Storage.

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

540 {
541  cms::Exception ex("FileResizeError");
542  ex << "XrdFile::resize(name='" << m_name << "') not implemented";
543  ex.addContext("Calling XrdFile::resize()");
544  addConnection(ex);
545  throw ex;
546 }
std::string m_name
Definition: XrdFile.h:71
void addConnection(cms::Exception &)
Definition: XrdFile.cc:564
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 424 of file XrdFile.cc.

References addConnection(), cms::Exception::addContext(), assert(), mergeVDriftHistosByStation::file, getActiveFile(), m_name, m_offset, m_size, gen::n, and alignCSCRings::s.

425 {
426  if (n > 0x7fffffff) {
427  cms::Exception ex("FileWriteError");
428  ex << "XrdFile::write(name='" << m_name << "', n=" << n
429  << ") too many bytes, limit is 0x7fffffff";
430  ex.addContext("Calling XrdFile::write()");
431  addConnection(ex);
432  throw ex;
433  }
434  auto file = getActiveFile();
435 
436  XrdCl::XRootDStatus s = file->Write(m_offset, n, from);
437  if (!s.IsOK()) {
438  cms::Exception ex("FileWriteError");
439  ex << "XrdFile::write(name='" << m_name << "', n=" << n
440  << ") failed with error '" << s.ToStr()
441  << "' (errno=" << s.errNo << ", code=" << s.code << ")";
442  ex.addContext("Calling XrdFile::write()");
443  addConnection(ex);
444  throw ex;
445  }
446  m_offset += n;
447  assert(m_size != -1);
448  if (m_offset > m_size)
449  m_size = m_offset;
450 
451  return n;
452 }
assert(m_qm.get())
IOOffset m_offset
Definition: XrdFile.h:68
std::shared_ptr< XrdCl::File > getActiveFile()
Definition: XrdFile.cc:549
IOOffset m_size
Definition: XrdFile.h:69
std::string m_name
Definition: XrdFile.h:71
void addConnection(cms::Exception &)
Definition: XrdFile.cc:564
IOSize XrdFile::write ( const void *  from,
IOSize  n,
IOOffset  pos 
)
virtual

Reimplemented from Storage.

Definition at line 455 of file XrdFile.cc.

References addConnection(), cms::Exception::addContext(), assert(), mergeVDriftHistosByStation::file, getActiveFile(), m_name, m_size, gen::n, and alignCSCRings::s.

456 {
457  if (n > 0x7fffffff) {
458  cms::Exception ex("FileWriteError");
459  ex << "XrdFile::write(name='" << m_name << "', n=" << n
460  << ") too many bytes, limit is 0x7fffffff";
461  ex.addContext("Calling XrdFile::write()");
462  addConnection(ex);
463  throw ex;
464  }
465  auto file = getActiveFile();
466 
467  XrdCl::XRootDStatus s = file->Write(pos, n, from);
468  if (!s.IsOK()) {
469  cms::Exception ex("FileWriteError");
470  ex << "XrdFile::write(name='" << m_name << "', n=" << n
471  << ") failed with error '" << s.ToStr()
472  << "' (errno=" << s.errNo << ", code=" << s.code << ")";
473  ex.addContext("Calling XrdFile::write()");
474  addConnection(ex);
475  throw ex;
476  }
477  assert (m_size != -1);
478  if (static_cast<IOOffset>(pos + n) > m_size)
479  m_size = pos + n;
480 
481  return n;
482 }
assert(m_qm.get())
std::shared_ptr< XrdCl::File > getActiveFile()
Definition: XrdFile.cc:549
IOOffset m_size
Definition: XrdFile.h:69
std::string m_name
Definition: XrdFile.h:71
void addConnection(cms::Exception &)
Definition: XrdFile.cc:564

Member Data Documentation

bool XrdFile::m_close
private

Definition at line 70 of file XrdFile.h.

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

std::string XrdFile::m_name
private

Definition at line 71 of file XrdFile.h.

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

IOOffset XrdFile::m_offset
private

Definition at line 68 of file XrdFile.h.

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

std::atomic<unsigned int> XrdFile::m_op_count
private

Definition at line 72 of file XrdFile.h.

Referenced by readv().

std::shared_ptr<XrdAdaptor::RequestManager> XrdFile::m_requestmanager
private

Definition at line 67 of file XrdFile.h.

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

IOOffset XrdFile::m_size
private

Definition at line 69 of file XrdFile.h.

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