CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Member Functions
Storage Class Referenceabstract

#include <Storage.h>

Inheritance diagram for Storage:
IOInput IOOutput DavixFile DCacheFile File LocalCacheFile LStoreFile StorageAccountProxy XrdFile RemoteFile

Public Types

enum  Relative { SET, CURRENT, END }
 

Public Member Functions

virtual void close (void)
 
virtual bool eof (void) const
 
virtual void flush (void)
 
virtual IOOffset position (IOOffset offset, Relative whence=SET)=0
 
virtual IOOffset position (void) const
 
virtual bool prefetch (const IOPosBuffer *what, IOSize n)
 
IOSize read (IOBuffer into)
 
IOSize read (IOBuffer into, IOOffset pos)
 
virtual IOSize read (void *into, IOSize n)=0
 
virtual IOSize read (void *into, IOSize n, IOOffset pos)
 
int read (void)
 
virtual IOSize readv (IOBuffer *into, IOSize buffers)
 
virtual IOSize readv (IOPosBuffer *into, IOSize buffers)
 
virtual void resize (IOOffset size)=0
 
virtual void rewind (void)
 
virtual IOOffset size (void) const
 
 Storage (void)
 
virtual IOSize write (const void *from, IOSize n)=0
 
virtual IOSize write (const void *from, IOSize n, IOOffset pos)
 
IOSize write (IOBuffer from)
 
IOSize write (IOBuffer from, IOOffset pos)
 
IOSize write (unsigned char byte)
 
virtual IOSize writev (const IOBuffer *from, IOSize buffers)
 
virtual IOSize writev (const IOPosBuffer *from, IOSize buffers)
 
 ~Storage (void) override
 
- Public Member Functions inherited from IOInput
IOSize read (IOBuffer into)
 
virtual IOSize read (void *into, IOSize n)=0
 
int read (void)
 
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
virtual IOSize write (const void *from, IOSize n)=0
 
IOSize write (IOBuffer from)
 
IOSize write (unsigned char byte)
 
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

Storageoperator= (const Storage &)=delete
 
 Storage (const Storage &)=delete
 

Detailed Description

Definition at line 20 of file Storage.h.

Member Enumeration Documentation

◆ Relative

Enumerator
SET 
CURRENT 
END 

Definition at line 22 of file Storage.h.

22 { SET, CURRENT, END };

Constructor & Destructor Documentation

◆ Storage() [1/2]

Storage::Storage ( void  )

Definition at line 5 of file Storage.cc.

5 {}

◆ ~Storage()

Storage::~Storage ( void  )
override

Definition at line 7 of file Storage.cc.

7 {}

◆ Storage() [2/2]

Storage::Storage ( const Storage )
privatedelete

Member Function Documentation

◆ close()

void Storage::close ( void  )
virtual

◆ eof()

bool Storage::eof ( void  ) const
virtual

Definition at line 98 of file Storage.cc.

98 { return position() == size(); }

References position(), and size().

◆ flush()

void Storage::flush ( void  )
virtual

Reimplemented in File, StorageAccountProxy, and LocalCacheFile.

Definition at line 93 of file Storage.cc.

93 {}

◆ operator=()

Storage& Storage::operator= ( const Storage )
privatedelete

◆ position() [1/2]

virtual IOOffset Storage::position ( IOOffset  offset,
Relative  whence = SET 
)
pure virtual

◆ position() [2/2]

IOOffset Storage::position ( void  ) const
virtual

Definition at line 72 of file Storage.cc.

72  {
73  Storage *self = const_cast<Storage *>(this);
74  return self->position(0, CURRENT);
75 }

References CURRENT.

Referenced by eof(), read(), lhef::StorageInputStream::readBytes(), readv(), rewind(), size(), lhef::StorageInputStream::StorageInputStream(), and write().

◆ prefetch()

bool Storage::prefetch ( const IOPosBuffer what,
IOSize  n 
)
virtual

Reimplemented in XrdFile, File, StorageAccountProxy, and LocalCacheFile.

Definition at line 90 of file Storage.cc.

90 { return false; }

◆ read() [1/5]

IOSize IOInput::read

Read from the input stream into the buffer starting at into and of size n.

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 simply forwards the call to read(void *, IOSize) method.

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

Definition at line 80 of file IOInput.cc.

80 { return read(into.data(), into.size()); }

◆ read() [2/5]

IOSize Storage::read ( IOBuffer  into,
IOOffset  pos 
)

Definition at line 10 of file Storage.cc.

10 { return read(into.data(), into.size(), pos); }

References IOBuffer::data(), IOInput::read(), and IOBuffer::size().

◆ read() [3/5]

IOSize IOInput::read

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

◆ read() [4/5]

IOSize Storage::read ( void *  into,
IOSize  n,
IOOffset  pos 
)
virtual

Reimplemented in XrdFile, File, StorageAccountProxy, and LocalCacheFile.

Definition at line 12 of file Storage.cc.

12  {
13  // FIXME: this is not thread safe! split into separate interface
14  // that a particular storage can choose to support or not? make
15  // sure that throw semantics are correct here!
16  // FIXME: use saveposition object in case exceptions are thrown?
17  IOOffset here = position();
18  position(pos);
19  n = read(into, n);
20  position(here);
21  return n;
22 }

References dqmiodumpmetadata::n, position(), and IOInput::read().

Referenced by PixelSLinkDataInputSource::PixelSLinkDataInputSource(), lhef::StorageInputStream::readBytes(), PixelSLinkDataInputSource::setRunAndEventInfo(), and lhef::StorageInputStream::StorageInputStream().

◆ read() [5/5]

int IOInput::read

Read the next single byte from the input stream and return it as an unsigned char cast to an int, -1 to indicate end of intput data.

If this is a blocking stream, the call will block until the byte can be read, end of data is reached, or an exception is thrown. For a non-blocking input a character is returned if one is available, otherwise an exception is thrown.

The base class implementation simply forwards the call to read(void *, IOSize) method.

Returns
The byte cast from a unsigned char to an int (in range 0...255, inclusive) if one could be read, or -1 to indicate end of input data.
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).

Definition at line 52 of file IOInput.cc.

52  {
53  unsigned char byte;
54  IOSize n = read(&byte, 1);
55  return n == 0 ? -1 : byte;
56 }

◆ readv() [1/2]

IOSize IOInput::readv

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.

Definition at line 111 of file IOInput.cc.

111  {
112  assert(!buffers || into);
113 
114  // Keep reading as long as possible; ignore errors if we have read
115  // something, otherwise pass it on.
116  IOSize status;
117  IOSize done = 0;
118  try {
119  for (IOSize i = 0; i < buffers; done += status, ++i)
120  if ((status = read(into[i])) == 0)
121  break;
122  } catch (cms::Exception &) {
123  if (!done)
124  throw;
125  }
126 
127  return done;
128 }

◆ readv() [2/2]

IOSize Storage::readv ( IOPosBuffer into,
IOSize  buffers 
)
virtual

Reimplemented in XrdFile, StorageAccountProxy, LocalCacheFile, DavixFile, and DCacheFile.

Definition at line 24 of file Storage.cc.

24  {
25  IOOffset here = position();
26  IOSize total = 0;
27  for (IOSize i = 0; i < n; ++i) {
28  try {
29  position(into[i].offset());
30  total += read(into[i].data(), into[i].size());
31  } catch (cms::Exception &) {
32  if (!total)
33  throw;
34  break;
35  }
36  }
37  position(here);
38  return total;
39 }

References data, mps_fire::i, dqmiodumpmetadata::n, hltrates_dqm_sourceclient-live_cfg::offset, position(), IOInput::read(), size(), and dqmMemoryStats::total.

◆ resize()

virtual void Storage::resize ( IOOffset  size)
pure virtual

◆ rewind()

void Storage::rewind ( void  )
virtual

Definition at line 87 of file Storage.cc.

87 { position(0); }

References position().

◆ size()

IOOffset Storage::size ( void  ) const
virtual

Reimplemented in File.

Definition at line 77 of file Storage.cc.

77  {
78  // FIXME: use saveposition object in case exceptions are thrown?
79  Storage *self = const_cast<Storage *>(this);
80  IOOffset here = position();
81  self->position(0, END);
83  self->position(here); // FIXME: VERIFY()?
84  return size;
85 }

References END, and position().

Referenced by ntupleDataFormat._Collection::__iter__(), ntupleDataFormat._Collection::__len__(), eof(), StorageAccountProxy::prefetch(), LocalCacheFile::readv(), readv(), XrdFile::readv(), StorageAccountProxy::resize(), and writev().

◆ write() [1/5]

IOSize IOOutput::write

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.

◆ write() [2/5]

IOSize Storage::write ( const void *  from,
IOSize  n,
IOOffset  pos 
)
virtual

Reimplemented in XrdFile, File, StorageAccountProxy, and LocalCacheFile.

Definition at line 44 of file Storage.cc.

44  {
45  // FIXME: this is not thread safe! split into separate interface
46  // that a particular storage can choose to support or not? make
47  // sure that throw semantics are correct here!
48 
49  // FIXME: use saveposition object in case exceptions are thrown?
50  IOOffset here = position();
51  position(pos);
52  n = write(from, n);
53  position(here);
54  return n;
55 }

References dqmiodumpmetadata::n, and position().

Referenced by write(), and writev().

◆ write() [3/5]

IOSize IOOutput::write

Write to the output stream the buffer from. This method is simply redirected to write(const void *, IOSize).

Note that derived classes should not normally call this method, as it simply routes the call back to derived class through the other virtual functions. Use this method only at the "outside edge" when transferring calls from one object to another, not in up/down calls in the inheritance tree.

Returns
The number of bytes actually written. This is less or equal to the size of the buffer. The value can be less than requested if the stream is unable to accept all the output for platform or implementation reasons.
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.

Definition at line 59 of file IOOutput.cc.

59 { return write(from.data(), from.size()); }

◆ write() [4/5]

IOSize Storage::write ( IOBuffer  from,
IOOffset  pos 
)

Definition at line 42 of file Storage.cc.

42 { return write(from.data(), from.size(), pos); }

References IOBuffer::data(), IOBuffer::size(), and write().

◆ write() [5/5]

IOSize IOOutput::write

Write a single byte to the output stream. This method is simply redirected to write(const void *, IOSize).

Note that derived classes should not normally call this method, as it simply routes the call back to derived class through the other virtual functions. Use this method only at the "outside edge" when transferring calls from one object to another, not in up/down calls in the inheritance tree.

Returns
The number of bytes written. Normally this will be one, but can be zero if the stream is in non-blocking mode and cannot accept output 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 – zero will be returned.

Definition at line 39 of file IOOutput.cc.

39 { return write(&byte, 1); }

◆ writev() [1/2]

IOSize IOOutput::writev

Write to the output stream from multiple buffers. There are buffers to fill in an array starting at from. The buffers are filled in the order given, each buffer fully before the subsequent buffers. The method uses write(const void *, IOSize), but may be implemented more efficiently in derived classes.

Note that derived classes should not normally call this method, as it simply routes the call back to derived class through the other virtual functions. Use this method only at the "outside edge" when transferring calls from one object to another, not in up/down calls in the inheritance tree.

Returns
The number of bytes actually written. This is less or equal to the size of the buffers. The value can be less than requested if the stream is unable to accept all the output for platform or implementation reasons. Note that the return value indicates the number of bytes written, not the number of buffers; it is the sum total of bytes written from all the buffers.
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.

Definition at line 84 of file IOOutput.cc.

84  {
85  assert(!buffers || from);
86 
87  // Keep writing as long as possible; ignore errors if we have
88  // written something, otherwise pass it on.
89  IOSize x;
90  IOSize done = 0;
91  try {
92  for (IOSize i = 0; i < buffers; ++i) {
93  done += (x = write(from[i].data(), from[i].size()));
94  if (x < from[i].size())
95  break;
96  }
97  } catch (cms::Exception &) {
98  if (!done)
99  throw;
100  }
101 
102  return done;
103 }

◆ writev() [2/2]

IOSize Storage::writev ( const IOPosBuffer from,
IOSize  buffers 
)
virtual

Reimplemented in StorageAccountProxy, and LocalCacheFile.

Definition at line 57 of file Storage.cc.

57  {
58  IOSize total = 0;
59  for (IOSize i = 0; i < n; ++i) {
60  try {
61  total += write(from[i].data(), from[i].size(), from[i].offset());
62  } catch (cms::Exception &) {
63  if (!total)
64  throw;
65  break;
66  }
67  }
68  return total;
69 }

References data, mps_fire::i, dqmiodumpmetadata::n, hltrates_dqm_sourceclient-live_cfg::offset, size(), dqmMemoryStats::total, and write().

Storage::size
virtual IOOffset size(void) const
Definition: Storage.cc:77
IOBuffer::size
IOSize size(void) const
Definition: IOBuffer.h:34
mps_fire.i
i
Definition: mps_fire.py:428
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
mps_update.status
status
Definition: mps_update.py:69
pos
Definition: PixelAliasList.h:18
Storage::END
Definition: Storage.h:22
Storage::SET
Definition: Storage.h:22
cms::cuda::assert
assert(be >=bs)
DDAxes::x
fileCollector.done
done
Definition: fileCollector.py:123
IOBuffer::data
void * data(void) const
Definition: IOBuffer.h:31
IOOffset
int64_t IOOffset
Definition: IOTypes.h:19
Storage::position
virtual IOOffset position(void) const
Definition: Storage.cc:72
IOInput::read
int read(void)
Definition: IOInput.cc:52
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
Storage::CURRENT
Definition: Storage.h:22
dqmMemoryStats.total
total
Definition: dqmMemoryStats.py:152
cms::Exception
Definition: Exception.h:70
hltrates_dqm_sourceclient-live_cfg.offset
offset
Definition: hltrates_dqm_sourceclient-live_cfg.py:82
IOSize
size_t IOSize
Definition: IOTypes.h:14
Storage
Definition: Storage.h:20
Storage::write
virtual IOSize write(const void *from, IOSize n, IOOffset pos)
Definition: Storage.cc:44