Gotthard class implemented

git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@34 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
bergamaschi
2011-10-13 11:26:28 +00:00
parent 3367bb3026
commit ab27ab1c5d
36 changed files with 17857 additions and 161 deletions

View File

@ -5,10 +5,6 @@
#include <sys/shm.h>
//using namespace std;
int slsDetector::initSharedMemory(detectorType type, int id) {
@ -34,6 +30,12 @@ int slsDetector::initSharedMemory(detectorType type, int id) {
nc=12;
nd=6; // dacs+adcs
break;
case GOTTHARD:
nch=128;
nm=1;
nc=10;
nd=13; // dacs+adcs
break;
default:
nch=65535; // one EIGER module
nm=1; //modules/detector
@ -115,22 +117,25 @@ slsDetector::slsDetector(detectorType type, int id):
chanregs(NULL),
badChannelMask(NULL)
{
while (shmId<0) {
/**Initlializes shared memory \sa initSharedMemory
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--;
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;
std::cout<< "Detector id is " << id << std::endl;
#endif
detId=id;
/**Initializes the detector stucture \sa initializeDetectorSize
*/
initializeDetectorSize(type);
detId=id;
/**Initializes the detector stucture \sa initializeDetectorSize
*/
initializeDetectorSize(type);
}
@ -146,10 +151,17 @@ int slsDetector::initializeDetectorSize(detectorType type) {
/** sets onlineFlag to OFFLINE_FLAG */
thisDetector->onlineFlag=OFFLINE_FLAG;
/** set ports to defaults */
switch(type){
case GOTTHARD:
thisDetector->controlPort=DEFAULT_PORTNO_GOTTHARD;
thisDetector->stopPort=DEFAULT_PORTNO_GOTTHARD+1;
thisDetector->dataPort=DEFAULT_PORTNO_GOTTHARD+2;
break;
default:
thisDetector->controlPort=DEFAULT_PORTNO;
thisDetector->stopPort=DEFAULT_PORTNO+1;
thisDetector->dataPort=DEFAULT_PORTNO+2;
}
/** set thisDetector->myDetectorType to type and according to this set nChans, nChips, nDacs, nAdcs, nModMax, dynamicRange, nMod*/
thisDetector->myDetectorType=type;
switch(thisDetector->myDetectorType) {
@ -171,6 +183,15 @@ int slsDetector::initializeDetectorSize(detectorType type) {
thisDetector->nModMax[Y]=1;
thisDetector->dynamicRange=24;
break;
case GOTTHARD:
thisDetector->nChans=128;
thisDetector->nChips=10;
thisDetector->nDacs=8;
thisDetector->nAdcs=5;
thisDetector->nModMax[X]=1;
thisDetector->nModMax[Y]=1;
thisDetector->dynamicRange=1;
break;
default:
thisDetector->nChans=65536;
thisDetector->nChips=8;
@ -196,11 +217,11 @@ int slsDetector::initializeDetectorSize(detectorType type) {
else
thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*thisDetector->dynamicRange/8;
/** set trimDsdir, calDir and filePath to default to home directory*/
strcpy(thisDetector->trimDir,getenv("HOME"));
strcpy(thisDetector->settingsDir,getenv("HOME"));
strcpy(thisDetector->calDir,getenv("HOME"));
strcpy(thisDetector->filePath,getenv("HOME"));
/** sets trimbit file */
strcpy(thisDetector->trimFile,"none");
strcpy(thisDetector->settingsFile,"none");
/** set fileName to default to run*/
strcpy(thisDetector->fileName,"run");
/** set fileIndex to default to 0*/
@ -2324,7 +2345,7 @@ int slsDetector::setThresholdEnergy(int e_eV, int imod, detectorSettings isetti
*/
detectorSettings slsDetector::getSettings(int imod){
int fnum=F_SET_SETTINGS;
int ret=FAIL;
char mess[100];
@ -2359,16 +2380,29 @@ int slsDetector::setThresholdEnergy(int e_eV, int imod, detectorSettings isetti
};
detectorSettings slsDetector::setSettings( detectorSettings isettings, int imod){
#ifdef VERBOSE
//#ifdef VERBOSE
std::cout<< "slsDetector setSettings "<< std::endl;
#endif
//#endif
sls_detector_module *myMod=createModule();
int modmi=imod, modma=imod+1, im=imod;
string trimfname, calfname;
string settingsfname, calfname;
string ssettings;
detectorSettings minsettings, maxsettings;
if (isettings>=STANDARD && isettings<=HIGHGAIN) {
switch(thisDetector->myDetectorType){
case GOTTHARD:
minsettings = HIGHGAIN;
maxsettings = GAIN3;
break;
default:
minsettings = STANDARD;
maxsettings = HIGHGAIN;
}
if (isettings>=minsettings && isettings<=maxsettings) {
switch (isettings) {
case STANDARD:
ssettings="/standard";
@ -2382,10 +2416,26 @@ int slsDetector::setThresholdEnergy(int e_eV, int imod, detectorSettings isetti
ssettings="/highgain";
thisDetector->currentSettings=HIGHGAIN;
break;
case DYNAMICGAIN:
ssettings="/dynamicgain";
thisDetector->currentSettings=DYNAMICGAIN;
break;
case GAIN1:
ssettings="/gain1";
thisDetector->currentSettings=GAIN1;
break;
case GAIN2:
ssettings="/gain2";
thisDetector->currentSettings=GAIN2;
break;
case GAIN3:
ssettings="/gain3";
thisDetector->currentSettings=GAIN3;
break;
default:
std::cout<< "Unknown settings!" << std::endl;
}
if (imod<0) {
modmi=0;
// modma=thisDetector->nModMax[X]*thisDetector->nModMax[Y];
@ -2396,31 +2446,46 @@ int slsDetector::setThresholdEnergy(int e_eV, int imod, detectorSettings isetti
ostringstream ostfn, oscfn;
myMod->module=im;
//create file names
ostfn << thisDetector->trimDir << ssettings <<"/noise.sn" << setfill('0') << setw(3) << hex << getId(MODULE_SERIAL_NUMBER, im) << setbase(10);
oscfn << thisDetector->calDir << ssettings << "/calibration.sn" << setfill('0') << setw(3) << hex << getId(MODULE_SERIAL_NUMBER, im) << setbase(10);
//
trimfname=ostfn.str();
#ifdef VERBOSE
cout << trimfname << endl;
#endif
if (readTrimFile(trimfname,myMod)) {
switch(thisDetector->myDetectorType){
case GOTTHARD:
ostfn << thisDetector->settingsDir << ssettings <<"/settings.sn";// << setfill('0') << setw(3) << hex << getId(MODULE_SERIAL_NUMBER, im) << setbase(10);
oscfn << thisDetector->calDir << ssettings << "/calibration.sn";// << setfill('0') << setw(3) << hex << getId(MODULE_SERIAL_NUMBER, im) << setbase(10);
std::cout<< thisDetector->settingsDir<<endl<< thisDetector->calDir <<endl;
break;
default:
ostfn << thisDetector->settingsDir << ssettings <<"/noise.sn" << setfill('0') << setw(3) << hex << getId(MODULE_SERIAL_NUMBER, im) << setbase(10);
oscfn << thisDetector->calDir << ssettings << "/calibration.sn" << setfill('0') << setw(3) << hex << getId(MODULE_SERIAL_NUMBER, im) << setbase(10);
}
//oscfn << thisDetector->calDir << ssettings << "/calibration.sn" << setfill('0') << setw(3) << hex << getId(MODULE_SERIAL_NUMBER, im) << setbase(10);
settingsfname=ostfn.str();
//#ifdef VERBOSE
cout << "the settings name is "<<settingsfname << endl;
//#endif
if (readSettingsFile(settingsfname,myMod)) {
calfname=oscfn.str();
#ifdef VERBOSE
cout << calfname << endl;
cout << calfname << endl;
#endif
readCalibrationFile(calfname,myMod->gain, myMod->offset);
setModule(*myMod);
} else {
ostringstream ostfn,oscfn;
ostfn << thisDetector->trimDir << ssettings << ssettings << ".trim";
switch(thisDetector->myDetectorType){
case GOTTHARD:
ostfn << thisDetector->settingsDir << ssettings << ssettings << ".settings";
break;
default:
ostfn << thisDetector->settingsDir << ssettings << ssettings << ".trim";
}
oscfn << thisDetector->calDir << ssettings << ssettings << ".cal";
calfname=oscfn.str();
trimfname=ostfn.str();
settingsfname=ostfn.str();
#ifdef VERBOSE
cout << trimfname << endl;
cout << calfname << endl;
cout << settingsfname << endl;
cout << calfname << endl;
#endif
if (readTrimFile(trimfname,myMod)) {
if (readSettingsFile(settingsfname,myMod)) {
calfname=oscfn.str();
readCalibrationFile(calfname,myMod->gain, myMod->offset);
setModule(*myMod);
@ -2429,18 +2494,23 @@ int slsDetector::setThresholdEnergy(int e_eV, int imod, detectorSettings isetti
}
}
deleteModule(myMod);
/*
if (thisDetector->correctionMask&(1<<RATE_CORRECTION)) {
int isett=getSettings(imod);
float t[]=defaultTDead;
if (isett>-1 && isett<3) {
thisDetector->tDead=t[isett];
}
}
}
*/
return getSettings(imod);
};
// Acquisition functions
/* change these funcs accepting also ok/fail */
@ -3698,8 +3768,7 @@ int slsDetector::exitServer(){
int retval;
int fnum=F_EXIT_SERVER;
if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (controlSocket) {
controlSocket->Connect();
@ -3708,12 +3777,13 @@ int slsDetector::exitServer(){
controlSocket->Disconnect();
}
}
if (retval==OK) {
if (retval!=OK) {
std::cout<< std::endl;
std::cout<< "Shutting down the server" << std::endl;
std::cout<< std::endl;
}
return retval;
};

View File

@ -160,8 +160,8 @@ typedef struct sharedSlsDetector {
detectorType myDetectorType;
/** path of the trimbits files */
char trimDir[MAX_STR_LENGTH];
/** path of the trimbits/settings files */
char settingsDir[MAX_STR_LENGTH];
/** path of the calibration files */
char calDir[MAX_STR_LENGTH];
/** number of energies at which the detector has been trimmed (unused) */
@ -253,7 +253,7 @@ typedef struct sharedSlsDetector {
/* detector setup - not needed */
/** name root of the output files */
char trimFile[MAX_STR_LENGTH];
char settingsFile[MAX_STR_LENGTH];
/** detector settings (standard, fast, etc.) */
detectorSettings currentSettings;
/** detector threshold (eV) */
@ -322,6 +322,7 @@ typedef struct sharedSlsDetector {
\returns 1 if the detector structure has already be initlialized, 0 otherwise */
int exists() {return thisDetector->alreadyExisting;};
/**
Purely virtual function
Should be implemented in the specific detector class
@ -378,10 +379,10 @@ typedef struct sharedSlsDetector {
/* I/O */
/** returns the detector trimbit directory \sa sharedSlsDetector */
char* getTrimDir() {return thisDetector->trimDir;};
/** sets the detector trimbit directory \sa sharedSlsDetector */
char* setTrimDir(string s) {sprintf(thisDetector->trimDir, s.c_str()); return thisDetector->trimDir;};
/** returns the detector trimbit/settings directory \sa sharedSlsDetector */
char* getSettingsDir() {return thisDetector->settingsDir;};
/** sets the detector trimbit/settings directory \sa sharedSlsDetector */
char* setSettingsDir(string s) {sprintf(thisDetector->settingsDir, s.c_str()); return thisDetector->settingsDir;};
/** returns the number of trim energies and their value \sa sharedSlsDetector
\param point to the array that will contain the trim energies (in ev)
\returns number of trim energies
@ -404,49 +405,49 @@ typedef struct sharedSlsDetector {
/**
Pure virtual function
reads a trim file
reads a trim/settings file
\param fname name of the file to be read
\param myMod pointer to the module structure which has to be set. <BR> If it is NULL a new module structure will be created
\returns the pointer to myMod or NULL if reading the file failed
\sa mythenDetector::readTrimFile
\sa mythenDetector::readSettingsFile
*/
virtual sls_detector_module* readTrimFile(string fname, sls_detector_module* myMod=NULL)=0;
virtual sls_detector_module* readSettingsFile(string fname, sls_detector_module* myMod=NULL)=0;
/**
Pure virtual function
writes a trim file
writes a trim/settings file
\param fname name of the file to be written
\param mod module structure which has to be written to file
\returns OK or FAIL if the file could not be written
\sa ::sls_detector_module mythenDetector::writeTrimFile(string, sls_detector_module)
\sa ::sls_detector_module mythenDetector::writeSettingsFile(string, sls_detector_module)
*/
virtual int writeTrimFile(string fname, sls_detector_module mod)=0;
virtual int writeSettingsFile(string fname, sls_detector_module mod)=0;
/**
returns currently the loaded trimfile name
Pure virtual function
writes a trim/settings file for module number imod - the values will be read from the current detector structure
\param fname name of the file to be written
\param imod module number
\returns OK or FAIL if the file could not be written
\sa ::sls_detector_module sharedSlsDetector mythenDetector::writeSettingsFile(string, int)
*/
virtual int writeSettingsFile(string fname, int imod)=0;
const char *getTrimFile(){\
string s(thisDetector->trimFile); \
/**
returns currently the loaded trimfile/settingsfile name
*/
const char *getSettingsFile(){\
string s(thisDetector->settingsFile); \
if (s.length()>6) {\
if (s.substr(s.length()-6,3)==string(".sn") && s.substr(s.length()-3)!=string("xxx") ) \
return s.substr(0,s.length()-6).c_str(); \
} \
return thisDetector->trimFile;\
return thisDetector->settingsFile;\
};
/**
Pure virtual function
writes a trim file for module number imod - the values will be read from the current detector structure
\param fname name of the file to be written
\param imod module number
\returns OK or FAIL if the file could not be written
\sa ::sls_detector_module sharedSlsDetector mythenDetector::writeTrimFile(string, int)
*/
virtual int writeTrimFile(string fname, int imod)=0;
/**
sets the default output files path
\sa sharedSlsDetector
@ -899,7 +900,7 @@ typedef struct sharedSlsDetector {
\param imod module number (-1 all)
\returns current settings
in this function trimbits and calibration files are searched in the trimDir and calDir directories and the detector is initialized
in this function trimbits/settings and calibration files are searched in the settingsDir and calDir directories and the detector is initialized
*/
virtual detectorSettings setSettings(detectorSettings isettings, int imod=-1);