CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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  try {
45  std::rethrow_exception(lastException_);
46  } catch (cms::Exception& e) {
47  e.addContext("Rethrowing an exception that happened on a different read request.");
48  throw;
49  }
50  }
51  auto branchInfo = getBranchInfo(k);
52  if (not branchInfo) {
53  if (nextReader_) {
54  return nextReader_->getProduct(k, ep);
55  } else {
56  return std::shared_ptr<WrapperBase>();
57  }
58  }
59  TBranch* br = branchInfo->productBranch_;
60  if (br == nullptr) {
61  if (nextReader_) {
62  return nextReader_->getProduct(k, ep);
63  } else {
64  return std::shared_ptr<WrapperBase>();
65  }
66  }
67 
69  //make code exception safe
70  std::shared_ptr<void> refCoreStreamerGuard(nullptr, [](void*) {
71  setRefCoreStreamer(false);
72  ;
73  });
74  TClass* cp = branchInfo->classCache_;
75  if (nullptr == cp) {
76  branchInfo->classCache_ = TClass::GetClass(branchInfo->branchDescription_.wrappedName().c_str());
77  cp = branchInfo->classCache_;
78  branchInfo->offsetToWrapperBase_ = cp->GetBaseClassOffset(wrapperBaseTClass_);
79  }
80  void* p = cp->New();
81  std::unique_ptr<WrapperBase> edp = getWrapperBasePtr(p, branchInfo->offsetToWrapperBase_);
82  br->SetAddress(&p);
83  try {
84  //Run, Lumi, and ProcessBlock only have 1 entry number, which is index 0
86  } catch (...) {
87  lastException_ = std::current_exception();
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
InputType
Definition: InputType.h:5
BranchInfo const * getBranchInfo(BranchID const &k) const
RootTree const & tree_
tuple resources
Definition: mps_fire.py:263
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_
std::exception_ptr lastException_
static SharedResourcesRegistry * instance()
std::shared_ptr< WrapperBase > getProduct_(BranchID const &k, EDProductGetter const *ep) override
def move
Definition: eostools.py:511
BranchType branchType() const
Definition: RootTree.h:184
RootDelayedReader(RootTree const &tree, std::shared_ptr< InputFile > filePtr, InputType inputType)
EntryNumber const & entryNumberForIndex(unsigned int index) const
Definition: RootTree.cc:113
void getEntry(TBranch *branch, EntryNumber entry) const
Definition: RootTree.cc:382
void addContext(std::string const &context)
Definition: Exception.cc:165
unsigned int transitionIndex() const
std::unique_ptr< SharedResourcesAcquirer > resourceAcquirer_
edm::propagate_const< TClass * > wrapperBaseTClass_
std::unique_ptr< WrapperBase > getWrapperBasePtr(void *p, int offset)
edm::propagate_const< DelayedReader * > nextReader_
std::pair< SharedResourcesAcquirer, std::shared_ptr< std::recursive_mutex > > createAcquirerForSourceDelayedReader()