99
DAQChannelMap::DAQChannelMap() {
101
if (!this->InitializePyMod()) pymod_ok = false;
97
104
// load channel map based on data cards
98
105
bool DAQChannelMap::InitFromCards(Json::Value configJSON) {
106
_daq_devicename = "DAQ";
107
std::string _cabling_source = JsonWrapper::GetProperty(configJSON,
108
"DAQ_cabling_source",
109
JsonWrapper::stringValue).asString();
111
if (_cabling_source != "CDB" && _cabling_source != "file")
112
throw(MAUS::Exception(Exception::recoverable,
113
std::string("DAQChannelMap::InitFromCards"),
114
"Invalid DAQ_cabling_source card"));
116
_daq_cabling_by = JsonWrapper::GetProperty(configJSON,
118
JsonWrapper::stringValue).asString();
120
if (_daq_cabling_by != "run_number" && _daq_cabling_by != "date")
121
throw(MAUS::Exception(Exception::recoverable,
122
std::string("DAQChannelMap::InitFromCards"),
123
"Invalid DAQ_cabling_by card"));
125
_daq_cablingdate = "current";
126
if (_daq_cabling_by == "date")
127
_daq_cablingdate = JsonWrapper::GetProperty(configJSON,
128
"DAQ_cabling_date_from",
129
JsonWrapper::stringValue).asString();
99
132
_datafiles = JsonWrapper::GetProperty(configJSON,
101
JsonWrapper::stringValue).asString();
134
JsonWrapper::stringValue).asString();
104
136
// check if daa_data_file is a number, if it is get run-number from it
105
137
// else parse it and extract the run number
106
138
if (is_number(_datafiles)) {
107
runNum = atoi(_datafiles.c_str());
139
runNumber = atoi(_datafiles.c_str());
109
141
std::string delimiter = " ";
110
142
std::string token = _datafiles.substr(0, _datafiles.find(delimiter));
111
runNum = atoi(token.c_str());
114
// load the appropriate cabling file depending on runNum being > or < 6541
115
// DR -- this is a hack which should go away once the maps are in the CDB
116
std::string map_file_name = "";
118
assert(configJSON.isMember("DAQ_cabling_file_StepI"));
119
map_file_name = configJSON["DAQ_cabling_file_StepI"].asString();
122
assert(configJSON.isMember("DAQ_cabling_file"));
123
map_file_name = configJSON["DAQ_cabling_file"].asString();
125
char* pMAUS_ROOT_DIR = getenv("MAUS_ROOT_DIR");
126
if (!pMAUS_ROOT_DIR) {
127
Squeak::mout(Squeak::error) << "Could not find the $MAUS_ROOT_DIR environmental variable."
129
Squeak::mout(Squeak::error) << "Did you try running: source env.sh ?" << std::endl;
130
throw(MAUS::Exception(Exception::recoverable, "STRING", "DAQChannelMap::_InitFromCards"));
133
// Initialize the map by using text file.
134
bool loaded = InitFromFile(std::string(pMAUS_ROOT_DIR) + map_file_name);
143
runNumber = atoi(token.c_str());
147
if (_cabling_source == "CDB") {
148
if (!pymod_ok) return false;
149
loaded = this->InitFromCDB();
150
} else if (_cabling_source == "file") {
151
// load the appropriate cabling file depending on runNumber being > or < 6541
152
// DR -- this is a hack which should go away once the maps are in the CDB
153
std::string map_file_name = "";
154
if (runNumber < 6541) {
155
assert(configJSON.isMember("DAQ_cabling_file_StepI"));
156
map_file_name = configJSON["DAQ_cabling_file_StepI"].asString();
159
assert(configJSON.isMember("DAQ_cabling_file"));
160
map_file_name = configJSON["DAQ_cabling_file"].asString();
162
char* pMAUS_ROOT_DIR = getenv("MAUS_ROOT_DIR");
163
if (!pMAUS_ROOT_DIR) {
164
Squeak::mout(Squeak::error) <<
165
"Could not find the $MAUS_ROOT_DIR environmental variable."
167
Squeak::mout(Squeak::error)
168
<< "Did you try running: source env.sh ?" << std::endl;
169
throw(MAUS::Exception(Exception::recoverable,
170
"STRING", "DAQChannelMap::_InitFromCards"));
172
// Initialize the map by using text file.
173
loaded = InitFromFile(std::string(pMAUS_ROOT_DIR) + map_file_name);
174
213
bool DAQChannelMap::InitFromCDB() {
214
this->GetCabling(_daq_devicename);
218
while (!cblstr.eof()) {
219
key = new DAQChannelKey();
221
_chKey.push_back(key);
224
} catch (MAUS::Exception e) {
225
Squeak::mout(Squeak::error)
226
<< "Error in DAQChannelMap::InitFromCDB : Error during loading map." << std::endl
227
<< e.GetMessage() << std::endl;
231
if (_chKey.size() == 0) {
232
Squeak::mout(Squeak::error)
233
<< "Error in DAQChannelMap::InitFromCDB : No DAQ Channel Keys loaded. "
178
240
DAQChannelKey* DAQChannelMap::find(int ldc, int geo, int ch, int eqType) {
216
278
return !s.empty() && it == s.end();
281
bool DAQChannelMap::InitializePyMod() {
282
// import the get_tof_cabling module
283
// this python module access and gets cabling from the DB
284
PyLibMausCpp::initlibMausCpp();
285
_cabling_mod = PyImport_ImportModule("cabling.get_daq_cabling");
286
if (_cabling_mod == NULL) {
287
std::cerr << "Failed to import get_daq_cabling module" << std::endl;
291
PyObject* cabling_mod_dict = PyModule_GetDict(_cabling_mod);
292
if (cabling_mod_dict != NULL) {
293
PyObject* cabling_init = PyDict_GetItemString
294
(cabling_mod_dict, "GetCabling");
295
if (PyCallable_Check(cabling_init)) {
296
_tcabling = PyObject_Call(cabling_init, NULL, NULL);
299
if (_tcabling == NULL) {
300
std::cerr << "Failed to instantiate get_daq_cabling" << std::endl;
307
void DAQChannelMap::GetCabling(std::string devname) {
308
PyObject *py_arg = NULL, *py_value = NULL;
309
// setup the arguments to get_cabling_func
310
// the functions available are
311
// get_cabling_for_date(DEVICE, DATE)
312
// get_cabling_for_run(DEVICE, RUN)
314
_get_cabling_func = NULL;
315
if (_daq_cabling_by == "date") {
316
py_arg = Py_BuildValue("(ss)", devname.c_str(), _daq_cablingdate.c_str());
317
_get_cabling_func = PyObject_GetAttrString(_tcabling, "get_cabling_for_date");
318
} else if (_daq_cabling_by == "run_number") {
319
py_arg = Py_BuildValue("(si)", devname.c_str(), runNumber);
320
_get_cabling_func = PyObject_GetAttrString(_tcabling, "get_cabling_for_run");
322
throw(MAUS::Exception(MAUS::Exception::recoverable,
323
"Invalid daq_cabling_by type "+_daq_cabling_by,
324
"DAQChannelMap::GetCalib"));
327
if (_get_cabling_func == NULL)
328
throw(MAUS::Exception(MAUS::Exception::recoverable,
329
"Failed to find get_calib function",
330
"DAQChannelMap::GetCalib"));
332
if (py_arg == NULL) {
334
throw(MAUS::Exception(MAUS::Exception::recoverable,
335
"Failed to resolve arguments to get_cabling",
336
"MAUSEvaluator::evaluate"));
338
if (_get_cabling_func != NULL && PyCallable_Check(_get_cabling_func)) {
339
py_value = PyObject_CallObject(_get_cabling_func, py_arg);
340
// setup the streams to hold the different calibs
341
if (py_value != NULL)
342
cblstr << PyString_AsString(py_value);
344
if (py_value == NULL) {
347
throw(MAUS::Exception(MAUS::Exception::recoverable,
348
"Failed to parse argument "+devname,
349
"GetCalib::get_calib"));
352
Py_XDECREF(py_value);
219
356
} // namespace MAUS