Skip to content

Commit

Permalink
Merge pull request #12662 from Dr15Jones/protectTTreeAccessAfterExcep…
Browse files Browse the repository at this point in the history
…tion_7_6

Do not call TTree cache after an exception happens
  • Loading branch information
davidlange6 committed Dec 4, 2015
2 parents 0360c4e + 479c3f9 commit 505b7fa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
17 changes: 15 additions & 2 deletions IOPool/Input/src/RootDelayedReader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

#include "IOPool/Common/interface/getWrapperBasePtr.h"

#include "FWCore/Utilities/interface/EDMException.h"

#include "TBranch.h"
#include "TClass.h"

Expand Down Expand Up @@ -40,6 +42,9 @@ namespace edm {

std::unique_ptr<WrapperBase>
RootDelayedReader::getProduct_(BranchKey const& k, EDProductGetter const* ep) const {
if (lastException_) {
throw *lastException_;
}
iterator iter = branchIter(k);
if (!found(iter)) {
if (nextReader_) {
Expand All @@ -59,6 +64,9 @@ namespace edm {
}

setRefCoreStreamer(ep);
//make code exception safe
std::shared_ptr<void> refCoreStreamerGuard(nullptr,[](void*){ setRefCoreStreamer(false);
;});
TClass* cp = branchInfo.classCache_;
if(nullptr == cp) {
branchInfo.classCache_ = TClass::GetClass(branchInfo.branchDescription_.wrappedName().c_str());
Expand All @@ -68,12 +76,17 @@ namespace edm {
void* p = cp->New();
std::unique_ptr<WrapperBase> edp = getWrapperBasePtr(p, branchInfo.offsetToWrapperBase_);
br->SetAddress(&p);
tree_.getEntry(br, tree_.entryNumberForIndex(ep->transitionIndex()));
try{
tree_.getEntry(br, tree_.entryNumberForIndex(ep->transitionIndex()));
} catch(const edm::Exception& exception) {
lastException_ = std::make_unique<Exception>(exception);
lastException_->addContext("Rethrowing an exception that happened on a different thread.");
throw exception;
}
if(tree_.branchType() == InEvent) {
// CMS-THREADING For the primary input source calls to this function need to be serialized
InputFile::reportReadBranch(inputType_, std::string(br->GetName()));
}
setRefCoreStreamer(false);
return edp;
}
}
5 changes: 5 additions & 0 deletions IOPool/Input/src/RootDelayedReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace edm {
class InputFile;
class RootTree;
class SharedResourcesAcquirer;
class Exception;

//------------------------------------------------------------
// Class RootDelayedReader: pretends to support file reading.
Expand Down Expand Up @@ -60,6 +61,10 @@ namespace edm {
std::unique_ptr<SharedResourcesAcquirer> resourceAcquirer_;
InputType inputType_;
TClass* wrapperBaseTClass_;
//If a fatal exception happens we need to make a copy so we can
// rethrow that exception on other threads. This avoids TTree
// non-exception safety problems on later calls to TTree.
mutable std::unique_ptr<Exception> lastException_;
}; // class RootDelayedReader
//------------------------------------------------------------
}
Expand Down

0 comments on commit 505b7fa

Please sign in to comment.