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
RFIOFile Class Reference

#include <RFIOFile.h>

Inheritance diagram for RFIOFile:
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 IOSize read (void *into, IOSize n)
 
virtual IOSize readv (IOPosBuffer *into, IOSize buffers)
 
virtual void resize (IOOffset size)
 
 RFIOFile (void)
 
 RFIOFile (IOFD fd)
 
 RFIOFile (const char *name, int flags=IOFlags::OpenRead, int perms=0666)
 
 RFIOFile (const std::string &name, int flags=IOFlags::OpenRead, int perms=0666)
 
virtual IOSize write (const void *from, IOSize n)
 
 ~RFIOFile (void)
 
- Public Member Functions inherited from Storage
virtual bool eof (void) const
 
virtual void flush (void)
 
virtual IOOffset position (void) const
 
virtual bool prefetch (const IOPosBuffer *what, IOSize n)
 
virtual IOSize read (void *into, IOSize n, IOOffset pos)
 
IOSize read (IOBuffer into, IOOffset pos)
 
virtual void rewind (void)
 
virtual IOOffset size (void) const
 
 Storage (void)
 
virtual IOSize write (const void *from, IOSize n, IOOffset pos)
 
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)
 
virtual IOSize readv (IOBuffer *into, IOSize buffers)
 
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 reopen ()
 
ssize_t retryRead (void *into, IOSize n, int maxRetry=10)
 

Private Attributes

bool m_close
 
IOOffset m_curpos
 
IOFD m_fd
 
int m_flags
 
std::string m_name
 
int m_perms
 

Additional Inherited Members

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

Detailed Description

RFIO Storage object.

Definition at line 9 of file RFIOFile.h.

Constructor & Destructor Documentation

RFIOFile::RFIOFile ( void  )

Definition at line 30 of file RFIOFile.cc.

32  m_close (false),
33  m_flags (0),
34  m_perms (0),
35  m_curpos (0)
36 {}
bool m_close
Definition: RFIOFile.h:55
int m_flags
Definition: RFIOFile.h:57
IOOffset m_curpos
Definition: RFIOFile.h:59
#define EDM_IOFD_INVALID
Definition: IOTypes.h:8
int m_perms
Definition: RFIOFile.h:58
IOFD m_fd
Definition: RFIOFile.h:54
RFIOFile::RFIOFile ( IOFD  fd)

Definition at line 38 of file RFIOFile.cc.

39  : m_fd (fd),
40  m_close (true),
41  m_flags (0),
42  m_perms (0),
43  m_curpos (0)
44 {}
bool m_close
Definition: RFIOFile.h:55
int m_flags
Definition: RFIOFile.h:57
IOOffset m_curpos
Definition: RFIOFile.h:59
int m_perms
Definition: RFIOFile.h:58
IOFD m_fd
Definition: RFIOFile.h:54
RFIOFile::RFIOFile ( const char *  name,
int  flags = IOFlags::OpenRead,
int  perms = 0666 
)

Definition at line 46 of file RFIOFile.cc.

References open().

50  m_close (false),
51  m_flags (0),
52  m_perms (0),
53  m_curpos (0)
54 { open (name, flags, perms); }
bool m_close
Definition: RFIOFile.h:55
std::vector< Variable::Flags > flags
Definition: MVATrainer.cc:135
int m_flags
Definition: RFIOFile.h:57
virtual void open(const char *name, int flags=IOFlags::OpenRead, int perms=0666)
Definition: RFIOFile.cc:105
IOOffset m_curpos
Definition: RFIOFile.h:59
#define EDM_IOFD_INVALID
Definition: IOTypes.h:8
int m_perms
Definition: RFIOFile.h:58
IOFD m_fd
Definition: RFIOFile.h:54
RFIOFile::RFIOFile ( const std::string &  name,
int  flags = IOFlags::OpenRead,
int  perms = 0666 
)

Definition at line 56 of file RFIOFile.cc.

References flags, and open().

60  m_close (false),
61  m_flags (0),
62  m_perms (0),
63  m_curpos (0)
64 { open (name.c_str (), flags, perms); }
bool m_close
Definition: RFIOFile.h:55
std::vector< Variable::Flags > flags
Definition: MVATrainer.cc:135
int m_flags
Definition: RFIOFile.h:57
virtual void open(const char *name, int flags=IOFlags::OpenRead, int perms=0666)
Definition: RFIOFile.cc:105
IOOffset m_curpos
Definition: RFIOFile.h:59
#define EDM_IOFD_INVALID
Definition: IOTypes.h:8
int m_perms
Definition: RFIOFile.h:58
IOFD m_fd
Definition: RFIOFile.h:54
RFIOFile::~RFIOFile ( void  )

Definition at line 66 of file RFIOFile.cc.

References m_close, and m_name.

67 {
68  if (m_close)
69  edm::LogError("RFIOFileError")
70  << "Destructor called on RFIO file '" << m_name
71  << "' but the file is still open";
72 }
bool m_close
Definition: RFIOFile.h:55
std::string m_name
Definition: RFIOFile.h:56

Member Function Documentation

void RFIOFile::abort ( void  )
virtual

Definition at line 245 of file RFIOFile.cc.

References EDM_IOFD_INVALID, m_close, m_fd, rfio_close64(), and serrno.

246 {
247  serrno = 0;
248  if (m_fd != EDM_IOFD_INVALID)
249  rfio_close64 (m_fd);
250 
251  m_close = false;
253 }
bool m_close
Definition: RFIOFile.h:55
#define serrno
Definition: RFIO.h:10
#define EDM_IOFD_INVALID
Definition: IOTypes.h:8
int rfio_close64(int s)
Definition: RFIO.h:29
IOFD m_fd
Definition: RFIOFile.h:54
void RFIOFile::close ( void  )
virtual

Reimplemented from Storage.

Definition at line 201 of file RFIOFile.cc.

References EDM_IOFD_INVALID, m_close, m_fd, m_name, rfio_close64(), rfio_errno, rfio_serror(), serrno, stor::utils::sleep(), and ntuplemaker::status.

Referenced by lumiQTWidget.ApplicationWindow::fileQuit(), Vispa.Gui.BoxContentDialog.BoxContentDialog::keyPressEvent(), Vispa.Gui.FindDialog.FindDialog::keyPressEvent(), open(), and reopen().

202 {
203  if (m_fd == EDM_IOFD_INVALID)
204  {
205  edm::LogError("RFIOFileError")
206  << "RFIOFile::close(name='" << m_name
207  << "') called but the file is not open";
208  m_close = false;
209  return;
210  }
211 
212  serrno = 0;
213  if (rfio_close64 (m_fd) == -1)
214  {
215  // If we fail to close the file, report a warning.
216  edm::LogWarning("RFIOFileWarning")
217  << "rfio_close64(name='" << m_name
218  << "') failed with error '" << rfio_serror()
219  << "' (rfio_errno=" << rfio_errno << ", serrno=" << serrno << ")";
220 
221  // When rfio_close64 fails then try the system close function as
222  // per the advice from Olof Barring from the Castor operations.
223  int status = ::close(m_fd);
224  if (status < 0)
225  edm::LogWarning("RFIOFileWarning")
226  << "RFIOFile::close(): system level close after a failed"
227  << " rfio_close64 also failed with error '" << strerror (errno)
228  << "' (error code " << errno << ")";
229  else
230  edm::LogWarning("RFIOFileWarning")
231  << "RFIOFile::close(): system level close after a failed"
232  << " rfio_close64 succeeded";
233 
234  sleep(5);
235  }
236 
237  m_close = false;
239 
240  // Caused hang. Will be added back after problem is fix
241  // edm::LogInfo("RFIOFileInfo") << "Closed " << m_name;
242 }
bool m_close
Definition: RFIOFile.h:55
std::string m_name
Definition: RFIOFile.h:56
#define rfio_errno
Definition: RFIO.h:11
void sleep(Duration_t)
Definition: Utils.h:163
#define serrno
Definition: RFIO.h:10
virtual void close(void)
Definition: RFIOFile.cc:201
char * rfio_serror()
#define EDM_IOFD_INVALID
Definition: IOTypes.h:8
int rfio_close64(int s)
Definition: RFIO.h:29
tuple status
Definition: ntuplemaker.py:245
IOFD m_fd
Definition: RFIOFile.h:54
void RFIOFile::create ( const char *  name,
bool  exclusive = false,
int  perms = 0666 
)
virtual

Definition at line 77 of file RFIOFile.cc.

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

80 {
81  open (name,
83  | (exclusive ? IOFlags::OpenExclusive : 0)),
84  perms);
85 }
virtual void open(const char *name, int flags=IOFlags::OpenRead, int perms=0666)
Definition: RFIOFile.cc:105
void RFIOFile::create ( const std::string &  name,
bool  exclusive = false,
int  perms = 0666 
)
virtual

Definition at line 88 of file RFIOFile.cc.

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

91 {
92  open (name.c_str (),
94  | (exclusive ? IOFlags::OpenExclusive : 0)),
95  perms);
96 }
virtual void open(const char *name, int flags=IOFlags::OpenRead, int perms=0666)
Definition: RFIOFile.cc:105
void RFIOFile::open ( const char *  name,
int  flags = IOFlags::OpenRead,
int  perms = 0666 
)
virtual

Definition at line 105 of file RFIOFile.cc.

References cms::Exception::addContext(), close(), EDM_IOFD_INVALID, edm::errors::FileOpenError, flags, m_close, m_curpos, m_fd, m_flags, m_name, m_perms, mergeVDriftHistosByStation::name, O_NONBLOCK, IOFlags::OpenAppend, IOFlags::OpenCreate, IOFlags::OpenExclusive, IOFlags::OpenNonBlock, IOFlags::OpenRead, IOFlags::OpenTruncate, IOFlags::OpenUnbuffered, IOFlags::OpenWrite, rfio_errno, rfio_open64(), RFIO_READOPT, rfio_serror(), rfiosetopt(), serrno, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by create(), open(), reopen(), and RFIOFile().

108 {
109  // Save parameters for error recovery.
110  if (name == 0) {
111  m_name = "";
112  } else {
113  m_name = name;
114  }
115  m_flags = flags;
116  m_perms = perms;
117 
118  // Reset RFIO error code.
119  serrno = 0;
120 
121  // Disable buffering in rfio library? Note that doing this on
122  // one file disables it for everything. Not much we can do...
123  // but it does make a significant performance difference to the
124  // clients. Note also that docs say the flag turns off write
125  // buffering -- this turns off all buffering.
127  {
128  int readopt = 0;
129  rfiosetopt (RFIO_READOPT, &readopt, sizeof (readopt));
130  }
131  else
132  {
133  int readopt = 1;
134  rfiosetopt (RFIO_READOPT, &readopt, sizeof (readopt));
135  }
136 
137  if ((name == 0) || (*name == 0)) {
139  ex << "Cannot open a file without a name";
140  ex.addContext("Calling RFIOFile::open()");
141  throw ex;
142  }
143  if ((flags & (IOFlags::OpenRead | IOFlags::OpenWrite)) == 0) {
145  ex << "Must open file '" << name << "' at least for read or write";
146  ex.addContext("Calling RFIOFile::open()");
147  throw ex;
148  }
149  std::string lname (name);
150  if (lname.find ("//") == 0)
151  lname.erase(0, 1);
152 
153  // If I am already open, close old file first
154  if (m_fd != EDM_IOFD_INVALID && m_close)
155  close ();
156 
157  // Translate our flags to system flags
158  int openflags = 0;
159 
161  openflags |= O_RDWR;
162  else if (flags & IOFlags::OpenRead)
163  openflags |= O_RDONLY;
164  else if (flags & IOFlags::OpenWrite)
165  openflags |= O_WRONLY;
166 
168  openflags |= O_NONBLOCK;
169 
171  openflags |= O_APPEND;
172 
174  openflags |= O_CREAT;
175 
177  openflags |= O_EXCL;
178 
180  openflags |= O_TRUNC;
181 
182  IOFD newfd = EDM_IOFD_INVALID;
183  if ((newfd = rfio_open64 (lname.c_str(), openflags, perms)) == -1) {
185  ex << "rfio_open(name='" << lname
186  << "', flags=0x" << std::hex << openflags
187  << ", permissions=0" << std::oct << perms << std::dec
188  << ") => error '" << rfio_serror ()
189  << "' (rfio_errno=" << rfio_errno << ", serrno=" << serrno << ")";
190  ex.addContext("Calling RFIOFile::open()");
191  throw ex;
192  }
193  m_fd = newfd;
194  m_close = true;
195  m_curpos = 0;
196 
197  edm::LogInfo("RFIOFileInfo") << "Opened " << lname;
198 }
#define RFIO_READOPT
Definition: RFIO.h:9
bool m_close
Definition: RFIOFile.h:55
std::string m_name
Definition: RFIOFile.h:56
#define rfio_errno
Definition: RFIO.h:11
std::vector< Variable::Flags > flags
Definition: MVATrainer.cc:135
int m_flags
Definition: RFIOFile.h:57
int rfiosetopt(int opt, int *pval, int len)
#define serrno
Definition: RFIO.h:10
virtual void close(void)
Definition: RFIOFile.cc:201
int rfio_open64(const char *filepath, int flags, int mode)
char * rfio_serror()
int IOFD
Definition: IOTypes.h:22
IOOffset m_curpos
Definition: RFIOFile.h:59
#define EDM_IOFD_INVALID
Definition: IOTypes.h:8
int m_perms
Definition: RFIOFile.h:58
#define O_NONBLOCK
Definition: SysFile.h:21
IOFD m_fd
Definition: RFIOFile.h:54
void RFIOFile::open ( const std::string &  name,
int  flags = IOFlags::OpenRead,
int  perms = 0666 
)
virtual

Definition at line 99 of file RFIOFile.cc.

References flags, and open().

102 { 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: RFIOFile.cc:105
IOOffset RFIOFile::position ( IOOffset  offset,
Relative  whence = SET 
)
virtual

Implements Storage.

Definition at line 382 of file RFIOFile.cc.

References cms::Exception::addContext(), Storage::CURRENT, EDM_IOFD_INVALID, Storage::END, m_curpos, m_fd, m_name, query::result, rfio_errno, rfio_lseek64(), rfio_serror(), serrno, and Storage::SET.

383 {
384  if (m_fd == EDM_IOFD_INVALID) {
385  cms::Exception ex("FilePositionError");
386  ex << "RFIOFile::position() called on a closed file";
387  throw ex;
388  }
389  if (whence != CURRENT && whence != SET && whence != END) {
390  cms::Exception ex("FilePositionError");
391  ex << "RFIOFile::position() called with incorrect 'whence' parameter";
392  throw ex;
393  }
395  int mywhence = (whence == SET ? SEEK_SET
396  : whence == CURRENT ? SEEK_CUR
397  : SEEK_END);
398 
399  serrno = 0;
400  if ((result = rfio_lseek64 (m_fd, offset, mywhence)) == -1) {
401  cms::Exception ex("FilePositionError");
402  ex << "rfio_lseek(name='" << m_name << "', offset=" << offset
403  << ", whence=" << mywhence << ") failed at position "
404  << m_curpos << " with error '" << rfio_serror()
405  << "' (rfio_errno=" << rfio_errno << ", serrno=" << serrno << ")";
406  ex.addContext("Calling RFIOFile::position()");
407  throw ex;
408  }
409  m_curpos = result;
410  return result;
411 }
std::string m_name
Definition: RFIOFile.h:56
#define rfio_errno
Definition: RFIO.h:11
#define serrno
Definition: RFIO.h:10
tuple result
Definition: query.py:137
unsigned int offset(bool)
char * rfio_serror()
int64_t IOOffset
Definition: IOTypes.h:19
IOOffset m_curpos
Definition: RFIOFile.h:59
#define EDM_IOFD_INVALID
Definition: IOTypes.h:8
IOFD m_fd
Definition: RFIOFile.h:54
off64_t rfio_lseek64(int s, off64_t offset, int how)
IOSize RFIOFile::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 326 of file RFIOFile.cc.

References cms::Exception::addContext(), end, edm::errors::FileReadError, LogDebug, m_curpos, m_name, realNanoSecs(), retryRead(), rfio_errno, rfio_serror(), alignCSCRings::s, serrno, and dqm_diff::start.

327 {
328  // Be aware that when enabled these LogDebug prints
329  // will take more time than the read itself unless the reads
330  // are proceeding slower than under optimal conditions.
331  LogDebug("RFIOFileDebug") << "Entering RFIOFile read()";
332  double start = realNanoSecs();
333 
334  ssize_t s;
335  serrno = 0;
336  if ((s = retryRead (into, n, 3)) < 0) {
338  ex << "rfio_read(name='" << m_name << "', n=" << n << ") failed"
339  << " at position " << m_curpos << " with error '" << rfio_serror()
340  << "' (rfio_errno=" << rfio_errno << ", serrno=" << serrno << ")";
341  ex.addContext("Calling RFIOFile::read()");
342  throw ex;
343  }
344  m_curpos += s;
345 
346  double end = realNanoSecs();
347  LogDebug("RFIOFileDebug")
348  << "Exiting RFIOFile read(), elapsed time = " << end - start
349  << " ns, bytes read = " << s << ", file position = " << m_curpos;
350 
351  return s;
352 }
#define LogDebug(id)
tuple start
Check for commandline option errors.
Definition: dqm_diff.py:58
std::string m_name
Definition: RFIOFile.h:56
#define rfio_errno
Definition: RFIO.h:11
#define serrno
Definition: RFIO.h:10
#define end
Definition: vmac.h:38
static double realNanoSecs(void)
Definition: RFIOFile.cc:16
ssize_t retryRead(void *into, IOSize n, int maxRetry=10)
Definition: RFIOFile.cc:269
char * rfio_serror()
IOOffset m_curpos
Definition: RFIOFile.h:59
IOSize RFIOFile::readv ( IOPosBuffer into,
IOSize  buffers 
)
virtual

Reimplemented from Storage.

Definition at line 355 of file RFIOFile.cc.

References m_flags, IOFlags::OpenUnbuffered, Storage::prefetch(), and Storage::readv().

356 {
358  prefetch(into, buffers);
359  return Storage::readv(into, buffers);
360 }
virtual IOSize readv(IOPosBuffer *into, IOSize buffers)
Definition: Storage.cc:31
int m_flags
Definition: RFIOFile.h:57
virtual bool prefetch(const IOPosBuffer *what, IOSize n)
Definition: Storage.cc:119
void RFIOFile::reopen ( void  )
private

Definition at line 255 of file RFIOFile.cc.

References close(), m_curpos, m_flags, m_name, m_perms, open(), Storage::position(), and stor::utils::sleep().

Referenced by retryRead().

256 {
257  // Remember the current position in the file
258  IOOffset lastpos = m_curpos;
259  close();
260  sleep(5);
262 
263  // Set the position back to the same place it was
264  // before the file closed and opened.
265  position(lastpos);
266 }
std::string m_name
Definition: RFIOFile.h:56
int m_flags
Definition: RFIOFile.h:57
void sleep(Duration_t)
Definition: Utils.h:163
virtual void open(const char *name, int flags=IOFlags::OpenRead, int perms=0666)
Definition: RFIOFile.cc:105
virtual IOOffset position(void) const
Definition: Storage.cc:95
virtual void close(void)
Definition: RFIOFile.cc:201
int64_t IOOffset
Definition: IOTypes.h:19
IOOffset m_curpos
Definition: RFIOFile.h:59
int m_perms
Definition: RFIOFile.h:58
void RFIOFile::resize ( IOOffset  size)
virtual

Implements Storage.

Definition at line 414 of file RFIOFile.cc.

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

415 {
416  cms::Exception ex("FileResizeError");
417  ex << "RFIOFile::resize(name='" << m_name << "') not implemented";
418  throw ex;
419 }
std::string m_name
Definition: RFIOFile.h:56
ssize_t RFIOFile::retryRead ( void *  into,
IOSize  n,
int  maxRetry = 10 
)
private

Definition at line 269 of file RFIOFile.cc.

References edm::FlushMessageLog(), m_curpos, m_fd, m_name, reopen(), rfio_errno, rfio_read64(), rfio_serror(), alignCSCRings::s, serrno, and stor::utils::sleep().

Referenced by read().

270 {
271  // Attempt to read up to maxRetry times.
272  ssize_t s;
273  do
274  {
275  serrno = 0;
276  s = rfio_read64 (m_fd, into, n);
277  if ((s == -1 && serrno == 1004) || (s > ssize_t (n)))
278  {
279  // Wait a little while to allow Castor to recover from the timeout.
280  const char *sleepTimeMsg;
281  int secondsToSleep = 5;
282  switch (maxRetry)
283  {
284  case 1:
285  sleepTimeMsg = "10 minutes";
286  secondsToSleep = 600;
287  break;
288 
289  case 2:
290  sleepTimeMsg = "5 minutes";
291  secondsToSleep = 300;
292  break;
293 
294  default:
295  sleepTimeMsg = "1 minute";
296  secondsToSleep = 60;
297  }
298 
299  edm::LogWarning("RFIOFileRetry")
300  << "RFIOFile retrying read\n"
301  << " return value from rfio_read64 = " << s << " (normally this is bytes read, -1 for error)\n"
302  << " bytes requested = " << n << " (this and bytes read are equal unless error or EOF)\n"
303  << " rfio error message = " << rfio_serror() << " (explanation from server, if possible)\n"
304  << " serrno = " << serrno << " (rfio server error code, 0 = OK, 1004 = timeout, ...)\n"
305  << " rfio_errno = " << rfio_errno << " (rfio error from actually accessing the file)\n"
306  << " current position = " << m_curpos << " (in bytes, beginning of file is 0)\n"
307  << " retries left before quitting = " << maxRetry << "\n"
308  << " will close and reopen file " << m_name << "\n"
309  << " will sleep for " << sleepTimeMsg << " before attempting retry";
311  sleep(secondsToSleep);
312 
313  // Improve the chances of success by closing and reopening
314  // the file before retrying the read. This also resets
315  // the position in the file to the correct place.
316  reopen();
317  }
318  else
319  break;
320  } while (--maxRetry > 0);
321 
322  return s;
323 }
void FlushMessageLog()
std::string m_name
Definition: RFIOFile.h:56
#define rfio_errno
Definition: RFIO.h:11
void sleep(Duration_t)
Definition: Utils.h:163
int rfio_read64(int s, void *ptr, int size)
#define serrno
Definition: RFIO.h:10
char * rfio_serror()
void reopen()
Definition: RFIOFile.cc:255
IOOffset m_curpos
Definition: RFIOFile.h:59
IOFD m_fd
Definition: RFIOFile.h:54
IOSize RFIOFile::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 363 of file RFIOFile.cc.

References cms::Exception::addContext(), m_curpos, m_fd, m_name, rfio_errno, rfio_serror(), rfio_write64(), alignCSCRings::s, and serrno.

364 {
365  serrno = 0;
366  ssize_t s = rfio_write64 (m_fd, from, n);
367  if (s < 0) {
368  cms::Exception ex("FileWriteError");
369  ex << "rfio_write(name='" << m_name << "', n=" << n << ") failed"
370  << " at position " << m_curpos << " with error '" << rfio_serror()
371  << "' (rfio_errno=" << rfio_errno << ", serrno=" << serrno << ")";
372  ex.addContext("Calling RFIOFile::write()");
373  throw ex;
374  }
375  return s;
376 }
int rfio_write64(int s, const void *ptr, int size)
std::string m_name
Definition: RFIOFile.h:56
#define rfio_errno
Definition: RFIO.h:11
#define serrno
Definition: RFIO.h:10
char * rfio_serror()
IOOffset m_curpos
Definition: RFIOFile.h:59
IOFD m_fd
Definition: RFIOFile.h:54

Member Data Documentation

bool RFIOFile::m_close
private

Definition at line 55 of file RFIOFile.h.

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

IOOffset RFIOFile::m_curpos
private

Definition at line 59 of file RFIOFile.h.

Referenced by open(), position(), read(), reopen(), retryRead(), and write().

IOFD RFIOFile::m_fd
private

Definition at line 54 of file RFIOFile.h.

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

int RFIOFile::m_flags
private

Definition at line 57 of file RFIOFile.h.

Referenced by open(), readv(), and reopen().

std::string RFIOFile::m_name
private

Definition at line 56 of file RFIOFile.h.

Referenced by close(), open(), position(), read(), reopen(), resize(), retryRead(), write(), and ~RFIOFile().

int RFIOFile::m_perms
private

Definition at line 58 of file RFIOFile.h.

Referenced by open(), and reopen().