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  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  try {
45  std::rethrow_exception(lastException_);
46  } catch (edm::Exception const& e) {
47  //avoid growing the context each time the exception is rethrown.
48  auto copy = e;
49  copy.addContext("Rethrowing an exception that happened on a different read request.");
50  throw copy;
51  } catch (cms::Exception& e) {
52  //If we do anything here to 'copy', we would lose the actual type of the exception.
53  e.addContext("Rethrowing an exception that happened on a different read request.");
54  throw;
55  }
56  }
57  auto branchInfo = getBranchInfo(k);
58  if (not branchInfo) {
59  if (nextReader_) {
60  return nextReader_->getProduct(k, ep);
61  } else {
62  return std::shared_ptr<WrapperBase>();
63  }
64  }
65  TBranch* br = branchInfo->productBranch_;
66  if (br == nullptr) {
67  if (nextReader_) {
68  return nextReader_->getProduct(k, ep);
69  } else {
70  return std::shared_ptr<WrapperBase>();
71  }
72  }
73 
75  //make code exception safe
76  std::shared_ptr<void> refCoreStreamerGuard(nullptr, [](void*) {
77  setRefCoreStreamer(false);
78  ;
79  });
80  TClass* cp = branchInfo->classCache_;
81  if (nullptr == cp) {
82  branchInfo->classCache_ = TClass::GetClass(branchInfo->branchDescription_.wrappedName().c_str());
83  cp = branchInfo->classCache_;
84  branchInfo->offsetToWrapperBase_ = cp->GetBaseClassOffset(wrapperBaseTClass_);
85  }
86  void* p = cp->New();
87  std::unique_ptr<WrapperBase> edp = getWrapperBasePtr(p, branchInfo->offsetToWrapperBase_);
88  br->SetAddress(&p);
89  try {
90  //Run, Lumi, and ProcessBlock only have 1 entry number, which is index 0
91  tree_.getEntry(br, tree_.entryNumberForIndex(tree_.branchType() == InEvent ? ep->transitionIndex() : 0));
92  } catch (...) {
93  lastException_ = std::current_exception();
94  std::rethrow_exception(lastException_);
95  }
96  if (tree_.branchType() == InEvent) {
97  // CMS-THREADING For the primary input source calls to this function need to be serialized
99  }
100  return edp;
101  }
102 } // namespace edm
BranchInfo const * getBranchInfo(BranchID const &k) const
InputType
Definition: InputType.h:5
EntryNumber const & entryNumberForIndex(unsigned int index) const
Definition: RootTree.cc:113
RootTree const & tree_
void setRefCoreStreamer(bool resetAll=false)
static void reportReadBranch(InputType inputType, std::string const &branchname)
Definition: InputFile.cc:111
std::pair< SharedResourcesAcquirer *, std::recursive_mutex * > sharedResources_() const override
std::shared_ptr< std::recursive_mutex > mutex_
void getEntry(TBranch *branch, EntryNumber entry) const
Definition: RootTree.cc:382
std::exception_ptr lastException_
static SharedResourcesRegistry * instance()
std::shared_ptr< WrapperBase > getProduct_(BranchID const &k, EDProductGetter const *ep) override
RootDelayedReader(RootTree const &tree, std::shared_ptr< InputFile > filePtr, InputType inputType)
std::unique_ptr< SharedResourcesAcquirer > resourceAcquirer_
edm::propagate_const< TClass * > wrapperBaseTClass_
BranchType branchType() const
Definition: RootTree.h:184
HLT enums.
std::unique_ptr< WrapperBase > getWrapperBasePtr(void *p, int offset)
Definition: tree.py:1
edm::propagate_const< DelayedReader * > nextReader_
std::pair< SharedResourcesAcquirer, std::shared_ptr< std::recursive_mutex > > createAcquirerForSourceDelayedReader()
def move(src, dest)
Definition: eostools.py:511