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 
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() : static_cast<SharedResourcesAcquirer*>(nullptr)),
31  inputType_(inputType),
32  wrapperBaseTClass_(TClass::GetClass("edm::WrapperBase")) {
33  if(inputType == InputType::Primary) {
35  resourceAcquirer_=std::make_unique<SharedResourcesAcquirer>(std::move(resources.first));
36  mutex_ = resources.second;
37  }
38  }
39 
41  }
42 
43  std::pair<SharedResourcesAcquirer*, std::recursive_mutex*>
45  return std::make_pair(resourceAcquirer_.get(), mutex_.get());
46  }
47 
48  std::unique_ptr<WrapperBase>
50  if (lastException_) {
51  std::rethrow_exception(lastException_);
52  }
53  auto branchInfo = getBranchInfo(k);
54  if (not branchInfo) {
55  if (nextReader_) {
56  return nextReader_->getProduct(k, ep);
57  } else {
58  return std::unique_ptr<WrapperBase>();
59  }
60  }
61  TBranch* br = branchInfo->productBranch_;
62  if (br == nullptr) {
63  if (nextReader_) {
64  return nextReader_->getProduct(k, ep);
65  } else {
66  return std::unique_ptr<WrapperBase>();
67  }
68  }
69 
71  //make code exception safe
72  std::shared_ptr<void> refCoreStreamerGuard(nullptr,[](void*){ setRefCoreStreamer(false);
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 and Lumi only have 1 entry number, which is index 0
86  } catch(edm::Exception& exception) {
87  exception.addContext("Rethrowing an exception that happened on a different thread.");
88  lastException_ = std::current_exception();
89  } catch(...) {
90  lastException_ = std::current_exception();
91  }
92  if(lastException_) {
93  std::rethrow_exception(lastException_);
94  }
95  if(tree_.branchType() == InEvent) {
96  // CMS-THREADING For the primary input source calls to this function need to be serialized
98  }
99  return edp;
100  }
101 }
InputType
Definition: InputType.h:5
BranchInfo const * getBranchInfo(BranchID const &k) const
RootTree const & tree_
void setRefCoreStreamer(bool resetAll=false)
static void reportReadBranch(InputType inputType, std::string const &branchname)
Definition: InputFile.cc:128
#define nullptr
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:192
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:94
void getEntry(TBranch *branch, EntryNumber entry) const
Definition: RootTree.cc:370
std::unique_ptr< WrapperBase > getProduct_(BranchID const &k, EDProductGetter const *ep) override
void addContext(std::string const &context)
Definition: Exception.cc:227
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:510