Skip to content

Commit

Permalink
Allow the writers not to call finish() (AIDASoft#442)
Browse files Browse the repository at this point in the history
Co-authored-by: jmcarcell <jmcarcell@users.noreply.github.com>
  • Loading branch information
2 people authored and hegner committed Jul 27, 2023
1 parent 1b5fcf6 commit af55888
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
4 changes: 3 additions & 1 deletion include/podio/ROOTFrameWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class GenericParameters;
class ROOTFrameWriter {
public:
ROOTFrameWriter(const std::string& filename);
~ROOTFrameWriter() = default;
~ROOTFrameWriter();

ROOTFrameWriter(const ROOTFrameWriter&) = delete;
ROOTFrameWriter& operator=(const ROOTFrameWriter&) = delete;
Expand Down Expand Up @@ -83,6 +83,8 @@ class ROOTFrameWriter {
std::unordered_map<std::string, CategoryInfo> m_categories{}; ///< All categories

DatamodelDefinitionCollector m_datamodelCollector{};

bool m_finished{false}; ///< Whether writing has been actually done
};

} // namespace podio
Expand Down
4 changes: 3 additions & 1 deletion include/podio/SIOWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class DEPR_EVTSTORE SIOWriter {

public:
SIOWriter(const std::string& filename, EventStore* store);
~SIOWriter() = default;
~SIOWriter();

// non-copyable
SIOWriter(const SIOWriter&) = delete;
Expand All @@ -46,6 +46,8 @@ class DEPR_EVTSTORE SIOWriter {
std::shared_ptr<SIONumberedMetaDataBlock> m_collectionMetaData;
SIOFileTOCRecord m_tocRecord{};
std::vector<std::string> m_collectionsToWrite{};

bool m_finished{false};
};

} // namespace podio
Expand Down
8 changes: 8 additions & 0 deletions src/ROOTFrameWriter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ ROOTFrameWriter::ROOTFrameWriter(const std::string& filename) {
m_file = std::make_unique<TFile>(filename.c_str(), "recreate");
}

ROOTFrameWriter::~ROOTFrameWriter() {
if (!m_finished) {
finish();
}
}

void ROOTFrameWriter::writeFrame(const podio::Frame& frame, const std::string& category) {
writeFrame(frame, category, frame.getAvailableCollections());
}
Expand Down Expand Up @@ -143,6 +149,8 @@ void ROOTFrameWriter::finish() {

m_file->Write();
m_file->Close();

m_finished = true;
}

} // namespace podio
8 changes: 8 additions & 0 deletions src/SIOWriter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ SIOWriter::SIOWriter(const std::string& filename, EventStore* store) :
auto& libLoader [[maybe_unused]] = SIOBlockLibraryLoader::instance();
}

SIOWriter::~SIOWriter() {
if (!m_finished) {
finish();
}
}

void SIOWriter::writeEvent() {
if (m_firstEvent) {
// Write the collectionIDs as a separate record at the beginning of the
Expand Down Expand Up @@ -86,6 +92,8 @@ void SIOWriter::finish() {
m_stream.write(reinterpret_cast<char*>(&finalWords), sizeof(finalWords));

m_stream.close();

m_finished = true;
}

void SIOWriter::registerForWrite(const std::string& name) {
Expand Down

0 comments on commit af55888

Please sign in to comment.