53
60
"Enable_t0_correction",
54
61
JsonWrapper::booleanValue).asBool();
63
_tof_station = JsonWrapper::GetProperty(configJSON,
64
"TOF_trigger_station",
65
JsonWrapper::stringValue).asString();
67
// convert trigger station name to upper case
68
// the DB holds detector names in upper case
69
std::transform(_tof_station.begin(), _tof_station.end(),
71
std::ptr_fun<int, int>(std::toupper));
73
_tof_calibdate = JsonWrapper::GetProperty(configJSON,
74
"TOF_calib_date_from",
75
JsonWrapper::stringValue).asString();
76
// std::cout << "calib date: " << _tof_calibdate << std::endl;
56
78
char* pMAUS_ROOT_DIR = getenv("MAUS_ROOT_DIR");
57
79
if (!pMAUS_ROOT_DIR) {
58
80
Squeak::mout(Squeak::error)
387
423
return xConv.str();
426
void TOFCalibrationMap::Reset() {
427
// import the get_tof_calib module
428
// this python module access and gets calibrations from the DB
429
_calib_mod = PyImport_ImportModule("calibration.get_tof_calib");
430
if (_calib_mod == NULL) {
431
std::cerr << "Failed to import get_tof_calib module" << std::endl;
435
PyObject* calib_mod_dict = PyModule_GetDict(_calib_mod);
436
if (calib_mod_dict != NULL) {
437
PyObject* calib_init = PyDict_GetItemString
438
(calib_mod_dict, "GetCalib");
439
if (PyCallable_Check(calib_init)) {
440
_tcalib = PyObject_Call(calib_init, NULL, NULL);
443
if (_tcalib == NULL) {
444
std::cerr << "Failed to instantiate get_tof_calib" << std::endl;
448
// get the get_calib_func() function
449
_get_calib_func = PyObject_GetAttrString(_tcalib, "get_calib");
450
if (_get_calib_func == NULL) {
451
std::cerr << "Failed to find get_calib function" << std::endl;
456
void TOFCalibrationMap::GetCalib(std::string devname, std::string caltype, std::string fromdate) {
457
PyObject *py_arg = NULL, *py_value = NULL;
458
// setup the arguments to get_calib_func
459
// the arguments are 3 strings
460
// arg1 = device name (TOF0/TOF1/TOF2) uppercase
461
// arg2 = calibration type (tw/t0/trigger) lowercase
462
// arg3 = valid_from_date == either "current" or an actual date 'YYYY-MM-DD HH:MM:SS'
463
// default date argument is "current"
464
// this is set via TOF_calib_date_from card in ConfigurationDefaults
465
py_arg = Py_BuildValue("(sss)", devname.c_str(), caltype.c_str(), fromdate.c_str());
466
if (py_arg == NULL) {
468
throw(Squeal(Squeal::recoverable,
469
"Failed to resolve arguments to get_calib",
470
"MAUSEvaluator::evaluate"));
472
if (_get_calib_func != NULL && PyCallable_Check(_get_calib_func)) {
473
py_value = PyObject_CallObject(_get_calib_func, py_arg);
474
// setup the streams to hold the different calibs
475
if (py_value != NULL && strcmp(caltype.c_str(), "t0") == 0)
476
t0str << PyString_AsString(py_value);
477
if (strcmp(caltype.c_str(), "tw") == 0)
478
twstr << PyString_AsString(py_value);
479
if (strcmp(caltype.c_str(), "trigger") == 0)
480
trigstr << PyString_AsString(py_value);
482
if (py_value == NULL) {
485
throw(Squeal(Squeal::recoverable,
486
"Failed to parse argument "+devname,
487
"GetCalib::get_calib"));
490
Py_XDECREF(py_value);
494
bool TOFCalibrationMap::LoadT0Calib() {
495
this->GetCalib(_tof_station, "t0", _tof_calibdate);
500
while (!t0str.eof()) {
501
t0str >> key >> p0 >> reff;
503
int n = FindTOFChannelKey(key);
506
// std::cout << key << " pos:" << n << " t0:" << p0 << " reff:" << reff << std::endl;
509
Squeak::mout(Squeak::error)
510
<< "Error in TOFCalibrationMap::LoadT0File : Error during loading. " << std::endl
511
<< e.GetMessage() << std::endl;
518
bool TOFCalibrationMap::LoadTWCalib() {
519
this->GetCalib(_tof_station, "tw", _tof_calibdate);
520
double p0, p1, p2, p3;
523
while (!twstr.eof()) {
524
twstr >> key >> p0 >> p1 >> p2 >> p3;
525
// std::cout << "tw: " << key.str() << " " << key << std::endl;
527
int n = FindTOFChannelKey(key);
533
// std::cout<< key << " pos:" << n << " p0:" << p0 << " p1:" << p1 << std::endl;
536
Squeak::mout(Squeak::error)
537
<< "Error in TOFCalibrationMap::LoadTWFile : Error during loading. " << std::endl
538
<< e.GetMessage() << std::endl;
545
bool TOFCalibrationMap::LoadTriggerCalib() {
546
this->GetCalib(_tof_station, "trigger", _tof_calibdate);
550
while (!trigstr.eof()) {
551
trigstr >> Pkey >> dt;
553
_Tkey.push_back(Pkey);
555
// std::cout<< Pkey << " dt:" << dt << std::endl;
558
Squeak::mout(Squeak::error)
559
<< "Error in TOFCalibrationMap::LoadTriggerFile. Error during loading. " << std::endl
560
<< e.GetMessage() << std::endl;
563
// Use the last readed pixel key to set the number of the trigger station.
564
_triggerStation = Pkey.station();