Skip to content

Commit 23b1c99

Browse files
ChristianTackeGSIdennisklein
authored andcommitted
Refactor: Base Class for Fair{File,Mixed}Source
Introduce a new common base class for Fair{File,Mixed}Source. Both classes share a lot of common code. The new base class will contain all the common code. Start simple by moving fCheckInputBranches there. This also introduces proper deallocation for it.
1 parent f9f1648 commit 23b1c99

8 files changed

Lines changed: 66 additions & 18 deletions

base/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ set(sources
5555
sink/FairRootFileSink.cxx
5656
sink/FairSink.cxx
5757

58+
source/FairFileSourceBase.cxx
5859
source/FairFileSource.cxx
5960
source/FairMixedSource.cxx
6061
source/FairOnlineSource.cxx

base/FairLinkDef.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474

7575
#pragma link C++ class FairRunOnline;
7676
#pragma link C++ class FairSource;
77+
#pragma link C++ class FairFileSourceBase;
7778
#pragma link C++ class FairFileSource;
7879
#pragma link C++ class FairMixedSource;
7980
#pragma link C++ class FairOnlineSource;

base/source/FairFileSource.cxx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,13 @@
4747
using std::set;
4848

4949
FairFileSource::FairFileSource(TFile* f, const char* Title, UInt_t)
50-
: FairSource()
50+
: FairFileSourceBase()
5151
, fInputTitle(Title)
5252
, fRootFile(f)
5353
, fCurrentEntryNr(0)
5454
, fFriendFileList()
5555
, fInputChainList()
5656
, fFriendTypeList()
57-
, fCheckInputBranches()
5857
, fInputLevel()
5958
, fRunIdInfoAll()
6059
, fInChain(0)
@@ -88,14 +87,13 @@ FairFileSource::FairFileSource(TFile* f, const char* Title, UInt_t)
8887
}
8988

9089
FairFileSource::FairFileSource(const TString* RootFileName, const char* Title, UInt_t)
91-
: FairSource()
90+
: FairFileSourceBase()
9291
, fInputTitle(Title)
9392
, fRootFile(0)
9493
, fCurrentEntryNr(0)
9594
, fFriendFileList()
9695
, fInputChainList()
9796
, fFriendTypeList()
98-
, fCheckInputBranches()
9997
, fInputLevel()
10098
, fRunIdInfoAll()
10199
, fInChain(0)
@@ -130,14 +128,13 @@ FairFileSource::FairFileSource(const TString* RootFileName, const char* Title, U
130128
}
131129

132130
FairFileSource::FairFileSource(const TString RootFileName, const char* Title, UInt_t)
133-
: FairSource()
131+
: FairFileSourceBase()
134132
, fInputTitle(Title)
135133
, fRootFile(0)
136134
, fCurrentEntryNr(0)
137135
, fFriendFileList()
138136
, fInputChainList()
139137
, fFriendTypeList()
140-
, fCheckInputBranches()
141138
, fInputLevel()
142139
, fRunIdInfoAll()
143140
, fInChain(0)

base/source/FairFileSource.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#ifndef __FAIRROOT__FairFileSource__
1717
#define __FAIRROOT__FairFileSource__
1818

19-
#include "FairSource.h"
19+
#include "FairFileSourceBase.h"
2020

2121
#include <TArrayI.h>
2222
#include <TChain.h>
@@ -34,7 +34,7 @@ class FairMCEventHeader;
3434
class FairRuntimeDb;
3535
class TTree;
3636

37-
class FairFileSource : public FairSource
37+
class FairFileSource : public FairFileSourceBase
3838
{
3939
public:
4040
FairFileSource(TFile* f, const char* Title = "InputRootFile", UInt_t identifier = 0);
@@ -133,7 +133,6 @@ class FairFileSource : public FairSource
133133
std::list<TString> fFriendFileList; //!
134134
std::list<TString> fInputChainList; //!
135135
std::map<TString, TChain*> fFriendTypeList; //!
136-
std::map<TString, std::list<TString>*> fCheckInputBranches; //!
137136
std::list<TString> fInputLevel; //!
138137
std::map<TString, std::multimap<TString, TArrayI>> fRunIdInfoAll; //!
139138
/**Input Chain */

base/source/FairFileSourceBase.cxx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/********************************************************************************
2+
* Copyright (C) 2022 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3+
* *
4+
* This software is distributed under the terms of the *
5+
* GNU Lesser General Public Licence (LGPL) version 3, *
6+
* copied verbatim in the file "LICENSE" *
7+
********************************************************************************/
8+
9+
#include "FairFileSourceBase.h"
10+
11+
#include <algorithm> // for std::for_each
12+
13+
ClassImp(FairFileSourceBase);
14+
15+
FairFileSourceBase::~FairFileSourceBase()
16+
{
17+
std::for_each(fCheckInputBranches.begin(), fCheckInputBranches.end(), [](auto el) {
18+
delete el.second;
19+
el.second = nullptr;
20+
});
21+
fCheckInputBranches.clear();
22+
}

base/source/FairFileSourceBase.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/********************************************************************************
2+
* Copyright (C) 2022 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3+
* *
4+
* This software is distributed under the terms of the *
5+
* GNU Lesser General Public Licence (LGPL) version 3, *
6+
* copied verbatim in the file "LICENSE" *
7+
********************************************************************************/
8+
9+
#ifndef __FAIRROOT__FairFileSourceBase__
10+
#define __FAIRROOT__FairFileSourceBase__
11+
12+
#include "FairSource.h"
13+
14+
#include <list>
15+
#include <map>
16+
17+
/**
18+
* \brief Internal base class for FairFileSource and FairMixedSource
19+
*/
20+
class FairFileSourceBase : public FairSource
21+
{
22+
protected:
23+
FairFileSourceBase()
24+
: FairSource(){};
25+
virtual ~FairFileSourceBase();
26+
27+
std::map<TString, std::list<TString>*> fCheckInputBranches{}; //!
28+
29+
ClassDefOverride(FairFileSourceBase, 0);
30+
};
31+
32+
#endif

base/source/FairMixedSource.cxx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,13 @@ using std::map;
3838
using std::set;
3939

4040
FairMixedSource::FairMixedSource(TFile* f, const char* Title, UInt_t)
41-
: FairSource()
41+
: FairFileSourceBase()
4242
, fRootManager(0)
4343
, fInputTitle(Title)
4444
, fRootFile(f)
4545
, fFriendFileList()
4646
, fInputChainList()
4747
, fFriendTypeList()
48-
, fCheckInputBranches()
4948
, fInputLevel()
5049
, fRunIdInfoAll()
5150
, fListFolder(new TObjArray(16))
@@ -92,14 +91,13 @@ FairMixedSource::FairMixedSource(TFile* f, const char* Title, UInt_t)
9291
}
9392

9493
FairMixedSource::FairMixedSource(const TString* RootFileName, const char* Title, UInt_t)
95-
: FairSource()
94+
: FairFileSourceBase()
9695
, fRootManager(0)
9796
, fInputTitle(Title)
9897
, fRootFile(0)
9998
, fFriendFileList()
10099
, fInputChainList()
101100
, fFriendTypeList()
102-
, fCheckInputBranches()
103101
, fInputLevel()
104102
, fRunIdInfoAll()
105103
, fListFolder(new TObjArray(16))
@@ -146,14 +144,13 @@ FairMixedSource::FairMixedSource(const TString* RootFileName, const char* Title,
146144
}
147145

148146
FairMixedSource::FairMixedSource(const TString RootFileName, const Int_t signalId, const char* Title, UInt_t)
149-
: FairSource()
147+
: FairFileSourceBase()
150148
, fRootManager(0)
151149
, fInputTitle(Title)
152150
, fRootFile(0)
153151
, fFriendFileList()
154152
, fInputChainList()
155153
, fFriendTypeList()
156-
, fCheckInputBranches()
157154
, fInputLevel()
158155
, fRunIdInfoAll()
159156
, fListFolder(new TObjArray(16))

base/source/FairMixedSource.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#ifndef __FAIRROOT__FairMixedSource__
1717
#define __FAIRROOT__FairMixedSource__
1818

19-
#include "FairSource.h"
19+
#include "FairFileSourceBase.h"
2020

2121
#include <TArrayI.h>
2222
#include <TChain.h>
@@ -36,7 +36,7 @@ class TObject;
3636

3737
class FairRootManager;
3838

39-
class FairMixedSource : public FairSource
39+
class FairMixedSource : public FairFileSourceBase
4040
{
4141
public:
4242
FairMixedSource(TFile* f, const char* Title = "InputRootFile", UInt_t identifier = 0);
@@ -154,7 +154,6 @@ class FairMixedSource : public FairSource
154154
std::list<TString> fFriendFileList; //!
155155
std::list<TString> fInputChainList; //!
156156
std::map<TString, TChain*> fFriendTypeList; //!
157-
std::map<TString, std::list<TString>*> fCheckInputBranches; //!
158157
std::list<TString> fInputLevel; //!
159158
std::map<TString, std::multimap<TString, TArrayI>> fRunIdInfoAll; //!
160159
/** list of folders from all input (and friends) files*/

0 commit comments

Comments
 (0)