Get trimbits (#462)

* added the possibility to save settings file for m3 and eiger

* added save trimbits to gui

* update release notes

* python wip

* moved location of trimbits save option in gui

* python works

* updating getModule with all its parameters in the server side

* updating binaries
This commit is contained in:
Dhanya Thattil 2022-05-24 11:08:08 +02:00 committed by GitHub
parent d61741c28b
commit 365ac835eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 528 additions and 244 deletions

View File

@ -74,6 +74,7 @@ This document describes the differences between v7.0.0 and v6.x.x
- gap pixels in gui enabled by default
- rxr src files and classes (detectordata, ZmqSocket, helpDacs) added to sls namespace, and macros (namely from logger (logINFO etc)), slsDetectorGui (make_unique in implemtnation requires sls nemspace (points to std otherwise) but not deectorImpl.cpp)
- blackfin programing made seamless (nCE fixed which helps)
-save settings file for m3 and eiger
2. Resolved Issues
==================

View File

@ -1442,20 +1442,21 @@ class Detector(CppDetectorApi):
@property
def trimbits(self):
"""
[Eiger][Mythen3] Loads custom trimbit file to detector.
[Eiger][Mythen3] Loads/Saves custom trimbit file to detector.
Note
-----
If no extension specified, serial number of each module is attached.
:getter: Not implemented
:setter: Loads the trimbit file to detector
:getter: Saves the trimbits from the detector to file. Not implemented with 'trimbits'. Use saveTrimbits().
Example
-------
>>> d.trimbits = '/path_to_file/noise'
- 14:53:27.931 INFO: Settings file loaded: /path_to_file/noise.sn000
"""
return NotImplementedError("trimbits are set only")
raise NotImplementedError('trimbits is set only. Use saveTrimbits()')
@trimbits.setter
def trimbits(self, fname):
@ -2617,7 +2618,7 @@ class Detector(CppDetectorApi):
-------
>>> d.vetophoton = (2, 24, 2560, '/tmp/bla.txt')
"""
raise NotImplementedError('vetofile is set only')
raise NotImplementedError('vetophoton is set only')
@vetophoton.setter
def vetophoton(self, args):

View File

@ -144,6 +144,10 @@ void init_det(py::module &m) {
(void (Detector::*)(const std::string &, sls::Positions)) &
Detector::loadTrimbits,
py::arg(), py::arg() = Positions{})
.def("saveTrimbits",
(void (Detector::*)(const std::string &, sls::Positions)) &
Detector::saveTrimbits,
py::arg(), py::arg() = Positions{})
.def("getAllTrimbits",
(Result<int>(Detector::*)(sls::Positions) const) &
Detector::getAllTrimbits,
@ -187,12 +191,12 @@ void init_det(py::module &m) {
(void (Detector::*)(void (*)(double, int, void *), void *)) &
Detector::registerAcquisitionFinishedCallback,
py::arg(), py::arg())
.def(
"registerDataCallback",
(void (Detector::*)(
void (*)(detectorData *, uint64_t, uint32_t, void *), void *)) &
Detector::registerDataCallback,
py::arg(), py::arg())
.def("registerDataCallback",
(void (Detector::*)(
void (*)(sls::detectorData *, uint64_t, uint32_t, void *),
void *)) &
Detector::registerDataCallback,
py::arg(), py::arg())
.def("getNumberOfFrames",
(Result<int64_t>(Detector::*)(sls::Positions) const) &
Detector::getNumberOfFrames,

View File

@ -235,6 +235,7 @@
</property>
<addaction name="actionLoadConfiguration"/>
<addaction name="actionLoadTrimbits"/>
<addaction name="actionSaveTrimbits"/>
<addaction name="actionLoadParameters"/>
</widget>
<widget class="QMenu" name="menuModes">
@ -419,6 +420,11 @@ p, li { white-space: pre-wrap; }
<string>&amp;About</string>
</property>
</action>
<action name="actionSaveTrimbits">
<property name="text">
<string>Save Trimbits</string>
</property>
</action>
</widget>
<resources>
<include location="../include/icons.qrc"/>

View File

@ -197,6 +197,7 @@ void qDetectorMain::SetUpWidgetWindow() {
tabs->setTabEnabled(ADVANCED, false);
tabs->setTabEnabled(DEVELOPER, isDeveloper);
actionLoadTrimbits->setVisible(false);
actionSaveTrimbits->setVisible(false);
dockWidgetPlot->setFloating(false);
dockWidgetPlot->setFeatures(QDockWidget::NoDockWidgetFeatures);
@ -227,10 +228,12 @@ void qDetectorMain::SetUpDetector(const std::string &config_file, int multiID) {
detType = det->getDetectorType().tsquash(
"Different detector type for all modules.");
actionLoadTrimbits->setEnabled(false);
actionSaveTrimbits->setEnabled(false);
switch (detType) {
case slsDetectorDefs::EIGER:
case slsDetectorDefs::MYTHEN3:
actionLoadTrimbits->setEnabled(true);
actionSaveTrimbits->setEnabled(true);
break;
case slsDetectorDefs::GOTTHARD:
case slsDetectorDefs::JUNGFRAU:
@ -341,9 +344,9 @@ void qDetectorMain::EnableModes(QAction *action) {
enable = actionExpert->isChecked();
tabs->setTabEnabled(ADVANCED, enable);
actionLoadTrimbits->setVisible(enable &&
(detType == slsDetectorDefs::EIGER ||
detType == slsDetectorDefs::MYTHEN3));
bool visible = enable && (detType == slsDetectorDefs::EIGER || detType == slsDetectorDefs::MYTHEN3);
actionLoadTrimbits->setVisible(visible);
actionSaveTrimbits->setVisible(visible);
tabSettings->SetExportMode(enable);
LOG(logINFO) << "Expert Mode: " << qDefs::stringEnable(enable);
}
@ -419,6 +422,22 @@ void qDetectorMain::ExecuteUtilities(QAction *action) {
LOG(logINFO) << "Trimbits loaded successfully";
}
}
else if (action == actionSaveTrimbits) {
QString fPath =
QString((det->getSettingsPath().squash("/tmp/")).c_str());
LOG(logDEBUG) << "Saving Trimbits";
QString fName = QFileDialog::getSaveFileName(
this, tr("Save Detector Trimbits"), fPath,
tr("Trimbit files (*.trim noise.sn*);;All Files(*)"));
if (!fName.isEmpty()) {
det->saveTrimbits(std::string(fName.toAscii().constData()));
qDefs::Message(qDefs::INFORMATION,
"The Trimbits have been saved successfully.",
"qDetectorMain::ExecuteUtilities");
LOG(logINFO) << "Trimbits saved successfully";
}
}
}
CATCH_DISPLAY("Could not execute utilities.",
"qDetectorMain::ExecuteUtilities")
@ -579,6 +598,8 @@ void qDetectorMain::EnableTabs(bool enable) {
tabs->setTabEnabled(ADVANCED, expertTab);
actionLoadTrimbits->setVisible(expertTab &&
detType == slsDetectorDefs::EIGER);
actionSaveTrimbits->setVisible(expertTab &&
detType == slsDetectorDefs::EIGER);
// moved to here, so that its all in order, instead of signals and different
// threads

View File

@ -57,7 +57,6 @@ int normal = 0;
int eiger_highvoltage = 0;
int eiger_theo_highvoltage = 0;
int eiger_iodelay = 0;
int eiger_photonenergy = 0;
int eiger_dynamicrange = 0;
int eiger_parallelmode = 0;
int eiger_overflow32 = 0;
@ -682,17 +681,17 @@ void allocateDetectorStructureMemory() {
("modules from 0x%x to 0x%x\n", detectorModules, detectorModules));
LOG(logDEBUG1, ("chans from 0x%x to 0x%x\n", detectorChans, detectorChans));
LOG(logDEBUG1, ("dacs from 0x%x to 0x%x\n", detectorDacs, detectorDacs));
(detectorModules)->dacs = detectorDacs;
(detectorModules)->chanregs = detectorChans;
(detectorModules)->ndac = NDAC;
(detectorModules)->nchip = NCHIP;
(detectorModules)->nchan = NCHIP * NCHAN;
(detectorModules)->reg = 0;
(detectorModules)->iodelay = 0;
(detectorModules)->tau = 0;
(detectorModules)->eV[0] = 0;
(detectorModules)->eV[1] = 0;
(detectorModules)->eV[2] = 0;
detectorModules->dacs = detectorDacs;
detectorModules->chanregs = detectorChans;
detectorModules->ndac = NDAC;
detectorModules->nchip = NCHIP;
detectorModules->nchan = NCHIP * NCHAN;
detectorModules->reg = 0;
detectorModules->iodelay = 0;
detectorModules->tau = 0;
detectorModules->eV[0] = -1;
detectorModules->eV[1] = -1;
detectorModules->eV[2] = -1;
thisSettings = UNINITIALIZED;
// if trimval requested, should return -1 to acknowledge unknown
@ -732,9 +731,8 @@ void setupDetector() {
getSubExpTime(DEFAULT_SUBFRAME_DEADTIME);
setPeriod(DEFAULT_PERIOD);
setNumTriggers(DEFAULT_NUM_CYCLES);
eiger_dynamicrange = DEFAULT_DYNAMIC_RANGE;
setDynamicRange(DEFAULT_DYNAMIC_RANGE);
eiger_photonenergy = DEFAULT_PHOTON_ENERGY;
detectorModules->eV[0] = DEFAULT_PHOTON_ENERGY;
setParallelMode(DEFAULT_PARALLEL_MODE);
setOverFlowMode(DEFAULT_READOUT_OVERFLOW32_MODE);
setReadoutSpeed(DEFAULT_CLK_SPEED);
@ -1127,25 +1125,43 @@ int64_t getMeasuredSubPeriod() {
/* parameters - channel, module, settings */
void getModule(sls_detector_module* myMod) {
// serial number
myMod->serialnumber = detectorModules->serialnumber;
// reg (settings)
myMod->reg = detectorModules->reg;
// iodelay
myMod->iodelay = setIODelay(-1);
// tau
myMod->tau = (int) getCurrentTau();
// eV
myMod->eV[0] = detectorModules->eV[0];
// dacs
for (int idac = 0; idac < (detectorModules->ndac); idac++) {
*((myMod->dacs) + idac) = *((detectorModules->dacs) + idac);
}
// trimbits
for (int ichan = 0; ichan < (detectorModules->nchan); ichan++) {
*((myMod->chanregs) + ichan) = *((detectorModules->chanregs) + ichan);
}
}
int setModule(sls_detector_module myMod, char *mess) {
LOG(logINFO, ("Setting module with settings %d\n", myMod.reg));
if (((myMod.nchan) > (detectorModules->nchan)) || ((myMod.ndac) > (detectorModules->ndac))) {
strcpy(mess, "Could not set module as the number of channels or dacs do not match to the one in the detector server\n");
LOG(logERROR, (mess));
return FAIL;
}
// serial number (pointless)
detectorModules->serialnumber = myMod.serialnumber;
// settings
setSettings((enum detectorSettings)myMod.reg);
// copy module locally (module number, serial number
// dacs (pointless), trimbit values(if needed)
if (detectorModules) {
if (copyModule(detectorModules, &myMod) == FAIL) {
sprintf(mess, "Could not copy module\n");
LOG(logERROR, (mess));
setSettings(UNDEFINED);
LOG(logERROR, ("Settings has been changed to undefined\n"));
return FAIL;
}
}
// iodelay
if (setIODelay(myMod.iodelay) != myMod.iodelay) {
sprintf(mess, "Could not set module. Could not set iodelay %d\n",
@ -1178,60 +1194,15 @@ int setModule(sls_detector_module myMod, char *mess) {
}
}
#ifndef VIRTUAL
// trimbits
#ifndef VIRTUAL
if (myMod.nchan == 0) {
LOG(logINFO, ("Setting module without trimbits\n"));
} else {
LOG(logINFO, ("Setting module with trimbits\n"));
// includ gap pixels
unsigned int tt[263680];
int ip = 0, ich = 0;
for (int iy = 0; iy < 256; ++iy) {
for (int ichip = 0; ichip < 4; ++ichip) {
for (int ix = 0; ix < 256; ++ix) {
tt[ip++] = myMod.chanregs[ich++];
}
if (ichip < 3) {
tt[ip++] = 0;
tt[ip++] = 0;
}
}
}
// set trimbits
sharedMemory_lockLocalLink();
// if quad, set M8 and PROGRAM manually
if (!Feb_Control_SetChipSignalsToTrimQuad(1)) {
sharedMemory_unlockLocalLink();
if (setTrimbits(myMod.chanregs, mess) == FAIL) {
return FAIL;
}
if (!Feb_Control_SetTrimbits(tt, top)) {
sprintf(mess, "Could not set module. Could not set trimbits\n");
LOG(logERROR, (mess));
setSettings(UNDEFINED);
LOG(logERROR, ("Settings has been changed to undefined (random "
"trim file)\n"));
// if quad, reset M8 and PROGRAM manually
if (!Feb_Control_SetChipSignalsToTrimQuad(0)) {
sharedMemory_unlockLocalLink();
return FAIL;
}
sharedMemory_unlockLocalLink();
return FAIL;
}
// if quad, reset M8 and PROGRAM manually
if (!Feb_Control_SetChipSignalsToTrimQuad(0)) {
sharedMemory_unlockLocalLink();
return FAIL;
}
sharedMemory_unlockLocalLink();
}
#endif
@ -1284,6 +1255,7 @@ enum detectorSettings setSettings(enum detectorSettings sett) {
return thisSettings;
}
thisSettings = sett;
detectorModules->reg = sett;
LOG(logINFO, ("Settings: %d\n", thisSettings));
return thisSettings;
}
@ -1294,13 +1266,14 @@ enum detectorSettings getSettings() { return thisSettings; }
int getThresholdEnergy() {
LOG(logDEBUG1, ("Getting Threshold energy\n"));
return eiger_photonenergy;
return detectorModules->eV[0];
}
int setThresholdEnergy(int ev) {
LOG(logINFO, ("Setting threshold energy:%d\n", ev));
if (ev >= 0)
eiger_photonenergy = ev;
if (ev >= 0) {
detectorModules->eV[0] = ev;
}
return getThresholdEnergy();
}
@ -1910,6 +1883,7 @@ int setIODelay(int val) {
#else
eiger_iodelay = val;
#endif
detectorModules->iodelay = val;
}
return eiger_iodelay;
}
@ -2153,7 +2127,6 @@ void setDefaultSettingsTau_in_nsec(int t) {
int64_t getCurrentTau() {
if (!getRateCorrectionEnable()) {
eiger_tau_ns = 0;
return 0;
} else {
#ifndef VIRTUAL
sharedMemory_lockLocalLink();
@ -2162,8 +2135,9 @@ int64_t getCurrentTau() {
#else
eiger_tau_ns = eiger_virtual_ratetable_tau_in_ns;
#endif
return eiger_tau_ns;
}
detectorModules->tau = eiger_tau_ns;
return eiger_tau_ns;
}
void setExternalGating(int enable[]) {
@ -2184,6 +2158,68 @@ void setExternalGating(int enable[]) {
enable[1] = eiger_extgatingpolarity;
}
int setTrimbits(int* chanregs, char* mess) {
LOG(logINFO, ("Setting module with trimbits\n"));
#ifndef VIRTUAL
// include gap pixels
unsigned int tt[263680];
int ip = 0, ich = 0;
for (int iy = 0; iy < 256; ++iy) {
for (int ichip = 0; ichip < 4; ++ichip) {
for (int ix = 0; ix < 256; ++ix) {
tt[ip++] = chanregs[ich++];
}
if (ichip < 3) {
tt[ip++] = 0;
tt[ip++] = 0;
}
}
}
// set trimbits
sharedMemory_lockLocalLink();
// if quad, set M8 and PROGRAM manually
if (!Feb_Control_SetChipSignalsToTrimQuad(1)) {
sharedMemory_unlockLocalLink();
return FAIL;
}
if (!Feb_Control_SetTrimbits(tt, top)) {
sprintf(mess, "Could not set module. Could not set trimbits\n");
LOG(logERROR, (mess));
setSettings(UNDEFINED);
LOG(logERROR, ("Settings has been changed to undefined (random "
"trim file)\n"));
// if quad, reset M8 and PROGRAM manually
if (!Feb_Control_SetChipSignalsToTrimQuad(0)) {
sharedMemory_unlockLocalLink();
return FAIL;
}
sharedMemory_unlockLocalLink();
return FAIL;
}
// if quad, reset M8 and PROGRAM manually
if (!Feb_Control_SetChipSignalsToTrimQuad(0)) {
sharedMemory_unlockLocalLink();
return FAIL;
}
sharedMemory_unlockLocalLink();
// copying trimbits locally (if tirmbit value > -1)
for (int ichan = 0; ichan < (detectorModules->nchan); ichan++) {
if (*(chanregs + ichan) >= 0)
*((detectorModules->chanregs) + ichan) = *(chanregs + ichan);
}
#endif
return OK;
}
int setAllTrimbits(int val) {
LOG(logINFO, ("Setting all trimbits to %d\n", val));
#ifndef VIRTUAL
@ -2195,6 +2231,8 @@ int setAllTrimbits(int val) {
}
sharedMemory_unlockLocalLink();
#endif
// copying trimbits locally
if (detectorModules) {
for (int ichan = 0; ichan < (detectorModules->nchan); ichan++) {
*((detectorModules->chanregs) + ichan) = val;
@ -2906,53 +2944,6 @@ void readFrame(int *ret, char *mess) {
/* common */
int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod) {
LOG(logDEBUG1, ("Copying module\n"));
if (srcMod->serialnumber >= 0) {
destMod->serialnumber = srcMod->serialnumber;
}
// no trimbit feature
if (destMod->nchan && ((srcMod->nchan) > (destMod->nchan))) {
LOG(logINFO, ("Number of channels of source is larger than number of "
"channels of destination\n"));
return FAIL;
}
if ((srcMod->ndac) > (destMod->ndac)) {
LOG(logINFO, ("Number of dacs of source is larger than number of dacs "
"of destination\n"));
return FAIL;
}
LOG(logDEBUG1, ("DACs: src %d, dest %d\n", srcMod->ndac, destMod->ndac));
LOG(logDEBUG1, ("Chans: src %d, dest %d\n", srcMod->nchan, destMod->nchan));
if (srcMod->reg >= 0)
destMod->reg = srcMod->reg;
if (srcMod->iodelay >= 0)
destMod->iodelay = srcMod->iodelay;
if (srcMod->tau >= 0)
destMod->tau = srcMod->tau;
if (srcMod->eV[0] >= 0)
destMod->eV[0] = srcMod->eV[0];
LOG(logDEBUG1, ("Copying register %x (%x)\n", destMod->reg, srcMod->reg));
if (destMod->nchan != 0 && srcMod->nchan != 0) {
for (int ichan = 0; ichan < (srcMod->nchan); ichan++) {
if (*((srcMod->chanregs) + ichan) >= 0)
*((destMod->chanregs) + ichan) = *((srcMod->chanregs) + ichan);
}
} else
LOG(logINFO, ("Not Copying trimbits\n"));
for (int idac = 0; idac < (srcMod->ndac); idac++) {
if (*((srcMod->dacs) + idac) >= 0) {
*((destMod->dacs) + idac) = *((srcMod->dacs) + idac);
}
}
return OK;
}
int calculateDataBytes() {
if (send_to_ten_gig)
return eiger_dynamicrange * ONE_GIGA_CONSTANT * TEN_GIGA_BUFFER_SIZE;

View File

@ -421,7 +421,7 @@ void allocateDetectorStructureMemory() {
detectorDacs[idac] = 0;
}
// trimbits start at 0 //TODO: restart server will not have 0 always
// trimbits start at 0
for (int ichan = 0; ichan < (detectorModules->nchan); ichan++) {
*((detectorModules->chanregs) + ichan) = 0;
}
@ -1255,21 +1255,52 @@ int setDACS(int *dacs) {
return OK;
}
void getModule(sls_detector_module* myMod) {
// serial number
myMod->serialnumber = detectorModules->serialnumber;
// csr reg
myMod->reg = detectorModules->reg;
// eV
myMod->eV[0] = detectorModules->eV[0];
myMod->eV[1] = detectorModules->eV[1];
myMod->eV[2] = detectorModules->eV[2];
// dacs
for (int idac = 0; idac < (detectorModules->ndac); idac++) {
*((myMod->dacs) + idac) = *((detectorModules->dacs) + idac);
}
// trimbits
for (int ichan = 0; ichan < (detectorModules->nchan); ichan++) {
*((myMod->chanregs) + ichan) = *((detectorModules->chanregs) + ichan);
}
}
int setModule(sls_detector_module myMod, char *mess) {
LOG(logINFO, ("Setting module\n"));
if (((myMod.nchan) > (detectorModules->nchan)) || ((myMod.ndac) > (detectorModules->ndac))) {
strcpy(mess, "Could not set module as the number of channels or dacs do not match to the one in the detector server\n");
LOG(logERROR, (mess));
return FAIL;
}
// serial number (pointless)
detectorModules->serialnumber = myMod.serialnumber;
// csr reg
if (setChipStatusRegister(myMod.reg)) {
sprintf(mess, "Could not CSR from module\n");
LOG(logERROR, (mess));
return FAIL;
}
// dacs
if (setDACS(myMod.dacs)) {
sprintf(mess, "Could not set dacs\n");
LOG(logERROR, (mess));
return FAIL;
}
// threshold energy
for (int i = 0; i < NCOUNTERS; ++i) {
if (myMod.eV[i] >= 0) {
setThresholdEnergy(i, myMod.eV[i]);
@ -1338,6 +1369,12 @@ int setTrimbits(int *trimbits) {
return FAIL;
}
// copying trimbits locally (if tirmbit value > -1)
for (int ichan = 0; ichan < (detectorModules->nchan); ichan++) {
if (*(trimbits + ichan) >= 0)
*((detectorModules->chanregs) + ichan) = *(trimbits + ichan);
}
return (error ? FAIL : OK);
}
@ -2572,56 +2609,6 @@ u_int32_t runBusy() {
/* common */
int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod) {
LOG(logDEBUG1, ("Copying module\n"));
if (srcMod->serialnumber >= 0) {
destMod->serialnumber = srcMod->serialnumber;
}
// no trimbit feature
if (destMod->nchan && ((srcMod->nchan) > (destMod->nchan))) {
LOG(logINFO, ("Number of channels of source is larger than number of "
"channels of destination\n"));
return FAIL;
}
if ((srcMod->ndac) > (destMod->ndac)) {
LOG(logINFO, ("Number of dacs of source is larger than number of dacs "
"of destination\n"));
return FAIL;
}
LOG(logDEBUG1, ("DACs: src %d, dest %d\n", srcMod->ndac, destMod->ndac));
LOG(logDEBUG1, ("Chans: src %d, dest %d\n", srcMod->nchan, destMod->nchan));
if (srcMod->reg >= 0)
destMod->reg = srcMod->reg;
/*
if (srcMod->iodelay >= 0)
destMod->iodelay = srcMod->iodelay;
if (srcMod->tau >= 0)
destMod->tau = srcMod->tau;
*/
for (int i = 0; i < NCOUNTERS; ++i) {
if (srcMod->eV[i] >= 0)
destMod->eV[i] = srcMod->eV[i];
}
LOG(logDEBUG1, ("Copying register %x (%x)\n", destMod->reg, srcMod->reg));
if (destMod->nchan != 0 && srcMod->nchan != 0) {
for (int ichan = 0; ichan < (srcMod->nchan); ichan++) {
*((destMod->chanregs) + ichan) = *((srcMod->chanregs) + ichan);
}
} else
LOG(logINFO, ("Not Copying trimbits\n"));
for (int idac = 0; idac < (srcMod->ndac); idac++) {
if (*((srcMod->dacs) + idac) >= 0) {
*((destMod->dacs) + idac) = *((srcMod->dacs) + idac);
}
}
return OK;
}
int calculateDataBytes() {
int numCounters = __builtin_popcount(getCounterMask());
int dr = 0;
@ -2670,5 +2657,6 @@ int setChipStatusRegister(int csr) {
return FAIL;
}
detectorModules->reg = csr;
return iret;
}

View File

@ -26,6 +26,7 @@ int receiveData(int file_des, void *buf, int length, intType itype);
int sendDataOnly(int file_des, void *buf, int length);
int receiveDataOnly(int file_des, void *buf, int length);
int sendModule(int file_des, sls_detector_module *myMod);
int receiveModule(int file_des, sls_detector_module *myMod);
/**

View File

@ -308,9 +308,16 @@ int64_t getMeasurementTime();
#endif
// parameters - module, settings
#if defined(MYTHEN3D) || defined(EIGERD)
void getModule(sls_detector_module* myMod);
#endif
#if (!defined(CHIPTESTBOARDD)) && (!defined(MOENCHD)) && (!defined(GOTTHARD2D))
int setModule(sls_detector_module myMod, char *mess);
#endif
#ifdef EIGERD
int setTrimbits(int* chanregs, char* mess);
#endif
#ifdef MYTHEN3D
int setTrimbits(int *trimbits);
int setAllTrimbits(int val);
@ -662,9 +669,6 @@ u_int32_t runState(enum TLogLevel lev);
#endif
// common
#if defined(EIGERD) || defined(MYTHEN3D)
int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod);
#endif
int calculateDataBytes();
int getTotalNumberOfChannels();
#if defined(MOENCHD) || defined(CHIPTESTBOARDD)

View File

@ -303,3 +303,4 @@ int get_analog_pulsing(int);
int set_analog_pulsing(int);
int get_digital_pulsing(int);
int set_digital_pulsing(int);
int get_module(int);

View File

@ -406,66 +406,139 @@ int receiveDataOnly(int file_des, void *buf, int length) {
return total_received;
}
int sendModule(int file_des, sls_detector_module *myMod) {
enum TLogLevel level = logDEBUG1;
LOG(level, ("Sending Module\n"));
int ts = 0, n = 0;
n = sendData(file_des, &(myMod->serialnumber),
sizeof(myMod->serialnumber), INT32);
if (!n) {
return -1;
}
ts += n;
LOG(level, ("serialno sent %d bytes. serialno: %d\n", n,
myMod->serialnumber));
n = sendData(file_des, &(myMod->nchan), sizeof(myMod->nchan), INT32);
if (!n) {
return -1;
}
ts += n;
LOG(level, ("nchan sent %d bytes. nchan: %d\n", n, myMod->nchan));
n = sendData(file_des, &(myMod->nchip), sizeof(myMod->nchip), INT32);
if (!n) {
return -1;
}
ts += n;
LOG(level, ("nchip sent %d bytes. nchip: %d\n", n, myMod->nchip));
n = sendData(file_des, &(myMod->ndac), sizeof(myMod->ndac), INT32);
if (!n) {
return -1;
}
ts += n;
LOG(level, ("ndac sent %d bytes. ndac: %d\n", n, myMod->ndac));
n = sendData(file_des, &(myMod->reg), sizeof(myMod->reg), INT32);
if (!n) {
return -1;
}
ts += n;
LOG(level, ("reg sent %d bytes. reg: %d\n", n, myMod->reg));
n = sendData(file_des, &(myMod->iodelay), sizeof(myMod->iodelay), INT32);
if (!n) {
return -1;
}
ts += n;
LOG(level,
("iodelay sent %d bytes. iodelay: %d\n", n, myMod->iodelay));
n = sendData(file_des, &(myMod->tau), sizeof(myMod->tau), INT32);
if (!n) {
return -1;
}
ts += n;
LOG(level, ("tau sent %d bytes. tau: %d\n", n, myMod->tau));
n = sendData(file_des, myMod->eV, sizeof(myMod->eV), INT32);
if (!n) {
return -1;
}
ts += n;
LOG(level, ("eV sent %d bytes. eV: %d\n", n, myMod->eV[0]));
// dacs
n = sendData(file_des, myMod->dacs, sizeof(int) * (myMod->ndac), INT32);
if (!n) {
return -1;
}
ts += n;
LOG(level, ("dacs sent %d bytes.\n", n));
// channels
n = sendData(file_des, myMod->chanregs, sizeof(int) * (myMod->nchan),
INT32);
LOG(level, ("chanregs sent %d bytes.\n", n));
if (!n) {
return -1;
}
ts += n;
LOG(level, ("received module of size %d register %x\n", ts, myMod->reg));
return ts;
}
int receiveModule(int file_des, sls_detector_module *myMod) {
enum TLogLevel level = logDEBUG1;
LOG(level, ("Receiving Module\n"));
int ts = 0, n = 0;
int nDacs = myMod->ndac;
#if defined(EIGERD) || defined(MYTHEN3D)
int nChans = myMod->nchan; // can be zero for no trimbits
LOG(level, ("nChans: %d\n", nChans));
#endif
n = receiveData(file_des, &(myMod->serialnumber),
sizeof(myMod->serialnumber), INT32);
if (!n) {
return -1;
}
ts += n;
LOG(level, ("serialno received. %d bytes. serialno: %d\n", n,
LOG(level, ("serialno received %d bytes. serialno: %d\n", n,
myMod->serialnumber));
n = receiveData(file_des, &(myMod->nchan), sizeof(myMod->nchan), INT32);
if (!n) {
return -1;
}
ts += n;
LOG(level, ("nchan received. %d bytes. nchan: %d\n", n, myMod->nchan));
LOG(level, ("nchan received %d bytes. nchan: %d\n", n, myMod->nchan));
n = receiveData(file_des, &(myMod->nchip), sizeof(myMod->nchip), INT32);
if (!n) {
return -1;
}
ts += n;
LOG(level, ("nchip received. %d bytes. nchip: %d\n", n, myMod->nchip));
LOG(level, ("nchip received %d bytes. nchip: %d\n", n, myMod->nchip));
n = receiveData(file_des, &(myMod->ndac), sizeof(myMod->ndac), INT32);
if (!n) {
return -1;
}
ts += n;
LOG(level, ("ndac received. %d bytes. ndac: %d\n", n, myMod->ndac));
LOG(level, ("ndac received %d bytes. ndac: %d\n", n, myMod->ndac));
n = receiveData(file_des, &(myMod->reg), sizeof(myMod->reg), INT32);
if (!n) {
return -1;
}
ts += n;
LOG(level, ("reg received. %d bytes. reg: %d\n", n, myMod->reg));
LOG(level, ("reg received %d bytes. reg: %d\n", n, myMod->reg));
n = receiveData(file_des, &(myMod->iodelay), sizeof(myMod->iodelay), INT32);
if (!n) {
return -1;
}
ts += n;
LOG(level,
("iodelay received. %d bytes. iodelay: %d\n", n, myMod->iodelay));
("iodelay received %d bytes. iodelay: %d\n", n, myMod->iodelay));
n = receiveData(file_des, &(myMod->tau), sizeof(myMod->tau), INT32);
if (!n) {
return -1;
}
ts += n;
LOG(level, ("tau received. %d bytes. tau: %d\n", n, myMod->tau));
LOG(level, ("tau received %d bytes. tau: %d\n", n, myMod->tau));
n = receiveData(file_des, myMod->eV, sizeof(myMod->eV), INT32);
if (!n) {
return -1;
}
ts += n;
LOG(level, ("eV received. %d bytes. eV: %d\n", n, myMod->eV[0]));
LOG(level, ("eV received %d bytes. eV: %d\n", n, myMod->eV[0]));
// dacs
if (nDacs != (myMod->ndac)) {
LOG(logERROR, ("received wrong number of dacs. "
@ -478,24 +551,22 @@ int receiveModule(int file_des, sls_detector_module *myMod) {
return -1;
}
ts += n;
LOG(level, ("dacs received. %d bytes.\n", n));
LOG(level, ("dacs received %d bytes.\n", n));
// channels
#if defined(EIGERD) || defined(MYTHEN3D)
if (((myMod->nchan) != 0) && // no trimbits
(nChans != (myMod->nchan))) { // with trimbits
LOG(logERROR, ("received wrong number of channels. "
"Expected %d, got %d\n",
nChans, (myMod->nchan)));
return 0;
return -1;
}
n = receiveData(file_des, myMod->chanregs, sizeof(int) * (myMod->nchan),
INT32);
LOG(level, ("chanregs received. %d bytes.\n", n));
LOG(level, ("chanregs received %d bytes.\n", n));
if (!n && myMod->nchan != 0) {
return -1;
}
ts += n;
#endif
LOG(level, ("received module of size %d register %x\n", ts, myMod->reg));
return ts;
}

View File

@ -468,6 +468,7 @@ void function_table() {
flist[F_SET_ANALOG_PULSING] = &set_analog_pulsing;
flist[F_GET_DIGITAL_PULSING] = &get_digital_pulsing;
flist[F_SET_DIGITAL_PULSING] = &set_digital_pulsing;
flist[F_GET_MODULE] = &get_module;
// check
if (NUM_DET_FUNCTIONS >= RECEIVER_ENUM_START) {
@ -1555,6 +1556,71 @@ int read_register(int file_des) {
return Server_SendResult(file_des, INT32, &retval, sizeof(retval));
}
int get_module(int file_des) {
ret = OK;
memset(mess, 0, sizeof(mess));
sls_detector_module module;
int *myDac = NULL;
int *myChan = NULL;
module.dacs = NULL;
module.chanregs = NULL;
#if !defined(MYTHEN3D) && !defined(EIGERD)
functionNotImplemented();
#else
// allocate to receive module structure
// allocate dacs
myDac = malloc(getNumberOfDACs() * sizeof(int));
// error
if (getNumberOfDACs() > 0 && myDac == NULL) {
ret = FAIL;
sprintf(mess, "Could not allocate dacs\n");
LOG(logERROR, (mess));
} else
module.dacs = myDac;
// allocate chans
if (ret == OK) {
myChan = malloc(getTotalNumberOfChannels() * sizeof(int));
if (getTotalNumberOfChannels() > 0 && myChan == NULL) {
ret = FAIL;
sprintf(mess, "Could not allocate chans\n");
LOG(logERROR, (mess));
} else
module.chanregs = myChan;
}
// receive module structure
if (ret == OK) {
module.nchip = getNumberOfChips();
module.nchan = getTotalNumberOfChannels();
module.ndac = getNumberOfDACs();
// ensure nchan is not 0, else trimbits not copied
if (module.nchan == 0) {
strcpy(mess, "Could not get module as the number of channels to copy is 0\n");
LOG(logERROR, (mess));
return FAIL;
}
getModule(&module);
}
#endif
Server_SendResult(file_des, INT32, NULL, 0);
if (ret != FAIL) {
if (sendModule(file_des, &module) < 0) {
ret = FAIL;
}
}
if (myChan != NULL)
free(myChan);
if (myDac != NULL)
free(myDac);
return ret;
}
int set_module(int file_des) {
ret = OK;
memset(mess, 0, sizeof(mess));
@ -1631,8 +1697,10 @@ int set_module(int file_des) {
#endif
LOG(logDEBUG1, ("Settings: %d\n", retval));
}
free(myChan);
free(myDac);
if (myChan != NULL)
free(myChan);
if (myDac != NULL)
free(myDac);
#endif
return Server_SendResult(file_des, INT32, NULL, 0);

View File

@ -159,6 +159,10 @@ class Detector {
* is attached. */
void loadTrimbits(const std::string &fname, Positions pos = {});
/** [Eiger][Mythen3] If no extension specified, serial number of each module
* is attached. */
void saveTrimbits(const std::string &fname, Positions pos = {});
/** [Eiger][Mythen3] -1 if they are all different */
Result<int> getAllTrimbits(Positions pos = {}) const;

View File

@ -452,6 +452,31 @@ std::string CmdProxy::Threshold(int action) {
return os.str();
}
std::string CmdProxy::Trimbits(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[fname]\n\t[Eiger][Mythen3] Put will load the trimbit file to detector. If no extension specified, serial number of each module is attached. Get will save the trimbits from the detector to file with serial number added to file name."
<< '\n';
} else if (action == defs::GET_ACTION) {
if (args.size() != 1) {
WrongNumberOfParameters(1);
}
det->saveTrimbits(args[0], std::vector<int>{det_id});
os << args << '\n';
} else if (action == defs::PUT_ACTION) {
if (args.size() != 1) {
WrongNumberOfParameters(1);
}
det->loadTrimbits(args[0], std::vector<int>{det_id});
os << args << '\n';
} else {
throw RuntimeError("Unknown action");
}
return os.str();
}
std::string CmdProxy::TrimEnergies(int action) {
std::ostringstream os;
os << cmd << ' ';

View File

@ -782,7 +782,7 @@ class CmdProxy {
{"threshold", &CmdProxy::Threshold},
{"thresholdnotb", &CmdProxy::Threshold},
{"settingspath", &CmdProxy::settingspath},
{"trimbits", &CmdProxy::trimbits},
{"trimbits", &CmdProxy::Trimbits},
{"trimval", &CmdProxy::trimval},
{"trimen", &CmdProxy::TrimEnergies},
{"gappixels", &CmdProxy::GapPixels},
@ -1115,6 +1115,7 @@ class CmdProxy {
std::string ClientVersion(int action);
std::string DetectorSize(int action);
std::string Threshold(int action);
std::string Trimbits(int action);
std::string TrimEnergies(int action);
std::string GapPixels(int action);
/* acquisition parameters */
@ -1273,11 +1274,6 @@ class CmdProxy {
"[path]\n\t[Eiger][Mythen3] Directory where settings files "
"are loaded from/to.");
EXECUTE_SET_COMMAND_1ARG(
trimbits, loadTrimbits,
"[fname]\n\t[Eiger][Mythen3] Loads the trimbit file to detector. If no "
"extension specified, serial number of each module is attached.");
INTEGER_COMMAND_VEC_ID(
trimval, getAllTrimbits, setAllTrimbits, StringTo<int>,
"[n_trimval]\n\t[Eiger][Mythen3] All trimbits set to this "

View File

@ -273,6 +273,10 @@ void Detector::loadTrimbits(const std::string &fname, Positions pos) {
pimpl->Parallel(&Module::loadTrimbits, pos, fname);
}
void Detector::saveTrimbits(const std::string &fname, Positions pos) {
pimpl->Parallel(&Module::saveTrimbits, pos, fname);
}
Result<int> Detector::getAllTrimbits(Positions pos) const {
return pimpl->Parallel(&Module::getAllTrimbits, pos);
}

View File

@ -468,6 +468,27 @@ void Module::loadTrimbits(const std::string &fname) {
}
}
void Module::saveTrimbits(const std::string &fname) {
// find specific file if it has detid in file name (.snxxx)
if (shm()->detType == EIGER || shm()->detType == MYTHEN3) {
std::ostringstream ostfn;
ostfn << fname;
int moduleIdWidth = 3;
if (shm()->detType == MYTHEN3) {
moduleIdWidth = 4;
}
if ((fname.find(".sn") == std::string::npos) &&
(fname.find(".trim") == std::string::npos)) {
ostfn << ".sn" << std::setfill('0') << std::setw(moduleIdWidth)
<< std::dec << getModuleId();
}
auto myMod = getModule();
saveSettingsFile(myMod, ostfn.str());
} else {
throw RuntimeError("not implemented for this detector");
}
}
int Module::getAllTrimbits() const {
return sendToDetector<int>(F_SET_ALL_TRIMBITS, GET_FLAG);
}
@ -3310,7 +3331,36 @@ void Module::checkReceiverVersionCompatibility() {
sendToReceiver(F_RECEIVER_CHECK_VERSION, int64_t(APIRECEIVER), nullptr);
}
int Module::sendModule(sls_detector_module *myMod, ClientSocket &client) {
void Module::setModule(sls_detector_module &module, bool trimbits) {
LOG(logDEBUG1) << "Setting module with trimbits:" << trimbits;
// to exclude trimbits
if (!trimbits) {
module.nchan = 0;
module.nchip = 0;
}
auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
client.Send(F_SET_MODULE);
sendModule(&module, client);
if (client.Receive<int>() == FAIL) {
throw DetectorError("Module " + std::to_string(moduleIndex) +
" returned error: " + client.readErrorMessage());
}
}
sls_detector_module Module::getModule() {
LOG(logDEBUG1) << "Getting module";
sls_detector_module module(shm()->detType);
auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
client.Send(F_GET_MODULE);
if (client.Receive<int>() == FAIL) {
throw DetectorError("Module " + std::to_string(moduleIndex) +
" returned error: " + client.readErrorMessage());
}
receiveModule(&module, client);
return module;
}
void Module::sendModule(sls_detector_module *myMod, ClientSocket &client) {
constexpr TLogLevel level = logDEBUG1;
LOG(level) << "Sending Module";
int ts = 0;
@ -3353,28 +3403,41 @@ int Module::sendModule(sls_detector_module *myMod, ClientSocket &client) {
ts += n;
LOG(level) << "dacs sent. " << n << " bytes";
if (shm()->detType == EIGER || shm()->detType == MYTHEN3) {
n = client.Send(myMod->chanregs, sizeof(int) * (myMod->nchan));
ts += n;
LOG(level) << "channels sent. " << n << " bytes";
n = client.Send(myMod->chanregs, sizeof(int) * (myMod->nchan));
ts += n;
LOG(level) << "channels sent. " << n << " bytes";
int expectedBytesSent = sizeof(sls_detector_module) - sizeof(myMod->dacs) - sizeof(myMod->chanregs) + (myMod->ndac * sizeof(int)) + (myMod->nchan * sizeof(int));
if (expectedBytesSent != ts) {
throw RuntimeError("Module size " + std::to_string(ts) + " sent does not match expected size to be sent " + std::to_string(expectedBytesSent));
}
return ts;
}
void Module::setModule(sls_detector_module &module, bool trimbits) {
LOG(logDEBUG1) << "Setting module with trimbits:" << trimbits;
// to exclude trimbits
if (!trimbits) {
module.nchan = 0;
module.nchip = 0;
}
auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
client.Send(F_SET_MODULE);
sendModule(&module, client);
if (client.Receive<int>() == FAIL) {
throw DetectorError("Module " + std::to_string(moduleIndex) +
" returned error: " + client.readErrorMessage());
}
void Module::receiveModule(sls_detector_module *myMod, ClientSocket &client) {
constexpr TLogLevel level = logDEBUG1;
LOG(level) << "Receiving Module";
myMod->serialnumber = client.Receive<int>();
LOG(level) << "serialno: " << myMod->serialnumber;
myMod->nchan = client.Receive<int>();
LOG(level) << "nchan: " << myMod->nchan;
myMod->nchip = client.Receive<int>();
LOG(level) << "nchip: " << myMod->nchip;
myMod->ndac = client.Receive<int>();
LOG(level) << "ndac: " << myMod->ndac;
myMod->reg = client.Receive<int>();
LOG(level) << "reg: " << myMod->reg;
myMod->iodelay = client.Receive<int>();
LOG(level) << "iodelay: " << myMod->iodelay;
myMod->tau = client.Receive<int>();
LOG(level) << "tau: " << myMod->tau;
client.Receive(myMod->eV);
LOG(level) << "eV: " << ToString(myMod->eV);
client.Receive(myMod->dacs, sizeof(int) * (myMod->ndac));
LOG(level) << myMod->ndac << " dacs received";
client.Receive(myMod->chanregs, sizeof(int) * (myMod->nchan));
LOG(level) << myMod->nchan << " chans received";
}
void Module::updateReceiverStreamingIP() {
@ -3615,10 +3678,39 @@ sls_detector_module Module::readSettingsFile(const std::string &fname,
else {
throw RuntimeError("Not implemented for this detector");
}
LOG(logINFO) << "Settings file loaded: " << fname.c_str();
LOG(logINFO) << "Settings file loaded: " << fname;
return myMod;
}
void Module::saveSettingsFile(sls_detector_module &myMod, const std::string &fname) {
LOG(logDEBUG1) << moduleIndex << ": Saving settings to " << fname;
std::ofstream outfile(fname);
if (!outfile) {
throw RuntimeError("Could not write settings file: " + fname);
}
switch (shm()->detType) {
case MYTHEN3:
outfile.write(reinterpret_cast<char *>(&myMod.reg), sizeof(myMod.reg));
outfile.write(reinterpret_cast<char *>(myMod.dacs),
sizeof(int) * (myMod.ndac));
outfile.write(reinterpret_cast<char *>(myMod.chanregs),
sizeof(int) * (myMod.nchan));
break;
case EIGER:
outfile.write(reinterpret_cast<char *>(myMod.dacs),
sizeof(int) * (myMod.ndac));
outfile.write(reinterpret_cast<char *>(&myMod.iodelay),
sizeof(myMod.iodelay));
outfile.write(reinterpret_cast<char *>(&myMod.tau), sizeof(myMod.tau));
outfile.write(reinterpret_cast<char *>(myMod.chanregs),
sizeof(int) * (myMod.nchan));
break;
default:
throw RuntimeError("Saving settings file is not implemented for this detector.");
}
LOG(logINFO) << "Settings for " << shm()->hostname << " written to " << fname;
}
void Module::sendProgram(bool blackfin, std::vector<char> buffer,
const int functionEnum,
const std::string &functionType,

View File

@ -114,6 +114,7 @@ class Module : public virtual slsDetectorDefs {
std::string getSettingsDir() const;
std::string setSettingsDir(const std::string &dir);
void loadTrimbits(const std::string &fname);
void saveTrimbits(const std::string &fname);
int getAllTrimbits() const;
void setAllTrimbits(int val);
std::vector<int> getTrimEn() const;
@ -736,7 +737,9 @@ class Module : public virtual slsDetectorDefs {
void checkDetectorVersionCompatibility();
void checkReceiverVersionCompatibility();
void setModule(sls_detector_module &module, bool trimbits = true);
int sendModule(sls_detector_module *myMod, ClientSocket &client);
sls_detector_module getModule();
void sendModule(sls_detector_module *myMod, ClientSocket &client);
void receiveModule(sls_detector_module *myMod, ClientSocket &client);
void updateReceiverStreamingIP();
void updateRateCorrection();
@ -770,6 +773,7 @@ class Module : public virtual slsDetectorDefs {
std::string getTrimbitFilename(detectorSettings settings, int e_eV);
sls_detector_module readSettingsFile(const std::string &fname,
bool trimbits = true);
void saveSettingsFile(sls_detector_module &myMod, const std::string &fname);
void sendProgram(bool blackfin, std::vector<char> buffer,
const int functionEnum, const std::string &functionType,
const std::string serverName = "",

View File

@ -270,6 +270,7 @@ enum detFuncs {
F_SET_ANALOG_PULSING,
F_GET_DIGITAL_PULSING,
F_SET_DIGITAL_PULSING,
F_GET_MODULE,
NUM_DET_FUNCTIONS,
RECEIVER_ENUM_START = 512, /**< detector function should not exceed this
@ -646,6 +647,7 @@ const char* getFunctionNameFromEnum(enum detFuncs func) {
case F_SET_ANALOG_PULSING: return "F_SET_ANALOG_PULSING";
case F_GET_DIGITAL_PULSING: return "F_GET_DIGITAL_PULSING";
case F_SET_DIGITAL_PULSING: return "F_SET_DIGITAL_PULSING";
case F_GET_MODULE: return "F_GET_MODULE";
case NUM_DET_FUNCTIONS: return "NUM_DET_FUNCTIONS";
case RECEIVER_ENUM_START: return "RECEIVER_ENUM_START";

View File

@ -5,10 +5,10 @@
#define APILIB 0x220408
#define APIRECEIVER 0x220408
#define APIGUI 0x220328
#define APICTB 0x220518
#define APIGOTTHARD 0x220518
#define APIGOTTHARD2 0x220518
#define APIJUNGFRAU 0x220518
#define APIMYTHEN3 0x220518
#define APIMOENCH 0x220517
#define APIEIGER 0x220518
#define APICTB 0x220524
#define APIGOTTHARD 0x220524
#define APIGOTTHARD2 0x220524
#define APIJUNGFRAU 0x220524
#define APIMYTHEN3 0x220524
#define APIMOENCH 0x220519
#define APIEIGER 0x220524