Skip to content

Commit 6adb758

Browse files
ChristianTackeGSIdennisklein
authored andcommitted
docs: Document the "singleton" like pattern
Co-authored-by: Dennis Klein @dennisklein
1 parent c5d2faa commit 6adb758

15 files changed

Lines changed: 82 additions & 54 deletions

doxygen/singleton.dox

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* \weakgroup fairroot_singleton FairRoot/ROOT Style "singleton"-like Objects
3+
4+
These classes are currently using a singleton-like pattern that is
5+
NOT [the classic textbook pattern](https://en.wikipedia.org/wiki/Singleton_pattern).
6+
7+
This pattern is discouraged for new code!
8+
Also the existing code utilising it is slowly getting deprecated
9+
in favour of code not relying on singleton like behaviour.
10+
11+
Attributes / Design:
12+
13+
- There can only be one or zero instances per process (or thread for some).
14+
Note that zero is explicitly allowed.
15+
16+
Some classes enforce this at runtime, some don't.
17+
18+
- Global access via the static `::Instance()` function on the class
19+
returns a pointer to that object or `nullptr` if the instance does
20+
not exist. It DOES NOT lazily create the "singleton" instance (see
21+
also below).
22+
23+
Note: This function is likely getting deprecated in the process
24+
of getting away from this behaviour.
25+
26+
- Other code is responsible for creating (thus owning) and
27+
destructing the object. The object can be created on the stack,
28+
on the heap or even as a member variable of another class
29+
(constructors are public). That code can either be internal
30+
FairRoot code or code by the user (like with the \ref FairRun
31+
classes).
32+
33+
*/

fairroot/base/field/FairFieldFactory.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
class FairField;
1919

20+
/**
21+
* \ingroup base_sim fairroot_singleton
22+
*/
2023
class FairFieldFactory
2124
{
2225
public:

fairroot/base/sim/FairGeaneApplication.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/********************************************************************************
2-
* Copyright (C) 2014-2022 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, *
@@ -21,11 +21,11 @@ class FairField;
2121

2222
/**
2323
* The Main Application for GEANE
24+
* \ingroup base_sim fairroot_singleton
2425
* @author M. Al-Turany
2526
* @version 0.1
2627
* @since 10.11.10
2728
*/
28-
2929
class FairGeaneApplication : public TVirtualMCApplication
3030
{
3131
public:

fairroot/base/sim/FairMCApplication.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ enum class FairMCApplicationState
5353

5454
/**
5555
* The Main Application ( Interface to MonteCarlo application )
56+
* \ingroup base_sim fairroot_singleton
5657
* @author M. Al-Turany, D. Bertini
5758
* @version 0.1
5859
* @since 12.01.04
5960
*/
60-
6161
class FairMCApplication : public TVirtualMCApplication
6262
{
6363
public:
@@ -80,8 +80,7 @@ class FairMCApplication : public TVirtualMCApplication
8080
/** default destructor
8181
*/
8282
~FairMCApplication() override;
83-
/** Singelton instance
84-
*/
83+
8584
static FairMCApplication* Instance();
8685
virtual void AddDecayModes();
8786
/** Add user defined particles (optional) */

fairroot/base/steer/FairLinkManager.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
#include <TObject.h> // for TObject
1414
#include <set> // for set of branch types to ignore
1515

16+
/**
17+
* \ingroup base_steer fairroot_singleton
18+
*/
1619
class FairLinkManager : public TObject
1720
{
1821
public:
@@ -21,7 +24,6 @@ class FairLinkManager : public TObject
2124
/**dtor*/
2225
~FairLinkManager() override;
2326

24-
/** static access method */
2527
static FairLinkManager* Instance();
2628
virtual void AddIgnoreType(Int_t type); ///< Adds a BranchId (Type) to which links are not included in the link
2729
///< list. Either ignore types or include types can be given.

fairroot/base/steer/FairRadGridManager.h

Lines changed: 2 additions & 2 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,8 +24,8 @@ class TClonesArray;
2424

2525
/**
2626
* @class FairRadGridManager
27+
* \ingroup base_steer fairroot_singleton
2728
*/
28-
2929
class FairRadGridManager
3030
{
3131
public:

fairroot/base/steer/FairRadLenManager.h

Lines changed: 2 additions & 2 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, *
@@ -20,8 +20,8 @@ class TVirtualMC;
2020

2121
/**
2222
* @class FairRadLenManager
23+
* \ingroup base_steer fairroot_singleton
2324
*/
24-
2525
class FairRadLenManager
2626
{
2727
public:

fairroot/base/steer/FairRadMapManager.h

Lines changed: 2 additions & 2 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, *
@@ -20,8 +20,8 @@ class TVirtualMC;
2020

2121
/**
2222
* @class FairRadMapManager
23+
* \ingroup base_steer fairroot_singleton
2324
*/
24-
2525
class FairRadMapManager
2626
{
2727
public:

fairroot/base/steer/FairRun.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "FairSource.h"
1616

1717
#include <Rtypes.h> // for Int_t, Bool_t, etc
18+
#include <TFile.h> //
1819
#include <TMCtls.h> // for multi-threading
1920
#include <TNamed.h> // for TNamed
2021
#include <TString.h>
@@ -28,17 +29,15 @@ class FairRootManager;
2829
class FairRuntimeDb;
2930
class FairSink;
3031
class FairTask;
31-
class TFile;
3232
class FairField;
33-
class TGeoHMatrix;
3433

3534
/**
3635
* Configure the Simuation or Analysis
36+
* \ingroup base_steer fairroot_singleton
3737
* @author M. Al-Turany D. Bertini
3838
* @version 0.1
3939
* @since 12.01.04
4040
*/
41-
4241
class FairRun : public TNamed
4342
{
4443
friend class FairMCApplication;
@@ -52,9 +51,7 @@ class FairRun : public TNamed
5251
* default dtor
5352
*/
5453
~FairRun() override;
55-
/**
56-
* static instance
57-
*/
54+
5855
static FairRun* Instance();
5956
/**
6057
* Add a FAIRTask to the simulation or analysis

fairroot/base/steer/FairRunAna.h

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,27 @@
88
#ifndef FAIRRUNANA_H
99
#define FAIRRUNANA_H
1010

11-
/**
12-
* Configure and manage the Analysis
13-
* @author M. Al-Turany D. Bertini
14-
* @version 0.1
15-
* @since 28.02.05
16-
*/
17-
1811
#include "FairRootManager.h" // for FairRootManager
1912
#include "FairRun.h" // for FairRun
2013
#include "FairRunInfo.h" // for FairRunInfo
2114

2215
#include <Rtypes.h> // for Bool_t, Double_t, UInt_t, etc
16+
#include <TF1.h> //
2317
#include <TString.h> // for TString
2418

2519
class FairField;
26-
class TF1;
27-
class TFile;
28-
29-
class FairSource;
3020
class FairFileSource;
3121
class FairMixedSource;
3222

23+
/**
24+
* Configure and manage the Analysis
25+
* \ingroup base_steer fairroot_singleton
26+
* @author M. Al-Turany D. Bertini
27+
* @version 0.1
28+
* @since 28.02.05
29+
*/
3330
class FairRunAna : public FairRun
3431
{
35-
3632
public:
3733
static FairRunAna* Instance();
3834
~FairRunAna() override;
@@ -86,9 +82,9 @@ class FairRunAna : public FairRun
8682
Bool_t IsTimeStamp() { return fTimeStamps; }
8783

8884
/** Set the flag for proccessing lmd files */
89-
void StopProcessingLMD(void) { fFinishProcessingLMDFile = kTRUE; }
85+
void StopProcessingLMD() { fFinishProcessingLMDFile = kTRUE; }
9086
/** Get the status of lmd file proccessing */
91-
Bool_t GetLMDProcessingStatus(void) { return fFinishProcessingLMDFile; }
87+
Bool_t GetLMDProcessingStatus() { return fFinishProcessingLMDFile; }
9288

9389
protected:
9490
/**

0 commit comments

Comments
 (0)