CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
RootDelayedReader.cc
Go to the documentation of this file.
1 /*----------------------------------------------------------------------
2 ----------------------------------------------------------------------*/
3 
4 #include "RootDelayedReader.h"
5 #include "InputFile.h"
8 
11 
13 
15 
16 #include "TBranch.h"
17 #include "TClass.h"
18 
19 #include <cassert>
20 
21 namespace edm {
22 
23  RootDelayedReader::RootDelayedReader(RootTree const& tree, std::shared_ptr<InputFile> filePtr, InputType inputType)
24  : tree_(tree),
25  filePtr_(filePtr),
26  nextReader_(),
27  inputType_(inputType),
28  wrapperBaseTClass_(TClass::GetClass("edm::WrapperBase")) {
29  if (inputType == InputType::Primary) {
31  resourceAcquirer_ = std::make_unique<SharedResourcesAcquirer>(std::move(resources.first));
32  mutex_ = resources.second;
33  }
34  }
35 
37 
38  std::pair<SharedResourcesAcquirer*, std::recursive_mutex*> RootDelayedReader::sharedResources_() const {
39  return std::make_pair(resourceAcquirer_.get(), mutex_.get());
40  }
41 
42  std::shared_ptr<WrapperBase> RootDelayedReader::getProduct_(BranchID const& k, EDProductGetter const* ep) {
43  if (lastException_) {
44  std::rethrow_exception(lastException_);
45  }
46  auto branchInfo = getBranchInfo(k);
47  if (not branchInfo) {
48  if (nextReader_) {
49  return nextReader_->getProduct(k, ep);
50  } else {
51  return std::shared_ptr<WrapperBase>();
52  }
53  }
54  TBranch* br = branchInfo->productBranch_;
55  if (br == nullptr) {
56  if (nextReader_) {
57  return nextReader_->getProduct(k, ep);
58  } else {
59  return std::shared_ptr<WrapperBase>();
60  }
61  }
62 
64  //make code exception safe
65  std::shared_ptr<void> refCoreStreamerGuard(nullptr, [](void*) {
66  setRefCoreStreamer(false);
67  ;
68  });
69  TClass* cp = branchInfo->classCache_;
70  if (nullptr == cp) {
71  branchInfo->classCache_ = TClass::GetClass(branchInfo->branchDescription_.wrappedName().c_str());
72  cp = branchInfo->classCache_;
73  branchInfo->offsetToWrapperBase_ = cp->GetBaseClassOffset(wrapperBaseTClass_);
74  }
75  void* p = cp->New();
76  std::unique_ptr<WrapperBase> edp = getWrapperBasePtr(p, branchInfo->offsetToWrapperBase_);
77  br->SetAddress(&p);
78  try {
79  //Run, Lumi, and ProcessBlock only have 1 entry number, which is index 0
80  tree_.getEntry(br, tree_.entryNumberForIndex(tree_.branchType() == InEvent ? ep->transitionIndex() : 0));
81  } catch (edm::Exception& exception) {
82  exception.addContext("Rethrowing an exception that happened on a different thread.");
83  lastException_ = std::current_exception();
84  } catch (...) {
85  lastException_ = std::current_exception();
86  }
87  if (lastException_) {
88  std::rethrow_exception(lastException_);
89  }
90  if (tree_.branchType() == InEvent) {
91  // CMS-THREADING For the primary input source calls to this function need to be serialized
93  }
94  return edp;
95  }
96 } // namespace edm
edm::RootDelayedReader::getBranchInfo
BranchInfo const * getBranchInfo(BranchID const &k) const
Definition: RootDelayedReader.h:68
edm::RootDelayedReader::mutex_
std::shared_ptr< std::recursive_mutex > mutex_
Definition: RootDelayedReader.h:76
edm::getWrapperBasePtr
std::unique_ptr< WrapperBase > getWrapperBasePtr(void *p, int offset)
Definition: getWrapperBasePtr.h:8
getWrapperBasePtr.h
edm
HLT enums.
Definition: AlignableModifier.h:19
tree
Definition: tree.py:1
RootDelayedReader.h
edm::RootDelayedReader::resourceAcquirer_
std::unique_ptr< SharedResourcesAcquirer > resourceAcquirer_
Definition: RootDelayedReader.h:75
edm::RootDelayedReader::inputType_
InputType inputType_
Definition: RootDelayedReader.h:77
edm::RootDelayedReader::~RootDelayedReader
~RootDelayedReader() override
Definition: RootDelayedReader.cc:36
edm::SharedResourcesRegistry::createAcquirerForSourceDelayedReader
std::pair< SharedResourcesAcquirer, std::shared_ptr< std::recursive_mutex > > createAcquirerForSourceDelayedReader()
Definition: SharedResourcesRegistry.cc:64
edm::InputFile::reportReadBranch
static void reportReadBranch(InputType inputType, std::string const &branchname)
Definition: InputFile.cc:111
hgcal_conditions::parameters
Definition: HGCConditions.h:86
edm::RootDelayedReader::RootDelayedReader
RootDelayedReader(RootTree const &tree, std::shared_ptr< InputFile > filePtr, InputType inputType)
Definition: RootDelayedReader.cc:23
edm::InputType
InputType
Definition: InputType.h:5
edm::Exception
Definition: EDMException.h:77
EDMException.h
SharedResourcesAcquirer.h
edm::EDProductGetter
Definition: EDProductGetter.h:41
edm::RootDelayedReader::wrapperBaseTClass_
edm::propagate_const< TClass * > wrapperBaseTClass_
Definition: RootDelayedReader.h:78
edm::RootTree::entryNumberForIndex
EntryNumber const & entryNumberForIndex(unsigned int index) const
Definition: RootTree.cc:113
RefCoreStreamer.h
edm::RootDelayedReader::getProduct_
std::shared_ptr< WrapperBase > getProduct_(BranchID const &k, EDProductGetter const *ep) override
Definition: RootDelayedReader.cc:42
edm::BranchID
Definition: BranchID.h:14
edm::InEvent
Definition: BranchType.h:11
dqmdumpme.k
k
Definition: dqmdumpme.py:60
edm::SharedResourcesRegistry::instance
static SharedResourcesRegistry * instance()
Definition: SharedResourcesRegistry.cc:25
cppFunctionSkipper.exception
exception
Definition: cppFunctionSkipper.py:10
edm::RootTree::getEntry
void getEntry(TBranch *branch, EntryNumber entry) const
Definition: RootTree.cc:382
AlCaHLTBitMon_ParallelJobs.p
def p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
edm::RootDelayedReader::tree_
RootTree const & tree_
Definition: RootDelayedReader.h:71
beamvalidation.br
br
Definition: beamvalidation.py:397
InputFile.h
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::RootDelayedReader::nextReader_
edm::propagate_const< DelayedReader * > nextReader_
Definition: RootDelayedReader.h:73
eostools.move
def move(src, dest)
Definition: eostools.py:511
SharedResourcesRegistry.h
edm::InputType::Primary
mps_fire.resources
resources
Definition: mps_fire.py:263
edm::setRefCoreStreamer
void setRefCoreStreamer(bool resetAll=false)
Definition: RefCoreStreamer.cc:83
edm::RootTree::branchType
BranchType branchType() const
Definition: RootTree.h:184
EDProductGetter.h
edm::RootTree
Definition: RootTree.h:79
edm::RootDelayedReader::lastException_
std::exception_ptr lastException_
Definition: RootDelayedReader.h:89
SiStripBadComponentsDQMServiceTemplate_cfg.ep
ep
Definition: SiStripBadComponentsDQMServiceTemplate_cfg.py:86
edm::RootDelayedReader::sharedResources_
std::pair< SharedResourcesAcquirer *, std::recursive_mutex * > sharedResources_() const override
Definition: RootDelayedReader.cc:38