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  iterator iter = branchIter(k);
54  if (!found(iter)) {
55  if (nextReader_) {
56  return nextReader_->getProduct(k, ep);
57  } else {
58  return std::unique_ptr<WrapperBase>();
59  }
60  }
61  roottree::BranchInfo const& branchInfo = getBranchInfo(iter);
62  TBranch* br = branchInfo.productBranch_;
63  if (br == nullptr) {
64  if (nextReader_) {
65  return nextReader_->getProduct(k, ep);
66  } else {
67  return std::unique_ptr<WrapperBase>();
68  }
69  }
70 
72  //make code exception safe
73  std::shared_ptr<void> refCoreStreamerGuard(nullptr,[](void*){ setRefCoreStreamer(false);
74  ;});
75  TClass* cp = branchInfo.classCache_;
76  if(nullptr == cp) {
77  branchInfo.classCache_ = TClass::GetClass(branchInfo.branchDescription_.wrappedName().c_str());
78  cp = branchInfo.classCache_;
79  branchInfo.offsetToWrapperBase_ = cp->GetBaseClassOffset(wrapperBaseTClass_);
80  }
81  void* p = cp->New();
82  std::unique_ptr<WrapperBase> edp = getWrapperBasePtr(p, branchInfo.offsetToWrapperBase_);
83  br->SetAddress(&p);
84  try{
85  //Run and Lumi only have 1 entry number, which is index 0
87  } catch(edm::Exception& exception) {
88  exception.addContext("Rethrowing an exception that happened on a different thread.");
89  lastException_ = std::current_exception();
90  } catch(...) {
91  lastException_ = std::current_exception();
92  }
93  if(lastException_) {
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 }
InputType
Definition: InputType.h:5
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:128
#define nullptr
std::shared_ptr< std::recursive_mutex > mutex_
std::pair< SharedResourcesAcquirer *, std::recursive_mutex * > sharedResources_() const override
std::unique_ptr< WrapperBase > getProduct_(BranchKey const &k, EDProductGetter const *ep) override
std::exception_ptr lastException_
static SharedResourcesRegistry * instance()
BranchType branchType() const
Definition: RootTree.h:164
RootDelayedReader(RootTree const &tree, std::shared_ptr< InputFile > filePtr, InputType inputType)
roottree::BranchMap::const_iterator iterator
int k[5][pyjets_maxn]
EntryNumber const & entryNumberForIndex(unsigned int index) const
Definition: RootTree.cc:93
bool found(iterator const &iter) const
void getEntry(TBranch *branch, EntryNumber entry) const
Definition: RootTree.cc:357
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.
iterator branchIter(BranchKey const &k) const
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