Skip to content

chore: Improve closing on FairLmdSource #1465

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

Merged
merged 1 commit into from
Nov 27, 2023
Merged
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
17 changes: 16 additions & 1 deletion fairroot/online/source/FairLmdSource.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ FairLmdSource::FairLmdSource(const FairLmdSource& source)

FairLmdSource::~FairLmdSource()
{
CloseLmd();
Copy link

@YanzhaoW YanzhaoW Nov 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This step could be executed by its owner.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, no.

I don't think, the "owner" should be resposible for calling Close. It could be considered "being a good citizen", but it should not be strictly needed.

FairLmdSource mysource;
mysource.Open(…);
if (true)
  throw std::runtime_exception("Something else went wrong");
mysource.Close();

This should not leak resources! (See "RAII printciple").

So yes, This is some overhead for the developer of a FairSource/Sink. But that's how C++ is like.

fFileNames->Delete();
delete fFileNames;
}
Expand Down Expand Up @@ -121,6 +122,8 @@ Bool_t FairLmdSource::Init()

Bool_t FairLmdSource::OpenNextFile(TString fileName)
{
CloseLmd();

Int_t inputMode = GETEVT__FILE;
fxInputChannel = new s_evt_channel;
void* headptr = &fxInfoHeader;
Expand All @@ -133,6 +136,8 @@ Bool_t FairLmdSource::OpenNextFile(TString fileName)

if (status) {
LOG(error) << "File " << fileName << " opening failed.";
delete fxInputChannel;
fxInputChannel = nullptr;
return kFALSE;
}

Expand Down Expand Up @@ -166,7 +171,7 @@ Int_t FairLmdSource::ReadEvent(UInt_t)
}

if (GETEVT__NOMORE == status) {
Close();
CloseLmd();
}

TString name = (static_cast<TObjString*>(fFileNames->At(fCurrentFile)))->GetString();
Expand Down Expand Up @@ -236,7 +241,17 @@ Int_t FairLmdSource::ReadEvent(UInt_t)

void FairLmdSource::Close()
{
CloseLmd();
}
Comment on lines 242 to +245
Copy link

@YanzhaoW YanzhaoW Nov 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be implemented in the base class FairSource:

void FairSource::Close() {Close_imp();}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we postpone this for another PR?


void FairLmdSource::CloseLmd()
{
if (!fxInputChannel) {
return;
}
f_evt_get_close(fxInputChannel);
delete fxInputChannel;
fxInputChannel = nullptr;
Unpack(reinterpret_cast<Int_t*>(fxBuffer), sizeof(s_bufhe), -4, -4, -4, -4, -4);
fCurrentEvent = 0;
}
3 changes: 3 additions & 0 deletions fairroot/online/source/FairLmdSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ class FairLmdSource : public FairMbsSource

FairLmdSource& operator=(const FairLmdSource&);

private:
void CloseLmd();
Copy link

@YanzhaoW YanzhaoW Nov 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be an overridden private virtual function.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's please postpone this for another PR as well.


ClassDefOverride(FairLmdSource, 0);
};

Expand Down