ATLAS Offline Software
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
pool::DbBlob Class Reference

#include <pool/DbBlob.h>

Collaboration diagram for pool::DbBlob:

Public Types

enum  Mode { UNINITIALIZED, READING, WRITING }
 Streamer mode. More...
 
enum  SwapAction { SINGLE_BYTE, SWAP, NOSWAP }
 Data Sawp actions. More...
 
enum  State { INVALID =-1, VALID }
 Link state defintions. More...
 
typedef void(* Analyzer) (const void *data, int siz, const std::type_info &type)
 Definition of the buffer analyzer. More...
 

Public Member Functions

 DbBlob (bool do_swap=true)
 Standard constructor. More...
 
virtual ~DbBlob ()
 Standard destructor. More...
 
 DbBlob (const DbBlob &)=delete
 
DbBloboperator= (const DbBlob &)=delete
 
const char * data () const
 Read access to data buffer. More...
 
char * data ()
 write access to data buffer More...
 
void erase ()
 Reset the buffer. More...
 
int size () const
 Total buffer size. More...
 
bool isReading () const
 Get stream buffer state. More...
 
bool isWriting () const
 Get stream buffer state. More...
 
int buffPointer () const
 Retrieve current buffer pointer. More...
 
void setBuffPointer (int ptr)
 Retrieve current buffer pointer. More...
 
void setAnalyzer (Analyzer fun=0)
 Enable user analysis function. More...
 
void swapToBuffer (const void *source, int siz)
 Swap buffers: int, long, short, float and double. More...
 
void swapFromBuffer (void *target, int siz)
 Swap buffers: int, long, short, float and double. More...
 
void adopt (char *memory, int len)
 Adopt an external memory buffer. More...
 
void reserve (int len)
 Reserve buffer space; Default: 16 k buffer size. More...
 
void extend (int len)
 Extend the buffer. More...
 
void setMode (Mode m)
 Set mode of the stream and allocate buffer. More...
 
DbBlobwriteBytes (const char *str, int len)
 Write string to output stream. More...
 
DbBloboperator<< (long long int data)
 Output Streamer
More...
 
DbBloboperator>> (long long int &data)
 Input Streamer
More...
 
DbBloboperator<< (int data)
 Output Streamer
More...
 
DbBloboperator>> (int &data)
 Input Streamer
More...
 
DbBloboperator<< (unsigned int data)
 Output Streamer
More...
 
DbBloboperator>> (unsigned int &data)
 Input Streamer
More...
 
DbBloboperator<< (long data)
 Output Streamer
More...
 
DbBloboperator>> (long &data)
 Input Streamer
More...
 
DbBloboperator<< (unsigned long data)
 Output Streamer
More...
 
DbBloboperator>> (unsigned long &data)
 Input Streamer
More...
 
DbBloboperator<< (short data)
 Output Streamer
More...
 
DbBloboperator>> (short &data)
 Input Streamer
More...
 
DbBloboperator<< (unsigned short data)
 Output Streamer
More...
 
DbBloboperator>> (unsigned short &data)
 Input Streamer
More...
 
DbBloboperator<< (char data)
 Output Streamer
More...
 
DbBloboperator>> (char &data)
 Input Streamer
More...
 
DbBloboperator<< (unsigned char data)
 Output Streamer
More...
 
DbBloboperator>> (unsigned char &data)
 Input Streamer
More...
 
DbBloboperator<< (float data)
 Output Streamer
More...
 
DbBloboperator>> (float &data)
 Input Streamer
More...
 
DbBloboperator<< (double data)
 Output Streamer
More...
 
DbBloboperator>> (double &data)
 Input Streamer
More...
 
DbBloboperator>> (char *data)
 Streamer to read strings in (char*) format. More...
 
DbBloboperator<< (const char *data)
 Streamer to write strings in (char*) format. More...
 
DbBloboperator>> (std::string &data)
 Streamer to read strings in (std::string) format. More...
 
DbBloboperator<< (const std::string &data)
 Streamer to write strings in (std::string) format. More...
 

Protected Member Functions

SwapAction swapBuffer (int siz) const
 Check for byte swapping. More...
 

Protected Attributes

Mode m_mode
 Boolean indicating wether the stream is in read or write mode. More...
 
int m_pointer
 Current buffer pointer. More...
 
int m_length
 Total buffer length. More...
 
char * m_buffer
 Pointer to heap buffer. More...
 
bool m_swapEnabled
 Flag indicating swapping. More...
 
Analyzer m_analyzer
 Hook function for analysis of data to the stream. More...
 

Detailed Description

Description:

The stream buffer is a small object collecting object data. The basic idea behind the DbBlob is generic object conversion. The DbBlob acts as a byte stream (hence inheriting from a std::string) and stores any information streamed to the buffer. Since the information must be represented in a generic way on the fly byte swapping is performed. However, not only primitive data can be stored in the buffer, but also pointers to DataObjects (symbolic links) and pointers to contained objects. Automatically during serialization the persistent references to the corresponding objects and containers must be stored. These objects are accessible from the DbBlob object.

Author
M.Frank
Version
1.0

Definition at line 47 of file DbBlob.h.

Member Typedef Documentation

◆ Analyzer

typedef void(* pool::DbBlob::Analyzer) (const void *data, int siz, const std::type_info &type)

Definition of the buffer analyzer.

Definition at line 56 of file DbBlob.h.

Member Enumeration Documentation

◆ Mode

Streamer mode.

Enumerator
UNINITIALIZED 
READING 
WRITING 

Definition at line 50 of file DbBlob.h.

◆ State

Link state defintions.

Enumerator
INVALID 
VALID 

Definition at line 54 of file DbBlob.h.

54 {INVALID=-1, VALID };

◆ SwapAction

Data Sawp actions.

Enumerator
SINGLE_BYTE 
SWAP 
NOSWAP 

Definition at line 52 of file DbBlob.h.

Constructor & Destructor Documentation

◆ DbBlob() [1/2]

pool::DbBlob::DbBlob ( bool  do_swap = true)
inline

Standard constructor.

Definition at line 77 of file DbBlob.h.

77  :
79  m_pointer(0),
80  m_length(0),
81  m_buffer(0),
82  m_swapEnabled(do_swap) { m_analyzer = 0; }

◆ ~DbBlob()

virtual pool::DbBlob::~DbBlob ( )
virtual

Standard destructor.

◆ DbBlob() [2/2]

pool::DbBlob::DbBlob ( const DbBlob )
delete

Member Function Documentation

◆ adopt()

void pool::DbBlob::adopt ( char *  memory,
int  len 
)

Adopt an external memory buffer.

◆ buffPointer()

int pool::DbBlob::buffPointer ( ) const
inline

Retrieve current buffer pointer.

Definition at line 103 of file DbBlob.h.

103 { return m_pointer; }

◆ data() [1/2]

char* pool::DbBlob::data ( )
inline

write access to data buffer

Definition at line 92 of file DbBlob.h.

92 { return m_buffer; }

◆ data() [2/2]

const char* pool::DbBlob::data ( ) const
inline

Read access to data buffer.

Definition at line 90 of file DbBlob.h.

90 { return m_buffer; }

◆ erase()

void pool::DbBlob::erase ( )
inline

Reset the buffer.

Definition at line 94 of file DbBlob.h.

94 { m_pointer = 0; }

◆ extend()

void pool::DbBlob::extend ( int  len)
inline

Extend the buffer.

Definition at line 117 of file DbBlob.h.

117  {
118  if ( len + m_pointer > m_length ) {
119  // We have to be a bit generous here in order not to run too often
120  // into ::realloc().
121  int new_len = (m_length < 16384) ? 16384 : 2*m_length;
122  if ( m_length < len ) new_len += len;
123  reserve(new_len);
124  }
125  }

◆ isReading()

bool pool::DbBlob::isReading ( ) const
inline

Get stream buffer state.

Definition at line 98 of file DbBlob.h.

98 { return m_mode == READING;}

◆ isWriting()

bool pool::DbBlob::isWriting ( ) const
inline

Get stream buffer state.

Definition at line 101 of file DbBlob.h.

101 { return m_mode == WRITING;}

◆ operator<<() [1/13]

DbBlob& pool::DbBlob::operator<< ( char  data)
inline

Output Streamer

Definition at line 218 of file DbBlob.h.

218  {
219  swapToBuffer(&data, sizeof(data));
220  STREAM_ANALYSE(data, sizeof(data));
221  return *this;
222  }

◆ operator<<() [2/13]

DbBlob& pool::DbBlob::operator<< ( const char *  data)

Streamer to write strings in (char*) format.

◆ operator<<() [3/13]

DbBlob& pool::DbBlob::operator<< ( const std::string &  data)

Streamer to write strings in (std::string) format.

◆ operator<<() [4/13]

DbBlob& pool::DbBlob::operator<< ( double  data)
inline

Output Streamer

Definition at line 251 of file DbBlob.h.

251  {
252  swapToBuffer(&data, sizeof(data));
253  STREAM_ANALYSE(data, sizeof(data));
254  return *this;
255  }

◆ operator<<() [5/13]

DbBlob& pool::DbBlob::operator<< ( float  data)
inline

Output Streamer

Definition at line 240 of file DbBlob.h.

240  {
241  swapToBuffer(&data, sizeof(data));
242  STREAM_ANALYSE(data, sizeof(data));
243  return *this;
244  }

◆ operator<<() [6/13]

DbBlob& pool::DbBlob::operator<< ( int  data)
inline

Output Streamer

Definition at line 152 of file DbBlob.h.

152  {
153  swapToBuffer(&data, sizeof(data));
154  STREAM_ANALYSE(data, sizeof(data));
155  return *this;
156  }

◆ operator<<() [7/13]

DbBlob& pool::DbBlob::operator<< ( long  data)
inline

Output Streamer

Definition at line 174 of file DbBlob.h.

174  {
175  swapToBuffer(&data, sizeof(data));
176  STREAM_ANALYSE(data, sizeof(data));
177  return *this;
178  }

◆ operator<<() [8/13]

DbBlob& pool::DbBlob::operator<< ( long long int  data)
inline

Output Streamer

Definition at line 141 of file DbBlob.h.

141  {
142  swapToBuffer(&data, sizeof(data));
143  STREAM_ANALYSE(data, sizeof(data));
144  return *this;
145  }

◆ operator<<() [9/13]

DbBlob& pool::DbBlob::operator<< ( short  data)
inline

Output Streamer

Definition at line 196 of file DbBlob.h.

196  {
197  swapToBuffer(&data, sizeof(data));
198  STREAM_ANALYSE(data, sizeof(data));
199  return *this;
200  }

◆ operator<<() [10/13]

DbBlob& pool::DbBlob::operator<< ( unsigned char  data)
inline

Output Streamer

Definition at line 229 of file DbBlob.h.

229  {
230  swapToBuffer(&data, sizeof(data));
231  STREAM_ANALYSE(data, sizeof(data));
232  return *this;
233  }

◆ operator<<() [11/13]

DbBlob& pool::DbBlob::operator<< ( unsigned int  data)
inline

Output Streamer

Definition at line 163 of file DbBlob.h.

163  {
164  swapToBuffer(&data, sizeof(data));
165  STREAM_ANALYSE(data, sizeof(data));
166  return *this;
167  }

◆ operator<<() [12/13]

DbBlob& pool::DbBlob::operator<< ( unsigned long  data)
inline

Output Streamer

Definition at line 185 of file DbBlob.h.

185  {
186  swapToBuffer(&data, sizeof(data));
187  STREAM_ANALYSE(data, sizeof(data));
188  return *this;
189  }

◆ operator<<() [13/13]

DbBlob& pool::DbBlob::operator<< ( unsigned short  data)
inline

Output Streamer

Definition at line 207 of file DbBlob.h.

207  {
208  swapToBuffer(&data, sizeof(data));
209  STREAM_ANALYSE(data, sizeof(data));
210  return *this;
211  }

◆ operator=()

DbBlob& pool::DbBlob::operator= ( const DbBlob )
delete

◆ operator>>() [1/13]

DbBlob& pool::DbBlob::operator>> ( char &  data)
inline

Input Streamer

Definition at line 224 of file DbBlob.h.

224  {
225  swapFromBuffer(&data, sizeof(data));
226  return *this;
227  }

◆ operator>>() [2/13]

DbBlob& pool::DbBlob::operator>> ( char *  data)

Streamer to read strings in (char*) format.

◆ operator>>() [3/13]

DbBlob& pool::DbBlob::operator>> ( double &  data)
inline

Input Streamer

Definition at line 257 of file DbBlob.h.

257  {
258  swapFromBuffer(&data, sizeof(data));
259  return *this;
260  }

◆ operator>>() [4/13]

DbBlob& pool::DbBlob::operator>> ( float &  data)
inline

Input Streamer

Definition at line 246 of file DbBlob.h.

246  {
247  swapFromBuffer(&data, sizeof(data));
248  return *this;
249  }

◆ operator>>() [5/13]

DbBlob& pool::DbBlob::operator>> ( int &  data)
inline

Input Streamer

Definition at line 158 of file DbBlob.h.

158  {
159  swapFromBuffer(&data, sizeof(data));
160  return *this;
161  }

◆ operator>>() [6/13]

DbBlob& pool::DbBlob::operator>> ( long &  data)
inline

Input Streamer

Definition at line 180 of file DbBlob.h.

180  {
181  swapFromBuffer(&data, sizeof(data));
182  return *this;
183  }

◆ operator>>() [7/13]

DbBlob& pool::DbBlob::operator>> ( long long int &  data)
inline

Input Streamer

Definition at line 147 of file DbBlob.h.

147  {
148  swapFromBuffer(&data, sizeof(data));
149  return *this;
150  }

◆ operator>>() [8/13]

DbBlob& pool::DbBlob::operator>> ( short &  data)
inline

Input Streamer

Definition at line 202 of file DbBlob.h.

202  {
203  swapFromBuffer(&data, sizeof(data));
204  return *this;
205  }

◆ operator>>() [9/13]

DbBlob& pool::DbBlob::operator>> ( std::string &  data)

Streamer to read strings in (std::string) format.

◆ operator>>() [10/13]

DbBlob& pool::DbBlob::operator>> ( unsigned char &  data)
inline

Input Streamer

Definition at line 235 of file DbBlob.h.

235  {
236  swapFromBuffer(&data, sizeof(data));
237  return *this;
238  }

◆ operator>>() [11/13]

DbBlob& pool::DbBlob::operator>> ( unsigned int &  data)
inline

Input Streamer

Definition at line 169 of file DbBlob.h.

169  {
170  swapFromBuffer(&data, sizeof(data));
171  return *this;
172  }

◆ operator>>() [12/13]

DbBlob& pool::DbBlob::operator>> ( unsigned long &  data)
inline

Input Streamer

Definition at line 191 of file DbBlob.h.

191  {
192  swapFromBuffer(&data, sizeof(data));
193  return *this;
194  }

◆ operator>>() [13/13]

DbBlob& pool::DbBlob::operator>> ( unsigned short &  data)
inline

Input Streamer

Definition at line 213 of file DbBlob.h.

213  {
214  swapFromBuffer(&data, sizeof(data));
215  return *this;
216  }

◆ reserve()

void pool::DbBlob::reserve ( int  len)

Reserve buffer space; Default: 16 k buffer size.

◆ setAnalyzer()

void pool::DbBlob::setAnalyzer ( Analyzer  fun = 0)
inline

Enable user analysis function.

Definition at line 107 of file DbBlob.h.

107 { m_analyzer = fun; }

◆ setBuffPointer()

void pool::DbBlob::setBuffPointer ( int  ptr)
inline

Retrieve current buffer pointer.

Definition at line 105 of file DbBlob.h.

105 { m_pointer = ptr; }

◆ setMode()

void pool::DbBlob::setMode ( Mode  m)
inline

Set mode of the stream and allocate buffer.

Definition at line 127 of file DbBlob.h.

127  {
128  m_mode = m;
129  m_pointer = 0;
130  }

◆ size()

int pool::DbBlob::size ( ) const
inline

Total buffer size.

Definition at line 96 of file DbBlob.h.

96 { return m_length; }

◆ swapBuffer()

DbBlob::SwapAction pool::DbBlob::swapBuffer ( int  siz) const
inlineprotected

Check for byte swapping.

Definition at line 273 of file DbBlob.h.

273  {
274  switch(siz) {
275  case 1:
276  return SINGLE_BYTE;
277  default:
278  #if defined(__alpha) && !defined(__VMS)
279  return NOSWAP;
280  #elif defined(__sun) && defined(__SVR4) && defined(__i386)
281  return NOSWAP;
282  #elif defined(__linux) && !defined(__powerpc)
283  return NOSWAP;
284  #elif defined(BORLAND) || defined(_WIN32) || defined(WIN32)
285  return NOSWAP;
286  #elif defined(__APPLE__) && defined(__i386__)
287  return NOSWAP;
288  #elif defined(__APPLE__)
289  return SWAP;
290  #else
291  return m_swapEnabled ? SWAP : NOSWAP;
292  #endif
293  }
294  }

◆ swapFromBuffer()

void pool::DbBlob::swapFromBuffer ( void *  target,
int  siz 
)
inline

Swap buffers: int, long, short, float and double.

Swap bytes from the stream buffer to target buffer with arbitray size.

Definition at line 322 of file DbBlob.h.

322  {
323  char* tar = (char*)target;
324  char* src = (char*)m_buffer+m_pointer;
325  switch ( swapBuffer(siz) ) {
326  case SINGLE_BYTE:
327  *tar = *src;
328  break;
329  case SWAP:
330 #ifdef __APPLE__
331  for(int i = 0,j = siz-1;i<siz;i++,j--) tar[j] = src[i];
332 #else
333  ::_swab (src, tar, siz);
334 #endif
335  break;
336  case NOSWAP:
337  ::memcpy(tar, src, siz);
338  break;
339  }
340  m_pointer += siz;
341  }

◆ swapToBuffer()

void pool::DbBlob::swapToBuffer ( const void *  source,
int  siz 
)
inline

Swap buffers: int, long, short, float and double.

Swap bytes from a source buffer to the stream buffer with arbitray size.

Definition at line 297 of file DbBlob.h.

297  {
298  char buff[8], *tar;
299  const char* src = reinterpret_cast<const char*> (source);
300  extend (m_pointer+siz);
301  tar = (char*)m_buffer+m_pointer;
302  switch ( swapBuffer(siz) ) {
303  case SINGLE_BYTE:
304  *tar = *src;
305  break;
306  case SWAP:
307 #ifdef __APPLE__
308  for(int i = 0,j = siz-1;i<siz;i++,j--) tar[j] = src[i];
309 #else
310  ::_swab (src, buff, siz);
311 #endif
312  src = buff;
313  // Fall through.
314  case NOSWAP:
315  memcpy(tar, src, siz);
316  break;
317  }
318  m_pointer += siz;
319  }

◆ writeBytes()

DbBlob& pool::DbBlob::writeBytes ( const char *  str,
int  len 
)

Write string to output stream.

Member Data Documentation

◆ m_analyzer

Analyzer pool::DbBlob::m_analyzer
protected

Hook function for analysis of data to the stream.

Definition at line 70 of file DbBlob.h.

◆ m_buffer

char* pool::DbBlob::m_buffer
protected

Pointer to heap buffer.

Definition at line 66 of file DbBlob.h.

◆ m_length

int pool::DbBlob::m_length
protected

Total buffer length.

Definition at line 64 of file DbBlob.h.

◆ m_mode

Mode pool::DbBlob::m_mode
protected

Boolean indicating wether the stream is in read or write mode.

Definition at line 60 of file DbBlob.h.

◆ m_pointer

int pool::DbBlob::m_pointer
protected

Current buffer pointer.

Definition at line 62 of file DbBlob.h.

◆ m_swapEnabled

bool pool::DbBlob::m_swapEnabled
protected

Flag indicating swapping.

Definition at line 68 of file DbBlob.h.


The documentation for this class was generated from the following file:
get_hdefs.buff
buff
Definition: get_hdefs.py:61
generateReferenceFile.fun
fun
Definition: generateReferenceFile.py:18
pool::DbBlob::m_analyzer
Analyzer m_analyzer
Hook function for analysis of data to the stream.
Definition: DbBlob.h:70
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
WriteCellNoiseToCool.src
src
Definition: WriteCellNoiseToCool.py:513
pool::DbBlob::m_buffer
char * m_buffer
Pointer to heap buffer.
Definition: DbBlob.h:66
pool::DbBlob::swapFromBuffer
void swapFromBuffer(void *target, int siz)
Swap buffers: int, long, short, float and double.
Definition: DbBlob.h:322
pool::DbBlob::SINGLE_BYTE
@ SINGLE_BYTE
Definition: DbBlob.h:52
dbg::ptr
void * ptr(T *p)
Definition: SGImplSvc.cxx:74
pool::DbBlob::m_swapEnabled
bool m_swapEnabled
Flag indicating swapping.
Definition: DbBlob.h:68
pool::DbBlob::INVALID
@ INVALID
Definition: DbBlob.h:54
STREAM_ANALYSE
#define STREAM_ANALYSE(data, len)
Definition: DbBlob.h:137
pool::DbBlob::extend
void extend(int len)
Extend the buffer.
Definition: DbBlob.h:117
pool::DbBlob::reserve
void reserve(int len)
Reserve buffer space; Default: 16 k buffer size.
pool::DbBlob::READING
@ READING
Definition: DbBlob.h:50
lumiFormat.i
int i
Definition: lumiFormat.py:85
pool::DbBlob::VALID
@ VALID
Definition: DbBlob.h:54
pool::DbBlob::m_mode
Mode m_mode
Boolean indicating wether the stream is in read or write mode.
Definition: DbBlob.h:60
pool::DbBlob::swapBuffer
SwapAction swapBuffer(int siz) const
Check for byte swapping.
Definition: DbBlob.h:273
perfmonmt-printer.tar
tar
Definition: perfmonmt-printer.py:203
pool::DbBlob::data
const char * data() const
Read access to data buffer.
Definition: DbBlob.h:90
pool::DbBlob::WRITING
@ WRITING
Definition: DbBlob.h:50
copySelective.target
string target
Definition: copySelective.py:37
copySelective.source
string source
Definition: copySelective.py:32
pool::DbBlob::NOSWAP
@ NOSWAP
Definition: DbBlob.h:52
pool::DbBlob::m_length
int m_length
Total buffer length.
Definition: DbBlob.h:64
pool::DbBlob::SWAP
@ SWAP
Definition: DbBlob.h:52
_swab
#define _swab(source, target, radix)
Definition: DbBlob.h:19
pool::DbBlob::swapToBuffer
void swapToBuffer(const void *source, int siz)
Swap buffers: int, long, short, float and double.
Definition: DbBlob.h:297
pool::DbBlob::m_pointer
int m_pointer
Current buffer pointer.
Definition: DbBlob.h:62
pool::DbBlob::UNINITIALIZED
@ UNINITIALIZED
Definition: DbBlob.h:50