~christopher-hunt08/maus/maus_integrated_kalman

« back to all changes in this revision

Viewing changes to src/map/MapCppSimulation/MapCppSimulation.cc

  • Committer: Durga Rajaram
  • Date: 2014-07-16 15:13:05 UTC
  • mfrom: (659.1.92 cand)
  • Revision ID: durga@fnal.gov-20140716151305-q27rv1y9p03v9lks
Tags: MAUS-v0.9, MAUS-v0.9.0
MAUS-v0.9.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
#include <Python.h>
19
19
 
20
 
#include <vector>
21
20
#include <string>
22
21
 
23
 
#include "Utils/Exception.hh"
24
 
 
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"
30
 
 
31
25
#include "src/map/MapCppSimulation/MapCppSimulation.hh"
32
26
 
33
27
namespace MAUS {
34
 
 
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");
 
32
 
 
33
std::string birth_docstring =
 
34
std::string("Checks whether the visualisation manager is initialised.\n\n")+
 
35
std::string("  datacards: ignored.\n");
 
36
 
 
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");
 
41
 
 
42
std::string death_docstring = std::string("Does nothing.\n");
 
43
 
 
44
PyMODINIT_FUNC init_MapCppSimulation(void) {
 
45
  PyWrapMapBase<MAUS::MapCppSimulation>::PyWrapMapBaseModInit
 
46
                              ("MapCppSimulation",
 
47
                               class_docstring,
 
48
                               birth_docstring,
 
49
                               process_docstring,
 
50
                               death_docstring);
 
51
}
 
52
 
 
53
void MapCppSimulation::_birth(const std::string& argJsonConfigDocument) {
36
54
  // Check if the JSON document can be parsed, else return error only
37
 
  try {
38
 
    if (!Globals::HasInstance()) {
39
 
        GlobalsManager::InitialiseGlobals(argJsonConfigDocument);
40
 
    }
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);
48
 
  }
49
 
  return false;
50
 
}
51
 
 
52
 
std::string MapCppSimulation::process(std::string document) {
53
 
  Json::Value spill;
54
 
  try {spill = JsonWrapper::StringToJson(document);}
55
 
  catch (...) {
56
 
    return std::string("{\"errors\":{\"bad_json_document\":")+
57
 
           std::string("\"Failed to parse input document\"}}");
58
 
  }
59
 
  try {
60
 
    if (_doVis) {
61
 
        MAUS::MAUSGeant4Manager::GetInstance()->GetVisManager()->SetupRun();
62
 
    }
63
 
    Json::Value mc = JsonWrapper::GetProperty
64
 
                                  (spill, "mc_events", JsonWrapper::arrayValue);
65
 
    spill["mc_events"] =
66
 
                   MAUS::MAUSGeant4Manager::GetInstance()->RunManyParticles(mc);
67
 
    if (_doVis)
68
 
        MAUS::MAUSGeant4Manager::GetInstance()->GetVisManager()->TearDownRun();
69
 
  }
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);
76
 
  }
77
 
  Json::FastWriter writer;
78
 
  std::string output = writer.write(spill);
79
 
  return output;
80
 
}
81
 
 
82
 
bool MapCppSimulation::death() {
83
 
  return true;  // successful
 
55
  _doVis = MAUSGeant4Manager::GetInstance()->GetVisManager() != NULL;
 
56
}
 
57
 
 
58
void MapCppSimulation::_process(Json::Value* json_document) const {
 
59
  Json::Value& spill = *json_document;
 
60
  if (_doVis) {
 
61
      MAUS::MAUSGeant4Manager::GetInstance()->GetVisManager()->SetupRun();
 
62
  }
 
63
  Json::Value mc = JsonWrapper::GetProperty
 
64
                                (spill, "mc_events", JsonWrapper::arrayValue);
 
65
  spill["mc_events"] =
 
66
                 MAUS::MAUSGeant4Manager::GetInstance()->RunManyParticles(mc);
 
67
  if (_doVis)
 
68
      MAUS::MAUSGeant4Manager::GetInstance()->GetVisManager()->TearDownRun();
84
69
}
85
70
}