22
22
#include "Utils/Exception.hh"
23
23
#include "src/common_cpp/Utils/CppErrorHandler.hh"
24
#include "src/common_cpp/API/PyWrapMapBase.hh"
27
PyMODINIT_FUNC init_MapCppTrackerDigits(void) {
28
PyWrapMapBase<MAUS::MapCppTrackerDigits>::PyWrapMapBaseModInit
29
("MapCppTrackerDigits", "", "", "", "");
27
MapCppTrackerDigits::MapCppTrackerDigits(): _spill_json(NULL),
32
MapCppTrackerDigits::MapCppTrackerDigits()
33
: MapBase<Data>("MapCppTrackerDigits") {}
30
35
MapCppTrackerDigits::~MapCppTrackerDigits() {
31
if (_spill_json != NULL) {
34
if (_spill_cpp != NULL) {
39
bool MapCppTrackerDigits::birth(std::string argJsonConfigDocument) {
40
_classname = "MapCppTrackerDigits";
44
bool MapCppTrackerDigits::death() {
48
std::string MapCppTrackerDigits::process(std::string document) {
49
Json::FastWriter writer;
51
read_in_json(document);
54
if ( _json_root.isMember("daq_data") && !(_json_root["daq_data"].isNull()) ) {
56
Json::Value daq = _json_root.get("daq_data", 0);
57
// Fill spill object with
58
RealDataDigitization real;
60
real.process(_spill_cpp, daq);
61
// Save to JSON output.
62
save_to_json(_spill_cpp);
64
return writer.write(_json_root);
66
// If an exception is caught, the JSON file returned is the same that was read-in (_json_root)...
67
} catch (Exception& exception) {
69
return writer.write(_json_root);
73
ss << _classname << " says:" << reader.getFormatedErrorMessages();
74
errors["bad_json_document"] = ss.str();
75
_json_root["errors"] = errors;
76
return writer.write(_json_root);
78
// ... if everything went alright, we return a modified spill (_spill_json).
79
return writer.write(*_spill_json);
82
void MapCppTrackerDigits::read_in_json(std::string json_data) {
83
Json::FastWriter writer;
84
if (_spill_cpp != NULL) {
90
_json_root = JsonWrapper::StringToJson(json_data);
91
SpillProcessor spill_proc;
92
_spill_cpp = spill_proc.JsonToCpp(_spill_json);
94
Squeak::mout(Squeak::error) << "Bad json document" << std::endl;
95
_spill_cpp = new Spill();
96
MAUS::ErrorsMap errors = _spill_cpp->GetErrors();
98
ss << _classname << " says:" << reader.getFormatedErrorMessages();
99
errors["bad_json_document"] = ss.str();
100
_spill_cpp->GetErrors();
104
void MapCppTrackerDigits::save_to_json(Spill *spill) {
105
SpillProcessor spill_proc;
106
if (_spill_json != NULL) {
110
_spill_json = spill_proc.CppToJson(*spill, "");
38
void MapCppTrackerDigits::_birth(const std::string& argJsonConfigDocument) {
41
void MapCppTrackerDigits::_death() {
44
void MapCppTrackerDigits::_process(Data* data) const {
45
Json::Value& json_root = *(ConverterFactory().convert<Data, Json::Value>(data));
46
if ( json_root.isMember("daq_data") && !(json_root["daq_data"].isNull()) ) {
48
Json::Value daq = json_root.get("daq_data", 0);
49
// Fill spill object with
50
RealDataDigitization real;
52
real.process(data->GetSpill(), daq);
113
56
} // ~namespace MAUS