CMS 3D CMS Logo

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  resourceAcquirer_(inputType == InputType::Primary ? new SharedResourcesAcquirer()
28  : static_cast<SharedResourcesAcquirer*>(nullptr)),
29  inputType_(inputType),
30  wrapperBaseTClass_(TClass::GetClass("edm::WrapperBase")) {
31  if (inputType == InputType::Primary) {
33  resourceAcquirer_ = std::make_unique<SharedResourcesAcquirer>(std::move(resources.first));
34  mutex_ = resources.second;
35  }
36  }
37 
39 
40  std::pair<SharedResourcesAcquirer*, std::recursive_mutex*> RootDelayedReader::sharedResources_() const {
41  return std::make_pair(resourceAcquirer_.get(), mutex_.get());
42  }
43 
44  std::shared_ptr<WrapperBase> RootDelayedReader::getProduct_(BranchID const& k, EDProductGetter const* ep) {
45  if (lastException_) {
46  std::rethrow_exception(lastException_);
47  }
48  auto branchInfo = getBranchInfo(k);
49  if (not branchInfo) {
50  if (nextReader_) {
51  return nextReader_->getProduct(k, ep);
52  } else {
53  return std::shared_ptr<WrapperBase>();
54  }
55  }
56  TBranch* br = branchInfo->productBranch_;
57  if (br == nullptr) {
58  if (nextReader_) {
59  return nextReader_->getProduct(k, ep);
60  } else {
61  return std::shared_ptr<WrapperBase>();
62  }
63  }
64 
66  //make code exception safe
67  std::shared_ptr<void> refCoreStreamerGuard(nullptr, [](void*) {
68  setRefCoreStreamer(false);
69  ;
70  });
71  TClass* cp = branchInfo->classCache_;
72  if (nullptr == cp) {
73  branchInfo->classCache_ = TClass::GetClass(branchInfo->branchDescription_.wrappedName().c_str());
74  cp = branchInfo->classCache_;
75  branchInfo->offsetToWrapperBase_ = cp->GetBaseClassOffset(wrapperBaseTClass_);
76  }
77  void* p = cp->New();
78  std::unique_ptr<WrapperBase> edp = getWrapperBasePtr(p, branchInfo->offsetToWrapperBase_);
79  br->SetAddress(&p);
80  try {
81  //Run and Lumi only have 1 entry number, which is index 0
82  tree_.getEntry(br, tree_.entryNumberForIndex(tree_.branchType() == InEvent ? ep->transitionIndex() : 0));
83  } catch (edm::Exception& exception) {
84  exception.addContext("Rethrowing an exception that happened on a different thread.");
85  lastException_ = std::current_exception();
86  } catch (...) {
87  lastException_ = std::current_exception();
88  }
89  if (lastException_) {
90  std::rethrow_exception(lastException_);
91  }
92  if (tree_.branchType() == InEvent) {
93  // CMS-THREADING For the primary input source calls to this function need to be serialized
95  }
96  return edp;
97  }
98 } // namespace edm
edm::SharedResourcesAcquirer
Definition: SharedResourcesAcquirer.h:34
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
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
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:38
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:100
RefCoreStreamer.h
edm::RootDelayedReader::getProduct_
std::shared_ptr< WrapperBase > getProduct_(BranchID const &k, EDProductGetter const *ep) override
Definition: RootDelayedReader.cc:44
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
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
cppFunctionSkipper.exception
exception
Definition: cppFunctionSkipper.py:10
edm::RootTree::getEntry
void getEntry(TBranch *branch, EntryNumber entry) const
Definition: RootTree.cc:365
edm::RootDelayedReader::tree_
RootTree const & tree_
Definition: RootDelayedReader.h:71
beamvalidation.br
br
Definition: beamvalidation.py:398
InputFile.h
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:196
EDProductGetter.h
edm::RootTree
Definition: RootTree.h:103
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:40