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, Reflex::Type const &classDictionary) override
 Reads an object from a Blob and fills-in the container. More...
 
boost::shared_ptr< coral::Blob > write (const void *addressOfInputData, Reflex::Type 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 (Reflex::Type 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 183 of file BlobStreamingService.cc.

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

Referenced by write().

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

Definition at line 201 of file BlobStreamingService.cc.

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

Referenced by read().

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

Definition at line 176 of file BlobStreamingService.cc.

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

Referenced by read().

176  {
177  uuid const & id = *reinterpret_cast<uuid const*>(address);
179  return (v==variantIds+nVariants) ? OLD : (Variant)(v-variantIds);
180  }
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 ( Reflex::Type const &  classDictionary)
staticprivate

Definition at line 167 of file BlobStreamingService.cc.

References lumiQTWidget::t.

Referenced by read(), and write().

167  {
168  std::type_info const & t = classDictionary.TypeInfo();
169  if (t==typeid(std::vector<unsigned char>) ) return 1;
170  if (t==typeid(std::vector<char>) ) return 2;
171  return 0;
172  }
void cond::BlobStreamingService::read ( const coral::Blob &  blobData,
void *  addressOfContainer,
Reflex::Type 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(), gen::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 boost::shared_ptr< coral::Blob > expand(const coral::Blob &blobIn)
boost::shared_ptr< ora::IBlobStreamingService > rootService
static int isVectorChar(Reflex::Type const &classDictionary)
int k[5][pyjets_maxn]
boost::shared_ptr< coral::Blob > cond::BlobStreamingService::write ( const void *  addressOfInputData,
Reflex::Type const &  classDictionary,
bool  useCompression = true 
)
overridevirtual

Implements ora::IBlobStreamingService.

Definition at line 65 of file BlobStreamingService.cc.

References compress(), COMPRESSED_CHARS, COMPRESSED_TBUFFER, isVectorChar(), gen::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  }
std::pair< unsigned long long, unsigned long long > uuid
boost::shared_ptr< ora::IBlobStreamingService > rootService
static int isVectorChar(Reflex::Type const &classDictionary)
static boost::shared_ptr< coral::Blob > compress(const void *addr, size_t isize)
int k[5][pyjets_maxn]
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().