diff --git a/include/podio/SIOFrameWriter.h b/include/podio/SIOFrameWriter.h index a8a7d084f..c111261ca 100644 --- a/include/podio/SIOFrameWriter.h +++ b/include/podio/SIOFrameWriter.h @@ -17,7 +17,7 @@ class Frame; class SIOFrameWriter { public: SIOFrameWriter(const std::string& filename); - ~SIOFrameWriter() = default; + ~SIOFrameWriter(); SIOFrameWriter(const SIOFrameWriter&) = delete; SIOFrameWriter& operator=(const SIOFrameWriter&) = delete; @@ -37,6 +37,7 @@ class SIOFrameWriter { sio::ofstream m_stream{}; ///< The output file stream SIOFileTOCRecord m_tocRecord{}; ///< The "table of contents" of the written file DatamodelDefinitionCollector m_datamodelCollector{}; + bool m_finished{false}; ///< Has finish been called already? }; } // namespace podio diff --git a/src/SIOFrameWriter.cc b/src/SIOFrameWriter.cc index 360c948d2..85f497afe 100644 --- a/src/SIOFrameWriter.cc +++ b/src/SIOFrameWriter.cc @@ -26,6 +26,12 @@ SIOFrameWriter::SIOFrameWriter(const std::string& filename) { sio_utils::writeRecord(blocks, "podio_header_info", m_stream, sizeof(podio::version::Version), false); } +SIOFrameWriter::~SIOFrameWriter() { + if (!m_finished) { + finish(); + } +} + void SIOFrameWriter::writeFrame(const podio::Frame& frame, const std::string& category) { writeFrame(frame, category, frame.getAvailableCollections()); }