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 Types | Static Private Member Functions | Private Attributes | Static Private Attributes
cond::BlobStreamingService Class Reference
Inheritance diagram for cond::BlobStreamingService:
ora::IBlobStreamingService

Public Member Functions

 BlobStreamingService ()
 
void read (const coral::Blob &blobData, void *addressOfContainer, edm::TypeWithDict const &classDictionary) override
 Reads an object from a Blob and fills-in the container. More...
 
boost::shared_ptr< coral::Blob > write (const void *addressOfInputData, edm::TypeWithDict const &classDictionary, bool useCompression=true) override
 
virtual ~BlobStreamingService ()
 
- Public Member Functions inherited from ora::IBlobStreamingService
virtual ~IBlobStreamingService ()
 Empty destructor. More...
 

Private Types

typedef std::pair< unsigned
long long, unsigned long long > 
uuid
 
enum  Variant { OLD, COMPRESSED_TBUFFER, COMPRESSED_CHARS }
 

Static Private Member Functions

static boost::shared_ptr
< coral::Blob > 
compress (const void *addr, size_t isize)
 
static boost::shared_ptr
< coral::Blob > 
expand (const coral::Blob &blobIn)
 
static Variant findVariant (const void *address)
 
static int isVectorChar (edm::TypeWithDict const &classDictionary)
 

Private Attributes

boost::shared_ptr
< ora::IBlobStreamingService
rootService
 

Static Private Attributes

static const size_t m_idsize =sizeof(uuid)
 
static const size_t m_offset = m_idsize + sizeof(unsigned long long)
 
static const size_t nVariants =3
 
static uuid const variantIds [nVariants]
 

Detailed Description

Definition at line 23 of file BlobStreamingService.cc.

Member Typedef Documentation

typedef std::pair<unsigned long long, unsigned long long> cond::BlobStreamingService::uuid
private

Definition at line 38 of file BlobStreamingService.cc.

Member Enumeration Documentation

Constructor & Destructor Documentation

cond::BlobStreamingService::BlobStreamingService ( )

Definition at line 61 of file BlobStreamingService.cc.

cond::BlobStreamingService::~BlobStreamingService ( )
virtual

Definition at line 63 of file BlobStreamingService.cc.

63 {}

Member Function Documentation

boost::shared_ptr< coral::Blob > cond::BlobStreamingService::compress ( const void *  addr,
size_t  isize 
)
staticprivate

Definition at line 182 of file BlobStreamingService.cc.

References m_idsize, m_offset, and spu::zerr().

Referenced by write().

182  {
183  uLongf destLen = compressBound(isize);
184  size_t usize = destLen + m_offset;
185  boost::shared_ptr<coral::Blob> theBlob( new coral::Blob(usize));
186  void * startingAddress = (unsigned char*)(theBlob->startingAddress())+ m_offset;
187  int zerr = compress2( (unsigned char*)(startingAddress), &destLen,
188  (unsigned char*)(addr), isize,
189  9);
190  if (zerr!=0) edm::LogError("BlobStreamingService")<< "Compression error " << zerr;
191  destLen+= m_idsize + sizeof(unsigned long long);
192  theBlob->resize(destLen);
193 
194  startingAddress = (unsigned char*)(theBlob->startingAddress())+ m_idsize;
195  // write expanded size;
196  *reinterpret_cast<unsigned long long*>(startingAddress)=isize;
197  return theBlob;
198  }
void zerr(int)
boost::shared_ptr< coral::Blob > cond::BlobStreamingService::expand ( const coral::Blob &  blobIn)
staticprivate

Definition at line 200 of file BlobStreamingService.cc.

References compareJSON::const, m_idsize, m_offset, and spu::zerr().

Referenced by read().

200  {
201  if (size_t(blobIn.size()) < m_offset) return boost::shared_ptr<coral::Blob>(new coral::Blob());
202  long long csize = blobIn.size() - m_offset;
203  unsigned char const * startingAddress = (unsigned char const*)(blobIn.startingAddress())+ m_idsize;
204  unsigned long long usize = *reinterpret_cast<unsigned long long const*>(startingAddress);
205  startingAddress += sizeof(unsigned long long);
206  boost::shared_ptr<coral::Blob> theBlob( new coral::Blob(usize));
207  uLongf destLen = usize;
208  int zerr = uncompress((unsigned char *)(theBlob->startingAddress()), &destLen,
209  startingAddress, csize);
210  if (zerr!=0 || usize!=destLen)
211  edm::LogError("BlobStreamingService")<< "uncompressing error " << zerr
212  << " original size was " << usize
213  << " new size is " << destLen;
214 
215  return theBlob;
216  }
void zerr(int)
string const
Definition: compareJSON.py:14
BlobStreamingService::Variant cond::BlobStreamingService::findVariant ( const void *  address)
staticprivate

Definition at line 175 of file BlobStreamingService.cc.

References compareJSON::const, spr::find(), nVariants, OLD, findQualityFiles::v, and variantIds.

Referenced by read().

175  {
176  uuid const & id = *reinterpret_cast<uuid const*>(address);
178  return (v==variantIds+nVariants) ? OLD : (Variant)(v-variantIds);
179  }
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
std::pair< unsigned long long, unsigned long long > uuid
static uuid const variantIds[nVariants]
string const
Definition: compareJSON.py:14
int cond::BlobStreamingService::isVectorChar ( edm::TypeWithDict const &  classDictionary)
staticprivate

Definition at line 167 of file BlobStreamingService.cc.

Referenced by read(), and write().

167  {
168  if (classDictionary == typeid(std::vector<unsigned char>)) return 1;
169  if (classDictionary == typeid(std::vector<char>)) return 2;
170  return 0;
171  }
void cond::BlobStreamingService::read ( const coral::Blob &  blobData,
void *  addressOfContainer,
edm::TypeWithDict const &  classDictionary 
)
overridevirtual

Reads an object from a Blob and fills-in the container.

Implements ora::IBlobStreamingService.

Definition at line 111 of file BlobStreamingService.cc.

References COMPRESSED_CHARS, COMPRESSED_TBUFFER, expand(), findVariant(), isVectorChar(), relval_steps::k, m_offset, OLD, rootService, and findQualityFiles::v.

Referenced by Vispa.Plugins.EdmBrowser.EdmDataAccessor.EdmDataAccessor::goto(), and Vispa.Plugins.EdmBrowser.EdmDataAccessor.EdmDataAccessor::setFilterBranches().

111  {
112  // protect against small blobs...
113  Variant v = (size_t(blobData.size()) < m_offset) ? OLD : findVariant(blobData.startingAddress());
114  switch (v) {
115  case OLD :
116  {
117  rootService->read( blobData, addressOfContainer, classDictionary);
118  }
119  break;
120  case COMPRESSED_TBUFFER :
121  {
122  boost::shared_ptr<coral::Blob> blobIn = expand(blobData);
123  rootService->read( *blobIn, addressOfContainer, classDictionary);
124  }
125  break;
126  case COMPRESSED_CHARS :
127  {
128  boost::shared_ptr<coral::Blob> blobIn = expand(blobData);
129  int const k = isVectorChar(classDictionary);
130  switch (k) {
131  case 0 :
132  {
133  // error!!!
134  }
135  break;
136  case 1:
137  {
138  std::vector<unsigned char> & v = *reinterpret_cast< std::vector<unsigned char> *> (addressOfContainer);
139  // we should avoid the copy!
140  v.resize(blobIn->size());
141  std::memcpy(&v.front(),blobIn->startingAddress(),v.size());
142  }
143  break;
144  case 2:
145  {
146  std::vector<char> & v = *reinterpret_cast< std::vector<char> *> (addressOfContainer);
147  // we should avoid the copy!
148  v.resize(blobIn->size());
149  std::memcpy(&v.front(),blobIn->startingAddress(),v.size());
150  }
151  break;
152  }
153  }
154  }
155  }
static Variant findVariant(const void *address)
static int isVectorChar(edm::TypeWithDict const &classDictionary)
static boost::shared_ptr< coral::Blob > expand(const coral::Blob &blobIn)
boost::shared_ptr< ora::IBlobStreamingService > rootService
boost::shared_ptr< coral::Blob > cond::BlobStreamingService::write ( const void *  addressOfInputData,
edm::TypeWithDict const &  classDictionary,
bool  useCompression = true 
)
overridevirtual

Implements ora::IBlobStreamingService.

Definition at line 65 of file BlobStreamingService.cc.

References compress(), COMPRESSED_CHARS, COMPRESSED_TBUFFER, isVectorChar(), relval_steps::k, rootService, findQualityFiles::v, and variantIds.

Referenced by pkg.AbstractPkg::generate().

65  {
66  boost::shared_ptr<coral::Blob> blobOut;
67  int const k = isVectorChar(classDictionary);
68  switch (k) {
69  case 0 :
70  {
71  // at the moment we write TBuffer compressed, than we see....
72  // we may wish to avoid one buffer copy...
73  boost::shared_ptr<coral::Blob> buffer = rootService->write(addressOfInputData, classDictionary);
74  if( useCompression ){
75  blobOut = compress(buffer->startingAddress(),buffer->size());
76  *reinterpret_cast<uuid*>(blobOut->startingAddress()) = variantIds[COMPRESSED_TBUFFER];
77  } else {
78  blobOut = buffer;
79  }
80  }
81  break;
82  case 1 :
83  {
84  if( useCompression ){
85  std::vector<unsigned char> const & v = *reinterpret_cast< std::vector<unsigned char> const *> (addressOfInputData);
86  blobOut = compress(&v.front(),v.size());
87  *reinterpret_cast<uuid*>(blobOut->startingAddress()) = variantIds[COMPRESSED_CHARS];
88  } else {
89  blobOut = rootService->write(addressOfInputData,classDictionary);
90  }
91  }
92  break;
93  case 2 :
94  {
95  if( useCompression ){
96  std::vector<char> const & v = *reinterpret_cast<std::vector<char> const *> (addressOfInputData);
97  blobOut = compress(&v.front(),v.size());
98  *reinterpret_cast<uuid*>(blobOut->startingAddress()) = variantIds[COMPRESSED_CHARS];
99  } else {
100  blobOut = rootService->write(addressOfInputData,classDictionary);
101  }
102  }
103  break;
104 
105  }
106  return blobOut;
107 
108  }
static int isVectorChar(edm::TypeWithDict const &classDictionary)
std::pair< unsigned long long, unsigned long long > uuid
boost::shared_ptr< ora::IBlobStreamingService > rootService
static boost::shared_ptr< coral::Blob > compress(const void *addr, size_t isize)
static uuid const variantIds[nVariants]

Member Data Documentation

const size_t cond::BlobStreamingService::m_idsize =sizeof(uuid)
staticprivate

Definition at line 40 of file BlobStreamingService.cc.

Referenced by compress(), and expand().

const size_t cond::BlobStreamingService::m_offset = m_idsize + sizeof(unsigned long long)
staticprivate

Definition at line 41 of file BlobStreamingService.cc.

Referenced by compress(), expand(), and read().

const size_t cond::BlobStreamingService::nVariants =3
staticprivate

Definition at line 42 of file BlobStreamingService.cc.

Referenced by findVariant().

boost::shared_ptr<ora::IBlobStreamingService> cond::BlobStreamingService::rootService
private

Definition at line 56 of file BlobStreamingService.cc.

Referenced by read(), and write().

const BlobStreamingService::uuid cond::BlobStreamingService::variantIds
staticprivate
Initial value:
= {
,BlobStreamingService::uuid(0xf4e92f169c974e8eLL, 0x97851f372586010dLL)
,BlobStreamingService::uuid(0xc9a95a45e60243cfLL, 0x8dc549534f9a9274LL)
}

Definition at line 45 of file BlobStreamingService.cc.

Referenced by findVariant(), and write().