Skip to content

Commit 68f6ac1

Browse files
ChristianTackeGSIkarabowi
authored andcommitted
fix: Do not leak fListFolder in Fair*Source
1 parent 6c73515 commit 68f6ac1

File tree

6 files changed

+36
-34
lines changed

6 files changed

+36
-34
lines changed

fairroot/base/source/FairFileSource.cxx

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "FairFileSource.h"
1717

1818
#include "FairEventHeader.h"
19-
#include "FairLogger.h"
2019
#include "FairMCEventHeader.h"
2120
#include "FairRootManager.h"
2221

@@ -37,8 +36,9 @@
3736
#include <algorithm> // for find
3837
#include <cmath> // fmod
3938
#include <cstdlib> // exit
40-
#include <list> // for _List_iterator, list, etc
41-
#include <map> // multimap
39+
#include <fairlogger/Logger.h>
40+
#include <list> // for _List_iterator, list, etc
41+
#include <map> // multimap
4242
#include <typeinfo>
4343
#include <vector>
4444

@@ -53,7 +53,6 @@ FairFileSource::FairFileSource(TFile* f, const char* Title, UInt_t)
5353
, fRunIdInfoAll()
5454
, fInChain(0)
5555
, fInTree(0)
56-
, fListFolder(new TObjArray(16))
5756
, fCbmout(0)
5857
, fCbmroot(0)
5958
, fSourceIdentifier(0)
@@ -91,7 +90,6 @@ FairFileSource::FairFileSource(const TString* RootFileName, const char* Title, U
9190
, fRunIdInfoAll()
9291
, fInChain(0)
9392
, fInTree(0)
94-
, fListFolder(new TObjArray(16))
9593
, fCbmout(0)
9694
, fCbmroot(0)
9795
, fSourceIdentifier(0)
@@ -130,7 +128,6 @@ FairFileSource::FairFileSource(const TString RootFileName, const char* Title, UI
130128
, fRunIdInfoAll()
131129
, fInChain(0)
132130
, fInTree(0)
133-
, fListFolder(new TObjArray(16))
134131
, fCbmout(0)
135132
, fCbmroot(0)
136133
, fSourceIdentifier(0)
@@ -223,7 +220,7 @@ Bool_t FairFileSource::Init()
223220
}
224221

225222
gROOT->GetListOfBrowsables()->Add(fCbmroot);
226-
fListFolder->Add(fCbmroot);
223+
fListFolder.Add(fCbmroot);
227224

228225
// Store the information about the unique runids in the input file
229226
// together with the filename and the number of events for each runid
@@ -269,8 +266,8 @@ Bool_t FairFileSource::Init()
269266

270267
LOG(debug) << "Entries in this Source " << fNoOfEntries;
271268

272-
for (Int_t i = 0; i < fListFolder->GetEntriesFast(); i++) {
273-
TFolder* fold = static_cast<TFolder*>(fListFolder->At(i));
269+
for (Int_t i = 0; i < fListFolder.GetEntriesFast(); i++) {
270+
TFolder* fold = static_cast<TFolder*>(fListFolder.At(i));
274271
fEvtHeader = static_cast<FairEventHeader*>(fold->FindObjectAny("EventHeader."));
275272
fMCHeader = static_cast<FairMCEventHeader*>(fold->FindObjectAny("MCEventHeader."));
276273
if (fEvtHeader) {
@@ -281,7 +278,7 @@ Bool_t FairFileSource::Init()
281278
}
282279
}
283280

284-
FairRootManager::Instance()->SetListOfFolders(fListFolder);
281+
FairRootManager::Instance()->SetListOfFolders(&fListFolder);
285282

286283
AddFriendsToChain();
287284

@@ -536,7 +533,7 @@ void FairFileSource::CreateNewFriendChain(TString inputFile, TString inputLevel)
536533
}
537534
folderName1 = folderName1 + "_" + inputLevel;
538535
added->SetName(folderName1);
539-
fListFolder->Add(added);
536+
fListFolder.Add(added);
540537

541538
/**Get The list of branches from the friend file and add it to the actual list*/
542539
auto list = f->Get<TList>("BranchList");

fairroot/base/source/FairFileSource.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/********************************************************************************
2-
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
2+
* Copyright (C) 2014-2023 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
33
* *
44
* This software is distributed under the terms of the *
55
* GNU Lesser General Public Licence (LGPL) version 3, *
@@ -24,14 +24,14 @@
2424
#include <TFile.h>
2525
#include <TFolder.h>
2626
#include <TString.h>
27+
#include <TTree.h>
2728
#include <list>
2829
#include <map>
2930
#include <memory>
3031

3132
class FairEventHeader;
3233
class FairFileHeader;
3334
class FairMCEventHeader;
34-
class TTree;
3535

3636
class FairFileSource : public FairFileSourceBase
3737
{
@@ -73,7 +73,6 @@ class FairFileSource : public FairFileSourceBase
7373
}
7474
}
7575
void SetInTree(TTree* tempTree);
76-
TObjArray* GetListOfFolders() { return fListFolder; }
7776
TFolder* GetBranchDescriptionFolder() { return fCbmroot; }
7877
UInt_t GetEntries() { return fNoOfEntries; }
7978

@@ -125,8 +124,6 @@ class FairFileSource : public FairFileSourceBase
125124
TChain* fInChain;
126125
/**Input Tree */
127126
TTree* fInTree;
128-
/** list of folders from all input (and friends) files*/
129-
TObjArray* fListFolder; //!
130127
/**folder structure of output*/
131128
TFolder* fCbmout;
132129
/**folder structure of input*/

fairroot/base/source/FairFileSourceBase.cxx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,17 @@
88

99
#include "FairFileSourceBase.h"
1010

11+
#include "FairRootManager.h"
12+
1113
#include <TObjString.h>
1214
#include <fairlogger/Logger.h>
1315
#include <set>
1416

17+
FairFileSourceBase::~FairFileSourceBase()
18+
{
19+
FairRootManager::Instance()->SetListOfFolders(nullptr);
20+
}
21+
1522
Bool_t FairFileSourceBase::CompareBranchList(TFile* fileHandle, TString inputLevel)
1623
{
1724
// fill a set with the original branch structure

fairroot/base/source/FairFileSourceBase.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "FairSource.h"
1313

1414
#include <TFile.h>
15+
#include <TObjArray.h>
1516
#include <TTree.h>
1617
#include <list>
1718
#include <map>
@@ -21,14 +22,18 @@
2122
*/
2223
class FairFileSourceBase : public FairSource
2324
{
25+
friend class FairFileSource;
26+
friend class FairMixedSource;
27+
2428
public:
25-
~FairFileSourceBase() override = default;
29+
~FairFileSourceBase() override;
2630
void Reset() override {}
2731
Source_Type GetSourceType() override { return kFILE; }
2832
void SetParUnpackers() override {}
2933
Bool_t InitUnpackers() override { return kTRUE; }
3034
Bool_t ReInitUnpackers() override { return kTRUE; }
3135

36+
TObjArray* GetListOfFolders() { return &fListFolder; }
3237
Bool_t CompareBranchList(TFile* fileHandle, TString inputLevel);
3338

3439
protected:
@@ -39,6 +44,10 @@ class FairFileSourceBase : public FairSource
3944

4045
static bool ActivateObjectAnyImpl(TTree* source, void** obj, const std::type_info& info, const char* brname);
4146

47+
private:
48+
/** list of folders from all input (and friends) files*/
49+
TObjArray fListFolder{16}; //!
50+
4251
ClassDefOverride(FairFileSourceBase, 0);
4352
};
4453

fairroot/base/source/FairMixedSource.cxx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "FairMixedSource.h"
1717

1818
#include "FairEventHeader.h"
19-
#include "FairLogger.h"
2019
#include "FairMCEventHeader.h"
2120
#include "FairRootManager.h"
2221

@@ -30,6 +29,7 @@
3029
#include <TRandom.h> // for TRandom, gRandom
3130
#include <TString.h>
3231
#include <cmath> // floor, fmod
32+
#include <fairlogger/Logger.h>
3333

3434
FairMixedSource::FairMixedSource(TFile* f, const char* Title, UInt_t)
3535
: FairFileSourceBase()
@@ -41,7 +41,6 @@ FairMixedSource::FairMixedSource(TFile* f, const char* Title, UInt_t)
4141
, fFriendTypeList()
4242
, fInputLevel()
4343
, fRunIdInfoAll()
44-
, fListFolder(new TObjArray(16))
4544
, fCbmout(0)
4645
, fCbmroot(0)
4746
, fSourceIdentifier(0)
@@ -93,7 +92,6 @@ FairMixedSource::FairMixedSource(const TString* RootFileName, const char* Title,
9392
, fFriendTypeList()
9493
, fInputLevel()
9594
, fRunIdInfoAll()
96-
, fListFolder(new TObjArray(16))
9795
, fCbmout(0)
9896
, fCbmroot(0)
9997
, fSourceIdentifier(0)
@@ -145,7 +143,6 @@ FairMixedSource::FairMixedSource(const TString RootFileName, const Int_t signalI
145143
, fFriendTypeList()
146144
, fInputLevel()
147145
, fRunIdInfoAll()
148-
, fListFolder(new TObjArray(16))
149146
, fCbmout(0)
150147
, fCbmroot(0)
151148
, fSourceIdentifier(0)
@@ -268,7 +265,7 @@ Bool_t FairMixedSource::Init()
268265
}
269266

270267
gROOT->GetListOfBrowsables()->Add(fCbmroot);
271-
fListFolder->Add(fCbmroot);
268+
fListFolder.Add(fCbmroot);
272269

273270
// Store the information about the unique runids in the input file
274271
// together with the filename and the number of events for each runid
@@ -310,8 +307,8 @@ Bool_t FairMixedSource::Init()
310307
fNoOfEntries = fBackgroundChain->GetEntries();
311308
FairRootManager::Instance()->SetInChain(fBackgroundChain, 0);
312309

313-
for (Int_t i = 0; i < fListFolder->GetEntriesFast(); i++) {
314-
TFolder* fold = static_cast<TFolder*>(fListFolder->At(i));
310+
for (Int_t i = 0; i < fListFolder.GetEntriesFast(); i++) {
311+
TFolder* fold = static_cast<TFolder*>(fListFolder.At(i));
315312
fEvtHeader = static_cast<FairEventHeader*>(fold->FindObjectAny("EventHeader."));
316313
fMCHeader = static_cast<FairMCEventHeader*>(fold->FindObjectAny("MCEventHeader."));
317314
if (fEvtHeader) {
@@ -321,7 +318,7 @@ Bool_t FairMixedSource::Init()
321318
ActivateObject(reinterpret_cast<TObject**>(&fMCHeader), "MCEventHeader.");
322319
}
323320
}
324-
FairRootManager::Instance()->SetListOfFolders(fListFolder);
321+
FairRootManager::Instance()->SetListOfFolders(&fListFolder);
325322

326323
LOG(info) << "Entries in this Source " << fNoOfEntries << " ------------";
327324
return kTRUE;
@@ -527,7 +524,7 @@ Bool_t FairMixedSource::OpenBackgroundChain()
527524
}
528525

529526
gROOT->GetListOfBrowsables()->Add(fCbmroot);
530-
fListFolder->Add(fCbmroot);
527+
fListFolder.Add(fCbmroot);
531528
return kTRUE;
532529
}
533530

fairroot/base/source/FairMixedSource.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/********************************************************************************
2-
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
2+
* Copyright (C) 2014-2023 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
33
* *
44
* This software is distributed under the terms of the *
55
* GNU Lesser General Public Licence (LGPL) version 3, *
@@ -22,17 +22,15 @@
2222
#include <TChain.h>
2323
#include <TF1.h>
2424
#include <TFile.h>
25+
#include <TFolder.h>
26+
#include <TString.h>
2527
#include <list>
2628
#include <map>
2729
#include <memory>
2830

2931
class FairEventHeader;
3032
class FairFileHeader;
3133
class FairMCEventHeader;
32-
class TString;
33-
class TFolder;
34-
class TObject;
35-
3634
class FairRootManager;
3735

3836
class FairMixedSource : public FairFileSourceBase
@@ -111,7 +109,6 @@ class FairMixedSource : public FairFileSourceBase
111109
void SetFileHeader(FairFileHeader* f) { fFileHeader = f; }
112110
Double_t GetEventTime();
113111

114-
TObjArray* GetListOfFolders() { return fListFolder; }
115112
TFolder* GetBranchDescriptionFolder() { return fCbmroot; }
116113
UInt_t GetEntries() { return fNoOfEntries; }
117114

@@ -143,8 +140,6 @@ class FairMixedSource : public FairFileSourceBase
143140
std::map<TString, TChain*> fFriendTypeList; //!
144141
std::list<TString> fInputLevel; //!
145142
std::map<TString, std::multimap<TString, TArrayI>> fRunIdInfoAll; //!
146-
/** list of folders from all input (and friends) files*/
147-
TObjArray* fListFolder; //!
148143
/**folder structure of output*/
149144
TFolder* fCbmout;
150145
/**folder structure of input*/

0 commit comments

Comments
 (0)