~c-e-pidcott/maus/devel

« back to all changes in this revision

Viewing changes to src/common_cpp/Globals/GlobalsManager.cc

  • Committer: Chris Rogers
  • Date: 2012-10-03 07:19:33 UTC
  • mfrom: (659.1.40 release-candidate)
  • Revision ID: chris.rogers@stfc.ac.uk-20121003071933-kgrhvl1ec6w2jmug
Tags: MAUS-v0.3.3
MAUS-v0.3.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
#include "src/legacy/Interface/Squeal.hh"
19
19
#include "src/legacy/Interface/Squeak.hh"
20
20
#include "src/legacy/Interface/MICERun.hh"
21
 
#include "src/legacy/Interface/MiceMaterials.hh"
22
21
#include "src/legacy/Config/MiceModule.hh"
23
22
 
24
 
 
25
23
#include "src/common_cpp/Utils/CppErrorHandler.hh"
26
24
#include "src/common_cpp/Utils/RunActionManager.hh"
27
25
#include "src/common_cpp/Utils/Globals.hh"
48
46
    // initialisation. Beware!
49
47
    Globals::_process = process;
50
48
    try {
51
 
 
 
49
        std::cerr << "Globals manager" << std::endl;
52
50
        Json::Value config = JsonWrapper::StringToJson(json_datacards);
53
51
        process->_configuration_cards = new Json::Value(config);
54
52
        process->_legacy_mice_run = MICERun::getInstance();
60
58
        // we set up logging but for now leave singleton-like access
61
59
        // meaning that we can't reinitialise the logging
62
60
        Logging::setStandardOutputs(verbose_level);
 
61
        Logging::setOutputs(verbose_level);
63
62
        // we set up CppErrorHandler but for now leave singleton-like access
64
63
        // meaning that we can't reinitialise the error handler
65
64
        process->_error_handler = CppErrorHandler::getInstance();
73
72
           (*process->_configuration_cards, "simulation_geometry_filename",
74
73
            JsonWrapper::stringValue).asString();
75
74
        process->_mc_mods = new MiceModule(sim_file);
76
 
        process->_recon_mods = new MiceModule(rec_file);
 
75
        if (sim_file == rec_file) {
 
76
            process->_recon_mods = process->_mc_mods;
 
77
        } else {
 
78
            process->_recon_mods = new MiceModule(rec_file);
 
79
        }
77
80
        process->_legacy_mice_run->miceModule = process->_mc_mods;
78
 
        process->_mice_materials = new MiceMaterials();  // delete
79
 
        MICERun::getInstance()->miceMaterials = process->_mice_materials;
80
 
        fillMaterials(*MICERun::getInstance());
81
81
        process->_maus_geant4_manager = MAUSGeant4Manager::GetInstance();
82
 
        process->_field_constructor = MICERun::getInstance()->btFieldConstructor;
83
 
        process->_field_constructor->Print(Squeak::mout(Squeak::info));
 
82
        process->_mc_field_constructor = process->_maus_geant4_manager->GetField();
 
83
        process->_maus_geant4_manager->SetPhases();
 
84
        process->_mc_field_constructor->Print(Squeak::mout(Squeak::info));
 
85
        if (process->_recon_mods == process->_mc_mods) {
 
86
            process->_recon_field_constructor = process->_mc_field_constructor;
 
87
        } else {
 
88
            process->_recon_field_constructor =
 
89
                                 new BTFieldConstructor(process->_recon_mods);
 
90
        }
84
91
    } catch(Squeal squee) {
85
92
        Globals::_process = NULL;
86
93
        delete process;
93
100
    // (it's legacy anyway)
94
101
    if (Globals::_process == NULL) {
95
102
        throw(Squeal(Squeal::recoverable,
96
 
             "Attempt to delete Globals when it was already initialised",
 
103
             "Attempt to delete Globals when it was not initialised",
97
104
                      "GlobalsManager::DeleteGlobals"));
98
105
    }
99
 
    if (Globals::_process->_mice_materials != NULL) {
100
 
        delete Globals::_process->_mice_materials;
101
 
    }
102
106
    if (Globals::_process->_maus_geant4_manager != NULL) {
103
107
        // delete Globals::_process->_maus_geant4_manager;
104
108
    }
105
 
    if (Globals::_process->_field_constructor != NULL) {
 
109
    if (Globals::_process->_mc_field_constructor != NULL) {
106
110
        // delete Globals::_process->_field_constructor;
107
111
    }
108
 
    if (Globals::_process->_recon_mods != NULL) {
 
112
    if (Globals::GetInstance()->_recon_mods != NULL) {
109
113
        delete Globals::_process->_recon_mods;
 
114
        if (Globals::_process->_recon_mods == Globals::_process->_mc_mods) {
 
115
            Globals::_process->_mc_mods = NULL;
 
116
        }
 
117
        Globals::_process->_recon_mods = NULL;
110
118
    }
111
 
    if (Globals::_process->_mc_mods != NULL) {
 
119
    if (Globals::GetInstance()->_mc_mods != NULL) {
112
120
        delete Globals::_process->_mc_mods;
 
121
        Globals::_process->_mc_mods = NULL;
113
122
    }
114
123
    if (Globals::_process->_run_action_manager != NULL) {
115
124
        delete Globals::_process->_run_action_manager;
135
144
 
136
145
void GlobalsManager::SetReconstructionMiceModules
137
146
                                                      (MiceModule* recon_mods) {
138
 
    if (Globals::GetInstance()->_recon_mods != NULL) {
 
147
    if (Globals::GetInstance()->_recon_mods != NULL &&
 
148
      Globals::GetInstance()->_mc_mods != Globals::GetInstance()->_recon_mods) {
139
149
        delete Globals::_process->_recon_mods;
140
150
    }
141
151
    Globals:: _process->_recon_mods = recon_mods;
142
152
}
143
153
 
144
154
void GlobalsManager::SetMonteCarloMiceModules(MiceModule* mc_mods) {
145
 
    if (Globals::GetInstance()->_mc_mods != NULL) {
 
155
    if (Globals::GetInstance()->_mc_mods != NULL &&
 
156
      Globals::GetInstance()->_mc_mods != Globals::GetInstance()->_recon_mods) {
146
157
        delete Globals::_process->_mc_mods;
147
158
    }
148
159
    Globals::_process->_mc_mods = mc_mods;