This commit is contained in:
Erik Frojdh
2019-03-13 16:29:29 +01:00
parent 75ce111344
commit 85134443de
2 changed files with 89 additions and 87 deletions

View File

@ -41,8 +41,8 @@ slsDetector::slsDetector(detectorType type, int multiId, int id, bool verify)
initSharedMemory(true, type, multiId, verify); initSharedMemory(true, type, multiId, verify);
initializeDetectorStructure(type); initializeDetectorStructure(type);
initializeMembers(); // initializeMembers();
initializeDetectorStructurePointers(); // initializeDetectorStructurePointers();
} }
slsDetector::slsDetector(int multiId, int id, bool verify) slsDetector::slsDetector(int multiId, int id, bool verify)
@ -54,7 +54,7 @@ slsDetector::slsDetector(int multiId, int id, bool verify)
detectorType type = getDetectorTypeFromShm(multiId, verify); detectorType type = getDetectorTypeFromShm(multiId, verify);
initSharedMemory(false, type, multiId, verify); initSharedMemory(false, type, multiId, verify);
initializeMembers(); // initializeMembers();
} }
slsDetector::~slsDetector() { slsDetector::~slsDetector() {
@ -490,38 +490,38 @@ void slsDetector::initializeDetectorStructure(detectorType type) {
void slsDetector::initializeMembers() { void slsDetector::initializeMembers() {
// slsdetector // slsdetector
// assign addresses // assign addresses
char *goff = (char *)thisDetector; // char *goff = (char *)thisDetector;
detectorModules = (sls_detector_module *)(goff + thisDetector->modoff); // detectorModules = (sls_detector_module *)(goff + thisDetector->modoff);
dacs = (int *)(goff + thisDetector->dacoff); // dacs = (int *)(goff + thisDetector->dacoff);
chanregs = (int *)(goff + thisDetector->chanoff); // chanregs = (int *)(goff + thisDetector->chanoff);
} }
void slsDetector::initializeDetectorStructurePointers() { void slsDetector::initializeDetectorStructurePointers() {
sls_detector_module *thisMod; // sls_detector_module *thisMod;
// set thisMod to point to one of the detector structure modules // // set thisMod to point to one of the detector structure modules
thisMod = detectorModules; // thisMod = detectorModules;
thisMod->serialnumber = 0; // thisMod->serialnumber = 0;
thisMod->nchan = thisDetector->nChans * thisDetector->nChips; // thisMod->nchan = thisDetector->nChans * thisDetector->nChips;
thisMod->nchip = thisDetector->nChips; // thisMod->nchip = thisDetector->nChips;
thisMod->ndac = thisDetector->nDacs; // thisMod->ndac = thisDetector->nDacs;
thisMod->reg = 0; // thisMod->reg = 0;
thisMod->iodelay = 0; // thisMod->iodelay = 0;
thisMod->tau = 0; // thisMod->tau = 0;
thisMod->eV = 0; // thisMod->eV = 0;
// dacs and chanregs for thisMod is not allocated in // // dacs and chanregs for thisMod is not allocated in
// detectorModules in shared memory as they are already allocated separately // // detectorModules in shared memory as they are already allocated separately
// in shared memory (below) // // in shared memory (below)
// initializes the dacs values to 0 // // initializes the dacs values to 0
for (int i = 0; i < thisDetector->nDacs; ++i) { // for (int i = 0; i < thisDetector->nDacs; ++i) {
*(dacs + i) = 0; // *(dacs + i) = 0;
} // }
// initializes the channel registers to 0 // // initializes the channel registers to 0
for (int i = 0; i < thisDetector->nChans * thisDetector->nChips; ++i) { // for (int i = 0; i < thisDetector->nChans * thisDetector->nChips; ++i) {
*(chanregs + i) = -1; // *(chanregs + i) = -1;
} // }
} }
slsDetectorDefs::sls_detector_module *slsDetector::createModule() { slsDetectorDefs::sls_detector_module *slsDetector::createModule() {
@ -1265,9 +1265,10 @@ std::string slsDetector::getSettingsFile() {
return std::string(thisDetector->settingsFile); return std::string(thisDetector->settingsFile);
} }
int slsDetector::writeSettingsFile(const std::string &fname) { // int slsDetector::writeSettingsFile(const std::string &fname) {
return writeSettingsFile(fname, detectorModules[0]); // //TODO should read module from detector...
} // return writeSettingsFile(fname, getModule());
// }
slsDetectorDefs::detectorSettings slsDetector::getSettings() { slsDetectorDefs::detectorSettings slsDetector::getSettings() {
return sendSettingsOnly(GET_SETTINGS); return sendSettingsOnly(GET_SETTINGS);
@ -1591,8 +1592,8 @@ int slsDetector::saveSettingsFile(const std::string &fname) {
// get module // get module
int ret = FAIL; int ret = FAIL;
sls_detector_module *myMod = nullptr; sls_detector_module *myMod = getModule();
if ((myMod = getModule())) { if (myMod != nullptr) {
ret = writeSettingsFile(fn, *myMod); ret = writeSettingsFile(fn, *myMod);
deleteModule(myMod); deleteModule(myMod);
} }
@ -3987,13 +3988,14 @@ int slsDetector::getChanRegs(double *retval) {
int n = getTotalNumberOfChannels(); int n = getTotalNumberOfChannels();
// update chanregs // update chanregs
sls_detector_module *myMod = getModule(); sls_detector_module *myMod = getModule();
deleteModule(myMod);
//the original array has 0 initialized //the original array has 0 initialized
if (chanregs) { if (myMod->chanregs) {
for (int i = 0; i < n; ++i) { for (int i = 0; i < n; ++i) {
retval[i] = (double)(chanregs[i] & TRIMBITMASK); retval[i] = (double)(myMod->chanregs[i] & TRIMBITMASK);
} }
} }
deleteModule(myMod);
return n; return n;
} }
@ -4035,26 +4037,26 @@ int slsDetector::setModule(sls_detector_module module, int tb) {
// update client structure // update client structure
if (ret == OK) { if (ret == OK) {
if (detectorModules) { // if (detectorModules) {
if (thisDetector->myDetectorType == EIGER && tb && chanregs) { // if (thisDetector->myDetectorType == EIGER && tb && chanregs) {
for (int ichip = 0; ichip < thisDetector->nChips; ++ichip) { // for (int ichip = 0; ichip < thisDetector->nChips; ++ichip) {
for (int i = 0; i < thisDetector->nChans; ++i) { // for (int i = 0; i < thisDetector->nChans; ++i) {
chanregs[i + ichip * thisDetector->nChans] = // chanregs[i + ichip * thisDetector->nChans] =
module.chanregs[ichip * thisDetector->nChans + i]; // module.chanregs[ichip * thisDetector->nChans + i];
} // }
} // }
} // }
if (dacs) { // if (dacs) {
for (int i = 0; i < thisDetector->nDacs; ++i) { // for (int i = 0; i < thisDetector->nDacs; ++i) {
dacs[i] = module.dacs[i]; // dacs[i] = module.dacs[i];
} // }
} // }
(detectorModules)->serialnumber = module.serialnumber; // (detectorModules)->serialnumber = module.serialnumber;
(detectorModules)->reg = module.reg; // (detectorModules)->reg = module.reg;
(detectorModules)->iodelay = module.iodelay; // (detectorModules)->iodelay = module.iodelay;
(detectorModules)->tau = module.tau; // (detectorModules)->tau = module.tau;
(detectorModules)->eV = module.eV; // (detectorModules)->eV = module.eV;
} // }
if (module.eV != -1) { if (module.eV != -1) {
thisDetector->currentThresholdEV = module.eV; thisDetector->currentThresholdEV = module.eV;
} }
@ -4090,31 +4092,31 @@ slsDetectorDefs::sls_detector_module *slsDetector::getModule() {
} }
// update client structure // update client structure
if (ret == OK) { // if (ret == OK) {
if (detectorModules) { // if (detectorModules) {
if (thisDetector->myDetectorType == EIGER && chanregs) { // if (thisDetector->myDetectorType == EIGER && chanregs) {
for (int ichip = 0; ichip < thisDetector->nChips; ++ichip) { // for (int ichip = 0; ichip < thisDetector->nChips; ++ichip) {
for (int i = 0; i < thisDetector->nChans; ++i) { // for (int i = 0; i < thisDetector->nChans; ++i) {
chanregs[i + ichip * thisDetector->nChans] = // chanregs[i + ichip * thisDetector->nChans] =
myMod->chanregs[ichip * thisDetector->nChans + i]; // myMod->chanregs[ichip * thisDetector->nChans + i];
} // }
} // }
} // }
if (dacs) { // if (dacs) {
for (int i = 0; i < thisDetector->nDacs; ++i) { // for (int i = 0; i < thisDetector->nDacs; ++i) {
dacs[i] = myMod->dacs[i]; // dacs[i] = myMod->dacs[i];
} // }
} // }
(detectorModules)->serialnumber = myMod->serialnumber; // (detectorModules)->serialnumber = myMod->serialnumber;
(detectorModules)->reg = myMod->reg; // (detectorModules)->reg = myMod->reg;
(detectorModules)->iodelay = myMod->iodelay; // (detectorModules)->iodelay = myMod->iodelay;
(detectorModules)->tau = myMod->tau; // (detectorModules)->tau = myMod->tau;
(detectorModules)->eV = myMod->eV; // (detectorModules)->eV = myMod->eV;
} // }
} else { // } else {
deleteModule(myMod); // deleteModule(myMod);
myMod = nullptr; // myMod = nullptr;
} // }
return myMod; return myMod;
} }
@ -5526,7 +5528,7 @@ slsDetectorDefs::sls_detector_module *slsDetector::readSettingsFile(const std::s
return myMod; return myMod;
} }
int slsDetector::writeSettingsFile(const std::string &fname, sls_detector_module mod) { int slsDetector::writeSettingsFile(const std::string &fname, sls_detector_module& mod) {
FILE_LOG(logDEBUG1) << "Write settings file " << fname; FILE_LOG(logDEBUG1) << "Write settings file " << fname;

View File

@ -1769,7 +1769,7 @@ class slsDetector : public virtual slsDetectorDefs, public virtual errorDefs {
* @param mod module structure which has to be written to file * @param mod module structure which has to be written to file
* @returns OK or FAIL if the file could not be written * @returns OK or FAIL if the file could not be written
*/ */
int writeSettingsFile(const std::string &fname, sls_detector_module mod); int writeSettingsFile(const std::string &fname, sls_detector_module& mod);
/** slsDetector Id or position in the detectors list */ /** slsDetector Id or position in the detectors list */
int detId; int detId;
@ -1781,13 +1781,13 @@ class slsDetector : public virtual slsDetectorDefs, public virtual errorDefs {
sharedSlsDetector *thisDetector{nullptr}; sharedSlsDetector *thisDetector{nullptr};
/** pointer to detector module structures in shared memory */ /** pointer to detector module structures in shared memory */
sls_detector_module *detectorModules{nullptr}; // sls_detector_module *detectorModules{nullptr};
/** pointer to dac valuse in shared memory */ /** pointer to dac valuse in shared memory */
int *dacs{nullptr}; // int *dacs{nullptr};
/** pointer to channel registers in shared memory */ /** pointer to channel registers in shared memory */
int *chanregs{nullptr}; // int *chanregs{nullptr};
}; };
#endif #endif