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 176 of file HDF5ProductResolver.cc.

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

Referenced by threadFriendlyPrefetch().

176  {
177  std::vector<char> buffer;
178  if (iMemSize == compressedBuffer.size()) {
179  //memory was not compressed
180  //std::cout <<"NOT COMPRESSED"<<std::endl;
181  buffer = std::move(compressedBuffer);
182  } else {
183  // code 'cribbed' from ROOT
184  lzma_stream stream = LZMA_STREAM_INIT;
185 
186  auto returnStatus = lzma_stream_decoder(&stream, UINT64_MAX, 0U);
187  if (returnStatus != LZMA_OK) {
188  throw cms::Exception("H5CondFailedDecompress") << "failed to setup lzma";
189  }
190 
191  stream.next_in = reinterpret_cast<uint8_t*>(compressedBuffer.data());
192  stream.avail_in = compressedBuffer.size();
193 
194  buffer = std::vector<char>(iMemSize);
195  stream.next_out = reinterpret_cast<uint8_t*>(buffer.data());
196  stream.avail_out = buffer.size();
197 
198  returnStatus = lzma_code(&stream, LZMA_FINISH);
199  lzma_end(&stream);
200  if (returnStatus != LZMA_STREAM_END) {
201  throw cms::Exception("H5CondFailedDecompress") << "failed to decompress buffer using lzma";
202  }
203  }
204  return buffer;
205 }
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 143 of file HDF5ProductResolver.cc.

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

Referenced by threadFriendlyPrefetch().

143  {
144  std::vector<char> buffer;
145  if (iMemSize == compressedBuffer.size()) {
146  //memory was not compressed
147  //std::cout <<"NOT COMPRESSED"<<std::endl;
148  buffer = std::move(compressedBuffer);
149  } else {
150  //zlib compression was used
151  z_stream strm;
152  strm.zalloc = Z_NULL;
153  strm.zfree = Z_NULL;
154  strm.opaque = Z_NULL;
155  strm.avail_in = 0;
156  strm.next_in = Z_NULL;
157  auto ret = inflateInit(&strm);
158  assert(ret == Z_OK);
159 
160  strm.avail_in = compressedBuffer.size();
161  strm.next_in = reinterpret_cast<unsigned char*>(compressedBuffer.data());
162 
163  buffer = std::vector<char>(iMemSize);
164  strm.avail_out = buffer.size();
165  strm.next_out = reinterpret_cast<unsigned char*>(buffer.data());
166  ret = inflate(&strm, Z_FINISH);
167  assert(ret != Z_STREAM_ERROR);
168  //if(ret != Z_STREAM_END) {std::cout <<"mem "<<memSize<<" "<<ret<<" out "<<strm.avail_out<<std::endl;}
169  assert(ret == Z_STREAM_END);
170 
171  (void)inflateEnd(&strm);
172  }
173  return buffer;
174 }
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 245 of file HDF5ProductResolver.cc.

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

245 { 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 110 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().

110  {
111  using namespace cond::hdf5;
112  auto firstSync = convertSyncValue(iIOV.first(), record_->iovIsRunLumi_);
113 
114  auto itFound = findMatchingFirst(record_->iovFirsts_, firstSync);
115  assert(itFound != record_->iovFirsts_.end());
116 
117  return itFound - record_->iovFirsts_.begin();
118 }
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 237 of file HDF5ProductResolver.cc.

References data_.

237  {
238  ESSourceProductResolverBase::invalidateCache();
240 }
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 133 of file HDF5ProductResolver.cc.

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

133  {
134  if (exceptPtr_) {
135  rethrow_exception(exceptPtr_);
136  }
137  if (storageSize_ == 0) {
138  return;
139  }
141 }
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 {
83  iRecord.activityRegistry()->preESModuleSignal_.emit(iRecord.key(), context);
84  struct EndGuard {
85  EndGuard(edm::eventsetup::EventSetupRecordImpl const& iRecord,
86  edm::ESModuleCallingContext const& iContext)
87  : record_{iRecord}, context_{iContext} {}
88  ~EndGuard() { record_.activityRegistry()->postESModuleSignal_.emit(record_.key(), context_); }
90  edm::ESModuleCallingContext const& context_;
91  } guardAR(iRecord, context);
92 
93  auto index = indexForInterval(iov);
94 
96  iGroup.run(std::move(act));
97  exceptPtr_ = {};
98  } catch (...) {
99  exceptPtr_ = std::current_exception();
100  }
101  });
102  },
103  []() { return true; },
104  std::move(iTask),
105  iRecord,
106  iKey,
107  iParent);
108 }
#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 120 of file HDF5ProductResolver.cc.

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

Referenced by prefetchAsyncImpl().

120  {
121  auto payloadRef = dataProduct_->payloadForIOVs_[iIndex];
122  auto ds = file_->derefDataSet(payloadRef);
123  storageSize_ = ds->storageSize();
124  if (storageSize_ == 0) {
125  return;
126  }
127 
128  fileOffset_ = ds->fileOffset();
129  memSize_ = ds->findAttribute("memsize")->readUInt32();
130  type_ = ds->findAttribute("type")->readString();
131 }
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 207 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().

210  {
211  //Done interacting with the hdf5 API
212 
213  //std::cout <<" prefetch "<<dataProduct_->fileOffsets_[index]<<" "<<dataProduct_->storageSizes_[index]<<" "<<memSize<<std::endl;
214  std::vector<char> compressedBuffer(iStorageSize);
215  std::fstream file(fileName_.c_str());
216  file.seekg(iFileOffset);
217  file.read(compressedBuffer.data(), compressedBuffer.size());
218 
219  std::vector<char> buffer;
221  buffer = decompress_zlib(std::move(compressedBuffer), iMemSize);
223  buffer = decompress_lzma(std::move(compressedBuffer), iMemSize);
224  } else {
225  buffer = std::move(compressedBuffer);
226  }
227 
228  std::stringbuf sBuffer;
229  sBuffer.pubsetbuf(&buffer[0], buffer.size());
230  data_ = helper_->deserialize(sBuffer, iTypeName);
231  if (data_.get() == nullptr) {
232  throw cms::Exception("H5CondFailedDeserialization")
233  << "failed to deserialize: buffer size:" << buffer.size() << " type: '" << iTypeName << "'";
234  }
235 }
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