Static methods to check detector type; removed purely virtual functions to avoid error during compilation of multiSlsDetector.

git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@46 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
bergamaschi 2011-11-10 15:16:29 +00:00
parent 55ab200dbd
commit fa4fe558a5
2 changed files with 220 additions and 81 deletions

View File

@ -16,6 +16,7 @@ int slsDetector::initSharedMemory(detectorType type, int id) {
int nch, nm, nc, nd; int nch, nm, nc, nd;
int sz; int sz;
//shmId=-1;
switch(type) { switch(type) {
case MYTHEN: case MYTHEN:
@ -72,6 +73,7 @@ int slsDetector::initSharedMemory(detectorType type, int id) {
/** /**
shm_id returns -1 is shared memory initialization fails shm_id returns -1 is shared memory initialization fails
*/ */
//shmId=shm_id;
return shm_id; return shm_id;
} }
@ -93,6 +95,25 @@ int slsDetector::freeSharedMemory() {
return OK; return OK;
} }
slsDetector::slsDetector(detectorType type, int id): slsDetector::slsDetector(detectorType type, int id):
thisDetector(NULL), thisDetector(NULL),
@ -150,6 +171,149 @@ slsDetector::slsDetector(detectorType type, int id):
slsDetector::~slsDetector(){}; slsDetector::~slsDetector(){};
slsDetector::slsDetector(char *name, int id, int cport) :
thisDetector(NULL),
detId(0),
shmId(-1),
controlSocket(NULL),
stopSocket(NULL),
dataSocket(NULL),
currentPosition(0),
currentPositionIndex(0),
currentI0(0),
mergingBins(NULL),
mergingCounts(NULL),
mergingErrors(NULL),
mergingMultiplicity(NULL),
ffcoefficients(NULL),
fferrors(NULL),
detectorModules(NULL),
dacs(NULL),
adcs(NULL),
chipregs(NULL),
chanregs(NULL),
badChannelMask(NULL)
{
detectorType type=(detectorType)getDetectorType(name, cport);
while (shmId<0) {
/**Initlializes shared memory \sa initSharedMemory
if it fails the detector id is incremented until it succeeds
*/
shmId=initSharedMemory(type,id);
id++;
}
id--;
#ifdef VERBOSE
std::cout<< "Detector id is " << id << std::endl;
#endif
detId=id;
/**Initializes the detector stucture \sa initializeDetectorSize
*/
initializeDetectorSize(type);
pthread_mutex_t mp1 = PTHREAD_MUTEX_INITIALIZER;
mp=mp1;
pthread_mutex_init(&mp, NULL);
setTCPSocket(name, cport);
}
detectorType slsDetector::getDetectorType(char *name, int cport) {
int retval=FAIL;
detectorType t=GENERIC;
int fnum=F_GET_DETECTOR_TYPE;
MySocketTCP *s= new MySocketTCP(name, cport);
char m[1000];
if (s->Connect()>=0) {
s->SendDataOnly(&fnum,sizeof(fnum));
s->ReceiveDataOnly(&retval,sizeof(retval));
if (retval==OK)
s->ReceiveDataOnly(&t,sizeof(t));
else {
s->ReceiveDataOnly(m,sizeof(m));
std::cout<< "Detector returned error: " << m << std::endl;
}
s->Disconnect();
} else {
cout << "Cannot connect to server " << name << " over port " << cport << endl;
}
delete s;
return t;
}
detectorType slsDetector::getDetectorType(int id) {
detectorType t=GENERIC;
key_t mem_key=DEFAULT_SHM_KEY+id;
int shm_id;
int sz;
sz=sizeof(sharedSlsDetector);
shm_id = shmget(mem_key,sz,IPC_CREAT | 0666); // allocate shared memory
if (shm_id < 0) {
std::cout<<"*** shmget error (server) ***"<< shm_id << std::endl;
return t;
}
/**
thisDetector pointer is set to the memory address of the shared memory
*/
sharedSlsDetector* det = (sharedSlsDetector*) shmat(shm_id, NULL, 0); /* attach */
if (det == (void*)-1) {
std::cout<<"*** shmat error (server) ***" << std::endl;
return t;
}
/**
shm_id returns -1 is shared memory initialization fails
*/
//shmId=shm_id;
t=det->myDetectorType;
if (det->alreadyExisting==0) {
// Detach Memory address
if (shmdt(det) == -1) {
perror("shmdt failed\n");
return t;
}
//printf("Shared memory %d detached\n", shmId);
// remove shared memory
if (shmctl(shm_id, IPC_RMID, 0) == -1) {
perror("shmctl(IPC_RMID) failed\n");
return t;
}
//printf("Shared memory %d deleted\n", shmId);
}
return t;
}
int slsDetector::initializeDetectorSize(detectorType type) { int slsDetector::initializeDetectorSize(detectorType type) {
char *goff; char *goff;
goff=(char*)thisDetector; goff=(char*)thisDetector;
@ -203,12 +367,12 @@ int slsDetector::initializeDetectorSize(detectorType type) {
thisDetector->dynamicRange=1; thisDetector->dynamicRange=1;
break; break;
default: default:
thisDetector->nChans=65536; thisDetector->nChans=0;
thisDetector->nChips=8; thisDetector->nChips=0;
thisDetector->nDacs=16; thisDetector->nDacs=0;
thisDetector->nAdcs=16; thisDetector->nAdcs=0;
thisDetector->nModMax[X]=6; thisDetector->nModMax[X]=0;
thisDetector->nModMax[Y]=6; thisDetector->nModMax[Y]=0;
thisDetector->dynamicRange=32; thisDetector->dynamicRange=32;
} }
thisDetector->nModsMax=thisDetector->nModMax[0]*thisDetector->nModMax[1]; thisDetector->nModsMax=thisDetector->nModMax[0]*thisDetector->nModMax[1];
@ -987,26 +1151,26 @@ int slsDetector::setDetectorType(string const type){
return setDetectorType(dtype); return setDetectorType(dtype);
}; };
void slsDetector::getDetectorType(char *type){ string slsDetector::getDetectorType(){
switch (thisDetector->myDetectorType) { switch (thisDetector->myDetectorType) {
case MYTHEN: case MYTHEN:
strcpy(type,"Mythen"); return string("Mythen");
break; break;
case PILATUS: case PILATUS:
strcpy(type,"Pilatus"); return string("Pilatus");
break; break;
case EIGER: case EIGER:
strcpy(type,"Eiger"); return string("Eiger");
break; break;
case GOTTHARD: case GOTTHARD:
strcpy(type,"Gotthard"); return string("Gotthard");
break; break;
case AGIPD: case AGIPD:
strcpy(type,"Agipd"); return string("Agipd");
break; break;
default: default:
strcpy(type,"Unknown"); return string("Unknown");
break; break;
} }
}; };

View File

@ -309,6 +309,9 @@ typedef struct sharedSlsDetector {
*/ */
slsDetector(detectorType type=GENERIC, int id=0); slsDetector(detectorType type=GENERIC, int id=0);
slsDetector(char *name, int id=0, int cport=DEFAULT_PORTNO);
//slsDetector(string const fname); //slsDetector(string const fname);
// ~slsDetector(){while(dataQueue.size()>0){}}; // ~slsDetector(){while(dataQueue.size()>0){}};
/** destructor */ /** destructor */
@ -329,13 +332,13 @@ typedef struct sharedSlsDetector {
/sa mythenDetector::readConfigurationFile /sa mythenDetector::readConfigurationFile
*/ */
virtual int readConfigurationFile(string const fname)=0; virtual int readConfigurationFile(string const fname){};
/** /**
Purely virtual function Purely virtual function
Should be implemented in the specific detector class Should be implemented in the specific detector class
/sa mythenDetector::writeConfigurationFile /sa mythenDetector::writeConfigurationFile
*/ */
virtual int writeConfigurationFile(string const fname)=0; virtual int writeConfigurationFile(string const fname){};
/* /*
@ -348,13 +351,13 @@ typedef struct sharedSlsDetector {
Should be implemented in the specific detector class Should be implemented in the specific detector class
/sa mythenDetector::dumpDetectorSetup /sa mythenDetector::dumpDetectorSetup
*/ */
virtual int dumpDetectorSetup(string const fname, int level=0)=0; virtual int dumpDetectorSetup(string const fname, int level=0){};
/** /**
Purely virtual function Purely virtual function
Should be implemented in the specific detector class Should be implemented in the specific detector class
/sa mythenDetector::retrieveDetectorSetup /sa mythenDetector::retrieveDetectorSetup
*/ */
virtual int retrieveDetectorSetup(string const fname, int level=0)=0; virtual int retrieveDetectorSetup(string const fname, int level=0){};
/** /**
configure the socket communication and initializes the socket instances configure the socket communication and initializes the socket instances
@ -412,7 +415,7 @@ typedef struct sharedSlsDetector {
\sa mythenDetector::readSettingsFile \sa mythenDetector::readSettingsFile
*/ */
virtual sls_detector_module* readSettingsFile(string fname, sls_detector_module* myMod=NULL)=0; virtual sls_detector_module* readSettingsFile(string fname, sls_detector_module* myMod=NULL){};
/** /**
Pure virtual function Pure virtual function
@ -423,7 +426,7 @@ typedef struct sharedSlsDetector {
\sa ::sls_detector_module mythenDetector::writeSettingsFile(string, sls_detector_module) \sa ::sls_detector_module mythenDetector::writeSettingsFile(string, sls_detector_module)
*/ */
virtual int writeSettingsFile(string fname, sls_detector_module mod)=0; virtual int writeSettingsFile(string fname, sls_detector_module mod){};
/** /**
Pure virtual function Pure virtual function
@ -433,7 +436,7 @@ typedef struct sharedSlsDetector {
\returns OK or FAIL if the file could not be written \returns OK or FAIL if the file could not be written
\sa ::sls_detector_module sharedSlsDetector mythenDetector::writeSettingsFile(string, int) \sa ::sls_detector_module sharedSlsDetector mythenDetector::writeSettingsFile(string, int)
*/ */
virtual int writeSettingsFile(string fname, int imod)=0; virtual int writeSettingsFile(string fname, int imod){};
/** /**
@ -511,7 +514,7 @@ typedef struct sharedSlsDetector {
\sa mythenDetector::writeDataFile \sa mythenDetector::writeDataFile
*/ */
virtual int writeDataFile(string fname, float *data, float *err=NULL, float *ang=NULL, char dataformat='f', int nch=-1)=0; virtual int writeDataFile(string fname, float *data, float *err=NULL, float *ang=NULL, char dataformat='f', int nch=-1){};
/** /**
Pure virtual function Pure virtual function
@ -521,7 +524,7 @@ typedef struct sharedSlsDetector {
\returns OK or FAIL if it could not write the file or data=NULL \returns OK or FAIL if it could not write the file or data=NULL
\sa mythenDetector::writeDataFile \sa mythenDetector::writeDataFile
*/ */
virtual int writeDataFile(string fname, int *data)=0; virtual int writeDataFile(string fname, int *data){};
/** /**
Pure virtual function Pure virtual function
@ -537,7 +540,7 @@ typedef struct sharedSlsDetector {
\sa mythenDetector::readDataFile \sa mythenDetector::readDataFile
*/ */
virtual int readDataFile(string fname, float *data, float *err=NULL, float *ang=NULL, char dataformat='f', int nch=0)=0; virtual int readDataFile(string fname, float *data, float *err=NULL, float *ang=NULL, char dataformat='f', int nch=0){};
/** /**
Pure virtual function Pure virtual function
@ -547,7 +550,7 @@ typedef struct sharedSlsDetector {
\returns OK or FAIL if it could not read the file or data=NULL \returns OK or FAIL if it could not read the file or data=NULL
\sa mythenDetector::readDataFile \sa mythenDetector::readDataFile
*/ */
virtual int readDataFile(string fname, int *data)=0; virtual int readDataFile(string fname, int *data){};
/** /**
returns the location of the calibration files returns the location of the calibration files
@ -569,7 +572,7 @@ typedef struct sharedSlsDetector {
\offset reference to the offset variable \offset reference to the offset variable
\sa sharedSlsDetector mythenDetector::readCalibrationFile \sa sharedSlsDetector mythenDetector::readCalibrationFile
*/ */
virtual int readCalibrationFile(string fname, float &gain, float &offset)=0; virtual int readCalibrationFile(string fname, float &gain, float &offset){};
/** /**
Pure virtual function Pure virtual function
writes a calibration file writes a calibration file
@ -578,7 +581,7 @@ typedef struct sharedSlsDetector {
\param offset \param offset
\sa sharedSlsDetector mythenDetector::writeCalibrationFile \sa sharedSlsDetector mythenDetector::writeCalibrationFile
*/ */
virtual int writeCalibrationFile(string fname, float gain, float offset)=0; virtual int writeCalibrationFile(string fname, float gain, float offset){};
/** /**
@ -636,7 +639,7 @@ typedef struct sharedSlsDetector {
normally the detector knows what type of detector it is normally the detector knows what type of detector it is
\param type is the string where the detector type will be written ("Mythen", "Pilatus", "XFS", "Gotthard", Agipd") \param type is the string where the detector type will be written ("Mythen", "Pilatus", "XFS", "Gotthard", Agipd")
*/ */
void getDetectorType(char *type); string getDetectorType();
// Detector configuration functions // Detector configuration functions
@ -1041,6 +1044,17 @@ typedef struct sharedSlsDetector {
*/ */
int setDynamicRange(int n=-1); int setDynamicRange(int n=-1);
/**
set/get dynamic range
\returns number of bytes sent by the detector
\sa sharedSlsDetector
*/
int getDataBytes(){return thisDetector->dataBytes;};
/** /**
set roi set roi
@ -1511,62 +1525,23 @@ enum {GET_ACTION, PUT_ACTION, READOUT_ACTION};
/**
returns the detector type from hostname and controlport
\param
\param action can be PUT_ACTION or GET_ACTION (from text client even READOUT_ACTION for acquisition)
*/
static detectorType getDetectorType(char *name, int cport=DEFAULT_PORTNO);
/**
returns the detector type from hostname and controlport
\param
\param action can be PUT_ACTION or GET_ACTION (from text client even READOUT_ACTION for acquisition)
*/
static detectorType getDetectorType(int id);
int getDetectorId() { return detId;};
protected: protected: