CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 
24  RootTree const& tree,
25  std::shared_ptr<InputFile> filePtr,
26  InputType inputType) :
27  tree_(tree),
28  filePtr_(filePtr),
29  nextReader_(),
30  resourceAcquirer_(inputType == InputType::Primary ? new SharedResourcesAcquirer(SharedResourcesRegistry::instance()->createAcquirerForSourceDelayedReader()) : static_cast<SharedResourcesAcquirer*>(nullptr)),
31  inputType_(inputType),
32  wrapperBaseTClass_(TClass::GetClass("edm::WrapperBase")) {
33  }
34 
36  }
37 
40  return resourceAcquirer_.get();
41  }
42 
43  std::unique_ptr<WrapperBase>
45  if (lastException_) {
46  throw *lastException_;
47  }
48  iterator iter = branchIter(k);
49  if (!found(iter)) {
50  if (nextReader_) {
51  return nextReader_->getProduct(k, ep);
52  } else {
53  return std::unique_ptr<WrapperBase>();
54  }
55  }
56  roottree::BranchInfo const& branchInfo = getBranchInfo(iter);
57  TBranch* br = branchInfo.productBranch_;
58  if (br == nullptr) {
59  if (nextReader_) {
60  return nextReader_->getProduct(k, ep);
61  } else {
62  return std::unique_ptr<WrapperBase>();
63  }
64  }
65 
67  //make code exception safe
68  std::shared_ptr<void> refCoreStreamerGuard(nullptr,[](void*){ setRefCoreStreamer(false);
69  ;});
70  TClass* cp = branchInfo.classCache_;
71  if(nullptr == cp) {
72  branchInfo.classCache_ = TClass::GetClass(branchInfo.branchDescription_.wrappedName().c_str());
73  cp = branchInfo.classCache_;
74  branchInfo.offsetToWrapperBase_ = cp->GetBaseClassOffset(wrapperBaseTClass_);
75  }
76  void* p = cp->New();
77  std::unique_ptr<WrapperBase> edp = getWrapperBasePtr(p, branchInfo.offsetToWrapperBase_);
78  br->SetAddress(&p);
79  try{
81  } catch(const edm::Exception& exception) {
82  lastException_ = std::make_unique<Exception>(exception);
83  lastException_->addContext("Rethrowing an exception that happened on a different thread.");
84  throw exception;
85  }
86  if(tree_.branchType() == InEvent) {
87  // CMS-THREADING For the primary input source calls to this function need to be serialized
89  }
90  return edp;
91  }
92 }
InputType
Definition: InputType.h:5
static PFTauRenderPlugin instance
RootTree const & tree_
void setRefCoreStreamer(bool resetAll=false)
BranchInfo const & getBranchInfo(iterator const &iter) const
static void reportReadBranch(InputType inputType, std::string const &branchname)
Definition: InputFile.cc:119
#define nullptr
virtual std::unique_ptr< WrapperBase > getProduct_(BranchKey const &k, EDProductGetter const *ep) override
BranchDescription const branchDescription_
Definition: RootTree.h:49
BranchType branchType() const
Definition: RootTree.h:154
RootDelayedReader(RootTree const &tree, std::shared_ptr< InputFile > filePtr, InputType inputType)
roottree::BranchMap::const_iterator iterator
std::unique_ptr< Exception > lastException_
EntryNumber const & entryNumberForIndex(unsigned int index) const
Definition: RootTree.cc:92
bool found(iterator const &iter) const
void getEntry(TBranch *branch, EntryNumber entry) const
Definition: RootTree.cc:355
SharedResourcesAcquirer * sharedResources_() const override
unsigned int transitionIndex() const
std::unique_ptr< SharedResourcesAcquirer > resourceAcquirer_
edm::propagate_const< TClass * > wrapperBaseTClass_
TBranch * productBranch_
Definition: RootTree.h:50
iterator branchIter(BranchKey const &k) const
std::unique_ptr< WrapperBase > getWrapperBasePtr(void *p, int offset)
edm::propagate_const< DelayedReader * > nextReader_
std::string const & wrappedName() const