CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Protected Attributes
StorageAccountProxy Class Reference

#include <StorageAccountProxy.h>

Inheritance diagram for StorageAccountProxy:
Storage IOInput IOOutput

Public Member Functions

virtual void close (void)
 
virtual void flush (void)
 
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)
 
 StorageAccountProxy (const std::string &storageClass, std::unique_ptr< Storage > baseStorage)
 
virtual IOSize write (const void *from, IOSize n)
 
virtual IOSize write (const void *from, IOSize n, IOOffset pos)
 
virtual IOSize writev (const IOBuffer *from, IOSize n)
 
virtual IOSize writev (const IOPosBuffer *from, IOSize n)
 
 ~StorageAccountProxy (void)
 
- Public Member Functions inherited from Storage
virtual bool eof (void) const
 
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 ~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)
 
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...
 

Protected Attributes

std::unique_ptr< Storagem_baseStorage
 
StorageAccount::Counterm_statsPosition
 
StorageAccount::Counterm_statsPrefetch
 
StorageAccount::Counterm_statsRead
 
StorageAccount::Counterm_statsReadV
 
StorageAccount::Counterm_statsWrite
 
StorageAccount::Counterm_statsWriteV
 
StorageAccount::StorageClassToken m_token
 

Additional Inherited Members

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

Detailed Description

Proxy class that wraps SEAL's Storage class with one that ticks StorageAccount counters for significant operations. The returned Storage objects from StorageMaker are automatically wrapped with this class.

Future improvement would be to implement more methods so that the wrapper itself doesn't cause peroformance degradation if the base storage does actually implement "sophisticated" features.

Definition at line 17 of file StorageAccountProxy.h.

Constructor & Destructor Documentation

StorageAccountProxy::StorageAccountProxy ( const std::string &  storageClass,
std::unique_ptr< Storage baseStorage 
)

Definition at line 3 of file StorageAccountProxy.cc.

References StorageAccount::construct, StorageAccount::counter(), m_token, and StorageAccount::Stamp::tick().

5  : m_baseStorage (std::move(baseStorage)),
13 {
15  stats.tick ();
16 }
StorageAccount::Counter & m_statsWrite
StorageAccount::Counter & m_statsPosition
std::unique_ptr< Storage > m_baseStorage
StorageAccount::Counter & m_statsRead
StorageAccount::StorageClassToken m_token
static StorageClassToken tokenForStorageClassName(std::string const &iName)
StorageAccount::Counter & m_statsWriteV
StorageAccount::Counter & m_statsPrefetch
static Counter & counter(StorageClassToken token, Operation operation)
StorageAccount::Counter & m_statsReadV
StorageAccountProxy::~StorageAccountProxy ( void  )

Definition at line 18 of file StorageAccountProxy.cc.

References StorageAccount::counter(), StorageAccount::destruct, m_baseStorage, m_token, and StorageAccount::Stamp::tick().

19 {
21  m_baseStorage.release();
22  stats.tick ();
23 }
std::unique_ptr< Storage > m_baseStorage
StorageAccount::StorageClassToken m_token
static Counter & counter(StorageClassToken token, Operation operation)

Member Function Documentation

void StorageAccountProxy::close ( void  )
virtual
void StorageAccountProxy::flush ( void  )
virtual

Reimplemented from Storage.

Definition at line 115 of file StorageAccountProxy.cc.

References StorageAccount::counter(), StorageAccount::flush, m_baseStorage, m_token, and StorageAccount::Stamp::tick().

116 {
118  m_baseStorage->flush ();
119  stats.tick ();
120 }
std::unique_ptr< Storage > m_baseStorage
StorageAccount::StorageClassToken m_token
static Counter & counter(StorageClassToken token, Operation operation)
IOOffset StorageAccountProxy::position ( IOOffset  offset,
Relative  whence = SET 
)
virtual

Implements Storage.

Definition at line 98 of file StorageAccountProxy.cc.

References m_baseStorage, m_statsPosition, query::result, and StorageAccount::Stamp::tick().

99 {
101  IOOffset result = m_baseStorage->position (offset, whence);
102  stats.tick ();
103  return result;
104 }
StorageAccount::Counter & m_statsPosition
std::unique_ptr< Storage > m_baseStorage
tuple result
Definition: query.py:137
int64_t IOOffset
Definition: IOTypes.h:19
bool StorageAccountProxy::prefetch ( const IOPosBuffer what,
IOSize  n 
)
virtual

Reimplemented from Storage.

Definition at line 131 of file StorageAccountProxy.cc.

References i, m_baseStorage, m_statsPrefetch, gen::n, Storage::size(), StorageAccount::Stamp::tick(), pileupDistInMC::total, and relativeConstraints::value.

132 {
134  bool value = m_baseStorage->prefetch(what, n);
135  if (value)
136  {
137  IOSize total = 0;
138  for (IOSize i = 0; i < n; ++i)
139  total += what[i].size();
140  stats.tick (total);
141  }
142  return value;
143 }
int i
Definition: DBlmapReader.cc:9
std::unique_ptr< Storage > m_baseStorage
StorageAccount::Counter & m_statsPrefetch
virtual IOOffset size(void) const
Definition: Storage.cc:102
size_t IOSize
Definition: IOTypes.h:14
IOSize StorageAccountProxy::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 26 of file StorageAccountProxy.cc.

References m_baseStorage, m_statsRead, query::result, and StorageAccount::Stamp::tick().

27 {
29  IOSize result = m_baseStorage->read (into, n);
30  stats.tick (result);
31  return result;
32 }
std::unique_ptr< Storage > m_baseStorage
StorageAccount::Counter & m_statsRead
tuple result
Definition: query.py:137
size_t IOSize
Definition: IOTypes.h:14
IOSize StorageAccountProxy::read ( void *  into,
IOSize  n,
IOOffset  pos 
)
virtual

Reimplemented from Storage.

Definition at line 35 of file StorageAccountProxy.cc.

References m_baseStorage, m_statsRead, query::result, and StorageAccount::Stamp::tick().

36 {
38  IOSize result = m_baseStorage->read (into, n, pos);
39  stats.tick (result);
40  return result;
41 }
std::unique_ptr< Storage > m_baseStorage
StorageAccount::Counter & m_statsRead
tuple result
Definition: query.py:137
size_t IOSize
Definition: IOTypes.h:14
IOSize StorageAccountProxy::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 44 of file StorageAccountProxy.cc.

References m_baseStorage, m_statsReadV, query::result, and StorageAccount::Stamp::tick().

45 {
47  IOSize result = m_baseStorage->readv (into, n);
48  stats.tick (result, n);
49  return result;
50 }
std::unique_ptr< Storage > m_baseStorage
tuple result
Definition: query.py:137
size_t IOSize
Definition: IOTypes.h:14
StorageAccount::Counter & m_statsReadV
IOSize StorageAccountProxy::readv ( IOPosBuffer into,
IOSize  n 
)
virtual

Reimplemented from Storage.

Definition at line 53 of file StorageAccountProxy.cc.

References m_baseStorage, m_statsReadV, query::result, and StorageAccount::Stamp::tick().

54 {
56  IOSize result = m_baseStorage->readv (into, n);
57  stats.tick (result, n);
58  return result;
59 }
std::unique_ptr< Storage > m_baseStorage
tuple result
Definition: query.py:137
size_t IOSize
Definition: IOTypes.h:14
StorageAccount::Counter & m_statsReadV
void StorageAccountProxy::resize ( IOOffset  size)
virtual
IOSize StorageAccountProxy::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 62 of file StorageAccountProxy.cc.

References m_baseStorage, m_statsWrite, query::result, and StorageAccount::Stamp::tick().

63 {
65  IOSize result = m_baseStorage->write (from, n);
66  stats.tick (result);
67  return result;
68 }
StorageAccount::Counter & m_statsWrite
std::unique_ptr< Storage > m_baseStorage
tuple result
Definition: query.py:137
size_t IOSize
Definition: IOTypes.h:14
IOSize StorageAccountProxy::write ( const void *  from,
IOSize  n,
IOOffset  pos 
)
virtual

Reimplemented from Storage.

Definition at line 71 of file StorageAccountProxy.cc.

References m_baseStorage, m_statsWrite, query::result, and StorageAccount::Stamp::tick().

72 {
74  IOSize result = m_baseStorage->write (from, n, pos);
75  stats.tick (result);
76  return result;
77 }
StorageAccount::Counter & m_statsWrite
std::unique_ptr< Storage > m_baseStorage
tuple result
Definition: query.py:137
size_t IOSize
Definition: IOTypes.h:14
IOSize StorageAccountProxy::writev ( const IOBuffer from,
IOSize  buffers 
)
virtual

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.

Reimplemented from IOOutput.

Definition at line 80 of file StorageAccountProxy.cc.

References m_baseStorage, m_statsWriteV, query::result, and StorageAccount::Stamp::tick().

81 {
83  IOSize result = m_baseStorage->writev (from, n);
84  stats.tick (result, n);
85  return result;
86 }
std::unique_ptr< Storage > m_baseStorage
StorageAccount::Counter & m_statsWriteV
tuple result
Definition: query.py:137
size_t IOSize
Definition: IOTypes.h:14
IOSize StorageAccountProxy::writev ( const IOPosBuffer from,
IOSize  n 
)
virtual

Reimplemented from Storage.

Definition at line 89 of file StorageAccountProxy.cc.

References m_baseStorage, m_statsWriteV, query::result, and StorageAccount::Stamp::tick().

90 {
92  IOSize result = m_baseStorage->writev (from, n);
93  stats.tick (result, n);
94  return result;
95 }
std::unique_ptr< Storage > m_baseStorage
StorageAccount::Counter & m_statsWriteV
tuple result
Definition: query.py:137
size_t IOSize
Definition: IOTypes.h:14

Member Data Documentation

std::unique_ptr<Storage> StorageAccountProxy::m_baseStorage
protected
StorageAccount::Counter& StorageAccountProxy::m_statsPosition
protected

Definition at line 49 of file StorageAccountProxy.h.

Referenced by position().

StorageAccount::Counter& StorageAccountProxy::m_statsPrefetch
protected

Definition at line 50 of file StorageAccountProxy.h.

Referenced by prefetch().

StorageAccount::Counter& StorageAccountProxy::m_statsRead
protected

Definition at line 45 of file StorageAccountProxy.h.

Referenced by read().

StorageAccount::Counter& StorageAccountProxy::m_statsReadV
protected

Definition at line 46 of file StorageAccountProxy.h.

Referenced by readv().

StorageAccount::Counter& StorageAccountProxy::m_statsWrite
protected

Definition at line 47 of file StorageAccountProxy.h.

Referenced by write().

StorageAccount::Counter& StorageAccountProxy::m_statsWriteV
protected

Definition at line 48 of file StorageAccountProxy.h.

Referenced by writev().

StorageAccount::StorageClassToken StorageAccountProxy::m_token
protected

Definition at line 44 of file StorageAccountProxy.h.

Referenced by close(), flush(), resize(), StorageAccountProxy(), and ~StorageAccountProxy().