-
Notifications
You must be signed in to change notification settings - Fork 98
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,7 @@ FairLmdSource::FairLmdSource(const FairLmdSource& source) | |
|
||
FairLmdSource::~FairLmdSource() | ||
{ | ||
CloseLmd(); | ||
fFileNames->Delete(); | ||
delete fFileNames; | ||
} | ||
|
@@ -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; | ||
|
@@ -133,6 +136,8 @@ Bool_t FairLmdSource::OpenNextFile(TString fileName) | |
|
||
if (status) { | ||
LOG(error) << "File " << fileName << " opening failed."; | ||
delete fxInputChannel; | ||
fxInputChannel = nullptr; | ||
return kFALSE; | ||
} | ||
|
||
|
@@ -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(); | ||
|
@@ -236,7 +241,17 @@ Int_t FairLmdSource::ReadEvent(UInt_t) | |
|
||
void FairLmdSource::Close() | ||
{ | ||
CloseLmd(); | ||
} | ||
Comment on lines
242
to
+245
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be implemented in the base class void FairSource::Close() {Close_imp();} There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,6 +65,9 @@ class FairLmdSource : public FairMbsSource | |
|
||
FairLmdSource& operator=(const FairLmdSource&); | ||
|
||
private: | ||
void CloseLmd(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be an overridden private virtual function. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
}; | ||
|
||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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.