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 Attributes
DCacheFile Class Reference

#include <DCacheFile.h>

Inheritance diagram for DCacheFile:
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)
 
 DCacheFile (void)
 
 DCacheFile (IOFD fd)
 
 DCacheFile (const char *name, int flags=IOFlags::OpenRead, int perms=0666)
 
 DCacheFile (const std::string &name, int flags=IOFlags::OpenRead, 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 (IOBuffer *into, IOSize buffers)
 
virtual IOSize readv (IOPosBuffer *into, IOSize buffers)
 
virtual void resize (IOOffset size)
 
virtual IOSize write (const void *from, IOSize n)
 
 ~DCacheFile (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)
 
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 Attributes

bool m_close
 
IOFD m_fd
 
std::string m_name
 

Additional Inherited Members

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

Detailed Description

Definition at line 8 of file DCacheFile.h.

Constructor & Destructor Documentation

DCacheFile::DCacheFile ( void  )

Definition at line 10 of file DCacheFile.cc.

12  m_close (false)
13 {}
IOFD m_fd
Definition: DCacheFile.h:46
bool m_close
Definition: DCacheFile.h:47
#define EDM_IOFD_INVALID
Definition: IOTypes.h:8
DCacheFile::DCacheFile ( IOFD  fd)

Definition at line 15 of file DCacheFile.cc.

16  : m_fd (fd),
17  m_close (true)
18 {}
IOFD m_fd
Definition: DCacheFile.h:46
bool m_close
Definition: DCacheFile.h:47
DCacheFile::DCacheFile ( const char *  name,
int  flags = IOFlags::OpenRead,
int  perms = 0666 
)

Definition at line 20 of file DCacheFile.cc.

References open().

24  m_close (false)
25 { open (name, flags, perms); }
std::vector< Variable::Flags > flags
Definition: MVATrainer.cc:135
IOFD m_fd
Definition: DCacheFile.h:46
virtual void open(const char *name, int flags=IOFlags::OpenRead, int perms=0666)
Definition: DCacheFile.cc:72
bool m_close
Definition: DCacheFile.h:47
#define EDM_IOFD_INVALID
Definition: IOTypes.h:8
DCacheFile::DCacheFile ( const std::string &  name,
int  flags = IOFlags::OpenRead,
int  perms = 0666 
)

Definition at line 27 of file DCacheFile.cc.

References flags, and open().

31  m_close (false)
32 { open (name.c_str (), flags, perms); }
std::vector< Variable::Flags > flags
Definition: MVATrainer.cc:135
IOFD m_fd
Definition: DCacheFile.h:46
virtual void open(const char *name, int flags=IOFlags::OpenRead, int perms=0666)
Definition: DCacheFile.cc:72
bool m_close
Definition: DCacheFile.h:47
#define EDM_IOFD_INVALID
Definition: IOTypes.h:8
DCacheFile::~DCacheFile ( void  )

Definition at line 34 of file DCacheFile.cc.

References m_close, and m_name.

35 {
36  if (m_close)
37  edm::LogError("DCacheFileError")
38  << "Destructor called on dCache file '" << m_name
39  << "' but the file is still open";
40 }
bool m_close
Definition: DCacheFile.h:47
std::string m_name
Definition: DCacheFile.h:48

Member Function Documentation

void DCacheFile::abort ( void  )
virtual

Definition at line 171 of file DCacheFile.cc.

References EDM_IOFD_INVALID, m_close, and m_fd.

172 {
173  if (m_fd != EDM_IOFD_INVALID)
174  dc_close (m_fd);
175 
176  m_close = false;
178 }
IOFD m_fd
Definition: DCacheFile.h:46
bool m_close
Definition: DCacheFile.h:47
#define EDM_IOFD_INVALID
Definition: IOTypes.h:8
void DCacheFile::close ( void  )
virtual

Reimplemented from Storage.

Definition at line 145 of file DCacheFile.cc.

References EDM_IOFD_INVALID, m_close, m_fd, and m_name.

Referenced by python.Vispa.Gui.BoxContentDialog.BoxContentDialog::keyPressEvent(), python.Vispa.Gui.FindDialog.FindDialog::keyPressEvent(), and open().

146 {
147  if (m_fd == EDM_IOFD_INVALID)
148  {
149  edm::LogError("DCacheFileError")
150  << "DCacheFile::close(name='" << m_name
151  << "') called but the file is not open";
152  m_close = false;
153  return;
154  }
155 
156  dc_errno = 0;
157  if (dc_close (m_fd) == -1)
158  edm::LogWarning("DCacheFileWarning")
159  << "dc_close(name='" << m_name
160  << "') failed with error '" << dc_strerror (dc_errno)
161  << "' (dc_errno=" << dc_errno << ")";
162 
163  m_close = false;
165 
166  // Caused hang. Will be added back after problem is fixed.
167  // edm::LogInfo("DCacheFileInfo") << "Closed " << m_name;
168 }
IOFD m_fd
Definition: DCacheFile.h:46
bool m_close
Definition: DCacheFile.h:47
std::string m_name
Definition: DCacheFile.h:48
#define EDM_IOFD_INVALID
Definition: IOTypes.h:8
void DCacheFile::create ( const char *  name,
bool  exclusive = false,
int  perms = 0666 
)
virtual

Definition at line 44 of file DCacheFile.cc.

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

47 {
48  open (name,
50  | (exclusive ? IOFlags::OpenExclusive : 0)),
51  perms);
52 }
virtual void open(const char *name, int flags=IOFlags::OpenRead, int perms=0666)
Definition: DCacheFile.cc:72
void DCacheFile::create ( const std::string &  name,
bool  exclusive = false,
int  perms = 0666 
)
virtual

Definition at line 55 of file DCacheFile.cc.

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

58 {
59  open (name.c_str (),
61  | (exclusive ? IOFlags::OpenExclusive : 0)),
62  perms);
63 }
virtual void open(const char *name, int flags=IOFlags::OpenRead, int perms=0666)
Definition: DCacheFile.cc:72
void DCacheFile::open ( const char *  name,
int  flags = IOFlags::OpenRead,
int  perms = 0666 
)
virtual

Definition at line 72 of file DCacheFile.cc.

References close(), EDM_IOFD_INVALID, edm::hlt::Exception, m_close, m_fd, m_name, mergeVDriftHistosByStation::name, O_NONBLOCK, IOFlags::OpenAppend, IOFlags::OpenCreate, IOFlags::OpenExclusive, IOFlags::OpenNonBlock, IOFlags::OpenRead, IOFlags::OpenTruncate, IOFlags::OpenUnbuffered, and IOFlags::OpenWrite.

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

75 {
76  m_name = name;
77 
78  // Actual open
79  if ((name == 0) || (*name == 0))
80  throw cms::Exception("DCacheFile::open()")
81  << "Cannot open a file without a name";
82 
84  throw cms::Exception("DCacheFile::open()")
85  << "Must open file '" << name << "' at least for read or write";
86 
87  // If I am already open, close old file first
88  if (m_fd != EDM_IOFD_INVALID && m_close)
89  close ();
90 
91  // Translate our flags to system flags
92  int openflags = 0;
93 
95  openflags |= O_RDWR;
96  else if (flags & IOFlags::OpenRead)
97  openflags |= O_RDONLY;
98  else if (flags & IOFlags::OpenWrite)
99  openflags |= O_WRONLY;
100 
102  openflags |= O_NONBLOCK;
103 
105  openflags |= O_APPEND;
106 
108  openflags |= O_CREAT;
109 
111  openflags |= O_EXCL;
112 
114  openflags |= O_TRUNC;
115 
116  IOFD newfd = EDM_IOFD_INVALID;
117  dc_errno = 0;
118  if ((newfd = dc_open (name, openflags, perms)) == -1)
119  throw cms::Exception("DCacheFile::open()")
120  << "dc_open(name='" << name
121  << "', flags=0x" << std::hex << openflags
122  << ", permissions=0" << std::oct << perms << std::dec
123  << ") => error '" << dc_strerror(dc_errno)
124  << "' (dc_errno=" << dc_errno << ")";
125 
126  m_fd = newfd;
127 
128  // Turn off read-ahead, or adjust read-ahead size depending on
129  // whether buffering has been requested. This is a very tricky
130  // balance here. Without read-ahead data processing appears to
131  // become exceedingly slow, and with default (1MB) read-ahead
132  // it appears to saturate disk servers and network. Try tread
133  // reasonable middle ground here.
135  dc_noBuffering(m_fd);
136  else
137  dc_setBufferSize(m_fd, 64000);
138 
139  m_close = true;
140 
141  edm::LogInfo("DCacheFileInfo") << "Opened " << m_name;
142 }
std::vector< Variable::Flags > flags
Definition: MVATrainer.cc:135
IOFD m_fd
Definition: DCacheFile.h:46
virtual void close(void)
Definition: DCacheFile.cc:145
bool m_close
Definition: DCacheFile.h:47
int IOFD
Definition: IOTypes.h:22
std::string m_name
Definition: DCacheFile.h:48
#define EDM_IOFD_INVALID
Definition: IOTypes.h:8
#define O_NONBLOCK
Definition: SysFile.h:21
void DCacheFile::open ( const std::string &  name,
int  flags = IOFlags::OpenRead,
int  perms = 0666 
)
virtual

Definition at line 66 of file DCacheFile.cc.

References flags, and open().

69 { 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: DCacheFile.cc:72
IOOffset DCacheFile::position ( IOOffset  offset,
Relative  whence = SET 
)
virtual

Implements Storage.

Definition at line 318 of file DCacheFile.cc.

References Storage::CURRENT, EDM_IOFD_INVALID, Storage::END, edm::hlt::Exception, m_fd, m_name, query::result, and Storage::SET.

319 {
320  if (m_fd == EDM_IOFD_INVALID)
321  throw cms::Exception("DCacheFile::position()")
322  << "DCacheFile::position() called on a closed file";
323  if (whence != CURRENT && whence != SET && whence != END)
324  throw cms::Exception("DCacheFile::position()")
325  << "DCacheFile::position() called with incorrect 'whence' parameter";
326 
328  int mywhence = (whence == SET ? SEEK_SET
329  : whence == CURRENT ? SEEK_CUR
330  : SEEK_END);
331 
332  dc_errno = 0;
333  if ((result = dc_lseek64 (m_fd, offset, mywhence)) == -1)
334  throw cms::Exception("DCacheFile::position()")
335  << "dc_lseek64(name='" << m_name << "', offset=" << offset
336  << ", whence=" << mywhence << ") failed with error '"
337  << dc_strerror (dc_errno) << "' (dc_errno=" << dc_errno << ")";
338 
339  // FIXME: dCache returns incorrect value on SEEK_END.
340  // Remove this hack when dcap has been fixed.
341  if (whence == SEEK_END && (result = dc_lseek64 (m_fd, result, SEEK_SET)) == -1)
342  throw cms::Exception("DCacheFile::position()")
343  << "dc_lseek64(name='" << m_name << "', offset=" << offset
344  << ", whence=" << SEEK_SET << ") failed with error '"
345  << dc_strerror (dc_errno) << "' (dc_errno=" << dc_errno << ")";
346 
347  return result;
348 }
IOFD m_fd
Definition: DCacheFile.h:46
tuple result
Definition: query.py:137
unsigned int offset(bool)
int64_t IOOffset
Definition: IOTypes.h:19
std::string m_name
Definition: DCacheFile.h:48
#define EDM_IOFD_INVALID
Definition: IOTypes.h:8
IOSize DCacheFile::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 197 of file DCacheFile.cc.

References BUGLINE, generateEDF::done, edm::hlt::Exception, m_fd, m_name, and asciidump::s.

198 {
199  IOSize done = 0;
200  while (done < n)
201  {
202  dc_errno = 0;
203  ssize_t s = dc_read (m_fd, (char *) into + done, n - done);
204  if (s == -1)
205  throw cms::Exception("DCacheFile::read()")
206  << "dc_read(name='" << m_name << "', n=" << (n-done)
207  << ") failed with error '" << dc_strerror(dc_errno)
208  << "' (dc_errno=" << dc_errno << ")";
209  else if (s == 0)
210  // end of file
211  break;
212  else if (s < ssize_t (n-done))
213  edm::LogInfo("DCacheFileWarning")
214  << "dc_read(name='" << m_name << "', n=" << (n-done)
215  << ") returned a short read of " << s << " bytes; "
216  << "please report a bug in dCache referencing the "
217  << "comment on line " << BUGLINE << " of " << __FILE__;
218  done += s;
219  }
220 
221  return done;
222 }
IOFD m_fd
Definition: DCacheFile.h:46
static const int BUGLINE
Definition: DCacheFile.cc:181
std::string m_name
Definition: DCacheFile.h:48
size_t IOSize
Definition: IOTypes.h:14
string s
Definition: asciidump.py:422
IOSize DCacheFile::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 250 of file DCacheFile.cc.

References runTheMatrix::data, edm::hlt::Exception, i, m_fd, m_name, n, and IOBuffer::size().

251 {
252  assert (! buffers || into);
253 
254  // readv may not support zero buffers.
255  if (! buffers)
256  return 0;
257 
258  // Convert the buffers to system format.
259  std::vector<iovec> bufs (buffers);
260  for (IOSize i = 0; i < buffers; ++i)
261  {
262  bufs [i].iov_len = into [i].size ();
263  bufs [i].iov_base = (caddr_t) into [i].data ();
264  }
265 
266  // Read as long as signals cancel the read before doing anything.
267  dc_errno = 0;
268  ssize_t n = dc_readv (m_fd, &bufs [0], buffers);
269 
270  // If it was serious error, throw it.
271  if (n == -1)
272  throw cms::Exception("DCacheFile::readv()")
273  << "dc_readv(name='" << m_name << "', iov[" << buffers
274  << "]) failed with error '" << dc_strerror(dc_errno)
275  << "' (dc_errno=" << dc_errno << ")";
276 
277  // Return the number of bytes actually read.
278  return n;
279 }
int i
Definition: DBlmapReader.cc:9
IOFD m_fd
Definition: DCacheFile.h:46
IOSize size(void) const
Definition: IOBuffer.h:50
std::string m_name
Definition: DCacheFile.h:48
size_t IOSize
Definition: IOTypes.h:14
IOSize DCacheFile::readv ( IOPosBuffer into,
IOSize  buffers 
)
virtual

Reimplemented from Storage.

Definition at line 282 of file DCacheFile.cc.

References runTheMatrix::data, edm::hlt::Exception, i, m_fd, m_name, n, IOPosBuffer::offset(), and IOPosBuffer::size().

283 {
284  assert (! buffers || into);
285 
286  // readv may not support zero buffers.
287  if (! buffers)
288  return 0;
289 
290  // Convert the buffers to system format.
291  std::vector<iovec2> bufs (buffers);
292  for (IOSize i = 0; i < buffers; ++i)
293  {
294  bufs [i].offset = into [i].offset ();
295  bufs [i].len = into [i].size ();
296  bufs [i].buf = (char *) into [i].data ();
297  }
298 
299  // Read as long as signals cancel the read before doing anything.
300  dc_errno = 0;
301  ssize_t n = dc_readv2 (m_fd, &bufs [0], buffers);
302 
303  // If it was serious error, throw it.
304  if (n == -1)
305  throw cms::Exception("DCacheFile::readv()")
306  << "dc_readv2(name='" << m_name << "', iov2[" << buffers
307  << "]) failed with error '" << dc_strerror(dc_errno)
308  << "' (dc_errno=" << dc_errno << ")";
309 
310  // Return the number of bytes actually read.
311  return n;
312 }
int i
Definition: DBlmapReader.cc:9
IOFD m_fd
Definition: DCacheFile.h:46
IOOffset offset(void) const
Definition: IOPosBuffer.h:50
IOSize size(void) const
Definition: IOPosBuffer.h:60
std::string m_name
Definition: DCacheFile.h:48
size_t IOSize
Definition: IOTypes.h:14
void DCacheFile::resize ( IOOffset  size)
virtual

Implements Storage.

Definition at line 351 of file DCacheFile.cc.

References edm::hlt::Exception, and m_name.

Referenced by python.Vispa.Gui.TextDialog.TextDialog::__init__(), python.Vispa.Plugins.ConfigEditor.ToolDialog.ToolDialog::__init__(), python.Vispa.Main.MainWindow.MainWindow::_loadIni(), and python.Vispa.Gui.PortConnection.PointToPointConnection::updateConnection().

352 {
353  throw cms::Exception("DCacheFile::resize()")
354  << "DCacheFile::resize(name='" << m_name << "') not implemented";
355 }
std::string m_name
Definition: DCacheFile.h:48
IOSize DCacheFile::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 225 of file DCacheFile.cc.

References BUGLINE, generateEDF::done, edm::hlt::Exception, m_fd, m_name, and asciidump::s.

226 {
227  IOSize done = 0;
228  while (done < n)
229  {
230  dc_errno = 0;
231  ssize_t s = dc_write (m_fd, (const char *) from + done, n - done);
232  if (s == -1)
233  throw cms::Exception("DCacheFile::write()")
234  << "dc_write(name='" << m_name << "', n=" << (n-done)
235  << ") failed with error '" << dc_strerror(dc_errno)
236  << "' (dc_errno=" << dc_errno << ")";
237  else if (s < ssize_t (n-done))
238  edm::LogInfo("DCacheFileWarning")
239  << "dc_write(name='" << m_name << "', n=" << (n-done)
240  << ") returned a short write of " << s << " bytes; "
241  << "please report a bug in dCache referencing the "
242  << "comment on line " << BUGLINE << " of " << __FILE__;
243  done += s;
244  }
245 
246  return done;
247 }
IOFD m_fd
Definition: DCacheFile.h:46
static const int BUGLINE
Definition: DCacheFile.cc:181
static std::string from(" from ")
std::string m_name
Definition: DCacheFile.h:48
size_t IOSize
Definition: IOTypes.h:14
string s
Definition: asciidump.py:422

Member Data Documentation

bool DCacheFile::m_close
private

Definition at line 47 of file DCacheFile.h.

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

IOFD DCacheFile::m_fd
private

Definition at line 46 of file DCacheFile.h.

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

std::string DCacheFile::m_name
private

Definition at line 48 of file DCacheFile.h.

Referenced by close(), open(), position(), read(), readv(), resize(), write(), and ~DCacheFile().