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 | Friends
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]
 

Friends

int test::BlobStreaming::test ()
 

Detailed Description

Definition at line 30 of file BlobStreamingService.cc.

Member Typedef Documentation

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

Definition at line 47 of file BlobStreamingService.cc.

Member Enumeration Documentation

Constructor & Destructor Documentation

cond::BlobStreamingService::BlobStreamingService ( )

Definition at line 70 of file BlobStreamingService.cc.

cond::BlobStreamingService::~BlobStreamingService ( )
virtual

Definition at line 72 of file BlobStreamingService.cc.

72 {}

Member Function Documentation

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

Definition at line 191 of file BlobStreamingService.cc.

References m_idsize, m_offset, reco::formula::startingAddress(), and spu::zerr().

Referenced by write().

191  {
192  uLongf destLen = compressBound(isize);
193  size_t usize = destLen + m_offset;
194  boost::shared_ptr<coral::Blob> theBlob( new coral::Blob(usize));
195  void * startingAddress = (unsigned char*)(theBlob->startingAddress())+ m_offset;
196  int zerr = compress2( (unsigned char*)(startingAddress), &destLen,
197  (unsigned char*)(addr), isize,
198  9);
199  if (zerr!=0) edm::LogError("BlobStreamingService")<< "Compression error " << zerr;
200  destLen+= m_idsize + sizeof(unsigned long long);
201  theBlob->resize(destLen);
202 
203  startingAddress = (unsigned char*)(theBlob->startingAddress())+ m_idsize;
204  // write expanded size;
205  *reinterpret_cast<unsigned long long*>(startingAddress)=isize;
206  return theBlob;
207  }
void zerr(int)
double const * startingAddress(ArrayAdaptor const &iV)
boost::shared_ptr< coral::Blob > cond::BlobStreamingService::expand ( const coral::Blob &  blobIn)
staticprivate

Definition at line 209 of file BlobStreamingService.cc.

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

Referenced by read().

209  {
210  if (size_t(blobIn.size()) < m_offset) return boost::shared_ptr<coral::Blob>(new coral::Blob());
211  long long csize = blobIn.size() - m_offset;
212  unsigned char const * startingAddress = (unsigned char const*)(blobIn.startingAddress())+ m_idsize;
213  unsigned long long usize = *reinterpret_cast<unsigned long long const*>(startingAddress);
214  startingAddress += sizeof(unsigned long long);
215  boost::shared_ptr<coral::Blob> theBlob( new coral::Blob(usize));
216  uLongf destLen = usize;
217  int zerr = uncompress((unsigned char *)(theBlob->startingAddress()), &destLen,
218  startingAddress, csize);
219  if (zerr!=0 || usize!=destLen)
220  edm::LogError("BlobStreamingService")<< "uncompressing error " << zerr
221  << " original size was " << usize
222  << " new size is " << destLen;
223 
224  return theBlob;
225  }
void zerr(int)
double const * startingAddress(ArrayAdaptor const &iV)
string const
Definition: compareJSON.py:14
BlobStreamingService::Variant cond::BlobStreamingService::findVariant ( const void *  address)
staticprivate

Definition at line 184 of file BlobStreamingService.cc.

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

Referenced by read().

184  {
185  uuid const & id = *reinterpret_cast<uuid const*>(address);
187  return (v==variantIds+nVariants) ? OLD : (Variant)(v-variantIds);
188  }
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 176 of file BlobStreamingService.cc.

Referenced by read(), and write().

176  {
177  if (classDictionary == typeid(std::vector<unsigned char>)) return 1;
178  if (classDictionary == typeid(std::vector<char>)) return 2;
179  return 0;
180  }
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 120 of file BlobStreamingService.cc.

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

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

120  {
121  // protect against small blobs...
122  Variant v = (size_t(blobData.size()) < m_offset) ? OLD : findVariant(blobData.startingAddress());
123  switch (v) {
124  case OLD :
125  {
126  rootService->read( blobData, addressOfContainer, classDictionary);
127  }
128  break;
129  case COMPRESSED_TBUFFER :
130  {
131  boost::shared_ptr<coral::Blob> blobIn = expand(blobData);
132  rootService->read( *blobIn, addressOfContainer, classDictionary);
133  }
134  break;
135  case COMPRESSED_CHARS :
136  {
137  boost::shared_ptr<coral::Blob> blobIn = expand(blobData);
138  int const k = isVectorChar(classDictionary);
139  switch (k) {
140  case 0 :
141  {
142  // error!!!
143  }
144  break;
145  case 1:
146  {
147  std::vector<unsigned char> & v = *reinterpret_cast< std::vector<unsigned char> *> (addressOfContainer);
148  // we should avoid the copy!
149  v.resize(blobIn->size());
150  std::memcpy(&v.front(),blobIn->startingAddress(),v.size());
151  }
152  break;
153  case 2:
154  {
155  std::vector<char> & v = *reinterpret_cast< std::vector<char> *> (addressOfContainer);
156  // we should avoid the copy!
157  v.resize(blobIn->size());
158  std::memcpy(&v.front(),blobIn->startingAddress(),v.size());
159  }
160  break;
161  }
162  }
163  }
164  }
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 74 of file BlobStreamingService.cc.

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

Referenced by pkg.AbstractPkg::generate().

74  {
75  boost::shared_ptr<coral::Blob> blobOut;
76  int const k = isVectorChar(classDictionary);
77  switch (k) {
78  case 0 :
79  {
80  // at the moment we write TBuffer compressed, than we see....
81  // we may wish to avoid one buffer copy...
82  boost::shared_ptr<coral::Blob> buffer = rootService->write(addressOfInputData, classDictionary);
83  if( useCompression ){
84  blobOut = compress(buffer->startingAddress(),buffer->size());
85  *reinterpret_cast<uuid*>(blobOut->startingAddress()) = variantIds[COMPRESSED_TBUFFER];
86  } else {
87  blobOut = buffer;
88  }
89  }
90  break;
91  case 1 :
92  {
93  if( useCompression ){
94  std::vector<unsigned char> const & v = *reinterpret_cast< std::vector<unsigned char> const *> (addressOfInputData);
95  blobOut = compress(&v.front(),v.size());
96  *reinterpret_cast<uuid*>(blobOut->startingAddress()) = variantIds[COMPRESSED_CHARS];
97  } else {
98  blobOut = rootService->write(addressOfInputData,classDictionary);
99  }
100  }
101  break;
102  case 2 :
103  {
104  if( useCompression ){
105  std::vector<char> const & v = *reinterpret_cast<std::vector<char> const *> (addressOfInputData);
106  blobOut = compress(&v.front(),v.size());
107  *reinterpret_cast<uuid*>(blobOut->startingAddress()) = variantIds[COMPRESSED_CHARS];
108  } else {
109  blobOut = rootService->write(addressOfInputData,classDictionary);
110  }
111  }
112  break;
113 
114  }
115  return blobOut;
116 
117  }
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]

Friends And Related Function Documentation

int test::BlobStreaming::test ( )
friend

Member Data Documentation

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

Definition at line 49 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 50 of file BlobStreamingService.cc.

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

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

Definition at line 51 of file BlobStreamingService.cc.

Referenced by findVariant().

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

Definition at line 65 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 54 of file BlobStreamingService.cc.

Referenced by findVariant(), and write().