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

Remove calling Close method in FairRootManager/FairRun #1468

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
* `virtual bool operator<(const FairTimeStamp* rValue) const` changed to `bool operator<(const FairTimeStamp& rValue) const`
* FairModule::svList is gone. This was never intended as a public
API.
* Remove calling `Close()`
* `FairSink::Close()` and `FairSource::Close()` are no longer called in FairRoot.
* Derived classes from `FairSink` and `FairSource` should close the resources automatically in their destructors.

### Deprecations

Expand Down
1 change: 0 additions & 1 deletion examples/MQ/pixelDetector/src/FairOnlineSink.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class FairOnlineSink : public FairSink
FairOnlineSink& operator=(const FairOnlineSink&) = delete;

Bool_t InitSink() override { return kTRUE; }
void Close() override {}
void Reset() override {}

Sink_Type GetSinkType() override { return kONLINESINK; }
Expand Down
10 changes: 5 additions & 5 deletions examples/MQ/pixelDetector/src/PixelDigiBinSource.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ Int_t PixelDigiBinSource::ReadEvent(UInt_t i)
for (Int_t idata = 0; idata < head[3]; idata++) {
LOG(debug) << " --/" << idata << "/--> " << dataCont[idata * dataSize + 0] << " / "
<< dataCont[idata * dataSize + 1] << " / " << dataCont[idata * dataSize + 2] << " / "
<< dataCont[idata * dataSize + 3] << " / "
<< " 0.";
<< dataCont[idata * dataSize + 3] << " / " << " 0.";
new (fDigis[fNDigis]) PixelDigi(-1,
dataCont[idata * dataSize + 0],
dataCont[idata * dataSize + 1],
Expand Down Expand Up @@ -138,11 +137,12 @@ Bool_t PixelDigiBinSource::ActivateObject(TObject** obj, const char* BrName)
return kTRUE;
}

void PixelDigiBinSource::Close() { fInputFile.close(); }

YanzhaoW marked this conversation as resolved.
Show resolved Hide resolved
void PixelDigiBinSource::Reset() {}

Int_t PixelDigiBinSource::CheckMaxEventNo(Int_t /*EvtEnd*/) { return -1; }
Int_t PixelDigiBinSource::CheckMaxEventNo(Int_t /*EvtEnd*/)
{
return -1;
}

void PixelDigiBinSource::FillEventHeader(FairEventHeader* feh)
{
Expand Down
4 changes: 3 additions & 1 deletion examples/MQ/pixelDetector/src/PixelDigiBinSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class PixelDigiBinSource : public FairSource
Bool_t Init() override;

Int_t ReadEvent(UInt_t i = 0) override;
void Close() override;
void Reset() override;
Bool_t SpecifyRunId() override
{
Expand Down Expand Up @@ -78,6 +77,9 @@ class PixelDigiBinSource : public FairSource
PixelDigiBinSource(const PixelDigiBinSource&);
PixelDigiBinSource& operator=(const PixelDigiBinSource&);

// Private member functions:
void Close() override { fInputFile.close(); }

ClassDefOverride(PixelDigiBinSource, 1);
};

Expand Down
7 changes: 4 additions & 3 deletions examples/MQ/pixelDetector/src/PixelDigiSource.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,12 @@ Bool_t PixelDigiSource::ActivateObject(TObject** obj, const char* BrName)
return kTRUE;
}

void PixelDigiSource::Close() { fInputFile.close(); }

void PixelDigiSource::Reset() {}

Int_t PixelDigiSource::CheckMaxEventNo(Int_t /*EvtEnd*/) { return -1; }
Int_t PixelDigiSource::CheckMaxEventNo(Int_t /*EvtEnd*/)
{
return -1;
}

void PixelDigiSource::FillEventHeader(FairEventHeader* feh)
{
Expand Down
3 changes: 2 additions & 1 deletion examples/MQ/pixelDetector/src/PixelDigiSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class PixelDigiSource : public FairSource
Bool_t Init() override;

Int_t ReadEvent(UInt_t i = 0) override;
void Close() override;
void Reset() override;
Bool_t SpecifyRunId() override
{
Expand Down Expand Up @@ -78,6 +77,8 @@ class PixelDigiSource : public FairSource
PixelDigiSource(const PixelDigiSource&);
PixelDigiSource& operator=(const PixelDigiSource&);

void Close() override { fInputFile.close(); }

ClassDefOverride(PixelDigiSource, 1);
};

Expand Down
4 changes: 0 additions & 4 deletions fairroot/base/sim/FairMCApplication.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -478,10 +478,6 @@ void FairMCApplication::FinishRunOnWorker()
LOG(debug) << "FairMCApplication::FinishRunOnWorker: ";

FinishRun();

// Close the sink on workers so that the execution of main FairRunSim->Run()
// finishes with the output files properly closed.
fRootManager->CloseSink();
}

//_____________________________________________________________________________
Expand Down
5 changes: 3 additions & 2 deletions fairroot/base/sink/FairRootFileSink.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ void FairRootFileSink::TruncateBranchNames(TBranch* b, TString ffn)

void FairRootFileSink::Close()
{
if (fRootFile) {
if (fRootFile != nullptr) {
fRootFile->Close();
}
}
Expand Down Expand Up @@ -251,7 +251,8 @@ void FairRootFileSink::WriteFolder()
}
}

namespace impl {
namespace impl
{
// a helper function to demangle a type_name
inline std::string demangle(const char* name)
{
Expand Down
2 changes: 1 addition & 1 deletion fairroot/base/sink/FairRootFileSink.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class FairRootFileSink : public FairSink
~FairRootFileSink() override = default;

Bool_t InitSink() override;
void Close() override;
void Reset() override;

Sink_Type GetSinkType() override { return kFILESINK; }
Expand Down Expand Up @@ -66,6 +65,7 @@ class FairRootFileSink : public FairSink
void WriteGeometry() override;

FairSink* CloneSink() override;
void Close() override;
ChristianTackeGSI marked this conversation as resolved.
Show resolved Hide resolved

private:
/** Title of input sink, could be input, background or signal*/
Expand Down
2 changes: 1 addition & 1 deletion fairroot/base/sink/FairSink.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class FairSink
virtual ~FairSink();

virtual Bool_t InitSink() = 0;
virtual void Close() = 0;
virtual void Close() {}
virtual void Reset() = 0;

virtual Sink_Type GetSinkType() = 0;
Expand Down
14 changes: 8 additions & 6 deletions fairroot/base/source/FairFileSource.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@ FairFileSource::FairFileSource(const TString RootFileName, const char* Title, UI
LOG(debug) << "FairFileSource created------------";
}

FairFileSource::~FairFileSource() = default;

Bool_t FairFileSource::Init()
{
if (IsInitialized) {
Expand Down Expand Up @@ -303,11 +301,15 @@ Bool_t FairFileSource::SpecifyRunId()
return fInChain->GetEntry(0) != 0;
}

void FairFileSource::Close() { CloseInFile(); }

void FairFileSource::AddFriend(TString fName) { fFriendFileList.push_back(fName); }
void FairFileSource::AddFriend(TString fName)
{
fFriendFileList.push_back(fName);
}

void FairFileSource::AddFile(TString FileName) { fInputChainList.push_back(FileName); }
void FairFileSource::AddFile(TString FileName)
{
fInputChainList.push_back(FileName);
}

void FairFileSource::AddFriendsToChain()
{
Expand Down
7 changes: 3 additions & 4 deletions fairroot/base/source/FairFileSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@ class FairFileSource : public FairFileSourceBase
FairFileSource(const TString* RootFileName, const char* Title = "InputRootFile", UInt_t identifier = 0);
FairFileSource(const TString RootFileName, const char* Title = "InputRootFile", UInt_t identifier = 0);
// FairFileSource(const FairFileSource& file);
~FairFileSource() override;
~FairFileSource() override = default;

Bool_t Init() override;
Int_t ReadEvent(UInt_t i = 0) override;
void Close() override;

/**Check the maximum event number we can run to*/
Int_t CheckMaxEventNo(Int_t EvtEnd = 0) override;
Expand All @@ -65,9 +64,9 @@ class FairFileSource : public FairFileSourceBase
void CreateNewFriendChain(TString inputFile, TString inputLevel);
TTree* GetInTree() { return fInChain->GetTree(); }
TChain* GetInChain() { return fInChain; }
void CloseInFile()
[[deprecated("Use Close() function")]] void CloseInFile()
{
if (fRootFile) {
if (fRootFile != nullptr) {
fRootFile->Close();
}
}
Expand Down
8 changes: 8 additions & 0 deletions fairroot/base/source/FairFileSourceBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ class FairFileSourceBase : public FairSource
/** list of folders from all input (and friends) files*/
TObjArray fListFolder{16}; //!

// private virtual methods:
void Close() override
{
if (fRootFile != nullptr) {
fRootFile->Close();
}
}

ClassDefOverride(FairFileSourceBase, 0);
};

Expand Down
9 changes: 4 additions & 5 deletions fairroot/base/source/FairMixedSource.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,6 @@ FairMixedSource::FairMixedSource(const TString RootFileName, const Int_t signalI
// }
}

FairMixedSource::~FairMixedSource() = default;

Bool_t FairMixedSource::Init()
{
fOutHeader = new FairEventHeader();
Expand Down Expand Up @@ -387,8 +385,6 @@ Int_t FairMixedSource::ReadEvent(UInt_t i)
return 0;
}

void FairMixedSource::Close() {}

void FairMixedSource::FillEventHeader(FairEventHeader* feh)
{
feh->SetEventTime(fOutHeader->GetEventTime());
Expand Down Expand Up @@ -423,7 +419,10 @@ void FairMixedSource::SetSignalFile(TString name, UInt_t identifier)
}
}

void FairMixedSource::AddSignalFile(TString name, UInt_t identifier) { SetSignalFile(name, identifier); }
void FairMixedSource::AddSignalFile(TString name, UInt_t identifier)
{
SetSignalFile(name, identifier);
}

TChain* FairMixedSource::GetSignalChainNo(UInt_t i)
{
Expand Down
3 changes: 1 addition & 2 deletions fairroot/base/source/FairMixedSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,10 @@ class FairMixedSource : public FairFileSourceBase
const char* Title = "InputRootFile",
UInt_t identifier = 0);
// FairMixedSource(const FairMixedSource& file);
~FairMixedSource() override;
ChristianTackeGSI marked this conversation as resolved.
Show resolved Hide resolved
~FairMixedSource() override = default;

Bool_t Init() override;
Int_t ReadEvent(UInt_t i = 0) override;
void Close() override;

/**Check the maximum event number we can run to*/
Int_t CheckMaxEventNo(Int_t EvtEnd = 0) override;
Expand Down
2 changes: 1 addition & 1 deletion fairroot/base/source/FairSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class FairSource : public TObject
virtual Bool_t Init() = 0;
virtual Int_t ReadEvent(UInt_t = 0) = 0;
virtual Bool_t SpecifyRunId() = 0;
virtual void Close() = 0;
virtual void Close() {}
virtual void Reset() = 0;
virtual Bool_t ActivateObject(TObject**, const char*) { return kFALSE; }
virtual Bool_t ActivateObjectAny(void**, const std::type_info&, const char*) { return kFALSE; }
Expand Down
4 changes: 2 additions & 2 deletions fairroot/base/steer/FairRootManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
#include <TRefArray.h> // for TRefArray
#include <TString.h> // for TString, operator<
#include <fairlogger/Logger.h>
#include <list>
#include <map> // for map, multimap, etc
#include <memory>
#include <string>
#include <type_traits> // is_pointer, remove_pointer, is_const, remove...
#include <typeinfo>
#include <list>

class BinaryFunctor;
class FairEventHeader;
Expand Down Expand Up @@ -69,7 +69,7 @@ class FairRootManager : public TObject

void CloseSink()
{
if (fSink) {
if (fSink != nullptr) {
fSink->Close();
}
}
Expand Down
1 change: 0 additions & 1 deletion fairroot/base/steer/FairRunAna.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,6 @@ void FairRunAna::TerminateRun()
// cout << ">>>------------------------------------------------<<<" << endl;
fRootManager->LastFill();
fRootManager->Write();
fRootManager->CloseSink();
ChristianTackeGSI marked this conversation as resolved.
Show resolved Hide resolved
}
//_____________________________________________________________________________

Expand Down
3 changes: 0 additions & 3 deletions fairroot/base/steer/FairRunSim.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,6 @@ void FairRunSim::Run(Int_t NEvents, Int_t)
{
fApp->RunMC(NEvents);
fWasMT = fApp->GetIsMT();
if (fSink) {
fSink->Close();
}
ChristianTackeGSI marked this conversation as resolved.
Show resolved Hide resolved
}

void FairRunSim::SetField(FairField* field)
Expand Down
1 change: 0 additions & 1 deletion fairroot/online/source/FairOnlineSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class FairOnlineSource : public FairSource

Bool_t Init() override = 0;
Int_t ReadEvent(UInt_t = 0) override = 0;
void Close() override = 0;

void SetParUnpackers() override;

Expand Down
3 changes: 0 additions & 3 deletions fairroot/online/steer/FairRunOnline.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,6 @@ void FairRunOnline::Finish()
fTask->FinishTask();
fRootManager->LastFill();
fRootManager->Write();
GetSource()->Close();

fRootManager->CloseSink();
ChristianTackeGSI marked this conversation as resolved.
Show resolved Hide resolved
}

void FairRunOnline::ActivateHttpServer(Int_t refreshRate, Int_t httpServer)
Expand Down
Loading