Skip to content

Commit

Permalink
fix: Multiple Leaks around FairGeoLoader
Browse files Browse the repository at this point in the history
Also some small other stylistic changes
  • Loading branch information
ChristianTackeGSI committed Feb 22, 2024
1 parent cbe100c commit c598da4
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 39 deletions.
13 changes: 8 additions & 5 deletions fairroot/base/steer/FairRunSim.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,11 @@ void FairRunSim::Init()
// fOutFile=fRootManager->OpenOutFile(fOutname);
LOG(info) << "============== FairRunSim: Initialising simulation run ==============";

auto loader = new FairGeoLoader(fLoaderName.Data(), "Geo Loader");
FairGeoInterface* GeoInterFace = loader->getGeoInterface();
GeoInterFace->SetNoOfSets(ListOfModules->GetEntries());
GeoInterFace->setMediaFile(MatFname.Data());
GeoInterFace->readMedia();
fGeoLoader = std::make_unique<FairGeoLoader>(fLoaderName.Data(), "Geo Loader");
FairGeoInterface* geointerFace = fGeoLoader->getGeoInterface();
geointerFace->SetNoOfSets(ListOfModules->GetEntries());
geointerFace->setMediaFile(MatFname.Data());
geointerFace->readMedia();

// gSystem->cd(flout.Data());

Expand Down Expand Up @@ -389,6 +389,9 @@ void FairRunSim::ls(Option_t* option) const
{
FairRun::ls(option);
TROOT::IncreaseDirLevel();
if (fGeoLoader) {
fGeoLoader->ls(option);
}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
if (fGen) {
Expand Down
3 changes: 3 additions & 0 deletions fairroot/base/steer/FairRunSim.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <utility>

class FairField;
class FairGeoLoader;
class FairMCEventHeader;
class FairMesh;
class FairModule;
Expand Down Expand Up @@ -223,6 +224,8 @@ class FairRunSim : public FairRun

bool fWasMT{false}; //! /** Actual MT mode used */

std::unique_ptr<FairGeoLoader> fGeoLoader; //!

protected:
Int_t count{0}; //!< Internal counter
FairMCApplication* fApp{nullptr}; //!< Main VMC application
Expand Down
13 changes: 3 additions & 10 deletions fairroot/geobase/FairGeoLoader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,40 +31,33 @@ FairGeoLoader* FairGeoLoader::Instance() { return fgInstance; }

FairGeoLoader::FairGeoLoader()
: TNamed()
, fInterface(NULL)
, fGeoBuilder(NULL)
{
fgInstance = this;
}

FairGeoLoader::FairGeoLoader(const char* Name, const char* title)
: TNamed(Name, title)
, fInterface(NULL)
, fGeoBuilder(NULL)
{
if (fgInstance) {
Fatal("FairGeoLoader", "Singleton instance already exists.");
return;
}
fgInstance = this;
fInterface = new FairGeoInterface;
if (strncmp(Name, "TGeo", 4) == 0) {
TGeoManager* geom = new TGeoManager("FAIRGeom", "FAIR geometry");
fGeoBuilder = new FairGeoRootBuilder("TGeo builder", "geometry builder");
(static_cast<FairGeoRootBuilder*>(fGeoBuilder))->setGeoManager(geom);
auto geom = std::make_unique<TGeoManager>("FAIRGeom", "FAIR geometry");
fGeoBuilder = std::make_unique<FairGeoRootBuilder>("TGeo builder", "geometry builder", std::move(geom));
} else if (strncmp(Name, "G3Native", 8) == 0) {
cout << "-I- FairGeoLoader() : Native G3 Geometry is used: This option is not supported any more!" << endl;
exit(0);
// gGeoManager = NULL;
// fGeoBuilder=new FairGeoG3Builder("G3 builder","geometry builder");
}

fInterface->setGeomBuilder(fGeoBuilder);
fInterface.setGeomBuilder(fGeoBuilder.get());
}

FairGeoLoader::~FairGeoLoader()
{
delete fInterface;
if (fgInstance == this) {
// Do not point to a destructed object!
fgInstance = nullptr;
Expand Down
24 changes: 15 additions & 9 deletions fairroot/geobase/FairGeoLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,40 @@
#ifndef FairGeoLOADER_H
#define FairGeoLOADER_H

#include "FairGeoInterface.h"

#include <Rtypes.h> // for FairGeoLoader::Class, etc
#include <TNamed.h> // for TNamed
#include <memory>

class FairGeoInterface;
class FairGeoBuilder;
/**New Geometry Loader, this loader handel the Hades geometry description
* @author Ilse koenig
* @author M. Al-Turany*/

/**
* New Geometry Loader, this loader handel the Hades geometry description
* \ingroup geobase fairroot_singleton
* @author Ilse koenig
* @author M. Al-Turany
*/
class FairGeoLoader : public TNamed
{
public:
FairGeoLoader(const char* Name, const char* title);
FairGeoLoader();
~FairGeoLoader() override;
FairGeoInterface* getGeoInterface() { return fInterface; }
FairGeoBuilder* getGeoBuilder() { return fGeoBuilder; }
FairGeoInterface* getGeoInterface() { return &fInterface; }
FairGeoBuilder* getGeoBuilder() { return fGeoBuilder.get(); }
/** static access method*/
static FairGeoLoader* Instance();

private:
FairGeoLoader(const FairGeoLoader&);
FairGeoLoader& operator=(const FairGeoLoader&);
static FairGeoLoader* fgInstance; //! /**Singleton instance*/
FairGeoInterface* fInterface; //! /** Hades Geometry Interface*/
FairGeoBuilder* fGeoBuilder; //! /**Geometry builder*/

ClassDefOverride(FairGeoLoader, 1);
FairGeoInterface fInterface{}; //!< Hades Geometry Interface
std::unique_ptr<FairGeoBuilder> fGeoBuilder; //!< Geometry builder

ClassDefOverride(FairGeoLoader, 0);
};

#endif
16 changes: 7 additions & 9 deletions fairroot/geobase/FairGeoRootBuilder.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include "FairGeoVector.h" // for FairGeoVector

#include <TArrayD.h> // for TArrayD
#include <TGeoManager.h> // for TGeoManager
#include <TGeoMaterial.h> // for TGeoMixture, TGeoMaterial
#include <TGeoMatrix.h> // for TGeoCombiTrans, etc
#include <TGeoMedium.h> // for TGeoMedium
Expand All @@ -34,17 +33,16 @@

FairGeoRootBuilder::FairGeoRootBuilder()
: FairGeoBuilder()
, geoManager(nullptr)
{
// Default constructor
}
{}

FairGeoRootBuilder::FairGeoRootBuilder(const char* name, const char* title)
: FairGeoBuilder(name, title)
, geoManager(nullptr)
{
// Constructor
}
{}

FairGeoRootBuilder::FairGeoRootBuilder(const char* name, const char* title, std::unique_ptr<TGeoManager> geom)
: FairGeoBuilder(name, title)
, geoManager(std::move(geom))
{}

Bool_t FairGeoRootBuilder::createNode(FairGeoNode* volu, Int_t hadFormat)
{
Expand Down
11 changes: 5 additions & 6 deletions fairroot/geobase/FairGeoRootBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,29 @@

#include "FairGeoBuilder.h" // for FairGeoBuilder

#include <Rtypes.h> // for FairGeoRootBuilder::Class, etc
#include <TGeoManager.h>

class FairGeoMedium;
class FairGeoNode;
class TGeoManager;

/**
* class to create geometry in ROOT
* \ingroup geobase
* @author M. Al-Turany
*/
class FairGeoRootBuilder : public FairGeoBuilder
{
private:
FairGeoRootBuilder(const FairGeoRootBuilder&);
FairGeoRootBuilder& operator=(const FairGeoRootBuilder&);

protected:
TGeoManager* geoManager; // ROOT geometry manager
std::unique_ptr<TGeoManager> geoManager; //!< ROOT geometry manager

public:
FairGeoRootBuilder();
FairGeoRootBuilder(const char*, const char*);
FairGeoRootBuilder(const char*, const char*, std::unique_ptr<TGeoManager>);
~FairGeoRootBuilder() override = default;
void setGeoManager(TGeoManager* me) { geoManager = me; }
[[deprecated]] void setGeoManager(TGeoManager* me) { geoManager.reset(me); }
Bool_t createNode(FairGeoNode*, Int_t hadFormat = 0) override;
Int_t createMedium(FairGeoMedium*) override;
void finalize() override;
Expand Down

0 comments on commit c598da4

Please sign in to comment.