Skip to content

Commit 9ff6d7e

Browse files
authored
Allow calling finish() multiple times, with no effect after the first (#798)
* Allow calling finish() multiple times, with no effect after the first * Move the check to finish() also for SIOWriter --------- Co-authored-by: jmcarcell <jmcarcell@users.noreply.github.com>
1 parent 6e1de6f commit 9ff6d7e

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

src/RNTupleWriter.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ RNTupleWriter::RNTupleWriter(const std::string& filename) :
2828
}
2929

3030
RNTupleWriter::~RNTupleWriter() {
31-
if (!m_finished) {
32-
finish();
33-
}
31+
finish();
3432
}
3533

3634
template <typename T>
@@ -235,6 +233,9 @@ RNTupleWriter::CategoryInfo& RNTupleWriter::getCategoryInfo(const std::string& c
235233
}
236234

237235
void RNTupleWriter::finish() {
236+
if (m_finished) {
237+
return;
238+
}
238239
auto metadata = root_compat::RNTupleModel::Create();
239240

240241
const auto podioVersion = podio::version::build_version;

src/ROOTWriter.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ ROOTWriter::ROOTWriter(const std::string& filename) {
1717
}
1818

1919
ROOTWriter::~ROOTWriter() {
20-
if (!m_finished) {
21-
finish();
22-
}
20+
finish();
2321
}
2422

2523
void ROOTWriter::writeFrame(const podio::Frame& frame, const std::string& category) {
@@ -168,6 +166,9 @@ void ROOTWriter::resetBranches(CategoryInfo& categoryInfo,
168166
}
169167

170168
void ROOTWriter::finish() {
169+
if (m_finished) {
170+
return;
171+
}
171172
auto* metaTree = new TTree(root_utils::metaTreeName, "metadata tree for podio I/O functionality");
172173
metaTree->SetDirectory(m_file.get());
173174

src/SIOWriter.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ SIOWriter::SIOWriter(const std::string& filename) {
2525
}
2626

2727
SIOWriter::~SIOWriter() {
28-
if (!m_finished) {
29-
finish();
30-
}
28+
finish();
3129
}
3230

3331
void SIOWriter::writeFrame(const podio::Frame& frame, const std::string& category) {
@@ -55,6 +53,9 @@ void SIOWriter::writeFrame(const podio::Frame& frame, const std::string& categor
5553
}
5654

5755
void SIOWriter::finish() {
56+
if (m_finished) {
57+
return;
58+
}
5859
auto edmDefMap = std::make_shared<podio::SIOMapBlock<std::string, std::string>>(
5960
m_datamodelCollector.getDatamodelDefinitionsToWrite());
6061

0 commit comments

Comments
 (0)