From 0bf2f7a7873543871d67c6278a874a0365010862 Mon Sep 17 00:00:00 2001 From: Christian Tacke <58549698+ChristianTackeGSI@users.noreply.github.com> Date: Tue, 21 Nov 2023 15:41:24 +0100 Subject: [PATCH] feat: Close Sink/Source in FairRun dtor If we destruct the sink/source during destruction of a FairRun (via unique_ptr), we could probably call the Close method of the sink and source as well. The dtor of a sink/source should handle cleaning up anyway. But being nice and closing it could be considered "being good citizens". See: https://github.com/FairRootGroup/FairRoot/issues/1462 --- fairroot/base/sink/FairSink.h | 13 +++++++++---- fairroot/base/source/FairSource.h | 6 ++++++ fairroot/base/steer/FairRun.cxx | 7 +++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/fairroot/base/sink/FairSink.h b/fairroot/base/sink/FairSink.h index 4be278b77e..3f406e004a 100644 --- a/fairroot/base/sink/FairSink.h +++ b/fairroot/base/sink/FairSink.h @@ -16,16 +16,15 @@ #define FAIRSINK_H #include +#include +#include #include +#include #include // map #include // unique_ptr #include // string #include // type_info -class TObject; -class TFolder; -class TTree; - enum Sink_Type { kONLINESINK, @@ -40,6 +39,12 @@ class FairSink virtual ~FairSink(); virtual Bool_t InitSink() = 0; + + /** + * \note It might be called multiple times, please handle that. + * \note It will be called from the dtor of FairRun. + * Don't interact with FairRun here. + */ virtual void Close() = 0; virtual void Reset() = 0; diff --git a/fairroot/base/source/FairSource.h b/fairroot/base/source/FairSource.h index e76a477e0b..296c66d705 100644 --- a/fairroot/base/source/FairSource.h +++ b/fairroot/base/source/FairSource.h @@ -35,6 +35,12 @@ class FairSource : public TObject virtual Bool_t Init() = 0; virtual Int_t ReadEvent(UInt_t = 0) = 0; virtual Bool_t SpecifyRunId() = 0; + + /** + * \note It might be called multiple times, please handle that. + * \note It will be called from the dtor of FairRun. + * Don't interact with FairRun here. + */ virtual void Close() = 0; virtual void Reset() = 0; virtual Bool_t ActivateObject(TObject**, const char*) { return kFALSE; } diff --git a/fairroot/base/steer/FairRun.cxx b/fairroot/base/steer/FairRun.cxx index acceeadebb..2e4cb3eb81 100644 --- a/fairroot/base/steer/FairRun.cxx +++ b/fairroot/base/steer/FairRun.cxx @@ -82,6 +82,13 @@ FairRun::~FairRun() { LOG(debug) << "Enter Destructor of FairRun"; + if (fSource) { + fSource->Close(); + } + if (fSink) { + fSink->Close(); + } + // So that FairRootManager does not try to delete these, because we will do that: fRootManager->SetSource(nullptr); fRootManager->SetSink(nullptr);