~ryan-bayes/maus/1432

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/* This file is part of MAUS: http://micewww.pp.rl.ac.uk/projects/maus
 *
 * MAUS is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * MAUS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with MAUS.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include <sstream>

#include "Utils/Exception.hh"
#include "src/common_cpp/Utils/Globals.hh"
#include "src/common_cpp/Utils/VersionNumber.hh"
#include "src/legacy/Interface/STLUtils.hh"
#include "Geant4/G4PVPlacement.hh"

namespace MAUS {

Globals* Globals::_process = NULL;

Globals* Globals::GetInstance() {
    if (_process != NULL) {
        return _process;
    } else {
        // watch out here, error handler not initialised(!)
        throw(Exception(Exception::recoverable,
                     std::string("Attempt to get Globals ")+
                          "instance when it has not been initialised",
                          "Globals::GetInstance()"));
    }
    return NULL; // appease gcc
}

Globals::~Globals() {
}

bool Globals::HasInstance() {
    return _process != NULL;
}

Globals::Globals()
  : _configuration_cards(NULL), _legacy_mice_run(NULL), _error_handler(NULL),
    _legacy_cards(NULL), _run_action_manager(NULL), _mc_mods(NULL),
    _recon_mods(NULL), _mc_field_constructor(NULL),
    _recon_field_constructor(NULL), _maus_geant4_manager(NULL) {
}

// in all the below I call GetInstance() to check that _process is initialised
RunActionManager* Globals::GetRunActionManager() {
    return GetInstance()->_run_action_manager;
}

CppErrorHandler* Globals::GetErrorHandler() {
    return GetInstance()->_error_handler;
}

Json::Value* Globals::GetConfigurationCards() {
    return GetInstance()->_configuration_cards;
}

dataCards* Globals::GetLegacyCards() {
    return GetInstance()->_legacy_cards;
}

BTFieldConstructor* Globals::GetMCFieldConstructor() {
    return GetInstance()->_mc_field_constructor;
}

BTFieldConstructor* Globals::GetReconFieldConstructor() {
    return GetInstance()->_recon_field_constructor;
}

MAUSGeant4Manager* Globals::GetGeant4Manager() {
    return GetInstance()->_maus_geant4_manager;
}

MiceModule* Globals::GetMonteCarloMiceModules() {
    return GetInstance()->_mc_mods;
}

MiceModule* Globals::GetReconstructionMiceModules() {
    return GetInstance()->_recon_mods;
}

GeometryNavigator* Globals::GetMCGeometryNavigator() {
    return GetInstance()->_mc_geometry_navigator;
}

std::string Globals::GetVersionNumberString() {
    std::string version = STLUtils::ToString(MAUS_VERSION_NUMBER_X)+"."+
                          STLUtils::ToString(MAUS_VERSION_NUMBER_Y)+"."+
                          STLUtils::ToString(MAUS_VERSION_NUMBER_Z);
    return version;
}

}  // namespace MAUS