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::unique_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::unique_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::unique_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
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
InputType
Definition: InputType.h:5
BranchInfo const * getBranchInfo(BranchID const &k) const
RootTree const & tree_
#define nullptr
void setRefCoreStreamer(bool resetAll=false)
static void reportReadBranch(InputType inputType, std::string const &branchname)
Definition: InputFile.cc:111
std::shared_ptr< std::recursive_mutex > mutex_
std::pair< SharedResourcesAcquirer *, std::recursive_mutex * > sharedResources_() const override
std::exception_ptr lastException_
static SharedResourcesRegistry * instance()
BranchType branchType() const
Definition: RootTree.h:194
RootDelayedReader(RootTree const &tree, std::shared_ptr< InputFile > filePtr, InputType inputType)
int k[5][pyjets_maxn]
EntryNumber const & entryNumberForIndex(unsigned int index) const
Definition: RootTree.cc:99
void getEntry(TBranch *branch, EntryNumber entry) const
Definition: RootTree.cc:364
std::unique_ptr< WrapperBase > getProduct_(BranchID const &k, EDProductGetter const *ep) override
void addContext(std::string const &context)
Definition: Exception.cc:165
unsigned int transitionIndex() const
std::unique_ptr< SharedResourcesAcquirer > resourceAcquirer_
edm::propagate_const< TClass * > wrapperBaseTClass_
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