gotthard fixed roi only xmin and xmax.remove updateoffsets

This commit is contained in:
2019-08-14 09:20:50 +02:00
parent 2fe06c7163
commit d4d8cbe9bc
28 changed files with 573 additions and 1419 deletions

View File

@ -82,16 +82,10 @@ class Detector {
/**
* Sets the maximum number of channels of complete detector in both
* dimensions. -1 means no limit in this dimension. This value is used to
* calculate row and column offsets for each module.
* calculate row and column channels for each module.
*/
void setMaxNumberOfChannels(const defs::coordinates value);
/** [Gotthard] */
Result<defs::coordinates> getDetectorOffsets(Positions pos = {}) const;
/** [Gotthard] */
void setDetectorOffsets(defs::coordinates value, Positions pos = {});
/** [Eiger with specific quad hardware] */
Result<bool> getQuad(Positions pos = {}) const;
@ -664,15 +658,16 @@ class Detector {
/** [Eiger] If it is set, it resets chips completely (else partially) before an acquisition TODO: if it makes sense */
void setCounterBit(bool value, Positions pos = {});
/** [Gotthard, CTB]*/
Result<std::vector<defs::ROI>> getROI(Positions pos = {}) const;
/** [Gotthard]*/
Result<defs::ROI> getROI(Positions pos = {}) const;
/**
* [Gotthard Options: Only a single chip or all chips, only 1 ROI allowed]
* [CTB: multiple ROIs allowed]
* subset modules not allowed
* [Gotthard]
* Options: Only a single ROI per module
* Can set only a single ROI at a time
* @param module position index
*/
void setROI(std::vector<defs::ROI> value, Positions pos = {});
void setROI(defs::ROI value, int moduleId);
/** [CTB]*/
Result<uint32_t> getADCEnableMask(Positions pos = {}) const;

View File

@ -65,16 +65,6 @@ struct sharedMultiSlsDetector {
/** total number of channels including gap pixels in one dimension */
int numberOfChannelInclGapPixels[2];
/** total number of channels for all detectors */
int maxNumberOfChannels;
/** max number of channels for all detectors in one dimension*/
int maxNumberOfChannel[2];
/** max number of channels including gap pixels for all detectors in
* one dimension*/
int maxNumberOfChannelInclGapPixels[2];
/** max number of channels allowed for the complete set of detectors in
* one dimension */
int maxNumberOfChannelsPerDetector[2];
@ -432,8 +422,7 @@ class multiSlsDetector : public virtual slsDetectorDefs {
/**
* Returns the maximum number of channels of all sls detectors in each
* dimension d from shared memory. multi detector shared memory variable to
* calculate offsets for each sls detector
* dimension d from shared memory.
* @param d dimension d
* @returns the maximum number of channels of all sls detectors in dimension
* d
@ -442,8 +431,7 @@ class multiSlsDetector : public virtual slsDetectorDefs {
/**
* Sets the maximum number of channels of all sls detectors in each
* dimension d from shared memory, multi detector shared memory variable to
* calculate offsets for each sls detector
* dimension d from shared memory
* @param d dimension d
* @param i maximum number of channels for multi structure in dimension d
* @returns the maximum number of channels of all sls detectors in dimension
@ -453,37 +441,18 @@ class multiSlsDetector : public virtual slsDetectorDefs {
/**
* Returns maximum number of channels of all sls detectors in each
* dimension d from shared memory, multi detector shared memory variable to
* calculate offsets for each sls detector
* dimension d from shared memory
* @returns maximum number of channels of all sls detectors
*/
slsDetectorDefs::coordinates getMaxNumberOfChannels() const; //
/**
* Sets maximum number of channels of all sls detectors in each
* dimension d from shared memory, multi detector shared memory variable to
* calculate offsets for each sls detector
* dimension d from shared memory
* @param c maximum number of channels of all sls detectors
*/
void setMaxNumberOfChannels(const slsDetectorDefs::coordinates c); //
/**
* Get Detector offset from shared memory in dimension d
* @param d dimension d
* @param detPos -1 for all detectors in list or specific detector position
* @returns offset in dimension d, -1 if pos is not an actual position in
* list
*/
int getDetectorOffset(dimension d, int detPos = -1); //
/**
* Set Detector offset in shared memory in dimension d
* @param d dimension d
* @param off offset for detector
* @param detPos -1 for all detectors in list or specific detector position
*/
void setDetectorOffset(dimension d, int off, int detPos = -1);//
/**
* Get Quad Type (Only for Eiger Quad detector hardware)
* @param detPos -1 for all detectors in list or specific detector position
@ -1376,22 +1345,27 @@ class multiSlsDetector : public virtual slsDetectorDefs {
int setCounterBit(int i = -1, int detPos = -1); //
/**
* Set ROI (Gotthard)
* At the moment only one set allowed
* @param n number of rois
* @param roiLimits array of roi
* Clear ROI (Gotthard)
* @param detPos -1 for all detectors in list or specific detector position
*/
void setROI(int n = -1, ROI roiLimits[] = nullptr, int detPos = -1);
void clearROI(int detPos = -1);
/**
* Get ROI from each detector and convert it to the multi detector scale
* (Gotthard)
* @param n number of rois
* @param detPos -1 for all detectors in list or specific detector position
* @returns OK or FAIL
* Set ROI (Gotthard)
* At the moment only one set allowed per module
* Only allowed to set one ROI per module
* @param arg roi
* @param detPos specific detector position
*/
const ROI *getROI(int &n, int detPos = -1);
void setROI(slsDetectorDefs::ROI arg, int detPos = -1);
/**
* Get ROI (Gotthard)
* Only allowed to set one ROI per module
* @param detPos specific detector position
* @returns roi
*/
slsDetectorDefs::ROI getROI(int detPos) const;
/**
* Set ADC Enable Mask (CTB, Moench)
@ -2187,14 +2161,6 @@ class multiSlsDetector : public virtual slsDetectorDefs {
*/
void initializeMembers(bool verify = true);
/**
* Appends detectors to the end of the list in shared memory
* Connects to them
* @param name concatenated hostname of the sls detectors to be appended to
* the list
*/
void addMultipleDetectors(const char *name);//
/**
* Update user details in detector structure
*/
@ -2206,23 +2172,6 @@ class multiSlsDetector : public virtual slsDetectorDefs {
*/
bool isAcquireReady();
/**
* Decodes which detector and the corresponding channel numbers for it
* Mainly useful in a multi detector setROI (Gotthard)
* @param offsetX channel number or total channel offset in x direction
* @param offsetY channel number or total channel offset in y direction
* @param channelX channel number from detector offset in x direction
* @param channelY channel number from detector offset in x direction
* @returns detector id or -1 if channel number out of range
*/
int decodeNChannel(int offsetX, int offsetY, int &channelX, int &channelY);
/**
* Updates the channel offsets in X and Y dimension for all the sls
* detectors It is required for decodeNMod and setting ROI
*/
void updateOffsets();
/**
* Execute in command line and return result
* @param cmd command
@ -2230,12 +2179,26 @@ class multiSlsDetector : public virtual slsDetectorDefs {
*/
std::string exec(const char *cmd);
/**
* Appends detectors to the end of the list in shared memory
* Connects to them
* @param name concatenated hostname of the sls detectors to be appended to
* the list
*/
void addMultipleDetectors(const char *name);//
/**
* Add sls detector
* @param s hostname of the single detector
*/
void addSlsDetector(const std::string &hostname);
/**
* Updates the channel size in X and Y dimension for all the sls
* detectors
*/
void updateDetectorSize();
/**
* increments file index
* @param detPos -1 for all detectors in list or specific detector position
@ -2243,13 +2206,6 @@ class multiSlsDetector : public virtual slsDetectorDefs {
*/
int incrementFileIndex(int detPos = -1);
/**
* Ensures that min is less than max in both dimensions (Gotthard)
* @param n number of rois
* @param r array of rois
*/
void verifyMinMaxROI(int n, ROI r[]);
/**
* add gap pixels to the image (only for Eiger in 4 bit mode)
* @param image pointer to image without gap pixels

View File

@ -13,7 +13,7 @@
class ServerInterface;
#define SLS_SHMAPIVERSION 0x190726
#define SLS_SHMVERSION 0x190726
#define SLS_SHMVERSION 0x190813
/**
* @short structure allocated in shared memory to store detector settings for
@ -35,10 +35,6 @@ struct sharedSlsDetector {
/** END OF FIXED PATTERN -----------------------------------------------*/
/** Detector offset in the X & Y direction in the multi detector structure
*/
int offset[2];
/** Number of detectors in multi list in x dir and y dir */
int multiSize[2];
@ -75,11 +71,8 @@ struct sharedSlsDetector {
/** size of the data that are transfered from the detector */
int dataBytes;
/** number of rois defined */
int nROI;
/** list of rois */
slsDetectorDefs::ROI roiLimits[MAX_ROIS];
/** roi */
slsDetectorDefs::ROI roi;
/** adc enable mask */
uint32_t adcEnableMask;
@ -339,7 +332,7 @@ class slsDetector : public virtual slsDetectorDefs {
/**
* Update total number of channels (chiptestboard or moench)
* depending on the number of samples, roi, readout flags(ctb)
* depending on the number of samples, adenablemask, readout flags(ctb)
*/
void updateTotalNumberOfChannels();
@ -423,32 +416,6 @@ class slsDetector : public virtual slsDetectorDefs {
*/
int getReadNLines();
/**
* Get Detector offset from shared memory in dimension d
* @param d dimension d
* @returns offset in dimension d
*/
int getDetectorOffset(dimension d) const;
/**
* Get Detector offset from shared memory in dimension d
* @returns offset
*/
slsDetectorDefs::coordinates getDetectorOffsets() const;
/**
* Set Detector offset in shared memory in dimension d
* @param d dimension d
* @param off offset for detector
*/
void setDetectorOffset(dimension d, int off);
/**
* Set Detector offset in shared memory
* @param value offset for detector
*/
void setDetectorOffsets(slsDetectorDefs::coordinates value);
/**
* Set Detector offset in shared memory in dimension d
* @param detx number of detectors in X dir in multi list
@ -1143,35 +1110,29 @@ class slsDetector : public virtual slsDetectorDefs {
*/
int setCounterBit(int cb = -1);
/**
* Clear ROI (Gotthard)
*/
void clearROI();
/**
* Set ROI (Gotthard)
* At the moment only one set allowed
* @param n number of rois
* @param roiLimits array of roi
* Also calls configuremac
* @param arg roi
*/
void setROI(int n = -1, ROI roiLimits[] = nullptr);
void setROI(slsDetectorDefs::ROI arg);
/**
* Get ROI from each detector and convert it to the multi detector scale
* (Gotthard)
* @param n number of rois
* @returns OK or FAIL
* Send ROI from shared memory to Receiver (Gotthard)
*/
const slsDetectorDefs::ROI *getROI(int &n);
void sendROItoReceiver();
/**
* Returns number of rois
* @returns number of ROIs
* Get ROI (Gotthard)
* Update receiver if different from shm
* @returns roi
*/
int getNRoi();
/**
* Send ROI to the detector after calculating
* from setROI
* @param n number of ROIs (-1 to get)
* @param roiLimits ROI
*/
void sendROI(int n = -1, ROI roiLimits[] = nullptr);
slsDetectorDefs::ROI getROI();
/**
* Set ADC Enable Mask (CTB, Moench)

View File

@ -104,7 +104,7 @@ public:
/**
* Returns the maximum number of channels of all detectors
* (provided by user in config file using detsizechan command)
* Offsets are calculated according to these dimensions
* number of channels in x and y are calculated according to these dimensions
* @param nx number of channels in horizontal
* @param ny number of channels in vertical
* @returns the maximum number of channels of all detectors
@ -112,15 +112,13 @@ public:
int getMaximumDetectorSize(int &nx, int &ny);
/**
* Returns the size and offsets of detector/multi detector
* @param x horizontal position origin in channel number
* @param y vertical position origin in channel number
* Returns the size of detector/multi detector
* @param nx number of channels in horiziontal
* @param ny number of channels in vertical
* @param detPos -1 for all detectors in list or specific detector position
* @returns the total number of channels of all sls detectors
*/
int getDetectorSize(int &x, int &y, int &nx, int &ny, int detPos = -1);
int getDetectorSize(int &nx, int &ny, int detPos);
/**
* Gets detector type
@ -496,22 +494,22 @@ public:
int setFlowControl10G(int enable = -1, int detPos = -1);
/**
* Set ROI (Gotthard) (>= 1 roi, but max 1 roi per module)
* At the moment only one set allowed
* @param n number of rois
* @param roiLimits array of roi
* @param detPos -1 for all detectors in list or specific detector position
* Set ROI (Gotthard)
* At the moment only one set allowed per module
* Only allowed to set one ROI per module
* @param arg roi
* @param detPos specific detector position
*/
void setROI(int n=-1, slsDetectorDefs::ROI roiLimits[]=NULL, int detPos = -1);
void setROI(slsDetectorDefs::ROI arg, int detPos = -1);
/**
* Get ROI from each detector and convert it to the multi detector scale (Gotthard)
* >= 1 roi, but max 1 roi per module
* @param n number of rois
* @param detPos -1 for all detectors in list or specific detector position
* @returns pointer to array of ROI structure
* Get ROI (Gotthard)
* Only allowed to set one ROI per module
* @param detPos specific detector position
* @returns roi
*/
const slsDetectorDefs::ROI* getROI(int &n, int detPos = -1);
slsDetectorDefs::ROI getROI(int detPos = -1);

View File

@ -110,16 +110,6 @@ void Detector::setMaxNumberOfChannels(const defs::coordinates value) {
pimpl->setMaxNumberOfChannels(value);
}
Result<defs::coordinates> Detector::getDetectorOffsets(Positions pos) const {
return pimpl->Parallel(&slsDetector::getDetectorOffsets, pos);
}
void Detector::setDetectorOffsets(defs::coordinates value, Positions pos) {
pimpl->Parallel(&slsDetector::setDetectorOffsets, pos, value);
// pimpl->Parallel<defs::coordinates>(&slsDetector::setDetectorOffset, pos,
// value);
}
Result<bool> Detector::getQuad(Positions pos) const {
return pimpl->Parallel(&slsDetector::getQuad, pos);
}
@ -1071,41 +1061,15 @@ void Detector::setCounterBit(bool value, Positions pos) {
pimpl->Parallel(&slsDetector::setCounterBit, pos, value);
}
Result<std::vector<defs::ROI>> Detector::getROI(Positions pos) const {
//vector holding module_id for the modules that should be read
const std::vector<int> id_vec = [&]() {
if (pos.empty() || (pos.size() == 1 && pos[0] == -1)){
std::vector<int> tmp;
for(size_t i=0; i!= pimpl->size(); ++i)
tmp.push_back(i);
return tmp;
}else{
return pos;
}
}();
//values to return
Result<std::vector<defs::ROI>> res;
//for each detector id get the ROI
for (const auto& i :id_vec){
int n = 0;
auto ptr = pimpl->getROI(n, i);
// res.emplace_back(ptr, ptr+n);
}
return res;
Result<defs::ROI> Detector::getROI(Positions pos) const {
return pimpl->Parallel(&slsDetector::getROI, pos);
}
void Detector::setROI(std::vector<defs::ROI> value, Positions pos) {
if (pos.empty() || (pos.size() == 1 && pos[0] == -1)) {
pimpl->setROI(static_cast<int>(value.size()), value.data(), -1);
} else if (pos.size() > 1) {
throw RuntimeError("Cannot set roi to a subset of modules");
} else {
pimpl->Parallel(&slsDetector::setROI, pos,
static_cast<int>(value.size()), value.data());
void Detector::setROI(defs::ROI value, int moduleId) {
if (moduleId < 0 && size() > 1) {
throw RuntimeError("Cannot set ROI for all modules simultaneously");
}
pimpl->Parallel(&slsDetector::setROI, {moduleId}, value);
}
Result<uint32_t> Detector::getADCEnableMask(Positions pos) const {

View File

@ -283,8 +283,8 @@ void multiSlsDetector::initializeDetectorStructure() {
multi_shm()->numberOfChannel[Y] = 0;
multi_shm()->numberOfChannelInclGapPixels[X] = 0;
multi_shm()->numberOfChannelInclGapPixels[Y] = 0;
multi_shm()->maxNumberOfChannelsPerDetector[X] = 0;
multi_shm()->maxNumberOfChannelsPerDetector[Y] = 0;
multi_shm()->maxNumberOfChannelsPerDetector[X] = -1;
multi_shm()->maxNumberOfChannelsPerDetector[Y] = -1;
multi_shm()->acquiringFlag = false;
multi_shm()->receiver_upstream = false;
}
@ -303,9 +303,6 @@ void multiSlsDetector::initializeMembers(bool verify) {
throw;
}
}
// depend on number of detectors
updateOffsets();
}
void multiSlsDetector::updateUserdetails() {
@ -333,197 +330,6 @@ bool multiSlsDetector::isAcquireReady() {
return OK != 0u;
}
int multiSlsDetector::decodeNChannel(int offsetX, int offsetY, int &channelX,
int &channelY) {
channelX = -1;
channelY = -1;
// loop over
for (size_t i = 0; i < detectors.size(); ++i) {
int x = detectors[i]->getDetectorOffset(X);
int y = detectors[i]->getDetectorOffset(Y);
// check x offset range
if ((offsetX >= x) &&
(offsetX <
(x + detectors[i]->getTotalNumberOfChannelsInclGapPixels(X)))) {
if (offsetY == -1) {
channelX = offsetX - x;
return i;
} else {
// check y offset range
if ((offsetY >= y) &&
(offsetY <
(y + detectors[i]->getTotalNumberOfChannelsInclGapPixels(
Y)))) {
channelX = offsetX - x;
channelY = offsetY - y;
return i;
}
}
}
}
return -1;
}
void multiSlsDetector::updateOffsets() {
FILE_LOG(logDEBUG1) << "Updating Multi-Detector Offsets";
int offsetX = 0, offsetY = 0, numX = 0, numY = 0;
int maxChanX = multi_shm()->maxNumberOfChannelsPerDetector[X];
int maxChanY = multi_shm()->maxNumberOfChannelsPerDetector[Y];
int prevChanX = 0;
int prevChanY = 0;
bool firstTime = true;
multi_shm()->numberOfChannel[X] = 0;
multi_shm()->numberOfChannel[Y] = 0;
multi_shm()->numberOfDetector[X] = 0;
multi_shm()->numberOfDetector[Y] = 0;
// gap pixels
int offsetX_gp = 0, offsetY_gp = 0, numX_gp = 0, numY_gp = 0;
int prevChanX_gp = 0, prevChanY_gp = 0;
multi_shm()->numberOfChannelInclGapPixels[X] = 0;
multi_shm()->numberOfChannelInclGapPixels[Y] = 0;
for (size_t idet = 0; idet < detectors.size(); ++idet) {
FILE_LOG(logDEBUG1)
<< "offsetX:" << offsetX << " prevChanX:" << prevChanX
<< " offsetY:" << offsetY << " prevChanY:" << prevChanY
<< " offsetX_gp:" << offsetX_gp << " prevChanX_gp:" << prevChanX_gp
<< " offsetY_gp:" << offsetY_gp << " prevChanY_gp:" << prevChanY_gp;
// incrementing in both direction
if (firstTime) {
// incrementing in both directions
firstTime = false;
if ((maxChanX > 0) &&
((offsetX + detectors[idet]->getTotalNumberOfChannels(X)) >
maxChanX)) {
FILE_LOG(logWARNING)
<< "\nDetector[" << idet
<< "] exceeds maximum channels "
"allowed for complete detector set in X dimension!";
}
if ((maxChanY > 0) &&
((offsetY + detectors[idet]->getTotalNumberOfChannels(Y)) >
maxChanY)) {
FILE_LOG(logERROR)
<< "\nDetector[" << idet
<< "] exceeds maximum channels "
"allowed for complete detector set in Y dimension!";
}
prevChanX = detectors[idet]->getTotalNumberOfChannels(X);
prevChanY = detectors[idet]->getTotalNumberOfChannels(Y);
prevChanX_gp =
detectors[idet]->getTotalNumberOfChannelsInclGapPixels(X);
prevChanY_gp =
detectors[idet]->getTotalNumberOfChannelsInclGapPixels(Y);
numX += detectors[idet]->getTotalNumberOfChannels(X);
numY += detectors[idet]->getTotalNumberOfChannels(Y);
numX_gp +=
detectors[idet]->getTotalNumberOfChannelsInclGapPixels(X);
numY_gp +=
detectors[idet]->getTotalNumberOfChannelsInclGapPixels(Y);
++multi_shm()->numberOfDetector[X];
++multi_shm()->numberOfDetector[Y];
FILE_LOG(logDEBUG1) << "incrementing in both direction";
}
// incrementing in y direction
else if ((maxChanY == -1) ||
((maxChanY > 0) && ((offsetY + prevChanY +
detectors[idet]->getTotalNumberOfChannels(
Y)) <= maxChanY))) {
offsetY += prevChanY;
offsetY_gp += prevChanY_gp;
prevChanY = detectors[idet]->getTotalNumberOfChannels(Y);
prevChanY_gp =
detectors[idet]->getTotalNumberOfChannelsInclGapPixels(Y);
numY += detectors[idet]->getTotalNumberOfChannels(Y);
numY_gp +=
detectors[idet]->getTotalNumberOfChannelsInclGapPixels(Y);
// increment in y again only in the first column (else you double
// increment)
if (multi_shm()->numberOfDetector[X] == 1)
++multi_shm()->numberOfDetector[Y];
FILE_LOG(logDEBUG1) << "incrementing in y direction";
}
// incrementing in x direction
else {
if ((maxChanX > 0) &&
((offsetX + prevChanX +
detectors[idet]->getTotalNumberOfChannels(X)) > maxChanX)) {
FILE_LOG(logDEBUG1)
<< "\nDetector[" << idet
<< "] exceeds maximum channels "
"allowed for complete detector set in X dimension!";
}
offsetY = 0;
offsetY_gp = 0;
prevChanY = detectors[idet]->getTotalNumberOfChannels(Y);
prevChanY_gp =
detectors[idet]->getTotalNumberOfChannelsInclGapPixels(Y);
numY = 0; // assuming symmetry with this statement.
// whats on 1st column should be on 2nd column
numY_gp = 0;
offsetX += prevChanX;
offsetX_gp += prevChanX_gp;
prevChanX = detectors[idet]->getTotalNumberOfChannels(X);
prevChanX_gp =
detectors[idet]->getTotalNumberOfChannelsInclGapPixels(X);
numX += detectors[idet]->getTotalNumberOfChannels(X);
numX_gp +=
detectors[idet]->getTotalNumberOfChannelsInclGapPixels(X);
++multi_shm()->numberOfDetector[X];
FILE_LOG(logDEBUG1) << "incrementing in x direction";
}
double bytesperchannel =
(double)detectors[idet]->getDataBytes() /
(double)(detectors[idet]->getTotalNumberOfChannels(X) *
detectors[idet]->getTotalNumberOfChannels(Y));
detectors[idet]->setDetectorOffset(
X, (bytesperchannel >= 1.0) ? offsetX_gp : offsetX);
detectors[idet]->setDetectorOffset(
Y, (bytesperchannel >= 1.0) ? offsetY_gp : offsetY);
FILE_LOG(logDEBUG1) << "Detector[" << idet << "] has offsets ("
<< detectors[idet]->getDetectorOffset(X) << ", "
<< detectors[idet]->getDetectorOffset(Y) << ")";
// offsetY has been reset sometimes and offsetX the first time,
// but remember the highest values
if (numX > multi_shm()->numberOfChannel[X]) {
multi_shm()->numberOfChannel[X] = numX;
}
if (numY > multi_shm()->numberOfChannel[Y]) {
multi_shm()->numberOfChannel[Y] = numY;
}
if (numX_gp > multi_shm()->numberOfChannelInclGapPixels[X]) {
multi_shm()->numberOfChannelInclGapPixels[X] = numX_gp;
}
if (numY_gp > multi_shm()->numberOfChannelInclGapPixels[Y]) {
multi_shm()->numberOfChannelInclGapPixels[Y] = numY_gp;
}
}
FILE_LOG(logDEBUG1)
<< "\n\tNumber of Channels in X direction:"
<< multi_shm()->numberOfChannel[X]
<< "\n\tNumber of Channels in Y direction:"
<< multi_shm()->numberOfChannel[Y]
<< "\n\tNumber of Channels in X direction with Gap Pixels:"
<< multi_shm()->numberOfChannelInclGapPixels[X]
<< "\n\tNumber of Channels in Y direction with Gap Pixels:"
<< multi_shm()->numberOfChannelInclGapPixels[Y];
multi_shm()->numberOfChannels =
multi_shm()->numberOfChannel[0] * multi_shm()->numberOfChannel[1];
for (auto &d : detectors) {
d->updateMultiSize(multi_shm()->numberOfDetector[0],
multi_shm()->numberOfDetector[1]);
}
}
std::string multiSlsDetector::exec(const char *cmd) {
int bufsize = 128;
@ -560,8 +366,6 @@ void multiSlsDetector::setHostname(const std::vector<std::string> &name) {
for (const auto &hostname : name) {
addSlsDetector(hostname);
}
updateOffsets();
}
void multiSlsDetector::setHostname(const char *name, int detPos) {
@ -598,8 +402,7 @@ void multiSlsDetector::addMultipleDetectors(const char *name) {
for (const auto &hostname : sls::split(name, '+')) {
addSlsDetector(hostname);
}
updateOffsets();
updateDetectorSize();
}
void multiSlsDetector::addSlsDetector(const std::string &hostname) {
@ -623,11 +426,63 @@ void multiSlsDetector::addSlsDetector(const std::string &hostname) {
sls::make_unique<slsDetector>(type, multiId, pos, false));
multi_shm()->numberOfDetectors = detectors.size();
multi_shm()->numberOfChannels += detectors[pos]->getTotalNumberOfChannels();
detectors[pos]->setHostname(hostname);
multi_shm()->multiDetectorType = getDetectorTypeAsEnum(-1);// -1 needed here
}
void multiSlsDetector::updateDetectorSize() {
FILE_LOG(logDEBUG) << "Updating Multi-Detector Size: " << size();
int my = detectors[0]->getTotalNumberOfChannels(Y);
int mx = detectors[0]->getTotalNumberOfChannels(X);
int mgy = detectors[0]->getTotalNumberOfChannelsInclGapPixels(Y);
int mgx = detectors[0]->getTotalNumberOfChannelsInclGapPixels(X);
if (mgy == 0) {
mgy = my;
mgx = mx;
}
int maxy = multi_shm()->maxNumberOfChannelsPerDetector[Y];
if (maxy == -1) {
maxy = my * size();
}
int ndety = maxy / my;
int ndetx = size() / ndety;
if ((maxy % my) > 0) {
++ndetx;
}
multi_shm()->numberOfDetector[X] = ndetx;
multi_shm()->numberOfDetector[Y] = ndety;
multi_shm()->numberOfChannel[X] = mx * ndetx;
multi_shm()->numberOfChannel[Y] = my * ndety;
multi_shm()->numberOfChannelInclGapPixels[X] = mgx * ndetx;
multi_shm()->numberOfChannelInclGapPixels[Y] = mgy * ndety;
FILE_LOG(logDEBUG)
<< "\n\tNumber of Detectors in X direction:"
<< multi_shm()->numberOfDetector[X]
<< "\n\tNumber of Detectors in Y direction:"
<< multi_shm()->numberOfDetector[Y]
<< "\n\tNumber of Channels in X direction:"
<< multi_shm()->numberOfChannel[X]
<< "\n\tNumber of Channels in Y direction:"
<< multi_shm()->numberOfChannel[Y]
<< "\n\tNumber of Channels in X direction with Gap Pixels:"
<< multi_shm()->numberOfChannelInclGapPixels[X]
<< "\n\tNumber of Channels in Y direction with Gap Pixels:"
<< multi_shm()->numberOfChannelInclGapPixels[Y];
multi_shm()->numberOfChannels =
multi_shm()->numberOfChannel[0] * multi_shm()->numberOfChannel[1];
for (auto &d : detectors) {
d->updateMultiSize(multi_shm()->numberOfDetector[0],
multi_shm()->numberOfDetector[1]);
}
}
slsDetectorDefs::detectorType multiSlsDetector::getDetectorTypeAsEnum() const {
return multi_shm()->multiDetectorType;
}
@ -732,14 +587,6 @@ void multiSlsDetector::setMaxNumberOfChannels(const slsDetectorDefs::coordinates
multi_shm()->maxNumberOfChannelsPerDetector[Y] = c.y;
}
int multiSlsDetector::getDetectorOffset(dimension d, int detPos) {
return detectors[detPos]->getDetectorOffset(d);
}
void multiSlsDetector::setDetectorOffset(dimension d, int off, int detPos) {
detectors[detPos]->setDetectorOffset(d, off);
}
int multiSlsDetector::getQuad(int detPos) {
int retval = detectors[0]->getQuad();
if (retval && size() > 1) {
@ -1272,8 +1119,6 @@ int multiSlsDetector::setDynamicRange(int dr, int detPos) {
// change in dr
if (dr != -1 && dr != prevValue) {
updateOffsets();
// update speed, check ratecorrection
if (getDetectorTypeAsEnum() == EIGER) {
@ -2172,318 +2017,40 @@ int multiSlsDetector::setCounterBit(int i, int detPos) {
return sls::minusOneIfDifferent(r);
}
void multiSlsDetector::verifyMinMaxROI(int n, ROI r[]) {
int temp;
for (int i = 0; i < n; ++i) {
if ((r[i].xmax) < (r[i].xmin)) {
temp = r[i].xmax;
r[i].xmax = r[i].xmin;
r[i].xmin = temp;
}
if ((r[i].ymax) < (r[i].ymin)) {
temp = r[i].ymax;
r[i].ymax = r[i].ymin;
r[i].ymin = temp;
}
}
}
void multiSlsDetector::setROI(int n, ROI roiLimits[], int detPos) {
void multiSlsDetector::clearROI(int detPos) {
// single
if (detPos >= 0) {
detectors[detPos]->setROI(n, roiLimits);
detectors[detPos]->clearROI();
}
// multi
int xmin = 0, xmax = 0, ymin = 0, ymax = 0, channelX = 0, channelY = 0,
idet = 0, lastChannelX = 0, lastChannelY = 0, index = 0, offsetX = 0,
offsetY = 0;
bool invalidroi = false;
int ndet = detectors.size();
ROI allroi[ndet][n];
int nroi[ndet];
for (int i = 0; i < ndet; ++i) {
nroi[i] = 0;
}
if ((n < 0) || (roiLimits == nullptr)) {
throw RuntimeError("Cannot set ROI due to Invalid ROI");
}
// ensures min < max
verifyMinMaxROI(n, roiLimits);
FILE_LOG(logDEBUG1) << "Setting ROI for " << n << "rois:";
for (int i = 0; i < n; ++i) {
FILE_LOG(logDEBUG1)
<< i << ":" << roiLimits[i].xmin << "\t" << roiLimits[i].xmax
<< "\t" << roiLimits[i].ymin << "\t" << roiLimits[i].ymax;
}
// for each roi
for (int i = 0; i < n; ++i) {
xmin = roiLimits[i].xmin;
xmax = roiLimits[i].xmax;
ymin = roiLimits[i].ymin;
ymax = roiLimits[i].ymax;
if (size() > 1) {
// check roi max values
idet = decodeNChannel(xmax, ymax, channelX, channelY);
FILE_LOG(logDEBUG1) << "Decoded Channel max vals: " << std::endl
<< "det:" << idet << "\t" << xmax << "\t"
<< ymax << "\t" << channelX << "\t" << channelY;
if (idet == -1) {
FILE_LOG(logERROR) << "invalid roi";
continue;
}
// split in x dir
while (xmin <= xmax) {
invalidroi = false;
ymin = roiLimits[i].ymin;
// split in y dir
while (ymin <= ymax) {
// get offset for each detector
idet = decodeNChannel(xmin, ymin, channelX, channelY);
FILE_LOG(logDEBUG1)
<< "Decoded Channel min vals: " << std::endl
<< "det:" << idet << "\t" << xmin << "\t" << ymin
<< "\t" << channelX << "\t" << channelY;
if (idet < 0 || idet >= (int)detectors.size()) {
FILE_LOG(logDEBUG1) << "invalid roi";
invalidroi = true;
break;
}
// get last channel for each det in x and y dir
lastChannelX =
(detectors[idet]->getTotalNumberOfChannelsInclGapPixels(
X)) -
1;
lastChannelY =
(detectors[idet]->getTotalNumberOfChannelsInclGapPixels(
Y)) -
1;
offsetX = detectors[idet]->getDetectorOffset(X);
offsetY = detectors[idet]->getDetectorOffset(Y);
// at the end in x dir
if ((offsetX + lastChannelX) >= xmax) {
lastChannelX = xmax - offsetX;
}
// at the end in y dir
if ((offsetY + lastChannelY) >= ymax) {
lastChannelY = ymax - offsetY;
}
FILE_LOG(logDEBUG1)
<< "lastChannelX:" << lastChannelX << "\t"
<< "lastChannelY:" << lastChannelY;
// creating the list of roi for corresponding detector
index = nroi[idet];
allroi[idet][index].xmin = channelX;
allroi[idet][index].xmax = lastChannelX;
allroi[idet][index].ymin = channelY;
allroi[idet][index].ymax = lastChannelY;
nroi[idet] = nroi[idet] + 1;
ymin = lastChannelY + offsetY + 1;
if ((lastChannelY + offsetY) == ymax) {
ymin = ymax + 1;
}
FILE_LOG(logDEBUG1)
<< "nroi[idet]:" << nroi[idet] << "\tymin:" << ymin;
}
if (invalidroi) {
break;
}
xmin = lastChannelX + offsetX + 1;
if ((lastChannelX + offsetX) == xmax) {
xmin = xmax + 1;
}
}
} else { // FIXME: check if xmax is greater? or reduce logic above?
idet = 0;
nroi[idet] = n;
index = 0;
allroi[idet][index].xmin = xmin;
allroi[idet][index].xmax = xmax;
allroi[idet][index].ymin = ymin;
allroi[idet][index].ymax = ymax;
// nroi[idet] = nroi[idet] + 1;
}
}
FILE_LOG(logDEBUG1) << "Setting ROI :";
for (size_t i = 0; i < detectors.size(); ++i) {
FILE_LOG(logDEBUG1) << "detector " << i;
for (int j = 0; j < nroi[i]; ++j) {
FILE_LOG(logDEBUG1)
<< allroi[i][j].xmin << "\t" << allroi[i][j].xmax << "\t"
<< allroi[i][j].ymin << "\t" << allroi[i][j].ymax;
}
}
// settings the rois for each detector
for (size_t i = 0; i != detectors.size(); ++i) {
detectors[i]->setROI(nroi[i], allroi[i]);
}
parallelCall(&slsDetector::clearROI);
}
const slsDetectorDefs::ROI *multiSlsDetector::getROI(int &n, int detPos) {
void multiSlsDetector::setROI(slsDetectorDefs::ROI arg, int detPos) {
// single
if (detPos >= 0) {
return detectors[detPos]->getROI(n);
detectors[detPos]->setROI(arg);
}
// multi
n = 0;
int num = 0;
int ndet = detectors.size();
int maxroi = ndet * MAX_ROIS;
ROI temproi;
ROI roiLimits[maxroi];
ROI *retval = new ROI[maxroi];
const ROI *temp = nullptr;
int index = 0;
if (detPos < 0 && size() > 1) {
throw RuntimeError("Cannot set ROI for all modules simultaneously");
}
detectors[0]->setROI(arg);
}
// get each detector's roi array
for (size_t idet = 0; idet < detectors.size(); ++idet) {
temp = detectors[idet]->getROI(index);
if (temp != nullptr) {
if (index != 0) {
FILE_LOG(logINFO) << "detector " << idet << ":";
}
for (int j = 0; j < index; ++j) {
FILE_LOG(logINFO)
<< temp[j].xmin << "\t" << temp[j].xmax << "\t"
<< temp[j].ymin << "\t" << temp[j].ymax;
int x = detectors[idet]->getDetectorOffset(X);
int y = detectors[idet]->getDetectorOffset(Y);
roiLimits[n].xmin = temp[j].xmin + x;
roiLimits[n].xmax = temp[j].xmax + x;
roiLimits[n].ymin = temp[j].ymin + y;
roiLimits[n].ymax = temp[j].ymin + y;
++n;
}
}
slsDetectorDefs::ROI multiSlsDetector::getROI(int detPos) const {
// single
if (detPos >= 0) {
return detectors[detPos]->getROI();
}
// empty roi
if (n == 0) {
return nullptr;
// multi
if (detPos < 0 && size() > 1) {
throw RuntimeError("Cannot get ROI for all modules simultaneously");
}
FILE_LOG(logDEBUG1) << "ROI :" << std::endl;
for (int j = 0; j < n; ++j) {
FILE_LOG(logDEBUG1)
<< roiLimits[j].xmin << "\t" << roiLimits[j].xmax << "\t"
<< roiLimits[j].ymin << "\t" << roiLimits[j].ymax;
}
// combine all the adjacent rois in x direction
for (int i = 0; i < n; ++i) {
// since the ones combined are replaced by -1
if ((roiLimits[i].xmin) == -1) {
continue;
}
for (int j = i + 1; j < n; ++j) {
// since the ones combined are replaced by -1
if ((roiLimits[j].xmin) == -1) {
continue;
}
// if y values are same
if (((roiLimits[i].ymin) == (roiLimits[j].ymin)) &&
((roiLimits[i].ymax) == (roiLimits[j].ymax))) {
// if adjacent, increase [i] range and replace all [j] with -1
if ((roiLimits[i].xmax) + 1 == roiLimits[j].xmin) {
roiLimits[i].xmax = roiLimits[j].xmax;
roiLimits[j].xmin = -1;
roiLimits[j].xmax = -1;
roiLimits[j].ymin = -1;
roiLimits[j].ymax = -1;
}
// if adjacent, increase [i] range and replace all [j] with -1
else if ((roiLimits[i].xmin) - 1 == roiLimits[j].xmax) {
roiLimits[i].xmin = roiLimits[j].xmin;
roiLimits[j].xmin = -1;
roiLimits[j].xmax = -1;
roiLimits[j].ymin = -1;
roiLimits[j].ymax = -1;
}
}
}
}
FILE_LOG(logDEBUG1) << "Combined along x axis Getting ROI :\ndetector "
<< n;
for (int j = 0; j < n; ++j) {
FILE_LOG(logDEBUG1)
<< roiLimits[j].xmin << "\t" << roiLimits[j].xmax << "\t"
<< roiLimits[j].ymin << "\t" << roiLimits[j].ymax;
}
// combine all the adjacent rois in y direction
for (int i = 0; i < n; ++i) {
// since the ones combined are replaced by -1
if ((roiLimits[i].ymin) == -1) {
continue;
}
for (int j = i + 1; j < n; ++j) {
// since the ones combined are replaced by -1
if ((roiLimits[j].ymin) == -1) {
continue;
}
// if x values are same
if (((roiLimits[i].xmin) == (roiLimits[j].xmin)) &&
((roiLimits[i].xmax) == (roiLimits[j].xmax))) {
// if adjacent, increase [i] range and replace all [j] with -1
if ((roiLimits[i].ymax) + 1 == roiLimits[j].ymin) {
roiLimits[i].ymax = roiLimits[j].ymax;
roiLimits[j].xmin = -1;
roiLimits[j].xmax = -1;
roiLimits[j].ymin = -1;
roiLimits[j].ymax = -1;
}
// if adjacent, increase [i] range and replace all [j] with -1
else if ((roiLimits[i].ymin) - 1 == roiLimits[j].ymax) {
roiLimits[i].ymin = roiLimits[j].ymin;
roiLimits[j].xmin = -1;
roiLimits[j].xmax = -1;
roiLimits[j].ymin = -1;
roiLimits[j].ymax = -1;
}
}
}
}
// get rid of -1s
for (int i = 0; i < n; ++i) {
if ((roiLimits[i].xmin) != -1) {
retval[num] = roiLimits[i];
++num;
}
}
// sort final roi
for (int i = 0; i < num; ++i) {
for (int j = i + 1; j < num; ++j) {
if (retval[j].xmin < retval[i].xmin) {
temproi = retval[i];
retval[i] = retval[j];
retval[j] = temproi;
}
}
}
n = num;
FILE_LOG(logDEBUG1) << "\nxmin\txmax\tymin\tymax";
for (int i = 0; i < n; ++i) {
FILE_LOG(logDEBUG1) << retval[i].xmin << "\t" << retval[i].xmax << "\t"
<< retval[i].ymin << "\t" << retval[i].ymax;
}
return retval;
return detectors[0]->getROI();
}
void multiSlsDetector::setADCEnableMask(uint32_t mask, int detPos) {
@ -2688,15 +2255,16 @@ int multiSlsDetector::enableGapPixels(int val, int detPos) {
int ret = sls::minusOneIfDifferent(r);
if (val != -1) {
updateOffsets();
multi_shm()->numberOfChannelInclGapPixels[X] = sls::sum(parallelCall(&slsDetector::getTotalNumberOfChannelsInclGapPixels, X));
multi_shm()->numberOfChannelInclGapPixels[Y] = sls::sum(parallelCall(&slsDetector::getTotalNumberOfChannelsInclGapPixels, Y));
}
return ret;
}
void multiSlsDetector::setGapPixelsEnable(bool enable, Positions pos){
Parallel(&slsDetector::enableGapPixels, pos, static_cast<int>(enable));
updateOffsets();
multi_shm()->numberOfChannelInclGapPixels[X] = sls::sum(parallelCall(&slsDetector::getTotalNumberOfChannelsInclGapPixels, X));
multi_shm()->numberOfChannelInclGapPixels[Y] = sls::sum(parallelCall(&slsDetector::getTotalNumberOfChannelsInclGapPixels, Y));
}
int multiSlsDetector::setTrimEn(std::vector<int> energies, int detPos) {

View File

@ -308,15 +308,13 @@ void slsDetector::initializeDetectorStructure(detectorType type) {
shm()->controlPort = DEFAULT_PORTNO;
sls::strcpy_safe(shm()->hostname, DEFAULT_HOSTNAME);
shm()->myDetectorType = type;
shm()->offset[X] = 0;
shm()->offset[Y] = 0;
shm()->multiSize[X] = 0;
shm()->multiSize[Y] = 0;
shm()->controlPort = DEFAULT_PORTNO;
shm()->stopPort = DEFAULT_PORTNO + 1;
sls::strcpy_safe(shm()->settingsDir, getenv("HOME"));
shm()->nROI = 0;
memset(shm()->roiLimits, 0, MAX_ROIS * sizeof(ROI));
shm()->roi.xmin = -1;
shm()->roi.xmax = -1;
shm()->adcEnableMask = BIT32_MASK;
shm()->roFlags = NORMAL_READOUT;
shm()->currentSettings = UNINITIALIZED;
@ -688,28 +686,6 @@ int slsDetector::getReadNLines() {
return retval;
}
int slsDetector::getDetectorOffset(dimension d) const {
return shm()->offset[d];
}
slsDetectorDefs::coordinates slsDetector::getDetectorOffsets() const {
slsDetectorDefs::coordinates coord;
coord.x = shm()->offset[X];
coord.y = shm()->offset[Y];
return coord;
}
void slsDetector::setDetectorOffset(dimension d, int off) {
if (off >= 0) {
shm()->offset[d] = off;
}
}
void slsDetector::setDetectorOffsets(slsDetectorDefs::coordinates value) {
shm()->offset[X] = value.x;
shm()->offset[Y] = value.y;
}
void slsDetector::updateMultiSize(int detx, int dety) {
shm()->multiSize[0] = detx;
shm()->multiSize[1] = dety;
@ -878,17 +854,9 @@ void slsDetector::updateCachedDetectorVariables() {
// roi
if (shm()->myDetectorType == GOTTHARD) {
n += client.Receive(&i32, sizeof(i32));
shm()->nROI = i32;
for (int i = 0; i < shm()->nROI; ++i) {
n += client.Receive(&i32, sizeof(i32));
shm()->roiLimits[i].xmin = i32;
n += client.Receive(&i32, sizeof(i32));
shm()->roiLimits[i].xmax = i32;
n += client.Receive(&i32, sizeof(i32));
shm()->roiLimits[i].ymin = i32;
n += client.Receive(&i32, sizeof(i32));
shm()->roiLimits[i].xmax = i32;
}
shm()->roi.xmin = i32;
n += client.Receive(&i32, sizeof(i32));
shm()->roi.xmax = i32;
}
if (shm()->myDetectorType == CHIPTESTBOARD ||
@ -1849,7 +1817,7 @@ std::string slsDetector::setReceiverHostname(const std::string &receiverIP) {
break;
case GOTTHARD:
sendROI(-1, nullptr);
sendROItoReceiver();
break;
default:
@ -2344,44 +2312,27 @@ int slsDetector::setCounterBit(int cb) {
return retval;
}
void slsDetector::setROI(int n, ROI roiLimits[]) {
std::sort(roiLimits, roiLimits + n,
[](ROI a, ROI b) { return a.xmin < b.xmin; });
sendROI(n, roiLimits);
void slsDetector::clearROI() {
FILE_LOG(logDEBUG1) << "Clearing ROI";
slsDetectorDefs::ROI arg;
arg.xmin = -1;
arg.xmax = -1;
setROI(arg);
}
const slsDetectorDefs::ROI *slsDetector::getROI(int &n) {
sendROI(-1, nullptr);
n = shm()->nROI;
return shm()->roiLimits;
}
int slsDetector::getNRoi() { return shm()->nROI; }
void slsDetector::sendROI(int n, ROI roiLimits[]) {
void slsDetector::setROI(slsDetectorDefs::ROI arg) {
int fnum = F_SET_ROI;
int ret = FAIL;
int narg = n;
// send roiLimits if given, else from shm
ROI *arg = (roiLimits != nullptr) ? roiLimits : shm()->roiLimits;
int nretval = 0;
ROI retval[MAX_ROIS];
FILE_LOG(logDEBUG1) << "Sending ROI to detector" << narg;
if (arg.xmin < 0 || arg.xmax >= getTotalNumberOfChannels()) {
arg.xmin = -1;
arg.xmax = -1;
}
FILE_LOG(logDEBUG) << "Sending ROI to detector [" << arg.xmin << ", " << arg.xmax << "]";
auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
client.Send(&fnum, sizeof(fnum));
client.Send(&narg, sizeof(narg));
if (narg != -1) {
for (int i = 0; i < narg; ++i) {
client.Send(&arg[i].xmin, sizeof(int));
client.Send(&arg[i].xmax, sizeof(int));
client.Send(&arg[i].ymin, sizeof(int));
client.Send(&arg[i].ymax, sizeof(int));
}
}
client.Send(&arg.xmin, sizeof(int));
client.Send(&arg.xmax, sizeof(int));
client.Receive(&ret, sizeof(ret));
// handle ret
if (ret == FAIL) {
char mess[MAX_STR_LENGTH]{};
@ -2389,65 +2340,63 @@ void slsDetector::sendROI(int n, ROI roiLimits[]) {
throw RuntimeError("Detector " + std::to_string(detId) +
" returned error: " + std::string(mess));
} else {
client.Receive(&nretval, sizeof(nretval));
int nrec = 0;
for (int i = 0; i < nretval; ++i) {
nrec += client.Receive(&retval[i].xmin, sizeof(int));
nrec += client.Receive(&retval[i].xmax, sizeof(int));
nrec += client.Receive(&retval[i].ymin, sizeof(int));
nrec += client.Receive(&retval[i].ymax, sizeof(int));
}
shm()->nROI = nretval;
FILE_LOG(logDEBUG1) << "nRoi: " << nretval;
for (int i = 0; i < nretval; ++i) {
shm()->roiLimits[i] = retval[i];
FILE_LOG(logDEBUG1)
<< "ROI [" << i << "] (" << shm()->roiLimits[i].xmin << ","
<< shm()->roiLimits[i].xmax << "," << shm()->roiLimits[i].ymin
<< "," << shm()->roiLimits[i].ymax << ")";
memcpy(&shm()->roi, &arg, sizeof(ROI));
if (ret == FORCE_UPDATE) {
updateCachedDetectorVariables();
}
}
if (ret == FORCE_UPDATE) {
updateCachedDetectorVariables();
}
// old firmware requires configuremac after setting roi
if (shm()->myDetectorType == GOTTHARD && n != -1) {
if (shm()->myDetectorType == GOTTHARD) {
configureMAC();
}
sendROItoReceiver();
}
void slsDetector::sendROItoReceiver() {
// update roi in receiver
if (shm()->useReceiverFlag) {
fnum = F_RECEIVER_SET_ROI;
ret = FAIL;
narg = shm()->nROI;
arg = shm()->roiLimits;
FILE_LOG(logDEBUG1) << "Sending ROI to receiver: " << shm()->nROI;
auto receiver = ReceiverSocket(shm()->rxHostname, shm()->rxTCPPort);
receiver.Send(&fnum, sizeof(fnum));
receiver.Send(&narg, sizeof(narg));
if (narg != -1) {
for (int i = 0; i < narg; ++i) {
receiver.Send(&arg[i].xmin, sizeof(int));
receiver.Send(&arg[i].xmax, sizeof(int));
receiver.Send(&arg[i].ymin, sizeof(int));
receiver.Send(&arg[i].ymax, sizeof(int));
}
}
receiver.Receive(&ret, sizeof(ret));
if (ret == FAIL) {
char mess[MAX_STR_LENGTH]{};
receiver.Receive(mess, MAX_STR_LENGTH);
throw ReceiverError("Receiver " + std::to_string(detId) +
" returned error: " + std::string(mess));
}
if (ret == FORCE_UPDATE) {
updateCachedReceiverVariables();
}
FILE_LOG(logDEBUG1) << "Sending ROI to receiver";
sendToReceiver(F_RECEIVER_SET_ROI, shm()->roi, nullptr);
}
}
slsDetectorDefs::ROI slsDetector::getROI() {
int fnum = F_GET_ROI;
int ret = FAIL;
FILE_LOG(logDEBUG1) << "Getting ROI from detector";
auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
client.Send(&fnum, sizeof(fnum));
client.Receive(&ret, sizeof(ret));
// handle ret
if (ret == FAIL) {
char mess[MAX_STR_LENGTH]{};
client.Receive(mess, MAX_STR_LENGTH);
throw RuntimeError("Detector " + std::to_string(detId) +
" returned error: " + std::string(mess));
} else {
ROI retval;
client.Receive(&retval.xmin, sizeof(int));
client.Receive(&retval.xmax, sizeof(int));
FILE_LOG(logDEBUG1)
<< "ROI retval [" << retval.xmin << ","
<< retval.xmax << "]";
if (ret == FORCE_UPDATE) {
updateCachedDetectorVariables();
}
// if different from shm, update and send to receiver
if (shm()->roi.xmin != retval.xmin || shm()->roi.xmax != retval.xmax) {
memcpy(&shm()->roi, &retval, sizeof(ROI));
sendROItoReceiver();
}
}
return shm()->roi;
}
void slsDetector::setADCEnableMask(uint32_t mask) {
uint32_t arg = mask;
FILE_LOG(logDEBUG1) << "Setting ADC Enable mask to 0x" << std::hex << arg

View File

@ -308,7 +308,14 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) {
++i;
/*! \page config
- <b>roi [i] [xmin] [xmax] [ymin] [ymax] </b> sets region of interest of the detector, where i is number of rois;i=0 to clear rois. Used for GOTTHARD only. \c Returns \c (int)
- <b>clearroi </b> resets region of interest of the detector. Used for GOTTHARD only. \c Returns \c (string)
*/
descrToFuncMap[i].m_pFuncName = "clearroi";
descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdDetectorSize;
++i;
/*! \page config
- <b>roi [xmin] [xmax] </b> sets region of interest of the detector. Used for GOTTHARD only. \c Returns \c (int)
*/
descrToFuncMap[i].m_pFuncName = "roi";
descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdDetectorSize;
@ -3252,28 +3259,28 @@ std::string slsDetectorCommand::cmdDetectorSize(int narg, const char * const arg
if (action == HELP_ACTION)
return helpDetectorSize(action);
int ret, val = -1, pos = -1, i;
int ret, val = -1;
char ans[1000];
if (action == PUT_ACTION) {
if (!sscanf(args[1], "%d", &val))
if (cmd != "roi" && !sscanf(args[1], "%d", &val))
return std::string("could not scan ") + std::string(args[0]) + std::string(" ") + std::string(args[1]);
if (cmd == "clearroi") {
myDet->clearROI(detPos);
}
if (cmd == "roi") {
//debug number of arguments
if ((val < 0) || (narg != ((val * 4) + 2)))
if (narg != 3)
return helpDetectorSize(action);
ROI allroi[val];
pos = 2;
for (i = 0; i < val; ++i) {
if ((!sscanf(args[pos++], "%d", &allroi[i].xmin)) ||
(!sscanf(args[pos++], "%d", &allroi[i].xmax)) ||
(!sscanf(args[pos++], "%d", &allroi[i].ymin)) ||
(!sscanf(args[pos++], "%d", &allroi[i].ymax)))
return std::string("cannot parse arguments for roi");
}
myDet->setROI(val, allroi, detPos);
ROI roi;
if (!sscanf(args[1], "%d", &roi.xmin))
return std::string("cannot parse arguments for roi xmin");
if (!sscanf(args[2], "%d", &roi.xmax))
return std::string("cannot parse arguments for roi xmax");
myDet->setROI(roi, detPos);
}
if (cmd == "detsizechan") {
@ -3308,17 +3315,21 @@ std::string slsDetectorCommand::cmdDetectorSize(int narg, const char * const arg
if ((!sscanf(args[1], "%d", &val)) || (val != 0 && val != 1))
return std::string("cannot scan gappixels mode: must be 0 or 1");
if (detPos < 0) // only in multi detector level to update offsets etc.
if (detPos < 0) // only in multi detector level to update number of channels etc.
myDet->enableGapPixels(val, detPos);
}
}
if (cmd == "dr") {
ret = myDet->setDynamicRange(val, detPos);
} else if (cmd == "clearroi") {
if (action == GET_ACTION) {
return std::string("Cannot get");
}
return std::string("successful");
} else if (cmd == "roi") {
const ROI* r = myDet->getROI(ret, detPos);
delete [] r;
ROI roi = myDet->getROI(detPos);
return (std::string("[") + std::to_string(roi.xmin) + std::string(",") + std::to_string(roi.xmax) + std::string("]"));
} else if (cmd == "detsizechan") {
sprintf(ans, "%d %d", myDet->getMaxNumberOfChannelsPerDetector(X), myDet->getMaxNumberOfChannelsPerDetector(Y));
return std::string(ans);
@ -3330,7 +3341,7 @@ std::string slsDetectorCommand::cmdDetectorSize(int narg, const char * const arg
return std::string("Not required for this detector\n");
ret = myDet->getFlippedData(Y, detPos);
} else if (cmd == "gappixels") {
if (detPos >= 0) // only in multi detector level to update offsets etc.
if (detPos >= 0) // only in multi detector level to update number of channels etc.
return std::string("Cannot execute this command from slsDetector level. Please use multiSlsDetector level.\n");
ret = myDet->enableGapPixels(-1, detPos);
}
@ -3349,7 +3360,8 @@ std::string slsDetectorCommand::helpDetectorSize(int action) {
std::ostringstream os;
if (action == PUT_ACTION || action == HELP_ACTION) {
os << "dr i \n sets the dynamic range of the detector" << std::endl;
os << "roi i xmin xmax ymin ymax \n sets region of interest where i is number of rois;i=0 to clear rois" << std::endl;
os << "clearroi \n resets region of interest" << std::endl;
os << "roi xmin xmax \n sets region of interest " << std::endl;
os << "detsizechan x y \n sets the maximum number of channels for complete detector set in both directions; -1 is no limit" << std::endl;
os << "quad i \n if i = 1, sets the detector size to a quad (Specific to an EIGER quad hardware). 0 by default."<< std::endl;
os << "flippeddatax x \n sets if the data should be flipped on the x axis" << std::endl;

View File

@ -14,14 +14,7 @@ int slsDetectorUsers::getMaximumDetectorSize(int &nx, int &ny){
return nx*ny;
}
int slsDetectorUsers::getDetectorSize(int &x, int &y, int &nx, int &ny, int detPos){
if (detPos < 0) {
x = 0;
y = 0;
} else {
x = detector.getDetectorOffset(slsDetectorDefs::X, detPos);
y = detector.getDetectorOffset(slsDetectorDefs::Y, detPos);
}
int slsDetectorUsers::getDetectorSize(int &nx, int &ny, int detPos){
nx=detector.getTotalNumberOfChannels(slsDetectorDefs::X, detPos);
ny=detector.getTotalNumberOfChannels(slsDetectorDefs::Y, detPos);
return nx*ny;
@ -226,12 +219,12 @@ int slsDetectorUsers::setFlowControl10G(int i, int detPos) {
return detector.setFlowControl10G(i, detPos);
}
void slsDetectorUsers::setROI(int n, slsDetectorDefs::ROI roiLimits[], int detPos) {
detector.setROI(n, roiLimits, detPos);
void slsDetectorUsers::setROI(slsDetectorDefs::ROI arg, int detPos) {
detector.setROI(arg, detPos);
}
const slsDetectorDefs::ROI* slsDetectorUsers::getROI(int &n, int detPos) {
return detector.getROI(n, detPos);
slsDetectorDefs::ROI slsDetectorUsers::getROI(int detPos) {
return detector.getROI(detPos);
}
/************************************************************************