CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
HDF5ProductResolver Class Reference

#include "HDF5ProductResolver.h"

Inheritance diagram for HDF5ProductResolver:
edm::eventsetup::ESSourceProductResolverBase edm::eventsetup::ESProductResolver

Public Member Functions

 HDF5ProductResolver (edm::SerialTaskQueue *iQueue, std::unique_ptr< cond::serialization::SerializationHelperBase >, cms::h5::File const *iFile, std::string const &iFileName, cond::hdf5::Compression iCompression, cond::hdf5::Record const *iRecord, cond::hdf5::DataProduct const *iDataProduct)
 
 HDF5ProductResolver (const HDF5ProductResolver &)=delete
 
const HDF5ProductResolveroperator= (const HDF5ProductResolver &)=delete
 
 ~HDF5ProductResolver () override
 
- Public Member Functions inherited from edm::eventsetup::ESSourceProductResolverBase
 ESSourceProductResolverBase ()
 
- Public Member Functions inherited from edm::eventsetup::ESProductResolver
bool cacheIsValid () const
 
 ESProductResolver ()
 
 ESProductResolver (ESProductResolver const &)=delete
 
void const * getAfterPrefetch (const EventSetupRecordImpl &iRecord, const DataKey &iKey, bool iTransiently) const
 
virtual void initializeForNewIOV ()
 
void invalidate ()
 
ESProductResolver const & operator= (ESProductResolver const &)=delete
 
void prefetchAsync (WaitingTaskHolder, EventSetupRecordImpl const &, DataKey const &, EventSetupImpl const *, ServiceToken const &, ESParentContext const &) const
 
ComponentDescription const * providerDescription () const
 returns the description of the ESProductResolverProvider which owns this Resolver More...
 
void resetIfTransient ()
 
void setProviderDescription (ComponentDescription const *iDesc)
 
virtual ~ESProductResolver ()
 

Private Member Functions

std::vector< char > decompress_lzma (std::vector< char >, std::size_t iMemSize) const
 
std::vector< char > decompress_zlib (std::vector< char >, std::size_t iMemSize) const
 
void const * getAfterPrefetchImpl () const final
 
std::ptrdiff_t indexForInterval (edm::ValidityInterval const &iIOV) const
 
void invalidateCache () final
 
void prefetch (edm::eventsetup::DataKey const &iKey, edm::EventSetupRecordDetails) final
 
void prefetchAsyncImpl (edm::WaitingTaskHolder iTask, edm::eventsetup::EventSetupRecordImpl const &iES, edm::eventsetup::DataKey const &iKey, edm::EventSetupImpl const *, edm::ServiceToken const &, edm::ESParentContext const &) final
 
void readFromHDF5api (std::ptrdiff_t iIndex)
 
void threadFriendlyPrefetch (uint64_t iFileOffset, std::size_t iStorageSize, std::size_t iMemSize, const std::string &iType)
 

Private Attributes

cond::hdf5::Compression compression_
 
cond::serialization::unique_void_ptr data_
 
cond::hdf5::DataProduct const * dataProduct_
 
std::exception_ptr exceptPtr_
 
cms::h5::File const * file_
 
std::string fileName_
 
uint64_t fileOffset_
 
std::unique_ptr< cond::serialization::SerializationHelperBasehelper_
 
std::size_t memSize_
 
edm::SerialTaskQueuequeue_
 
cond::hdf5::Record const * record_
 
std::size_t storageSize_
 
std::string type_
 

Additional Inherited Members

- Protected Member Functions inherited from edm::eventsetup::ESSourceProductResolverBase
void invalidateCache () override
 
void invalidateTransientCache () override
 
template<typename ASYNC , typename GUARD >
void prefetchAsyncImplTemplate (ASYNC iAsync, GUARD iGuardFactory, edm::WaitingTaskHolder iTask, edm::eventsetup::EventSetupRecordImpl const &iRecord, edm::eventsetup::DataKey const &iKey, edm::ESParentContext const &iContext)
 
- Protected Member Functions inherited from edm::eventsetup::ESProductResolver
void clearCacheIsValid ()
 

Detailed Description

Description: [one line class summary]

Usage: <usage>

Definition at line 36 of file HDF5ProductResolver.h.

Constructor & Destructor Documentation

◆ HDF5ProductResolver() [1/2]

HDF5ProductResolver::HDF5ProductResolver ( edm::SerialTaskQueue iQueue,
std::unique_ptr< cond::serialization::SerializationHelperBase iHelper,
cms::h5::File const *  iFile,
std::string const &  iFileName,
cond::hdf5::Compression  iCompression,
cond::hdf5::Record const *  iRecord,
cond::hdf5::DataProduct const *  iDataProduct 
)

Definition at line 44 of file HDF5ProductResolver.cc.

52  queue_(iQueue),
53  helper_(std::move(iHelper)),
54  file_(iFile),
55  fileName_(iFileName),
56  record_(iRecord),
57  dataProduct_(iDataProduct),
58  compression_(iCompression) {}
cond::hdf5::DataProduct const * dataProduct_
std::unique_ptr< cond::serialization::SerializationHelperBase > helper_
edm::SerialTaskQueue * queue_
cond::hdf5::Compression compression_
cond::hdf5::Record const * record_
def move(src, dest)
Definition: eostools.py:511
cms::h5::File const * file_

◆ ~HDF5ProductResolver()

HDF5ProductResolver::~HDF5ProductResolver ( )
override

Definition at line 65 of file HDF5ProductResolver.cc.

65 {}

◆ HDF5ProductResolver() [2/2]

HDF5ProductResolver::HDF5ProductResolver ( const HDF5ProductResolver )
delete

Member Function Documentation

◆ decompress_lzma()

std::vector< char > HDF5ProductResolver::decompress_lzma ( std::vector< char >  compressedBuffer,
std::size_t  iMemSize 
) const
private

Definition at line 178 of file HDF5ProductResolver.cc.

References edmScanValgrind::buffer, Exception, eostools::move(), cms::cuda::stream, and mitigatedMETSequence_cff::U.

Referenced by threadFriendlyPrefetch().

178  {
179  std::vector<char> buffer;
180  if (iMemSize == compressedBuffer.size()) {
181  //memory was not compressed
182  //std::cout <<"NOT COMPRESSED"<<std::endl;
183  buffer = std::move(compressedBuffer);
184  } else {
185  // code 'cribbed' from ROOT
186  lzma_stream stream = LZMA_STREAM_INIT;
187 
188  auto returnStatus = lzma_stream_decoder(&stream, UINT64_MAX, 0U);
189  if (returnStatus != LZMA_OK) {
190  throw cms::Exception("H5CondFailedDecompress") << "failed to setup lzma";
191  }
192 
193  stream.next_in = reinterpret_cast<uint8_t*>(compressedBuffer.data());
194  stream.avail_in = compressedBuffer.size();
195 
196  buffer = std::vector<char>(iMemSize);
197  stream.next_out = reinterpret_cast<uint8_t*>(buffer.data());
198  stream.avail_out = buffer.size();
199 
200  returnStatus = lzma_code(&stream, LZMA_FINISH);
201  lzma_end(&stream);
202  if (returnStatus != LZMA_STREAM_END) {
203  throw cms::Exception("H5CondFailedDecompress") << "failed to decompress buffer using lzma";
204  }
205  }
206  return buffer;
207 }
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t stream
def move(src, dest)
Definition: eostools.py:511

◆ decompress_zlib()

std::vector< char > HDF5ProductResolver::decompress_zlib ( std::vector< char >  compressedBuffer,
std::size_t  iMemSize 
) const
private

Definition at line 145 of file HDF5ProductResolver.cc.

References cms::cuda::assert(), edmScanValgrind::buffer, eostools::move(), runTheMatrix::ret, and funct::void.

Referenced by threadFriendlyPrefetch().

145  {
146  std::vector<char> buffer;
147  if (iMemSize == compressedBuffer.size()) {
148  //memory was not compressed
149  //std::cout <<"NOT COMPRESSED"<<std::endl;
150  buffer = std::move(compressedBuffer);
151  } else {
152  //zlib compression was used
153  z_stream strm;
154  strm.zalloc = Z_NULL;
155  strm.zfree = Z_NULL;
156  strm.opaque = Z_NULL;
157  strm.avail_in = 0;
158  strm.next_in = Z_NULL;
159  auto ret = inflateInit(&strm);
160  assert(ret == Z_OK);
161 
162  strm.avail_in = compressedBuffer.size();
163  strm.next_in = reinterpret_cast<unsigned char*>(compressedBuffer.data());
164 
165  buffer = std::vector<char>(iMemSize);
166  strm.avail_out = buffer.size();
167  strm.next_out = reinterpret_cast<unsigned char*>(buffer.data());
168  ret = inflate(&strm, Z_FINISH);
169  assert(ret != Z_STREAM_ERROR);
170  //if(ret != Z_STREAM_END) {std::cout <<"mem "<<memSize<<" "<<ret<<" out "<<strm.avail_out<<std::endl;}
171  assert(ret == Z_STREAM_END);
172 
173  (void)inflateEnd(&strm);
174  }
175  return buffer;
176 }
ret
prodAgent to be discontinued
assert(be >=bs)
TEMPL(T2) struct Divides void
Definition: Factorize.h:24
def move(src, dest)
Definition: eostools.py:511

◆ getAfterPrefetchImpl()

void const * HDF5ProductResolver::getAfterPrefetchImpl ( ) const
finalprivatevirtual

used to retrieve the data from the implementation. The data is then cached locally.

Implements edm::eventsetup::ESProductResolver.

Definition at line 247 of file HDF5ProductResolver.cc.

References data_, and cond::serialization::unique_void_ptr::get().

247 { return data_.get(); }
const void * get() const noexcept
cond::serialization::unique_void_ptr data_

◆ indexForInterval()

std::ptrdiff_t HDF5ProductResolver::indexForInterval ( edm::ValidityInterval const &  iIOV) const
private

Definition at line 112 of file HDF5ProductResolver.cc.

References cms::cuda::assert(), cond::hdf5::convertSyncValue(), cond::hdf5::findMatchingFirst(), edm::ValidityInterval::first(), cond::hdf5::Record::iovFirsts_, cond::hdf5::Record::iovIsRunLumi_, and record_.

Referenced by prefetchAsyncImpl().

112  {
113  using namespace cond::hdf5;
114  auto firstSync = convertSyncValue(iIOV.first(), record_->iovIsRunLumi_);
115 
116  auto itFound = findMatchingFirst(record_->iovFirsts_, firstSync);
117  assert(itFound != record_->iovFirsts_.end());
118 
119  return itFound - record_->iovFirsts_.begin();
120 }
std::vector< IOVSyncValue > iovFirsts_
Definition: Record.h:34
assert(be >=bs)
bool iovIsRunLumi_
Definition: Record.h:37
std::vector< IOVSyncValue >::const_iterator findMatchingFirst(std::vector< IOVSyncValue > const &iIOVs, IOVSyncValue iMatch)
Definition: IOVSyncValue.cc:19
cond::hdf5::Record const * record_
IOVSyncValue convertSyncValue(edm::IOVSyncValue const &iFrom, bool iIsRunLumi)

◆ invalidateCache()

void HDF5ProductResolver::invalidateCache ( )
finalprivatevirtual

indicates that the Resolver should invalidate any cached information as that information has 'expired' (i.e. we have moved to a new IOV)

Implements edm::eventsetup::ESProductResolver.

Definition at line 239 of file HDF5ProductResolver.cc.

References data_.

239  {
240  ESSourceProductResolverBase::invalidateCache();
242 }
cond::serialization::unique_void_ptr data_

◆ operator=()

const HDF5ProductResolver& HDF5ProductResolver::operator= ( const HDF5ProductResolver )
delete

◆ prefetch()

void HDF5ProductResolver::prefetch ( edm::eventsetup::DataKey const &  iKey,
edm::EventSetupRecordDetails  iRecord 
)
finalprivatevirtual

Implements edm::eventsetup::ESSourceProductResolverBase.

Definition at line 135 of file HDF5ProductResolver.cc.

References exceptPtr_, fileOffset_, memSize_, storageSize_, threadFriendlyPrefetch(), and type_.

135  {
136  if (exceptPtr_) {
137  rethrow_exception(exceptPtr_);
138  }
139  if (storageSize_ == 0) {
140  return;
141  }
143 }
void threadFriendlyPrefetch(uint64_t iFileOffset, std::size_t iStorageSize, std::size_t iMemSize, const std::string &iType)
std::exception_ptr exceptPtr_

◆ prefetchAsyncImpl()

void HDF5ProductResolver::prefetchAsyncImpl ( edm::WaitingTaskHolder  ,
edm::eventsetup::EventSetupRecordImpl const &  ,
edm::eventsetup::DataKey const &  iKey,
edm::EventSetupImpl const *  ,
edm::ServiceToken const &  ,
edm::ESParentContext const &   
)
finalprivatevirtual

This is the function which does the real work of getting the data if it is not already cached. The returning 'void const*' must point to an instance of the class type corresponding to the type designated in iKey. So if iKey refers to a base class interface the pointer must be a pointer to that base class interface and not a pointer to an inheriting class instance.

Implements edm::eventsetup::ESProductResolver.

Definition at line 71 of file HDF5ProductResolver.cc.

References edm::eventsetup::EventSetupRecordImpl::activityRegistry(), CMS_SA_ALLOW, visDQMUpload::context, edm::signalslot::Signal< T >::emit(), exceptPtr_, indexForInterval(), edm::eventsetup::EventSetupRecordImpl::key(), edm::ESModuleCallingContext::kRunning, eostools::move(), edm::ActivityRegistry::preESModuleSignal_, edm::eventsetup::ESSourceProductResolverBase::prefetchAsyncImplTemplate(), edm::eventsetup::ESProductResolver::providerDescription(), edm::SerialTaskQueue::push(), queue_, readFromHDF5api(), record_, and edm::eventsetup::EventSetupRecordImpl::validityInterval().

76  {
78  [this, iov = iRecord.validityInterval(), iParent, &iRecord](auto& iGroup, auto iActivity) {
79  queue_->push(iGroup, [this, &iGroup, act = std::move(iActivity), iov, iParent, &iRecord] {
80  CMS_SA_ALLOW try {
82  reinterpret_cast<std::uintptr_t>(this),
84  iParent);
85  iRecord.activityRegistry()->preESModuleSignal_.emit(iRecord.key(), context);
86  struct EndGuard {
87  EndGuard(edm::eventsetup::EventSetupRecordImpl const& iRecord,
88  edm::ESModuleCallingContext const& iContext)
89  : record_{iRecord}, context_{iContext} {}
90  ~EndGuard() { record_.activityRegistry()->postESModuleSignal_.emit(record_.key(), context_); }
92  edm::ESModuleCallingContext const& context_;
93  } guardAR(iRecord, context);
94 
95  auto index = indexForInterval(iov);
96 
98  iGroup.run(std::move(act));
99  exceptPtr_ = {};
100  } catch (...) {
101  exceptPtr_ = std::current_exception();
102  }
103  });
104  },
105  []() { return true; },
106  std::move(iTask),
107  iRecord,
108  iKey,
109  iParent);
110 }
#define CMS_SA_ALLOW
std::ptrdiff_t indexForInterval(edm::ValidityInterval const &iIOV) const
void push(oneapi::tbb::task_group &, const T &iAction)
asynchronously pushes functor iAction into queue
void prefetchAsyncImplTemplate(ASYNC iAsync, GUARD iGuardFactory, edm::WaitingTaskHolder iTask, edm::eventsetup::EventSetupRecordImpl const &iRecord, edm::eventsetup::DataKey const &iKey, edm::ESParentContext const &iContext)
ComponentDescription const * providerDescription() const
returns the description of the ESProductResolverProvider which owns this Resolver ...
edm::SerialTaskQueue * queue_
void readFromHDF5api(std::ptrdiff_t iIndex)
std::exception_ptr exceptPtr_
cond::hdf5::Record const * record_
def move(src, dest)
Definition: eostools.py:511

◆ readFromHDF5api()

void HDF5ProductResolver::readFromHDF5api ( std::ptrdiff_t  iIndex)
private

Definition at line 122 of file HDF5ProductResolver.cc.

References dataProduct_, cms::h5::File::derefDataSet(), file_, fileOffset_, memSize_, cond::hdf5::DataProduct::payloadForIOVs_, storageSize_, and type_.

Referenced by prefetchAsyncImpl().

122  {
123  auto payloadRef = dataProduct_->payloadForIOVs_[iIndex];
124  auto ds = file_->derefDataSet(payloadRef);
125  storageSize_ = ds->storageSize();
126  if (storageSize_ == 0) {
127  return;
128  }
129 
130  fileOffset_ = ds->fileOffset();
131  memSize_ = ds->findAttribute("memsize")->readUInt32();
132  type_ = ds->findAttribute("type")->readString();
133 }
cond::hdf5::DataProduct const * dataProduct_
std::vector< hobj_ref_t > payloadForIOVs_
Definition: DataProduct.h:35
std::shared_ptr< DataSet > derefDataSet(hobj_ref_t iRef) const
Definition: h5_File.cc:77
cms::h5::File const * file_

◆ threadFriendlyPrefetch()

void HDF5ProductResolver::threadFriendlyPrefetch ( uint64_t  iFileOffset,
std::size_t  iStorageSize,
std::size_t  iMemSize,
const std::string &  iType 
)
private

Definition at line 209 of file HDF5ProductResolver.cc.

References edmScanValgrind::buffer, compression_, data_, decompress_lzma(), decompress_zlib(), Exception, geometryDiff::file, fileName_, cond::serialization::unique_void_ptr::get(), helper_, cond::hdf5::kLZMA, cond::hdf5::kZLIB, and eostools::move().

Referenced by prefetch().

212  {
213  //Done interacting with the hdf5 API
214 
215  //std::cout <<" prefetch "<<dataProduct_->fileOffsets_[index]<<" "<<dataProduct_->storageSizes_[index]<<" "<<memSize<<std::endl;
216  std::vector<char> compressedBuffer(iStorageSize);
217  std::fstream file(fileName_.c_str());
218  file.seekg(iFileOffset);
219  file.read(compressedBuffer.data(), compressedBuffer.size());
220 
221  std::vector<char> buffer;
223  buffer = decompress_zlib(std::move(compressedBuffer), iMemSize);
225  buffer = decompress_lzma(std::move(compressedBuffer), iMemSize);
226  } else {
227  buffer = std::move(compressedBuffer);
228  }
229 
230  std::stringbuf sBuffer;
231  sBuffer.pubsetbuf(&buffer[0], buffer.size());
232  data_ = helper_->deserialize(sBuffer, iTypeName);
233  if (data_.get() == nullptr) {
234  throw cms::Exception("H5CondFailedDeserialization")
235  << "failed to deserialize: buffer size:" << buffer.size() << " type: '" << iTypeName << "'";
236  }
237 }
std::unique_ptr< cond::serialization::SerializationHelperBase > helper_
const void * get() const noexcept
cond::serialization::unique_void_ptr data_
cond::hdf5::Compression compression_
std::vector< char > decompress_lzma(std::vector< char >, std::size_t iMemSize) const
def move(src, dest)
Definition: eostools.py:511
std::vector< char > decompress_zlib(std::vector< char >, std::size_t iMemSize) const

Member Data Documentation

◆ compression_

cond::hdf5::Compression HDF5ProductResolver::compression_
private

Definition at line 80 of file HDF5ProductResolver.h.

Referenced by threadFriendlyPrefetch().

◆ data_

cond::serialization::unique_void_ptr HDF5ProductResolver::data_
private

◆ dataProduct_

cond::hdf5::DataProduct const* HDF5ProductResolver::dataProduct_
private

Definition at line 79 of file HDF5ProductResolver.h.

Referenced by readFromHDF5api().

◆ exceptPtr_

std::exception_ptr HDF5ProductResolver::exceptPtr_
private

Definition at line 87 of file HDF5ProductResolver.h.

Referenced by prefetch(), and prefetchAsyncImpl().

◆ file_

cms::h5::File const* HDF5ProductResolver::file_
private

Definition at line 76 of file HDF5ProductResolver.h.

Referenced by readFromHDF5api().

◆ fileName_

std::string HDF5ProductResolver::fileName_
private

Definition at line 77 of file HDF5ProductResolver.h.

Referenced by threadFriendlyPrefetch().

◆ fileOffset_

uint64_t HDF5ProductResolver::fileOffset_
private

Definition at line 83 of file HDF5ProductResolver.h.

Referenced by prefetch(), and readFromHDF5api().

◆ helper_

std::unique_ptr<cond::serialization::SerializationHelperBase> HDF5ProductResolver::helper_
private

Definition at line 75 of file HDF5ProductResolver.h.

Referenced by threadFriendlyPrefetch().

◆ memSize_

std::size_t HDF5ProductResolver::memSize_
private

Definition at line 86 of file HDF5ProductResolver.h.

Referenced by prefetch(), and readFromHDF5api().

◆ queue_

edm::SerialTaskQueue* HDF5ProductResolver::queue_
private

Definition at line 73 of file HDF5ProductResolver.h.

Referenced by prefetchAsyncImpl().

◆ record_

cond::hdf5::Record const* HDF5ProductResolver::record_
private

Definition at line 78 of file HDF5ProductResolver.h.

Referenced by indexForInterval(), and prefetchAsyncImpl().

◆ storageSize_

std::size_t HDF5ProductResolver::storageSize_
private

Definition at line 85 of file HDF5ProductResolver.h.

Referenced by prefetch(), and readFromHDF5api().

◆ type_

std::string HDF5ProductResolver::type_
private