CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes
HFShowerLibrary::BranchReader Struct Reference

Public Member Functions

 BranchReader ()
 
 BranchReader (TBranch *iBranch, FileFormat iFormat, size_t iReadOffset, size_t maxRecordsToCache)
 
HFShowerPhotonCollection getRecord (int) const
 
std::size_t numberOfRecords () const
 

Private Member Functions

void doCaching (size_t maxRecords)
 

Static Private Member Functions

static HFShowerPhotonCollection getRecordNewForm (TBranch *, int iEntry)
 
static HFShowerPhotonCollection getRecordNewFormV3 (TBranch *, int iEntry)
 
static HFShowerPhotonCollection getRecordOldForm (TBranch *, int iEntry)
 
static std::shared_ptr< BranchCache const > makeCache (BranchReader &, size_t maxRecordsToCache, std::string const &iFileName, std::string const &iBranchName)
 

Private Attributes

TBranch * branch_
 
std::shared_ptr< BranchCache const > cache_
 
FileFormat format_
 
size_t offset_
 

Detailed Description

Definition at line 93 of file HFShowerLibrary.h.

Constructor & Destructor Documentation

◆ BranchReader() [1/2]

HFShowerLibrary::BranchReader::BranchReader ( )
inline

◆ BranchReader() [2/2]

HFShowerLibrary::BranchReader::BranchReader ( TBranch *  iBranch,
FileFormat  iFormat,
size_t  iReadOffset,
size_t  maxRecordsToCache 
)
inline

Definition at line 95 of file HFShowerLibrary.h.

References branch_, and doCaching().

96  : branch_(iBranch), offset_(iReadOffset), format_(iFormat) {
97  if (0 < maxRecordsToCache) {
98  doCaching(maxRecordsToCache);
99  branch_ = nullptr;
100  }
101  }
void doCaching(size_t maxRecords)

Member Function Documentation

◆ doCaching()

void HFShowerLibrary::BranchReader::doCaching ( size_t  maxRecords)
private

Definition at line 440 of file HFShowerLibrary.cc.

Referenced by BranchReader().

440  {
441  cache_ = makeCache(*this, maxRecordsToCache, branch_->GetDirectory()->GetFile()->GetName(), branch_->GetName());
442 }
std::shared_ptr< BranchCache const > cache_
static std::shared_ptr< BranchCache const > makeCache(BranchReader &, size_t maxRecordsToCache, std::string const &iFileName, std::string const &iBranchName)

◆ getRecord()

HFShowerPhotonCollection HFShowerLibrary::BranchReader::getRecord ( int  record) const

Definition at line 501 of file HFShowerLibrary.cc.

References HFShowerLibrary::kNew, HFShowerLibrary::kNewV3, HFShowerLibrary::kOld, and AlCaHarvesting_cff::record.

Referenced by HFShowerLibrary::BranchCache::BranchCache(), and HFShowerLibrary::getRecord().

501  {
502  if (cache_) {
503  return cache_->getRecord(record);
504  }
505  int nrc = record - 1;
507 
508  switch (format_) {
509  case FileFormat::kNew: {
510  photo = getRecordNewForm(branch_, nrc + offset_);
511  break;
512  }
513  case FileFormat::kNewV3: {
514  photo = getRecordNewFormV3(branch_, nrc + offset_);
515  break;
516  }
517  case FileFormat::kOld: {
518  photo = getRecordOldForm(branch_, nrc);
519  break;
520  }
521  }
522  return photo;
523 }
static HFShowerPhotonCollection getRecordOldForm(TBranch *, int iEntry)
std::vector< HFShowerPhoton > HFShowerPhotonCollection
std::shared_ptr< BranchCache const > cache_
static HFShowerPhotonCollection getRecordNewForm(TBranch *, int iEntry)
static HFShowerPhotonCollection getRecordNewFormV3(TBranch *, int iEntry)

◆ getRecordNewForm()

HFShowerPhotonCollection HFShowerLibrary::BranchReader::getRecordNewForm ( TBranch *  iBranch,
int  iEntry 
)
staticprivate

Definition at line 475 of file HFShowerLibrary.cc.

References eostools::move(), and groupFilesInBlocks::temp.

475  {
477 
478  auto temp = std::make_unique<HFShowerPhotonCollection>();
479  iBranch->SetAddress(&temp);
480  iBranch->GetEntry(iEntry);
481  photo = std::move(*temp);
482 
483  return photo;
484 }
std::vector< HFShowerPhoton > HFShowerPhotonCollection
def move(src, dest)
Definition: eostools.py:511

◆ getRecordNewFormV3()

HFShowerPhotonCollection HFShowerLibrary::BranchReader::getRecordNewFormV3 ( TBranch *  iBranch,
int  iEntry 
)
staticprivate

Definition at line 485 of file HFShowerLibrary.cc.

References mps_fire::i, submitPVValidationJobs::t, and cmsswSequenceInfo::tp.

485  {
487 
488  std::vector<float> t;
489  std::vector<float>* tp = &t;
490  iBranch->SetAddress(&tp);
491  iBranch->GetEntry(iEntry);
492  unsigned int tSize = t.size() / 5;
493  photo.reserve(tSize);
494  for (unsigned int i = 0; i < tSize; i++) {
495  photo.emplace_back(t[i], t[1 * tSize + i], t[2 * tSize + i], t[3 * tSize + i], t[4 * tSize + i]);
496  }
497 
498  return photo;
499 }
std::vector< HFShowerPhoton > HFShowerPhotonCollection

◆ getRecordOldForm()

HFShowerPhotonCollection HFShowerLibrary::BranchReader::getRecordOldForm ( TBranch *  iBranch,
int  iEntry 
)
staticprivate

Definition at line 469 of file HFShowerLibrary.cc.

469  {
471  iBranch->SetAddress(&photo);
472  iBranch->GetEntry(iEntry);
473  return photo;
474 }
std::vector< HFShowerPhoton > HFShowerPhotonCollection

◆ makeCache()

std::shared_ptr< HFShowerLibrary::BranchCache const > HFShowerLibrary::BranchReader::makeCache ( BranchReader iReader,
size_t  maxRecordsToCache,
std::string const &  iFileName,
std::string const &  iBranchName 
)
staticprivate

Definition at line 444 of file HFShowerLibrary.cc.

References CMS_SA_ALLOW, mutex, s_mutex, and findQualityFiles::v.

445  {
446  //This allows sharing of the same cached data across the different modules (e.g. the per stream instances of OscarMTProducer
448  std::lock_guard<std::mutex> guard(s_mutex);
449  CMS_SA_ALLOW static std::map<std::pair<std::string, std::string>, std::weak_ptr<BranchCache>> s_map;
450  auto v = s_map[{iFileName, iBranchName}].lock();
451  if (v) {
452  return v;
453  }
454  v = std::make_shared<BranchCache>(iReader, maxRecordsToCache);
455  s_map[{iFileName, iBranchName}] = v;
456  return v;
457 }
#define CMS_SA_ALLOW
static std::recursive_mutex s_mutex
Definition: DQMService.cc:14
static std::mutex mutex
Definition: Proxy.cc:8

◆ numberOfRecords()

size_t HFShowerLibrary::BranchReader::numberOfRecords ( ) const

Definition at line 525 of file HFShowerLibrary.cc.

Referenced by HFShowerLibrary::BranchCache::BranchCache().

525 { return branch_->GetEntries() - offset_; }

Member Data Documentation

◆ branch_

TBranch* HFShowerLibrary::BranchReader::branch_
private

Definition at line 118 of file HFShowerLibrary.h.

Referenced by BranchReader(), tree.Tree::var(), and tree.Tree::vector().

◆ cache_

std::shared_ptr<BranchCache const> HFShowerLibrary::BranchReader::cache_
private

Definition at line 119 of file HFShowerLibrary.h.

◆ format_

FileFormat HFShowerLibrary::BranchReader::format_
private

Definition at line 121 of file HFShowerLibrary.h.

◆ offset_

size_t HFShowerLibrary::BranchReader::offset_
private

Definition at line 120 of file HFShowerLibrary.h.