new getDetectorType functions

This commit is contained in:
Erik Frojdh 2019-01-18 10:53:49 +01:00
parent 13d6d3f866
commit 10539f8533
10 changed files with 74 additions and 95 deletions

View File

@ -292,7 +292,7 @@ std::string multiSlsDetector::getUserDetails() {
sstream << "\nHostname: " << getHostname();
sstream << "\nType: ";
for (auto &d : detectors)
sstream << d->sgetDetectorsType() << "+";
sstream << d->getDetectorTypeAsString() << "+";
sstream << "\nPID: " << thisMultiDetector->lastPID
<< "\nUser: " << thisMultiDetector->lastUser
@ -475,7 +475,7 @@ void multiSlsDetector::addSlsDetector(const std::string& hostname) {
// slsdetector in initsharedmemory
// get type by connecting
detectorType type = slsDetector::getDetectorType(hostname.c_str(), DEFAULT_PORTNO);
detectorType type = slsDetector::getDetectorTypeAsEnum(hostname.c_str(), DEFAULT_PORTNO);
if (type == GENERIC) {
FILE_LOG(logERROR) << "Could not connect to Detector " << hostname
<< " to determine the type!";
@ -495,39 +495,38 @@ void multiSlsDetector::addSlsDetector(const std::string& hostname) {
detectors[pos]->getTotalNumberOfChannels();
}
slsDetectorDefs::detectorType multiSlsDetector::getDetectorsType(int detPos) {
slsDetectorDefs::detectorType multiSlsDetector::getDetectorTypeAsEnum(int detPos) {
// single
if (detPos >= 0) {
return detectors[detPos]->getDetectorsType();
return detectors[detPos]->getDetectorTypeAsEnum();
}
// multi
auto r = serialCall(&slsDetector::getDetectorsType);
auto r = serialCall(&slsDetector::getDetectorTypeAsEnum);
return (detectorType)sls::minusOneIfDifferent(r);
}
std::string multiSlsDetector::sgetDetectorsType(int detPos) {
std::string multiSlsDetector::getDetectorTypeAsString(int detPos) {
// single
if (detPos >= 0) {
return detectors[detPos]->sgetDetectorsType();
return detectors[detPos]->getDetectorTypeAsString();
}
// multi
auto r = serialCall(&slsDetector::sgetDetectorsType);
auto r = serialCall(&slsDetector::getDetectorTypeAsString);
return sls::concatenateIfDifferent(r);
}
std::string multiSlsDetector::getDetectorType(int detPos) {
return sgetDetectorsType(detPos);
int multiSlsDetector::getNumberOfDetectors() const {
return detectors.size();
}
int multiSlsDetector::getNumberOfDetectors() { return detectors.size(); }
int multiSlsDetector::getNumberOfDetectors(dimension d) {
int multiSlsDetector::getNumberOfDetectors(dimension d) const {
return thisMultiDetector->numberOfDetector[d];
}
void multiSlsDetector::getNumberOfDetectors(int &nx, int &ny) {
void multiSlsDetector::getNumberOfDetectors(int &nx, int &ny) const {
nx = thisMultiDetector->numberOfDetector[X];
ny = thisMultiDetector->numberOfDetector[Y];
}
@ -1036,7 +1035,7 @@ int multiSlsDetector::prepareAcquisition(int detPos) {
int multiSlsDetector::startAcquisition(int detPos) {
// single
if (detPos >= 0) {
if (detectors[detPos]->getDetectorsType() == EIGER) {
if (detectors[detPos]->getDetectorTypeAsEnum() == EIGER) {
if (detectors[detPos]->prepareAcquisition() == FAIL)
return FAIL;
}
@ -1044,7 +1043,7 @@ int multiSlsDetector::startAcquisition(int detPos) {
}
// multi
if (getDetectorsType() == EIGER) {
if (getDetectorTypeAsEnum() == EIGER) {
if (prepareAcquisition() == FAIL)
return FAIL;
}
@ -1083,7 +1082,7 @@ int multiSlsDetector::sendSoftwareTrigger(int detPos) {
int multiSlsDetector::startAndReadAll(int detPos) {
// single
if (detPos >= 0) {
if (detectors[detPos]->getDetectorsType() == EIGER) {
if (detectors[detPos]->getDetectorTypeAsEnum() == EIGER) {
if (detectors[detPos]->prepareAcquisition() == FAIL)
return FAIL;
}
@ -1091,7 +1090,7 @@ int multiSlsDetector::startAndReadAll(int detPos) {
}
// multi
if (getDetectorsType() == EIGER) {
if (getDetectorTypeAsEnum() == EIGER) {
if (prepareAcquisition() == FAIL)
return FAIL;
}
@ -1344,7 +1343,7 @@ int multiSlsDetector::setDynamicRange(int p, int detPos) {
}
// for usability
if (getDetectorsType() == EIGER) {
if (getDetectorTypeAsEnum() == EIGER) {
switch (p) {
case 32:
FILE_LOG(logINFO) << "Setting Clock to Quarter Speed to cope with "
@ -1389,7 +1388,7 @@ int multiSlsDetector::setDAC(int val, dacIndex idac, int mV, int detPos) {
// multi
auto r = parallelCall(&slsDetector::setDAC, val, idac, mV);
if (getDetectorsType() != EIGER || idac != HIGH_VOLTAGE)
if (getDetectorTypeAsEnum() != EIGER || idac != HIGH_VOLTAGE)
return sls::minusOneIfDifferent(r);
// ignore slave values for hv (-999)
@ -1690,7 +1689,7 @@ void multiSlsDetector::setClientDataStreamingInPort(int i, int detPos) {
else {
// calculate ports individually
int firstPort = i;
int numSockets = (getDetectorsType() == EIGER) ? 2 : 1;
int numSockets = (getDetectorTypeAsEnum() == EIGER) ? 2 : 1;
for (size_t idet = 0; idet < detectors.size(); ++idet) {
auto port = firstPort + (idet * numSockets);
@ -1728,7 +1727,7 @@ void multiSlsDetector::setReceiverDataStreamingOutPort(int i, int detPos) {
else {
// calculate ports individually
int firstPort = i;
int numSockets = (getDetectorsType() == EIGER) ? 2 : 1;
int numSockets = (getDetectorTypeAsEnum() == EIGER) ? 2 : 1;
for (size_t idet = 0; idet < detectors.size(); ++idet) {
auto port = firstPort + (idet * numSockets);
@ -2338,7 +2337,7 @@ int multiSlsDetector::setAllTrimbits(int val, int detPos) {
}
int multiSlsDetector::enableGapPixels(int val, int detPos) {
if (getDetectorsType() != EIGER) {
if (getDetectorTypeAsEnum() != EIGER) {
if (val >= 0) {
FILE_LOG(logERROR) << "Function (enableGapPixels) not implemented "
"for this detector";
@ -2872,7 +2871,7 @@ int multiSlsDetector::createReceivingDataSockets(const bool destroy) {
size_t numSockets = detectors.size();
size_t numSocketsPerDetector = 1;
if (getDetectorsType() == EIGER) {
if (getDetectorTypeAsEnum() == EIGER) {
numSocketsPerDetector = 2;
}
numSockets *= numSocketsPerDetector;
@ -2909,7 +2908,7 @@ void multiSlsDetector::readFrameFromReceiver() {
->numberOfDetector[Y]; // for eiger, to reverse the data
bool gappixelsenable = false;
bool eiger = false;
if (getDetectorsType() == EIGER) {
if (getDetectorTypeAsEnum() == EIGER) {
eiger = true;
nX *= 2;
gappixelsenable = detectors[0]->enableGapPixels(-1) >= 1 ? true : false;
@ -3497,7 +3496,7 @@ int multiSlsDetector::retrieveDetectorSetup(const std::string &fname1,
}
int multiSlsDetector::dumpDetectorSetup(const std::string &fname, int level) {
detectorType type = getDetectorsType();
detectorType type = getDetectorTypeAsEnum();
// std::string names[100];
std::vector<std::string> names;
// int nvar = 0;

View File

@ -280,14 +280,13 @@ class multiSlsDetector : public virtual slsDetectorDefs,
*/
void addMultipleDetectors(const char *name);
using slsDetectorDefs::getDetectorType;
/**
* Get Detector type for a particular sls detector or get the first one
* @param detPos -1 for all detectors in list or specific detector position
* @returns detector type of sls detector in position pos, if -1, returns
* the first det type
*/
detectorType getDetectorsType(int detPos = -1);
detectorType getDetectorTypeAsEnum(int detPos = -1);
/**
* Concatenates string types of all sls detectors or
@ -296,35 +295,27 @@ class multiSlsDetector : public virtual slsDetectorDefs,
* @returns detector type of sls detector in position pos, if -1,
* concatenates
*/
std::string sgetDetectorsType(int detPos = -1);
/**
* Gets Detector type (concatenates if different)
* @param detPos -1 for all detectors in list or specific detector position
* @returns detector type of sls detector in position pos, if -1,
* concatenates
*/
std::string getDetectorType(int detPos = -1);
std::string getDetectorTypeAsString(int detPos = -1);
/**
* Returns the number of detectors in the multidetector structure
* @returns number of detectors
*/
int getNumberOfDetectors();
int getNumberOfDetectors() const;
/**
* Returns number of detectors in dimension d
* @param d dimension d
* @returns number of detectors in dimension d
*/
int getNumberOfDetectors(dimension d);
int getNumberOfDetectors(dimension d) const;
/**
* Returns the number of detectors in each direction
@param nx number of detectors in x direction
@param ny number of detectors in y direction
*/
void getNumberOfDetectors(int &nx, int &ny);
void getNumberOfDetectors(int &nx, int &ny) const;
/**
* Returns the total number of channels of all sls detectors from shared

View File

@ -49,7 +49,7 @@ slsDetector::slsDetector(int multiId, int id, bool verify)
/* called from multi constructor to populate structure,
* so sls shared memory will be opened, not created */
// getDetectorType Froom shm will check if it was already existing
// getDetectorType From shm will check if it was already existing
detectorType type = getDetectorTypeFromShm(multiId, verify);
initSharedMemory(false, type, multiId, verify);
@ -752,16 +752,16 @@ slsDetectorDefs::detectorType slsDetector::getDetectorTypeFromShm(int multiId, b
// static function
slsDetectorDefs::detectorType slsDetector::getDetectorType(const char *name, int cport) {
slsDetectorDefs::detectorType slsDetector::getDetectorTypeAsEnum(const std::string& hostname, int cport) {
int fnum = F_GET_DETECTOR_TYPE;
int ret = FAIL;
detectorType retval = GENERIC;
MySocketTCP* mySocket = nullptr;
try {
mySocket = new MySocketTCP(name, cport);
mySocket = new MySocketTCP(hostname.c_str(), cport);
} catch(...) {
FILE_LOG(logERROR) << "Cannot create socket to control server " << name
FILE_LOG(logERROR) << "Cannot create socket to control server " << hostname
<< " over port " << cport;
return retval;
}
@ -773,7 +773,7 @@ slsDetectorDefs::detectorType slsDetector::getDetectorType(const char *name, int
mySocket->ReceiveDataOnly(&retval,sizeof(retval));
mySocket->Disconnect();
} else {
FILE_LOG(logERROR) << "Cannot connect to server " << name << " over port " << cport;
FILE_LOG(logERROR) << "Cannot connect to server " << hostname << " over port " << cport;
}
if (ret != FAIL) {
FILE_LOG(logDEBUG1) << "Detector type is " << retval;
@ -838,23 +838,20 @@ int slsDetector::setDetectorType(detectorType const type) {
int slsDetector::setDetectorType(const std::string& detector_type) {
return setDetectorType(getDetectorType(detector_type));
}
// int slsDetector::setDetectorType(const std::string& detector_type) {
// return setDetectorType(getDetectorType(detector_type));
// }
slsDetectorDefs::detectorType slsDetector::getDetectorsType() {
slsDetectorDefs::detectorType slsDetector::getDetectorTypeAsEnum() {
return thisDetector->myDetectorType;
}
std::string slsDetector::sgetDetectorsType() {
return getDetectorType(getDetectorsType());
std::string slsDetector::getDetectorTypeAsString() {
return slsDetectorDefs::detectorTypeToString(getDetectorTypeAsEnum());
}
std::string slsDetector::getDetectorType() {
return sgetDetectorsType();
}
int slsDetector::getTotalNumberOfChannels() {
@ -2697,7 +2694,7 @@ std::string slsDetector::setReceiver(const std::string& receiverIP) {
if (setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG) {
FILE_LOG(logDEBUG1) <<
"detector type:" << (slsDetectorDefs::getDetectorType(thisDetector->myDetectorType)) <<
"detector type:" << (slsDetectorDefs::detectorTypeToString(thisDetector->myDetectorType)) <<
"\ndetector id:" << detId <<
"\ndetector hostname:" << thisDetector->hostname <<
"\nfile path:" << thisDetector->receiver_filePath <<

View File

@ -373,7 +373,6 @@ public:
*/
void disconnectStop();
using slsDetectorDefs::getDetectorType;
/**
* Get detector type by connecting to the detector without creating an object
@ -381,7 +380,19 @@ public:
* @param cport TCP control port
* @returns detector tpe or GENERIC if failed
*/
static detectorType getDetectorType(const char *name, int cport=DEFAULT_PORTNO);
static detectorType getDetectorTypeAsEnum(const std::string& hostname, int cport=DEFAULT_PORTNO);
/**
* Get Detector type from shared memory variable
* @returns detector type from shared memory variable
*/
detectorType getDetectorTypeAsEnum();
/**
* Gets string version of detector type from shared memory variable
* @returns string version of detector type from shared memory variable
*/
std::string getDetectorTypeAsString();
/**
* Gets detector type from detector and set it in receiver
@ -394,27 +405,8 @@ public:
* Gets detector type (string) from detector and set it in receiver
* @param type string of detector type
* @returns detector type in receiver
*/
int setDetectorType(const std::string& detector_type);
/**
* Get Detector type from shared memory variable
* @returns detector type from shared memory variable
*/
detectorType getDetectorsType();
/**
* Gets string version of detector type from shared memory variable
* @returns string version of detector type from shared memory variable
*/
std::string sgetDetectorsType();
/**
* Just to overload getDetectorType from users
* Gets string version of detector type from shared memory variable
* @returns gets string version of detector type from shared memory variable
*/
std::string getDetectorType();
// */
// int setDetectorType(const std::string& detector_type);
/**
* Returns the total number of channels from shared memory
@ -1805,7 +1797,7 @@ private:
/** pointer to dac valuse in shared memory */
int *dacs {nullptr};
/** pointer to channal registers in shared memory */
/** pointer to channel registers in shared memory */
int *chanregs {nullptr};
};

View File

@ -3295,7 +3295,7 @@ std::string slsDetectorCommand::cmdSettings(int narg, char *args[], int action,
if (sett == -1)
return std::string("unknown settings scanned " + std::string(args[1]));
sett = myDet->setSettings(sett, detPos);
if (myDet->getDetectorsType(detPos) == EIGER) {
if (myDet->getDetectorTypeAsEnum(detPos) == EIGER) {
return myDet->getDetectorSettings(sett);
}
}
@ -3305,7 +3305,7 @@ std::string slsDetectorCommand::cmdSettings(int narg, char *args[], int action,
if (!sscanf(args[1], "%d", &val)) {
return std::string("invalid threshold value");
}
detectorType type = myDet->getDetectorsType(detPos);
detectorType type = myDet->getDetectorTypeAsEnum(detPos);
if (type != EIGER || (type == EIGER && narg <= 2)) {
myDet->setThresholdEnergy(val, GET_SETTINGS, 1, detPos);
} else {
@ -3322,7 +3322,7 @@ std::string slsDetectorCommand::cmdSettings(int narg, char *args[], int action,
if (!sscanf(args[1], "%d", &val)) {
return std::string("invalid threshold value");
}
detectorType type = myDet->getDetectorsType(detPos);
detectorType type = myDet->getDetectorTypeAsEnum(detPos);
if (type != EIGER)
return std::string("not implemented for this detector");
if (narg <= 2) {
@ -4049,7 +4049,7 @@ std::string slsDetectorCommand::cmdADC(int narg, char *args[], int action, int d
return std::string("cannot decode adc ") + cmd;
myDet->setOnline(ONLINE_FLAG, detPos);
if (myDet->getDetectorsType(detPos) == EIGER || myDet->getDetectorsType(detPos) == JUNGFRAU) {
if (myDet->getDetectorTypeAsEnum(detPos) == EIGER || myDet->getDetectorTypeAsEnum(detPos) == JUNGFRAU) {
int val = myDet->getADC(adc, detPos);
if (val == -1)
sprintf(answer, "%d", val);
@ -4106,7 +4106,7 @@ std::string slsDetectorCommand::cmdADC(int narg, char *args[], int action, int d
return std::string("cannot decode adc ")+cmd;
myDet->setOnline(ONLINE_FLAG, detPos);
if (myDet->getDetectorsType(detPos) == EIGER || myDet->getDetectorsType(detPos) == JUNGFRAU){
if (myDet->getDetectorTypeAsEnum(detPos) == EIGER || myDet->getDetectorTypeAsEnum(detPos) == JUNGFRAU){
int val = myDet->getADC(adc, detPos);
if (val == -1)
sprintf(answer,"%d",val);

View File

@ -6,7 +6,7 @@
int slsDetectorUsers::getNumberOfDetectors() {
int slsDetectorUsers::getNumberOfDetectors() const {
return detector.getNumberOfDetectors();
}
@ -30,7 +30,7 @@ int slsDetectorUsers::getDetectorSize(int &x, int &y, int &nx, int &ny, int detP
}
std::string slsDetectorUsers::getDetectorType(int detPos){
return detector.sgetDetectorsType(detPos);
return detector.getDetectorTypeAsString(detPos);
}
int slsDetectorUsers::setOnline(int const online, int detPos){
return detector.setOnline(online, detPos);

View File

@ -100,7 +100,7 @@ public:
* Returns the number of detectors in the multidetector structure
* @returns number of detectors
*/
int getNumberOfDetectors();
int getNumberOfDetectors() const;
/**
* Returns the maximum number of channels of all detectors
@ -215,14 +215,14 @@ public:
/**
* Check Detector Version Compatibility
* @param detPos -1 for all detectors in list or specific detector position
* @returns true if compatibile, else false
* @returns true if compatible, else false
*/
bool isDetectorVersionCompatible(int detPos = -1);
/**
* Check Receiver Version Compatibility
* @param detPos -1 for all detectors in list or specific detector position
* @returns true if compatibile, else false
* @returns true if compatible, else false
*/
bool isReceiverVersionCompatible(int detPos = -1);
@ -761,7 +761,7 @@ public:
*********************************************************************/
/**
* register calbback for accessing detector final data in client,
* register callback for accessing detector final data in client,
* also enables data streaming in client and receiver
* @param userCallback function for plotting/analyzing the data.
* Its arguments are

View File

@ -216,7 +216,7 @@ public:
*/
virtual void Print(TLogLevel level = logDEBUG1) const {
FILE_LOG(level) << "\n\nDetector Data Variables:";
FILE_LOG(level) << "myDetectorType: " << slsDetectorDefs::getDetectorType(myDetectorType);
FILE_LOG(level) << "myDetectorType: " << slsDetectorDefs::detectorTypeToString(myDetectorType);
FILE_LOG(level) << "Pixels X: " << nPixelsX;
FILE_LOG(level) << "Pixels Y: " << nPixelsY;
FILE_LOG(level) << "Empty Header: " << emptyHeader;

View File

@ -834,7 +834,7 @@ int slsReceiverImplementation::setDetectorType(const detectorType d) {
case EIGER:
case CHIPTESTBOARD:
case JUNGFRAU:
FILE_LOG(logINFO) << " ***** " << getDetectorType(d) << " Receiver *****";
FILE_LOG(logINFO) << " ***** " << detectorTypeToString(d) << " Receiver *****";
break;
default:
FILE_LOG(logERROR) << "This is an unknown receiver type " << (int)d;
@ -895,7 +895,7 @@ int slsReceiverImplementation::setDetectorType(const detectorType d) {
// check udp socket buffer size
setUDPSocketBufferSize(udpSocketBufferSize);
FILE_LOG(logDEBUG) << " Detector type set to " << getDetectorType(d);
FILE_LOG(logDEBUG) << " Detector type set to " << detectorTypeToString(d);
return OK;
}

View File

@ -572,7 +572,7 @@ public:
\param t string can be EIGER, GOTTHARD, JUNGFRAU, CHIPTESTBOARD
\returns Eiger, Gotthard, Jungfrau, JungfrauCTB, Unknown
*/
static std::string getDetectorType(detectorType t){ \
static std::string detectorTypeToString(detectorType t){ \
switch (t) { \
case EIGER: return std::string("Eiger"); \
case GOTTHARD: return std::string("Gotthard"); \
@ -585,7 +585,7 @@ public:
\param type can be Eiger, Gotthard, Jungfrau, JungfrauCTB
\returns EIGER, GOTTHARD, JUNGFRAU, CHIPTESTBOARD, GENERIC
*/
static detectorType getDetectorType(std::string const type){\
static detectorType detectorTypeToEnum(const std::string& type){\
if (type=="Eiger") return EIGER; \
if (type=="Gotthard") return GOTTHARD; \
if (type=="Jungfrau") return JUNGFRAU; \