21
21
#include "Utils/DAQChannelMap.hh"
22
22
#include "Utils/Exception.hh"
23
23
#include "Interface/dataCards.hh"
24
#include "API/PyWrapMapBase.hh"
25
26
#include "src/map/MapCppKLDigits/MapCppKLDigits.hh"
29
bool MapCppKLDigits::birth(std::string argJsonConfigDocument) {
31
_classname = "MapCppKLDigits";
30
PyMODINIT_FUNC init_MapCppKLDigits(void) {
31
PyWrapMapBase<MAUS::MapCppKLDigits>::PyWrapMapBaseModInit
32
("MapCppKLDigits", "", "", "", "");
35
MapCppKLDigits::MapCppKLDigits() : MapBase<Json::Value>("MapCppKLDigits") {
38
void MapCppKLDigits::_birth(const std::string& argJsonConfigDocument) {
33
40
char* pMAUS_ROOT_DIR = getenv("MAUS_ROOT_DIR");
35
42
if (!pMAUS_ROOT_DIR) {
36
Squeak::mout(Squeak::error)
37
<< "Could not find the $MAUS_ROOT_DIR environmental variable." << std::endl;
38
Squeak::mout(Squeak::error) << "Did you try running: source env.sh ?"
43
throw MAUS::Exception(Exception::recoverable,
44
"Could not find the $MAUS_ROOT_DIR environmental variable.",
45
"MapCppKLDigits::_birth");
43
48
// Check if the JSON document can be parsed, else return error only
46
Json::Value configJSON;
47
Json::Value map_file_name;
48
Json::Value xEnable_V1724_Unpacking;
49
configJSON = JsonWrapper::StringToJson(argJsonConfigDocument);
50
// this will contain the configuration
52
map_file_name = JsonWrapper::GetProperty(configJSON,
54
JsonWrapper::stringValue);
56
std::string xMapFile = std::string(pMAUS_ROOT_DIR) + map_file_name.asString();
57
bool loaded = _map.InitFromFile(xMapFile);
61
xEnable_V1724_Unpacking = JsonWrapper::GetProperty(configJSON,
62
"Enable_V1724_Unpacking",
63
JsonWrapper::booleanValue);
65
if (!xEnable_V1724_Unpacking.asBool()) {
66
Squeak::mout(Squeak::warning)
67
<< "WARNING in MapCppKLDigits::birth. The unpacking of the flashADC V1724 is disabled!!!"
68
<< " Are you shure you want this?"
73
} catch (Exception exc) {
74
CppErrorHandler::getInstance()->HandleExceptionNoJson(exc, _classname);
75
} catch (std::exception exc) {
76
CppErrorHandler::getInstance()->HandleStdExcNoJson(exc, _classname);
83
bool MapCppKLDigits::death() {return true;}
85
std::string MapCppKLDigits::process(std::string document) {
88
Json::FastWriter writer;
90
Json::Value xEventType;
91
// Check if the JSON document can be parsed, else return error only
92
try {root = JsonWrapper::StringToJson(document);}
96
ss << _classname << " says: Failed to parse input document";
97
errors["bad_json_document"] = ss.str();
98
root["errors"] = errors;
99
return writer.write(root);
50
Json::Value configJSON;
51
Json::Value map_file_name;
52
Json::Value xEnable_V1724_Unpacking;
53
configJSON = JsonWrapper::StringToJson(argJsonConfigDocument);
54
// this will contain the configuration
56
map_file_name = JsonWrapper::GetProperty(configJSON,
58
JsonWrapper::stringValue);
60
std::string xMapFile = std::string(pMAUS_ROOT_DIR) + map_file_name.asString();
61
bool loaded = _map.InitFromFile(xMapFile);
63
throw MAUS::Exception(Exception::recoverable,
64
"Failed to initialise map KLChannelMap",
65
"MapCppKLDigits::_birth");
67
// Load the calibration
68
bool loaded_cal = _mapcal.InitializeFromCards(configJSON);
70
throw MAUS::Exception(Exception::recoverable,
71
"Failed to initialise map KLChannelMap",
72
"MapCppKLDigits::_birth");
75
xEnable_V1724_Unpacking = JsonWrapper::GetProperty(configJSON,
76
"Enable_V1724_Unpacking",
77
JsonWrapper::booleanValue);
79
if (!xEnable_V1724_Unpacking.asBool()) {
80
Squeak::mout(Squeak::warning)
81
<< "WARNING in MapCppKLDigits::birth. The unpacking of the flashADC V1724 is disabled!!!"
82
<< " Are you shure you want this?"
103
xEventType = JsonWrapper::GetProperty(root,
88
void MapCppKLDigits::_death() {}
90
void MapCppKLDigits::_process(Json::Value* document) const {
92
Json::Value& root = *document;
93
Json::Value xEventType = JsonWrapper::GetProperty(root,
105
95
JsonWrapper::stringValue);
106
96
if (xEventType == "physics_event" || xEventType == "calibration_event") {
139
} catch (Exception exc) {
140
root = CppErrorHandler::getInstance()
141
->HandleException(root, exc, _classname);
142
} catch (std::exception exc) {
143
root = CppErrorHandler::getInstance()
144
->HandleStdExc(root, exc, _classname);
147
return writer.write(root);
150
131
bool MapCppKLDigits::SetConfiguration(std::string json_configuration) {
155
Json::Value MapCppKLDigits::makeDigits(Json::Value xDocDetData, Json::Value xDocTrig) {
135
Json::Value MapCppKLDigits::makeDigits(Json::Value xDocDetData,
136
Json::Value xDocTrig) const {
156
137
Json::Value xDocDigits;
157
138
// Get number of Particle trigger.
158
139
int n_part_event_triggers = xDocTrig.size();
209
190
KLChannelKey* xKlAdcKey = _map.find(&xAdcDaqKey);
192
// Get the gain factors
193
double gain = _mapcal.Gain(*xKlAdcKey);
196
int char_mm = JsonWrapper::GetProperty(xDocAdcHit,
198
JsonWrapper::intValue).asInt();
199
int char_pm = JsonWrapper::GetProperty(xDocAdcHit,
201
JsonWrapper::intValue).asInt();
212
208
xDocInfo["kl_key"] = xKlAdcKey->str();
213
209
xDocInfo["cell"] = xKlAdcKey->cell();
214
210
xDocInfo["pmt"] = xKlAdcKey->pmt();
217
xDocInfo["charge_mm"] = xDocAdcHit["charge_mm"];
218
xDocInfo["charge_pm"] = xDocAdcHit["charge_pm"];
213
xDocInfo["charge_mm"] = char_mm;
214
xDocInfo["charge_pm"] = char_pm;
219
215
xDocInfo["position_max"] = xDocAdcHit["position_max"];
220
216
xDocInfo["part_event_number"] = xDocAdcHit["part_event_number"];
221
217
xDocInfo["phys_event_number"] = xDocAdcHit["phys_event_number"];
224
// std::cout << "phys_event_number= " << xDocInfo["phys_event_number"] << std::endl;
225
// std::cout << "part_event_number= " << xDocInfo["part_event_number"] << std::endl;
226
// std::cout << "adc= " << xDocAdcHit["charge_mm"] << std::endl;
227
// std::cout << "kl_key= " << xDocInfo["kl_key"] << std::endl;
228
// std::cout << "kl_cell= " << xDocInfo["cell"] << std::endl;
229
// std::cout << "kl_pmt= " << xDocInfo["pmt"] << std::endl;
220
// std::cout << "phys_event_number= " << xDocInfo["phys_event_number"] << std::endl;
221
// std::cout << "part_event_number= " << xDocInfo["part_event_number"] << std::endl;
222
// std::cout << "adc before= " << xDocAdcHit["charge_mm"] << std::endl;
223
// std::cout << "adc after= " << char_mm << std::endl;
224
// std::cout << "gain= " << gain << std::endl;
225
// std::cout << "kl_key= " << xDocInfo["kl_key"] << std::endl;
226
// std::cout << "kl_cell= " << xDocInfo["cell"] << std::endl;
227
// std::cout << "kl_pmt= " << xDocInfo["pmt"] << std::endl;