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

fix memory leak and summary output bug #640

Closed
Closed
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
71 changes: 71 additions & 0 deletions source/digits_hits/include/GateEmptySD.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*----------------------
Copyright (C): OpenGATE Collaboration

This software is distributed under the terms
of the GNU Lesser General Public Licence (LGPL)
See LICENSE.md for further details
----------------------*/


#ifndef GateEmptySD_h
#define GateEmptySD_h 1

#include "G4VSensitiveDetector.hh"
#include "G4SDManager.hh"

#include "GateHit.hh"
class G4Step;
class G4HCofThisEvent;
class G4TouchableHistory;

class GateVVolume;
class GateVSystem;

//! List of typedefs for the multi-system usage.
typedef std::vector<GateVSystem*> GateSystemList;
typedef GateSystemList::iterator GateSystemIterator;
typedef GateSystemList::const_iterator GateSystemConstIterator;

/*! \class GateEmptySD
\brief The GateEmptySD is a sensitive detector , derived from G4VSensitiveDetector,
\brief to be used for removing existing SD from G4SDManager

- This SD is not exposed to the user. It's sole purpose of existing is to fix issue with
GateMultiSensitiveDetector, for a volume with both SD and actor attached to it.

- It will not ask for any dynamic memory allocation.

- It will not be registered in the GateDigitizerMgr.
*/
// Created by tontyoutoure@gmail.com 2023/10/24



class GateEmptySD : public G4VSensitiveDetector
{

public:
//! Constructor.
//! The argument is the name of the sensitive detector
GateEmptySD(const G4String& name);
//! Destructor
~GateEmptySD() = default;

//! Method overloading the virtual method Initialize() of G4VSensitiveDetector
void Initialize(G4HCofThisEvent*HCE) override;

//! Implementation of the pure virtual method ProcessHits().
G4bool ProcessHits(G4Step*aStep,G4TouchableHistory*ROhist) override;


private:
GateHitsCollection * crystalHitsCollection; //! Hit collection
G4int collectionID;
G4int HCID;

};




#endif
3 changes: 2 additions & 1 deletion source/digits_hits/src/GateActorManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "GateActorManager.hh"
#include "GateVActor.hh"
#include "GateMultiSensitiveDetector.hh"
#include "GateEmptySD.hh"

//-----------------------------------------------------------------------------
GateActorManager::GateActorManager()
Expand Down Expand Up @@ -311,7 +312,7 @@ void GateActorManager::SetMultiFunctionalDetector(GateVActor * actor, GateVVolum
G4String detectorName2 = "MSD_"+ num.str();

// Remove attached SD by replacing with a deactivated clone SD
G4VSensitiveDetector* replacementSD = volume->GetLogicalVolume()->GetSensitiveDetector()->Clone();
G4VSensitiveDetector* replacementSD = new GateEmptySD(volume->GetLogicalVolume()->GetSensitiveDetector()->GetName());
G4SDManager::GetSDMpointer()->AddNewDetector(replacementSD);
replacementSD->Activate(false);

Expand Down
44 changes: 44 additions & 0 deletions source/digits_hits/src/GateEmptySD.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*----------------------
Copyright (C): OpenGATE Collaboration

This software is distributed under the terms
of the GNU Lesser General Public Licence (LGPL)
See LICENSE.md for further details
----------------------*/

#include "GateEmptySD.hh"
#include "G4HCofThisEvent.hh"
#include "G4TouchableHistory.hh"
#include "G4Step.hh"
#include "G4SDManager.hh"


//------------------------------------------------------------------------------
// Constructor
GateEmptySD::GateEmptySD(const G4String& name)
:G4VSensitiveDetector(name)
{
G4String collName=name+"Collection";
collectionName.insert(collName);


HCID = G4SDManager::GetSDMpointer()->GetCollectionCapacity() ;

}
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// Method overloading the virtual method Initialize() of G4VSensitiveDetector
// Called at the beginning of each event
void GateEmptySD::Initialize(G4HCofThisEvent*HCE)
{
HCE->AddHitsCollection(HCID, nullptr);
}
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// Implementation of the pure virtual method ProcessHits().
G4bool GateEmptySD::ProcessHits(G4Step*aStep, G4TouchableHistory*)
{
return true;
}
Loading