18
18
#include <Python.h>
23
#include "Utils/Exception.hh"
25
#include "src/common_cpp/Utils/Globals.hh"
26
#include "src/common_cpp/Utils/JsonWrapper.hh"
27
#include "src/common_cpp/Utils/CppErrorHandler.hh"
22
#include "src/common_cpp/Simulation/MAUSGeant4Manager.hh"
23
#include "src/common_cpp/API/PyWrapMapBase.hh"
28
24
#include "src/common_cpp/Simulation/MAUSVisManager.hh"
29
#include "src/common_cpp/Globals/GlobalsManager.hh"
31
25
#include "src/map/MapCppSimulation/MapCppSimulation.hh"
35
bool MapCppSimulation::birth(std::string argJsonConfigDocument) {
28
std::string class_docstring =
29
std::string("MapCppSimulation is the interface from the MAUS module\n")+
30
std::string("framework to the Geant4 simulation modules. MapCppSimulation\n")+
31
std::string("tracks particles and fills the MC branch of the MAUS event.\n");
33
std::string birth_docstring =
34
std::string("Checks whether the visualisation manager is initialised.\n\n")+
35
std::string(" datacards: ignored.\n");
37
std::string process_docstring =
38
std::string("Run tracks through the simulation.\n\n")+
39
std::string(" data: data from a single spill. Tracks primary of each MC\n")+
40
std::string(" event in the spill data.\n");
42
std::string death_docstring = std::string("Does nothing.\n");
44
PyMODINIT_FUNC init_MapCppSimulation(void) {
45
PyWrapMapBase<MAUS::MapCppSimulation>::PyWrapMapBaseModInit
53
void MapCppSimulation::_birth(const std::string& argJsonConfigDocument) {
36
54
// Check if the JSON document can be parsed, else return error only
38
if (!Globals::HasInstance()) {
39
GlobalsManager::InitialiseGlobals(argJsonConfigDocument);
41
_doVis = MAUSGeant4Manager::GetInstance()->GetVisManager() != NULL;
42
return true; // Sucessful completion
43
// Normal session, no visualization
44
} catch (Exception& exception) {
45
MAUS::CppErrorHandler::getInstance()->HandleExceptionNoJson(exception, _classname);
46
} catch (std::exception& exc) {
47
MAUS::CppErrorHandler::getInstance()->HandleStdExcNoJson(exc, _classname);
52
std::string MapCppSimulation::process(std::string document) {
54
try {spill = JsonWrapper::StringToJson(document);}
56
return std::string("{\"errors\":{\"bad_json_document\":")+
57
std::string("\"Failed to parse input document\"}}");
61
MAUS::MAUSGeant4Manager::GetInstance()->GetVisManager()->SetupRun();
63
Json::Value mc = JsonWrapper::GetProperty
64
(spill, "mc_events", JsonWrapper::arrayValue);
66
MAUS::MAUSGeant4Manager::GetInstance()->RunManyParticles(mc);
68
MAUS::MAUSGeant4Manager::GetInstance()->GetVisManager()->TearDownRun();
70
catch (Exception& exception) {
71
spill = MAUS::CppErrorHandler::getInstance()
72
->HandleException(spill, exception, _classname);
73
} catch (std::exception& exc) {
74
spill = MAUS::CppErrorHandler::getInstance()
75
->HandleStdExc(spill, exc, _classname);
77
Json::FastWriter writer;
78
std::string output = writer.write(spill);
82
bool MapCppSimulation::death() {
83
return true; // successful
55
_doVis = MAUSGeant4Manager::GetInstance()->GetVisManager() != NULL;
58
void MapCppSimulation::_process(Json::Value* json_document) const {
59
Json::Value& spill = *json_document;
61
MAUS::MAUSGeant4Manager::GetInstance()->GetVisManager()->SetupRun();
63
Json::Value mc = JsonWrapper::GetProperty
64
(spill, "mc_events", JsonWrapper::arrayValue);
66
MAUS::MAUSGeant4Manager::GetInstance()->RunManyParticles(mc);
68
MAUS::MAUSGeant4Manager::GetInstance()->GetVisManager()->TearDownRun();