Skip to content

Commit

Permalink
Merge pull request #45142 from makortel/finishEndFileException_140x
Browse files Browse the repository at this point in the history
[14_0_X] Add context for exceptions being thrown via RootOutputFile::finishEndFile()
  • Loading branch information
cmsbuild authored Jun 13, 2024
2 parents afb8235 + 809f850 commit d9d953d
Showing 1 changed file with 50 additions and 33 deletions.
83 changes: 50 additions & 33 deletions IOPool/Output/src/RootOutputFile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -761,40 +761,57 @@ namespace edm {
}

void RootOutputFile::finishEndFile() {
metaDataTree_->SetEntries(-1);
RootOutputTree::writeTTree(metaDataTree_);
RootOutputTree::writeTTree(parameterSetsTree_);

RootOutputTree::writeTTree(parentageTree_);

// Create branch aliases for all the branches in the
// events/lumis/runs/processblock trees. The loop is over
// all types of data products.
for (unsigned int i = 0; i < treePointers_.size(); ++i) {
std::string processName;
BranchType branchType = InProcess;
if (i < InProcess) {
branchType = static_cast<BranchType>(i);
} else {
processName = om_->outputProcessBlockHelper().processesWithProcessBlockProducts()[i - InProcess];
}
setBranchAliases(treePointers_[i]->tree(), om_->keptProducts()[branchType], processName);
treePointers_[i]->writeTree();
}

// close the file -- mfp
// Just to play it safe, zero all pointers to objects in the TFile to be closed.
metaDataTree_ = parentageTree_ = nullptr;
for (auto& treePointer : treePointers_) {
treePointer->close();
treePointer = nullptr;
std::string_view status = "beginning";
std::string_view value = "";
try {
metaDataTree_->SetEntries(-1);
status = "writeTTree() for metadata";
RootOutputTree::writeTTree(metaDataTree_);
status = "writeTTree() for ParameterSets";
RootOutputTree::writeTTree(parameterSetsTree_);

status = "writeTTree() for parentage";
RootOutputTree::writeTTree(parentageTree_);

// Create branch aliases for all the branches in the
// events/lumis/runs/processblock trees. The loop is over
// all types of data products.
status = "writeTree() for ";
for (unsigned int i = 0; i < treePointers_.size(); ++i) {
std::string processName;
BranchType branchType = InProcess;
if (i < InProcess) {
branchType = static_cast<BranchType>(i);
} else {
processName = om_->outputProcessBlockHelper().processesWithProcessBlockProducts()[i - InProcess];
}
setBranchAliases(treePointers_[i]->tree(), om_->keptProducts()[branchType], processName);
value = treePointers_[i]->tree()->GetName();
treePointers_[i]->writeTree();
}

// close the file -- mfp
// Just to play it safe, zero all pointers to objects in the TFile to be closed.
status = "closing TTrees";
value = "";
metaDataTree_ = parentageTree_ = nullptr;
for (auto& treePointer : treePointers_) {
treePointer->close();
treePointer = nullptr;
}
status = "closing TFile";
filePtr_->Close();
filePtr_ = nullptr; // propagate_const<T> has no reset() function

// report that file has been closed
status = "reporting to JobReport";
Service<JobReport> reportSvc;
reportSvc->outputFileClosed(reportToken_);
} catch (cms::Exception& e) {
e.addContext("Calling RootOutputFile::finishEndFile() while closing " + file_);
e.addAdditionalInfo("While calling " + std::string(status) + std::string(value));
throw;
}
filePtr_->Close();
filePtr_ = nullptr; // propagate_const<T> has no reset() function

// report that file has been closed
Service<JobReport> reportSvc;
reportSvc->outputFileClosed(reportToken_);
}

void RootOutputFile::setBranchAliases(TTree* tree,
Expand Down

0 comments on commit d9d953d

Please sign in to comment.