~christopher-hunt08/maus/maus_integrated_kalman

« back to all changes in this revision

Viewing changes to src/map/MapCppTrackerDigits/MapCppTrackerDigits.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:
21
21
 
22
22
#include "Utils/Exception.hh"
23
23
#include "src/common_cpp/Utils/CppErrorHandler.hh"
 
24
#include "src/common_cpp/API/PyWrapMapBase.hh"
24
25
 
25
26
namespace MAUS {
 
27
PyMODINIT_FUNC init_MapCppTrackerDigits(void) {
 
28
  PyWrapMapBase<MAUS::MapCppTrackerDigits>::PyWrapMapBaseModInit
 
29
                                        ("MapCppTrackerDigits", "", "", "", "");
 
30
}
26
31
 
27
 
MapCppTrackerDigits::MapCppTrackerDigits(): _spill_json(NULL),
28
 
                                            _spill_cpp(NULL) {}
 
32
MapCppTrackerDigits::MapCppTrackerDigits()
 
33
    : MapBase<Data>("MapCppTrackerDigits") {}
29
34
 
30
35
MapCppTrackerDigits::~MapCppTrackerDigits() {
31
 
  if (_spill_json != NULL) {
32
 
    delete _spill_json;
33
 
  }
34
 
  if (_spill_cpp != NULL) {
35
 
    delete _spill_cpp;
36
 
  }
37
 
}
38
 
 
39
 
bool MapCppTrackerDigits::birth(std::string argJsonConfigDocument) {
40
 
  _classname = "MapCppTrackerDigits";
41
 
  return true;
42
 
}
43
 
 
44
 
bool MapCppTrackerDigits::death() {
45
 
  return true;
46
 
}
47
 
 
48
 
std::string MapCppTrackerDigits::process(std::string document) {
49
 
  Json::FastWriter writer;
50
 
 
51
 
  read_in_json(document);
52
 
 
53
 
  try {
54
 
    if ( _json_root.isMember("daq_data") && !(_json_root["daq_data"].isNull()) ) {
55
 
      // Get daq data.
56
 
      Json::Value daq = _json_root.get("daq_data", 0);
57
 
      // Fill spill object with
58
 
      RealDataDigitization real;
59
 
      real.initialise();
60
 
      real.process(_spill_cpp, daq);
61
 
      // Save to JSON output.
62
 
      save_to_json(_spill_cpp);
63
 
    } else {
64
 
      return writer.write(_json_root);
65
 
    }
66
 
  // If an exception is caught, the JSON file returned is the same that was read-in (_json_root)...
67
 
  } catch (Exception& exception) {
68
 
    exception.Print();
69
 
    return writer.write(_json_root);
70
 
  } catch (...) {
71
 
    Json::Value errors;
72
 
    std::stringstream ss;
73
 
    ss << _classname << " says:" << reader.getFormatedErrorMessages();
74
 
    errors["bad_json_document"] = ss.str();
75
 
    _json_root["errors"] = errors;
76
 
    return writer.write(_json_root);
77
 
  }
78
 
  // ... if everything went alright, we return a modified spill (_spill_json).
79
 
  return writer.write(*_spill_json);
80
 
}
81
 
 
82
 
void MapCppTrackerDigits::read_in_json(std::string json_data) {
83
 
  Json::FastWriter writer;
84
 
  if (_spill_cpp != NULL) {
85
 
    delete _spill_cpp;
86
 
    _spill_cpp = NULL;
87
 
  }
88
 
 
89
 
  try {
90
 
    _json_root = JsonWrapper::StringToJson(json_data);
91
 
    SpillProcessor spill_proc;
92
 
    _spill_cpp = spill_proc.JsonToCpp(_spill_json);
93
 
  } catch (...) {
94
 
    Squeak::mout(Squeak::error) << "Bad json document" << std::endl;
95
 
    _spill_cpp = new Spill();
96
 
    MAUS::ErrorsMap errors = _spill_cpp->GetErrors();
97
 
    std::stringstream ss;
98
 
    ss << _classname << " says:" << reader.getFormatedErrorMessages();
99
 
    errors["bad_json_document"] = ss.str();
100
 
    _spill_cpp->GetErrors();
101
 
  }
102
 
}
103
 
 
104
 
void MapCppTrackerDigits::save_to_json(Spill *spill) {
105
 
  SpillProcessor spill_proc;
106
 
  if (_spill_json != NULL) {
107
 
      delete _spill_json;
108
 
      _spill_json = NULL;
109
 
  }
110
 
  _spill_json = spill_proc.CppToJson(*spill, "");
111
 
}
112
 
 
 
36
}
 
37
 
 
38
void MapCppTrackerDigits::_birth(const std::string& argJsonConfigDocument) {
 
39
}
 
40
 
 
41
void MapCppTrackerDigits::_death() {
 
42
}
 
43
 
 
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()) ) {
 
47
    // Get daq data.
 
48
    Json::Value daq = json_root.get("daq_data", 0);
 
49
    // Fill spill object with
 
50
    RealDataDigitization real;
 
51
    real.initialise();
 
52
    real.process(data->GetSpill(), daq);
 
53
  }
 
54
  delete &json_root;
 
55
}
113
56
} // ~namespace MAUS