191
191
std::cout << "=================================================================" << std::endl;
194
bool KLCalibrationMap::InitializePyMod() {
195
// import the get_kl_calib module
196
// this python module access and gets calibrations from the DB
197
_calib_mod = PyImport_ImportModule("calibration.get_kl_calib");
198
if (_calib_mod == NULL) {
199
std::cerr << "Failed to import get_kl_calib module" << std::endl;
203
PyObject* calib_mod_dict = PyModule_GetDict(_calib_mod);
204
if (calib_mod_dict != NULL) {
205
PyObject* calib_init = PyDict_GetItemString
206
(calib_mod_dict, "GetCalib");
207
if (PyCallable_Check(calib_init)) {
208
_tcalib = PyObject_Call(calib_init, NULL, NULL);
211
if (_tcalib == NULL) {
212
std::cerr << "Failed to instantiate get_kl_calib" << std::endl;
216
// get the get_calib_func() function
217
_get_calib_func = PyObject_GetAttrString(_tcalib, "get_calib");
218
if (_get_calib_func == NULL) {
219
std::cerr << "Failed to find get_calib function" << std::endl;
194
bool KLCalibrationMap::GetCalibCAPI(std::string devname,
196
std::string fromdate) {
197
MAUS::CDB::Calibration cali;
201
cali.getStatus(status);
202
if (status.compare("OK") != 0) {
203
std::cerr << "+++ CDB Error status = " << status << std::endl;
206
// std::cerr << " Calibration status returned " << status << std::endl;
207
std::cout << "++ Getting KL Calib by DATE for " << fromdate.c_str() << std::endl;
208
if (fromdate.compare("current") == 0)
209
cali.getCurrentDetectorCalibration(devname.c_str(),
213
cali.getDetectorCalibrationForDate(devname.c_str(),
217
// std::cerr << result << "(" << result.size() << " characters)" << std::endl;
218
} catch (std::exception &e) {
219
std::cerr << e.what() << std::endl;
225
void KLCalibrationMap::GetCalib(std::string devname, std::string caltype, std::string fromdate) {
226
PyObject *py_arg = NULL, *py_value = NULL;
227
// setup the arguments to get_calib_func
228
// the arguments are 3 strings
229
// arg1 = device name (KL) uppercase
230
// arg2 = calibration type (gain) lowercase
231
// arg3 = valid_from_date == either "current" or an actual date 'YYYY-MM-DD HH:MM:SS'
232
// default date argument is "current"
233
// this is set via KL_calib_date_from card in ConfigurationDefaults
234
py_arg = Py_BuildValue("(sss)", devname.c_str(), caltype.c_str(), fromdate.c_str());
235
if (py_arg == NULL) {
237
throw(MAUS::Exceptions::Exception(MAUS::Exceptions::recoverable,
238
"Failed to resolve arguments to get_calib",
239
"MAUSEvaluator::evaluate"));
241
if (_get_calib_func != NULL && PyCallable_Check(_get_calib_func)) {
242
py_value = PyObject_CallObject(_get_calib_func, py_arg);
243
// setup the streams to hold the different calibs
244
if (py_value != NULL && strcmp(caltype.c_str(), "gain") == 0)
245
gainstr << PyString_AsString(py_value);
247
if (py_value == NULL) {
250
throw(MAUS::Exceptions::Exception(MAUS::Exceptions::recoverable,
251
"Failed to parse argument "+devname,
252
"GetCalib::get_calib"));
255
Py_XDECREF(py_value);
259
226
bool KLCalibrationMap::LoadGainCalib() {
260
this->GetCalib("KL", "gain", _kl_calibdate);
227
this->GetCalibCAPI("KL", "gain", _kl_calibdate);
262
229
KLChannelKey key;