Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14_0_X] Add context for exceptions being thrown via RootOutputFile::finishEndFile() #45142

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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