Merge branch 'master' of gitorious.psi.ch:sls_det_software/sls_detector_software

This commit is contained in:
bergamaschi 2015-09-24 10:54:48 +02:00
commit 11de59d87c
22 changed files with 539 additions and 266 deletions

View File

@ -18,7 +18,6 @@ using namespace std;
/** Error flags */ /** Error flags */
#define NUM_ERROR_FLAGS 32
#define CRITICAL_ERROR_MASK 0xFFFFFFFF #define CRITICAL_ERROR_MASK 0xFFFFFFFF
#define CANNOT_CONNECT_TO_DETECTOR 0x8000000000000000ULL #define CANNOT_CONNECT_TO_DETECTOR 0x8000000000000000ULL
@ -50,6 +49,8 @@ using namespace std;
#define RECEIVER_DYNAMIC_RANGE 0x0000000000000800ULL #define RECEIVER_DYNAMIC_RANGE 0x0000000000000800ULL
#define RECEIVER_TEN_GIGA 0x0000000000001000ULL #define RECEIVER_TEN_GIGA 0x0000000000001000ULL
#define ALLTIMBITS_NOT_SET 0x0000000000002000ULL #define ALLTIMBITS_NOT_SET 0x0000000000002000ULL
#define COULD_NOT_SET_SPEED_PARAMETERS 0x0000000000004000ULL
#define COULD_NOT_SET_READOUT_FLAGS 0x0000000000008000ULL
// 0x00000000FFFFFFFFULL // 0x00000000FFFFFFFFULL
/** @short class returning all error messages for error mask */ /** @short class returning all error messages for error mask */
@ -150,7 +151,11 @@ public:
if(slsErrorMask&ALLTIMBITS_NOT_SET) if(slsErrorMask&ALLTIMBITS_NOT_SET)
retval.append("Could not set all trimbits to value.\n"); retval.append("Could not set all trimbits to value.\n");
if(slsErrorMask&COULD_NOT_SET_SPEED_PARAMETERS)
retval.append("Could not set the speed parameter value\n");
if(slsErrorMask&COULD_NOT_SET_READOUT_FLAGS)
retval.append("Could not set the readout flag\n");
return retval; return retval;

View File

@ -140,6 +140,7 @@ typedef struct {
double offset; /**< is the module offset (V) */ double offset; /**< is the module offset (V) */
} sls_detector_module; } sls_detector_module;
/** /**
@short structure for a region of interest @short structure for a region of interest

View File

@ -43,8 +43,6 @@ unsigned int Feb_Control_triggerMode; //internal timer, external start,
unsigned int Feb_Control_externalEnableMode; //external enabling engaged and it's polarity unsigned int Feb_Control_externalEnableMode; //external enabling engaged and it's polarity
unsigned int Feb_Control_subFrameMode; unsigned int Feb_Control_subFrameMode;
unsigned int Feb_Control_photon_energy_eV;
unsigned int Feb_Control_nimages; unsigned int Feb_Control_nimages;
double Feb_Control_exposure_time_in_sec; double Feb_Control_exposure_time_in_sec;
int Feb_Control_subframe_exposure_time_in_10nsec; int Feb_Control_subframe_exposure_time_in_10nsec;
@ -450,7 +448,7 @@ int Feb_Control_AddModule1(unsigned int module_number, int top_enable, unsigned
return parameters_ok; return parameters_ok;
} }
/* not called anywhere**/
int Feb_Control_ReadSetUpFile(unsigned int module_num, char* file_name){ int Feb_Control_ReadSetUpFile(unsigned int module_num, char* file_name){
printf("Reading Setup file for module number:%d\n",module_num); printf("Reading Setup file for module number:%d\n",module_num);
char line[100]; char line[100];
@ -486,14 +484,14 @@ int Feb_Control_ReadSetUpFile(unsigned int module_num, char* file_name){
} }
Feb_Control_SetHighVoltage(f0); Feb_Control_SetHighVoltage(f0);
} }
/*
else if(!strcmp("photon_energy",str)){ else if(!strcmp("photon_energy",str)){
if(sscanf (line,"%s %f", str,&f0) < 2){ if(sscanf (line,"%s %f", str,&f0) < 2){
printf("Error reading photon_energy\n"); printf("Error reading photon_energy\n");
exit(0); exit(0);
} }
Feb_Control_SetPhotonEnergy(f0); Feb_Control_SetPhotonEnergy(f0);
} }*/
else if(!strcmp("dynamic_range",str)){ else if(!strcmp("dynamic_range",str)){
if(sscanf (line,"%s %d", str,&i0) < 2){ if(sscanf (line,"%s %d", str,&i0) < 2){
@ -591,32 +589,6 @@ unsigned int Feb_Control_GetNHalfModules(){
return n_half_modules; return n_half_modules;
} }
int Feb_Control_SetPhotonEnergy(unsigned int full_energy_eV){
/**
setDAC(VCMP_LL,val,imod,mV,retval);
setDAC(VCMP_LR,val,imod,mV,retval);
setDAC(VCMP_RL,val,imod,mV,retval);
ind = VCMP_RR;
*/
Feb_Control_photon_energy_eV = full_energy_eV;
printf("Setting photon energy to: %d eV\n",Feb_Control_photon_energy_eV);
return 1;
}
unsigned int Feb_Control_GetPhotonEnergy(){
/**
setDAC(VCMP_LL,val,imod,mV,retval);
setDAC(VCMP_LR,val,imod,mV,retval);
setDAC(VCMP_RL,val,imod,mV,retval);
ind = VCMP_RR;
*/
return Feb_Control_photon_energy_eV;
}
int Feb_Control_SetIDelays(unsigned int module_num, unsigned int ndelay_units){ int Feb_Control_SetIDelays(unsigned int module_num, unsigned int ndelay_units){
return Feb_Control_SetIDelays1(module_num,0,ndelay_units)&&Feb_Control_SetIDelays1(module_num,1,ndelay_units)&&Feb_Control_SetIDelays1(module_num,2,ndelay_units)&&Feb_Control_SetIDelays1(module_num,3,ndelay_units); return Feb_Control_SetIDelays1(module_num,0,ndelay_units)&&Feb_Control_SetIDelays1(module_num,1,ndelay_units)&&Feb_Control_SetIDelays1(module_num,2,ndelay_units)&&Feb_Control_SetIDelays1(module_num,3,ndelay_units);

View File

@ -121,8 +121,6 @@ int Feb_Control_GetModuleNumber();
int Feb_Control_SetHighVoltage(float value); int Feb_Control_SetHighVoltage(float value);
int Feb_Control_SetHighVoltage1(unsigned int module_num,float value); int Feb_Control_SetHighVoltage1(unsigned int module_num,float value);
int Feb_Control_SetPhotonEnergy(unsigned int full_energy_eV);
unsigned int Feb_Control_GetPhotonEnergy();
int Feb_Control_SetIDelays(unsigned int module_num, unsigned int ndelay_units); int Feb_Control_SetIDelays(unsigned int module_num, unsigned int ndelay_units);
int Feb_Control_SetIDelays1(unsigned int module_num, unsigned int chip_pos, unsigned int ndelay_units); int Feb_Control_SetIDelays1(unsigned int module_num, unsigned int chip_pos, unsigned int ndelay_units);

View File

@ -26,7 +26,8 @@ int *detectorChips=NULL;
int *detectorChans=NULL; int *detectorChans=NULL;
dacs_t *detectorDacs=NULL; dacs_t *detectorDacs=NULL;
dacs_t *detectorAdcs=NULL; dacs_t *detectorAdcs=NULL;
int* detectorGain = NULL;
int* detectorOffset = NULL;
int eiger_highvoltage = 0; int eiger_highvoltage = 0;
int eiger_iodelay = 0; int eiger_iodelay = 0;
@ -53,6 +54,8 @@ int dst_requested[32] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
//char Module_dac_names[16][10]= {"SvP","Vtr","Vrf","Vrs","SvN","Vtgstv","Vcmp_ll","Vcmp_lr","cal","Vcmp_rl","rxb_rb","rxb_lb","Vcmp_rr","Vcp","Vcn","Vis"};; //char Module_dac_names[16][10]= {"SvP","Vtr","Vrf","Vrs","SvN","Vtgstv","Vcmp_ll","Vcmp_lr","cal","Vcmp_rl","rxb_rb","rxb_lb","Vcmp_rr","Vcp","Vcn","Vis"};;
int default_dac_values[16] = {0,2480,3300,1400,4000,2556,1000,1000,4000,1000,1000,1000,1000,200,2000,1550}; int default_dac_values[16] = {0,2480,3300,1400,4000,2556,1000,1000,4000,1000,1000,1000,1000,200,2000,1550};
int default_gain_values[3] = {-314800,-314800,-314800};
int default_offset_values[3] = {3714000,3714000,3714000};
enum masterFlags masterMode=IS_SLAVE; enum masterFlags masterMode=IS_SLAVE;
@ -80,12 +83,16 @@ int initDetector(){
detectorChans=malloc(n*NCHIP*NCHAN*sizeof(int)); detectorChans=malloc(n*NCHIP*NCHAN*sizeof(int));
detectorDacs=malloc(n*NDAC*sizeof(dacs_t)); detectorDacs=malloc(n*NDAC*sizeof(dacs_t));
detectorAdcs=malloc(n*NADC*sizeof(dacs_t)); detectorAdcs=malloc(n*NADC*sizeof(dacs_t));
detectorGain=malloc(n*NGAIN*sizeof(int));
detectorOffset=malloc(n*NOFFSET*sizeof(int));
#ifdef VERBOSE #ifdef VERBOSE
printf("modules from 0x%x to 0x%x\n",detectorModules, detectorModules+n); printf("modules from 0x%x to 0x%x\n",detectorModules, detectorModules+n);
printf("chips from 0x%x to 0x%x\n",detectorChips, detectorChips+n*NCHIP); printf("chips from 0x%x to 0x%x\n",detectorChips, detectorChips+n*NCHIP);
printf("chans from 0x%x to 0x%x\n",detectorChans, detectorChans+n*NCHIP*NCHAN); printf("chans from 0x%x to 0x%x\n",detectorChans, detectorChans+n*NCHIP*NCHAN);
printf("dacs from 0x%x to 0x%x\n",detectorDacs, detectorDacs+n*NDAC); printf("dacs from 0x%x to 0x%x\n",detectorDacs, detectorDacs+n*NDAC);
printf("adcs from 0x%x to 0x%x\n",detectorAdcs, detectorAdcs+n*NADC); printf("adcs from 0x%x to 0x%x\n",detectorAdcs, detectorAdcs+n*NADC);
printf("gains from 0x%x to 0x%x\n",detectorGain, detectorGain+n*NGAIN);
printf("offsets from 0x%x to 0x%x\n",detectorOffset, detectorOffset+n*NOFFSET);
#endif #endif
for (imod=0; imod<n; imod++) { for (imod=0; imod<n; imod++) {
(detectorModules+imod)->dacs=detectorDacs+imod*NDAC; (detectorModules+imod)->dacs=detectorDacs+imod*NDAC;
@ -102,6 +109,10 @@ int initDetector(){
(detectorModules+imod)->reg=0; (detectorModules+imod)->reg=0;
/* initialize registers, dacs, retrieve sn, adc values etc */ /* initialize registers, dacs, retrieve sn, adc values etc */
} }
for(i=0;i<NGAIN;i++)
detectorGain[i] = default_gain_values[(int)STANDARD];
for(i=0;i<NOFFSET;i++)
detectorOffset[i] = default_offset_values[(int)STANDARD];
thisSettings = STANDARD;/**UNITIALIZED*/ thisSettings = STANDARD;/**UNITIALIZED*/
/*sChan=noneSelected; /*sChan=noneSelected;
sChip=noneSelected; sChip=noneSelected;
@ -124,14 +135,13 @@ int initDetector(){
for(i=0;i<(detectorModules)->ndac;i++) for(i=0;i<(detectorModules)->ndac;i++)
setDAC((enum detDacIndex)i,default_dac_values[i],(detectorModules)->module,0,retval); setDAC((enum detDacIndex)i,default_dac_values[i],(detectorModules)->module,0,retval);
//setting default measurement parameters //setting default measurement parameters
setTimer(FRAME_NUMBER,1); setTimer(FRAME_NUMBER,1);
setTimer(ACQUISITION_TIME,1E9); setTimer(ACQUISITION_TIME,1E9);
setTimer(SUBFRAME_ACQUISITION_TIME,DEFAULT_SUBFRAME_EXPOSURE_VAL); setTimer(SUBFRAME_ACQUISITION_TIME,DEFAULT_SUBFRAME_EXPOSURE_VAL);
setTimer(FRAME_PERIOD,1E9); setTimer(FRAME_PERIOD,1E9);
setDynamicRange(16); setDynamicRange(16);
setThresholdEnergy(8000,0); eiger_photonenergy = -1;
setReadOutFlags(NONPARALLEL); setReadOutFlags(NONPARALLEL);
setSpeed(0,1);//clk_devider,half speed setSpeed(0,1);//clk_devider,half speed
setHighVolage(0,0); setHighVolage(0,0);
@ -376,23 +386,30 @@ int enableTenGigabitEthernet(int val){
} }
int setModule(sls_detector_module myMod){ int setModule(sls_detector_module myMod, int* gain, int* offset){
int retval[2]; int retval[2];
int i;
//#ifdef VERBOSE //#ifdef VERBOSE
printf("Setting module with settings %d\n",myMod.reg); printf("Setting module with settings %d\n",myMod.reg);
//#endif //#endif
int i;
for(i=0;i<myMod.ndac;i++)
setDAC((enum detDacIndex)i,myMod.dacs[i],myMod.module,0,retval);
//set the settings variable
setSettings( (enum detectorSettings)myMod.reg,-1);
// thisSettings = (enum detectorSettings)myMod.reg; //set the gains and offset variables locally
// thisSettings = 0; for(i=0;i<NGAIN;i++)
detectorGain[i] = gain[i];
for(i=0;i<NOFFSET;i++)
detectorOffset[i] = offset[i];
//copy module locally
if (detectorModules) if (detectorModules)
copyModule(detectorModules,&myMod); copyModule(detectorModules,&myMod);
setSettings( (enum detectorSettings)myMod.reg,-1); // put the settings in the module register?!?!? //set dac values
for(i=0;i<myMod.ndac;i++)
setDAC((enum detDacIndex)i,myMod.dacs[i],myMod.module,0,retval);
//includ gap pixels //includ gap pixels
unsigned int tt[263680]; unsigned int tt[263680];
@ -409,23 +426,31 @@ int setModule(sls_detector_module myMod){
} }
} }
//set trimbits
if(!Feb_Control_SetTrimbits(Feb_Control_GetModuleNumber(),tt)){
cprintf(BG_RED,"Could not set trimbits\n");
return FAIL;
}
Feb_Control_SetTrimbits(Feb_Control_GetModuleNumber(),tt); //printf("set gainval[0]:%d\n",detectorGain[0]);
// use gain and offset!!!
return 0; return 0;
} }
int getModule(sls_detector_module *myMod){ int getModule(sls_detector_module *myMod, int* gain, int* offset){
int i; int i;
int retval[2]; int retval[2];
//printf("get gainval[0]:%d\n",detectorGain[0]);
//dacs //dacs
for(i=0;i<NDAC;i++) for(i=0;i<NDAC;i++)
setDAC((enum detDacIndex)i,-1,-1,0,retval); setDAC((enum detDacIndex)i,-1,-1,0,retval);
//gains, offsets
for(i=0;i<NGAIN;i++)
gain[i] = detectorGain[i];
for(i=0;i<NOFFSET;i++)
offset[i] = detectorOffset[i];
//trimbits //trimbits
unsigned int* tt; unsigned int* tt;
@ -464,10 +489,23 @@ int getThresholdEnergy(int imod){
} }
int setThresholdEnergy(int thr, int imod){ int setThresholdEnergy(int ev, int imod){
printf(" Setting threshold energy:%d\n",thr); printf(" Setting threshold energy:%d\n",ev);
if(Feb_Control_SetPhotonEnergy(thr)) int retval[2],i;
eiger_photonenergy = thr; int thrvalue[NGAIN];
if(ev >= 0){
eiger_photonenergy = ev;
//calculate thrvalues for dacs
for(i=0;i<NGAIN;i++)
thrvalue[i] = (int) ((((double)detectorGain[i]/1000) * ((double)ev/1000)) + ((double)detectorOffset[i]/1000));
//setdacs
setDAC(VCMP_LL,thrvalue[0],-1,0,retval);if(retval[0] != thrvalue[0]) cprintf(BG_RED,"Failed to set vcmp_ll to %d, got %d\n",retval[0],thrvalue[0]);
setDAC(VCMP_LR,thrvalue[1],-1,0,retval);if(retval[0] != thrvalue[1]) cprintf(BG_RED,"Failed to set vcmp_lr to %d, got %d\n",retval[0],thrvalue[1]);
setDAC(VCMP_RL,thrvalue[2],-1,0,retval);if(retval[0] != thrvalue[2]) cprintf(BG_RED,"Failed to set vcmp_rl to %d, got %d\n",retval[0],thrvalue[2]);
setDAC(VCMP_RR,thrvalue[3],-1,0,retval);if(retval[0] != thrvalue[3]) cprintf(BG_RED,"Failed to set vcmp_rr to %d, got %d\n",retval[0],thrvalue[3]);
}
return getThresholdEnergy(imod); return getThresholdEnergy(imod);
} }
@ -707,7 +745,7 @@ int setDynamicRange(int dr){
enum readOutFlags setReadOutFlags(enum readOutFlags val){ enum readOutFlags setReadOutFlags(enum readOutFlags val){
enum readOutFlags retval; enum readOutFlags retval = GET_READOUT_FLAGS;
if(val!=GET_READOUT_FLAGS){ if(val!=GET_READOUT_FLAGS){
@ -934,16 +972,16 @@ int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod){
int getTotalNumberOfChannels(){return getNumberOfChannelsPerModule();};//NCHIP*NCHAN*nModBoard;} int getTotalNumberOfChannels(){return getNumberOfChannelsPerModule();}
int getTotalNumberOfChips(){return 4;};//NCHIP*nModBoard;} int getTotalNumberOfChips(){return NCHIP;}
int getTotalNumberOfModules(){return 1;}//nModBoard;} int getTotalNumberOfModules(){return 1;}
int getNumberOfChannelsPerChip(){return (256*256);}//NCHAN;} int getNumberOfChannelsPerChip(){return NCHAN;}
int getNumberOfChannelsPerModule(){return getNumberOfChannelsPerChip() * getTotalNumberOfChips();}//NCHAN*NCHIP;} int getNumberOfChannelsPerModule(){return getNumberOfChannelsPerChip() * getTotalNumberOfChips();}
int getNumberOfChipsPerModule(){return 4;}//NCHIP;} int getNumberOfChipsPerModule(){return NCHIP;}
int getNumberOfDACsPerModule(){return 16;}//NDAC;} int getNumberOfDACsPerModule(){return NDAC;}
int getNumberOfADCsPerModule(){return 0;}//NADC;} int getNumberOfADCsPerModule(){return NADC;}
int getNumberOfGainsPerModule(){return NGAIN;}
int getNumberOfOffsetsPerModule(){return NOFFSET;}

View File

@ -25,6 +25,9 @@
#define NCHIP 4 #define NCHIP 4
#define NDAC 16 #define NDAC 16
#define NADC 0 #define NADC 0
#define NGAIN 4
#define NOFFSET 4
#define NMAXMODX 1 #define NMAXMODX 1
#define NMAXMODY 1 #define NMAXMODY 1
#define NMAXMOD NMAXMODX*NMAXMODY #define NMAXMOD NMAXMODX*NMAXMODY

View File

@ -4584,7 +4584,7 @@ int multiSlsDetector::resetFramesCaught() {
int* multiSlsDetector::readFrameFromReceiver(char* fName, int &acquisitionIndex, int &frameIndex){ int* multiSlsDetector::readFrameFromReceiver(char* fName, int &acquisitionIndex, int &frameIndex, int &subFrameIndex){
int nel=(thisMultiDetector->dataBytes)/sizeof(int); int nel=(thisMultiDetector->dataBytes)/sizeof(int);
if(nel <= 0){ if(nel <= 0){
cout << "Multislsdetector databytes not valid :" << thisMultiDetector->dataBytes << endl; cout << "Multislsdetector databytes not valid :" << thisMultiDetector->dataBytes << endl;
@ -4610,7 +4610,7 @@ int* multiSlsDetector::readFrameFromReceiver(char* fName, int &acquisitionIndex
for (int id=0; id<thisMultiDetector->numberOfDetectors; id++) { for (int id=0; id<thisMultiDetector->numberOfDetectors; id++) {
if (detectors[id]) { if (detectors[id]) {
n=detectors[id]->getDataBytes(); n=detectors[id]->getDataBytes();
retdet=detectors[id]->readFrameFromReceiver(fName, acquisitionIndex, frameIndex); retdet=detectors[id]->readFrameFromReceiver(fName, acquisitionIndex, frameIndex, subFrameIndex);
if(detectors[id]->getErrorMask()) if(detectors[id]->getErrorMask())
setErrorMask(getErrorMask()|(1<<id)); setErrorMask(getErrorMask()|(1<<id));
if (retdet){ if (retdet){

View File

@ -1160,9 +1160,10 @@ class multiSlsDetector : public slsDetectorUtils {
* @param fName file name of current frame() * @param fName file name of current frame()
* @param acquisitionIndex current acquisition index * @param acquisitionIndex current acquisition index
* @param frameIndex current frame index (for each scan) * @param frameIndex current frame index (for each scan)
* @param subFrameIndex current sub frame index (for 32 bit mode for eiger)
/returns a frame read from recever /returns a frame read from recever
*/ */
int* readFrameFromReceiver(char* fName, int &acquisitionIndex, int &frameIndex); int* readFrameFromReceiver(char* fName, int &acquisitionIndex, int &frameIndex, int &subFrameIndex);
/** Locks/Unlocks the connection to the receiver /** Locks/Unlocks the connection to the receiver
/param lock sets (1), usets (0), gets (-1) the lock /param lock sets (1), usets (0), gets (-1) the lock

View File

@ -10,9 +10,9 @@
using namespace std; using namespace std;
int dummyCallback(detectorData* d, int p,void*) { int dummyCallback(detectorData* d, int p,void*) {
cout << "got data " << p << endl; cout << "got data " << p << endl;
return 0;
} };
class multiSlsDetectorClient { class multiSlsDetectorClient {

View File

@ -20,7 +20,7 @@ int slsDetector::initSharedMemory(detectorType type, int id) {
*/ */
key_t mem_key=DEFAULT_SHM_KEY+id; key_t mem_key=DEFAULT_SHM_KEY+id;
int shm_id; int shm_id;
int nch, nm, nc, nd; int nch, nm, nc, nd, ng, no;
int sz; int sz;
//shmId=-1; //shmId=-1;
@ -31,18 +31,24 @@ int slsDetector::initSharedMemory(detectorType type, int id) {
nm=24; nm=24;
nc=10; nc=10;
nd=6; // dacs+adcs nd=6; // dacs+adcs
ng=0;
no=0;
break; break;
case PICASSO: case PICASSO:
nch=128; // complete mythen system nch=128; // complete mythen system
nm=24; nm=24;
nc=12; nc=12;
nd=6; // dacs+adcs nd=6; // dacs+adcs
ng=0;
no=0;
break; break;
case GOTTHARD: case GOTTHARD:
nch=128; nch=128;
nm=1; nm=1;
nc=10; nc=10;
nd=13; // dacs+adcs nd=13; // dacs+adcs
ng=0;
no=0;
break; break;
case PROPIX: case PROPIX:
nch=22*22; nch=22*22;
@ -55,33 +61,41 @@ int slsDetector::initSharedMemory(detectorType type, int id) {
nm=1; //modules/detector nm=1; //modules/detector
nc=4; //chips nc=4; //chips
nd=16; //dacs+adcs nd=16; //dacs+adcs
ng=4;
no=4;
break; break;
case MOENCH: case MOENCH:
nch=160*160; nch=160*160;
nm=1; //modules/detector nm=1; //modules/detector
nc=1; //chips nc=1; //chips
nd=9; //dacs+adcs nd=9; //dacs+adcs
ng=0;
no=0;
break; break;
case JUNGFRAUCTB: case JUNGFRAUCTB:
nch=32; nch=32;
nm=1; //modules/detector nm=1; //modules/detector
nc=1; //chips nc=1; //chips
nd=16; //dacs+adcs nd=16; //dacs+adcs
ng=0;
no=0;
break; break;
default: default:
nch=0; // dum! nch=0; // dum!
nm=0; //modules/detector nm=0; //modules/detector
nc=0; //chips nc=0; //chips
nd=0; //dacs+adcs nd=0; //dacs+adcs
ng=0;
no=0;
break; break;
} }
/** /**
The size of the shared memory is: The size of the shared memory is:
size of shared structure + ffcoefficents +fferrors + modules+ dacs+adcs+chips+chans size of shared structure + ffcoefficents +fferrors + modules+ dacs+adcs+chips+chans+gain+offset
*/ */
sz=sizeof(sharedSlsDetector)+nm*(2*nch*nc*sizeof(double)+sizeof(sls_detector_module)+sizeof(int)*nc+sizeof(dacs_t)*nd+sizeof(int)*nch*nc); sz=sizeof(sharedSlsDetector)+nm*(2*nch*nc*sizeof(double)+sizeof(sls_detector_module)+sizeof(int)*nc+sizeof(dacs_t)*nd+sizeof(int)*nch*nc+sizeof(int)*ng+sizeof(int)*no);
#ifdef VERBOSE #ifdef VERBOSE
std::cout<<"Size of shared memory is "<< sz << "(type " << type << " - id " << mem_key << ")"<< std::endl; std::cout<<"Size of shared memory is "<< sz << "(type " << type << " - id " << mem_key << ")"<< std::endl;
#endif #endif
@ -146,6 +160,8 @@ slsDetector::slsDetector(int id,multiSlsDetector *p) :slsDetectorUtils(),
adcs(NULL), adcs(NULL),
chipregs(NULL), chipregs(NULL),
chanregs(NULL), chanregs(NULL),
gain(NULL),
offset(NULL),
thisReceiver(NULL) thisReceiver(NULL)
@ -196,6 +212,8 @@ slsDetector::slsDetector(detectorType type, int id,multiSlsDetector *p): slsDete
adcs(NULL), adcs(NULL),
chipregs(NULL), chipregs(NULL),
chanregs(NULL), chanregs(NULL),
gain(NULL),
offset(NULL),
thisReceiver(NULL) thisReceiver(NULL)
{ {
@ -250,6 +268,8 @@ slsDetector::slsDetector(char *name, int id, int cport,multiSlsDetector *p) : sl
adcs(NULL), adcs(NULL),
chipregs(NULL), chipregs(NULL),
chanregs(NULL), chanregs(NULL),
gain(NULL),
offset(NULL),
thisReceiver(NULL) thisReceiver(NULL)
@ -529,6 +549,8 @@ int slsDetector::initializeDetectorSize(detectorType type) {
thisDetector->nChip[Y]=1; thisDetector->nChip[Y]=1;
thisDetector->nDacs=6; thisDetector->nDacs=6;
thisDetector->nAdcs=0; thisDetector->nAdcs=0;
thisDetector->nGain=0;
thisDetector->nOffset=0;
thisDetector->nModMax[X]=24; thisDetector->nModMax[X]=24;
thisDetector->nModMax[Y]=1; thisDetector->nModMax[Y]=1;
thisDetector->dynamicRange=24; thisDetector->dynamicRange=24;
@ -544,6 +566,8 @@ int slsDetector::initializeDetectorSize(detectorType type) {
thisDetector->nChip[Y]=1; thisDetector->nChip[Y]=1;
thisDetector->nDacs=6; thisDetector->nDacs=6;
thisDetector->nAdcs=0; thisDetector->nAdcs=0;
thisDetector->nGain=0;
thisDetector->nOffset=0;
thisDetector->nModMax[X]=6; thisDetector->nModMax[X]=6;
thisDetector->nModMax[Y]=1; thisDetector->nModMax[Y]=1;
thisDetector->dynamicRange=24; thisDetector->dynamicRange=24;
@ -555,6 +579,8 @@ int slsDetector::initializeDetectorSize(detectorType type) {
thisDetector->nChip[Y]=1; thisDetector->nChip[Y]=1;
thisDetector->nDacs=8; thisDetector->nDacs=8;
thisDetector->nAdcs=5; thisDetector->nAdcs=5;
thisDetector->nGain=0;
thisDetector->nOffset=0;
thisDetector->nModMax[X]=1; thisDetector->nModMax[X]=1;
thisDetector->nModMax[Y]=1; thisDetector->nModMax[Y]=1;
thisDetector->dynamicRange=16; thisDetector->dynamicRange=16;
@ -566,6 +592,8 @@ int slsDetector::initializeDetectorSize(detectorType type) {
thisDetector->nChip[Y]=1; thisDetector->nChip[Y]=1;
thisDetector->nDacs=8; thisDetector->nDacs=8;
thisDetector->nAdcs=5; thisDetector->nAdcs=5;
thisDetector->nGain=0;
thisDetector->nOffset=0;
thisDetector->nModMax[X]=1; thisDetector->nModMax[X]=1;
thisDetector->nModMax[Y]=1; thisDetector->nModMax[Y]=1;
thisDetector->dynamicRange=16; thisDetector->dynamicRange=16;
@ -577,6 +605,8 @@ int slsDetector::initializeDetectorSize(detectorType type) {
thisDetector->nChip[Y]=1; thisDetector->nChip[Y]=1;
thisDetector->nDacs=8; thisDetector->nDacs=8;
thisDetector->nAdcs=1; thisDetector->nAdcs=1;
thisDetector->nGain=0;
thisDetector->nOffset=0;
thisDetector->nModMax[X]=1; thisDetector->nModMax[X]=1;
thisDetector->nModMax[Y]=1; thisDetector->nModMax[Y]=1;
thisDetector->dynamicRange=16; thisDetector->dynamicRange=16;
@ -588,6 +618,8 @@ int slsDetector::initializeDetectorSize(detectorType type) {
thisDetector->nChip[Y]=1; thisDetector->nChip[Y]=1;
thisDetector->nDacs=16; thisDetector->nDacs=16;
thisDetector->nAdcs=1; thisDetector->nAdcs=1;
thisDetector->nGain=0;
thisDetector->nOffset=0;
thisDetector->nModMax[X]=1; thisDetector->nModMax[X]=1;
thisDetector->nModMax[Y]=1; thisDetector->nModMax[Y]=1;
thisDetector->dynamicRange=16; thisDetector->dynamicRange=16;
@ -599,6 +631,8 @@ int slsDetector::initializeDetectorSize(detectorType type) {
thisDetector->nChip[Y]=1; thisDetector->nChip[Y]=1;
thisDetector->nDacs=16; thisDetector->nDacs=16;
thisDetector->nAdcs=0; thisDetector->nAdcs=0;
thisDetector->nGain=4;
thisDetector->nOffset=4;
thisDetector->nModMax[X]=1; thisDetector->nModMax[X]=1;
thisDetector->nModMax[Y]=1; thisDetector->nModMax[Y]=1;
thisDetector->dynamicRange=16; thisDetector->dynamicRange=16;
@ -610,6 +644,8 @@ int slsDetector::initializeDetectorSize(detectorType type) {
thisDetector->nChip[Y]=0; thisDetector->nChip[Y]=0;
thisDetector->nDacs=0; thisDetector->nDacs=0;
thisDetector->nAdcs=0; thisDetector->nAdcs=0;
thisDetector->nGain=0;
thisDetector->nOffset=0;
thisDetector->nModMax[X]=0; thisDetector->nModMax[X]=0;
thisDetector->nModMax[Y]=0; thisDetector->nModMax[Y]=0;
thisDetector->dynamicRange=32; thisDetector->dynamicRange=32;
@ -725,7 +761,8 @@ int slsDetector::initializeDetectorSize(detectorType type) {
thisDetector->adcoff=thisDetector->dacoff+sizeof(dacs_t)*thisDetector->nDacs*thisDetector->nModsMax; thisDetector->adcoff=thisDetector->dacoff+sizeof(dacs_t)*thisDetector->nDacs*thisDetector->nModsMax;
thisDetector->chipoff=thisDetector->adcoff+sizeof(dacs_t)*thisDetector->nAdcs*thisDetector->nModsMax; thisDetector->chipoff=thisDetector->adcoff+sizeof(dacs_t)*thisDetector->nAdcs*thisDetector->nModsMax;
thisDetector->chanoff=thisDetector->chipoff+sizeof(int)*thisDetector->nChips*thisDetector->nModsMax; thisDetector->chanoff=thisDetector->chipoff+sizeof(int)*thisDetector->nChips*thisDetector->nModsMax;
thisDetector->gainoff=thisDetector->chanoff+sizeof(int)*thisDetector->nGain*thisDetector->nModsMax;
thisDetector->offsetoff=thisDetector->gainoff+sizeof(int)*thisDetector->nOffset*thisDetector->nModsMax;
//update?!?!?!? //update?!?!?!?
@ -745,6 +782,8 @@ int slsDetector::initializeDetectorSize(detectorType type) {
adcs=(dacs_t*)(goff+thisDetector->adcoff); adcs=(dacs_t*)(goff+thisDetector->adcoff);
chipregs=(int*)(goff+thisDetector->chipoff); chipregs=(int*)(goff+thisDetector->chipoff);
chanregs=(int*)(goff+thisDetector->chanoff); chanregs=(int*)(goff+thisDetector->chanoff);
gain=(int*)(goff+thisDetector->gainoff);
offset=(int*)(goff+thisDetector->offsetoff);
if (thisDetector->alreadyExisting==0) { if (thisDetector->alreadyExisting==0) {
/** if thisDetector is new, initialize its structures \sa initializeDetectorStructure(); */ /** if thisDetector is new, initialize its structures \sa initializeDetectorStructure(); */
initializeDetectorStructure(); initializeDetectorStructure();
@ -864,6 +903,18 @@ int slsDetector::initializeDetectorStructure() {
for (int ichan=0; ichan<thisDetector->nChans*thisDetector->nChips; ichan++) { for (int ichan=0; ichan<thisDetector->nChans*thisDetector->nChips; ichan++) {
*(chanregs+ichan+thisDetector->nChips*thisDetector->nChans*imod)=-1; *(chanregs+ichan+thisDetector->nChips*thisDetector->nChans*imod)=-1;
} }
/** initializes the gain values to 0 */
for (int igain=0; igain<thisDetector->nGain; igain++) {
*(gain+igain+thisDetector->nGain*imod)=0;
}
/** initializes the offset values to 0 */
for (int ioffset=0; ioffset<thisDetector->nOffset; ioffset++) {
*(offset+ioffset+thisDetector->nOffset*imod)=0;
}
/** initialize gain and offset to -1 */ /** initialize gain and offset to -1 */
thisMod->gain=-1.; thisMod->gain=-1.;
thisMod->offset=-1.; thisMod->offset=-1.;
@ -910,7 +961,7 @@ slsDetectorDefs::sls_detector_module* slsDetector::createModule(detectorType t)
nm=1; //modules/detector nm=1; //modules/detector
nc=4*1; //chips nc=4*1; //chips
nd=16; //dacs nd=16; //dacs
na=0; //use for gain???? na=0;
break; break;
case MOENCH: case MOENCH:
nch=160*160; nch=160*160;
@ -2554,6 +2605,8 @@ slsDetectorDefs::sls_detector_chip slsDetector::getChip(int ichip, int imod){
int slsDetector::setModule(int reg, int imod){ int slsDetector::setModule(int reg, int imod){
sls_detector_module myModule; sls_detector_module myModule;
int* g=0;
int* o=0;
#ifdef VERBOSE #ifdef VERBOSE
std::cout << "slsDetector set module " << std::endl; std::cout << "slsDetector set module " << std::endl;
@ -2622,16 +2675,14 @@ int slsDetector::setModule(int reg, int imod){
ads[i]=-1; ads[i]=-1;
myModule.adcs=ads; myModule.adcs=ads;
} }
ret=setModule(myModule); ret=setModule(myModule,g,o);
} }
return ret; return ret;
}; };
int slsDetector::setModule(sls_detector_module module, int* gainval, int* offsetval){
int slsDetector::setModule(sls_detector_module module){
int fnum=F_SET_MODULE; int fnum=F_SET_MODULE;
int retval; int retval;
@ -2649,6 +2700,13 @@ int slsDetector::setModule(sls_detector_module module){
if (connectControl() == OK){ if (connectControl() == OK){
controlSocket->SendDataOnly(&fnum,sizeof(fnum)); controlSocket->SendDataOnly(&fnum,sizeof(fnum));
sendModule(&module); sendModule(&module);
//extra gain and offset - eiger
if((thisDetector->nGain) && (gainval))
controlSocket->SendDataOnly(gainval,sizeof(int)*thisDetector->nGain);
if((thisDetector->nOffset) && (offsetval))
controlSocket->SendDataOnly(offsetval,sizeof(int)*thisDetector->nOffset);
controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
if (ret!=FAIL) { if (ret!=FAIL) {
controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); controlSocket->ReceiveDataOnly(&retval,sizeof(retval));
@ -2700,6 +2758,16 @@ int slsDetector::setModule(sls_detector_module module){
(detectorModules+imod)->reg=module.reg; (detectorModules+imod)->reg=module.reg;
} }
} }
if ((thisDetector->nGain) && (gainval) && (gain)) {
for (int i=0; i<thisDetector->nGain; i++)
gain[i+imod*thisDetector->nGain]=gainval[i];
}
if ((thisDetector->nOffset) && (offsetval) && (offset)) {
for (int i=0; i<thisDetector->nOffset; i++)
offset[i+imod*thisDetector->nOffset]=offsetval[i];
}
} }
#ifdef VERBOSE #ifdef VERBOSE
@ -2709,106 +2777,131 @@ int slsDetector::setModule(sls_detector_module module){
return retval; return retval;
}; };
slsDetectorDefs::sls_detector_module *slsDetector::getModule(int imod){ slsDetectorDefs::sls_detector_module *slsDetector::getModule(int imod){
#ifdef VERBOSE #ifdef VERBOSE
std::cout << "slsDetector get module " << std::endl; std::cout << "slsDetector get module " << std::endl;
#endif #endif
int fnum=F_GET_MODULE; int fnum=F_GET_MODULE;
sls_detector_module *myMod=createModule(); sls_detector_module *myMod=createModule();
int* gainval=0, *offsetval=0;
if(thisDetector->nGain)
gainval=new int[thisDetector->nGain];
if(thisDetector->nOffset)
offsetval=new int[thisDetector->nOffset];
//char *ptr, *goff=(char*)thisDetector; //char *ptr, *goff=(char*)thisDetector;
// int chanreg[thisDetector->nChans*thisDetector->nChips]; // int chanreg[thisDetector->nChans*thisDetector->nChips];
//int chipreg[thisDetector->nChips]; //int chipreg[thisDetector->nChips];
//double dac[thisDetector->nDacs], adc[thisDetector->nAdcs]; //double dac[thisDetector->nDacs], adc[thisDetector->nAdcs];
int ret=FAIL; int ret=FAIL;
char mess[100]; char mess[100];
// int n; // int n;
#ifdef VERBOSE #ifdef VERBOSE
std::cout<< "getting module " << imod << std::endl; std::cout<< "getting module " << imod << std::endl;
#endif #endif
myMod->module=imod; myMod->module=imod;
// myMod.nchan=thisDetector->nChans*thisDetector->nChips; // myMod.nchan=thisDetector->nChans*thisDetector->nChips;
//myMod.chanregs=chanreg; //myMod.chanregs=chanreg;
//myMod.nchip=thisDetector->nChips; //myMod.nchip=thisDetector->nChips;
//myMod.chipregs=chipreg; //myMod.chipregs=chipreg;
//myMod.ndac=thisDetector->nDacs; //myMod.ndac=thisDetector->nDacs;
//myMod.dacs=dac; //myMod.dacs=dac;
//myMod.ndac=thisDetector->nAdcs; //myMod.ndac=thisDetector->nAdcs;
//myMod.dacs=adc; //myMod.dacs=adc;
if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (connectControl() == OK){
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
controlSocket->SendDataOnly(&imod,sizeof(imod));
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
if (ret!=FAIL) {
receiveModule(myMod);
//extra gain and offset - eiger
if(thisDetector->nGain)
if (thisDetector->onlineFlag==ONLINE_FLAG) { controlSocket->ReceiveDataOnly(gainval,sizeof(int)*thisDetector->nGain);
if (connectControl() == OK){ if(thisDetector->nOffset)
controlSocket->SendDataOnly(&fnum,sizeof(fnum)); controlSocket->ReceiveDataOnly(offsetval,sizeof(int)*thisDetector->nOffset);
controlSocket->SendDataOnly(&imod,sizeof(imod)); } else {
controlSocket->ReceiveDataOnly(mess,sizeof(mess));
controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); std::cout<< "Detector returned error: " << mess << std::endl;
if (ret!=FAIL) { }
receiveModule(myMod); controlSocket->Disconnect();
} else { if (ret==FORCE_UPDATE)
controlSocket->ReceiveDataOnly(mess,sizeof(mess)); updateDetector();
std::cout<< "Detector returned error: " << mess << std::endl; }
}
controlSocket->Disconnect();
if (ret==FORCE_UPDATE)
updateDetector();
}
}
if (ret!=FAIL) {
if (detectorModules) {
if (imod>=0 && imod<thisDetector->nMod[X]*thisDetector->nMod[Y]) {
(detectorModules+imod)->nchan=myMod->nchan;
(detectorModules+imod)->nchip=myMod->nchip;
(detectorModules+imod)->ndac=myMod->ndac;
(detectorModules+imod)->nadc=myMod->nadc;
thisDetector->nChips=myMod->nchip;
thisDetector->nChans=myMod->nchan/myMod->nchip;
thisDetector->nDacs=myMod->ndac;
thisDetector->nAdcs=myMod->nadc;
for (int ichip=0; ichip<thisDetector->nChips; ichip++) {
if (chipregs)
chipregs[ichip+thisDetector->nChips*imod]=myMod->chipregs[ichip];
if (chanregs) {
for (int i=0; i<thisDetector->nChans; i++) {
chanregs[i+ichip*thisDetector->nChans+thisDetector->nChips*thisDetector->nChans*imod]=myMod->chanregs[ichip*thisDetector->nChans+i];
}
}
}
if (dacs) {
for (int i=0; i<thisDetector->nDacs; i++)
dacs[i+imod*thisDetector->nDacs]=myMod->dacs[i];
}
if (adcs) {
for (int i=0; i<thisDetector->nAdcs; i++)
adcs[i+imod*thisDetector->nAdcs]=myMod->adcs[i];
} }
(detectorModules+imod)->gain=myMod->gain;
(detectorModules+imod)->offset=myMod->offset; if (ret!=FAIL) {
(detectorModules+imod)->serialnumber=myMod->serialnumber; if (detectorModules) {
(detectorModules+imod)->reg=myMod->reg; if (imod>=0 && imod<thisDetector->nMod[X]*thisDetector->nMod[Y]) {
} (detectorModules+imod)->nchan=myMod->nchan;
} (detectorModules+imod)->nchip=myMod->nchip;
} else { (detectorModules+imod)->ndac=myMod->ndac;
deleteModule(myMod); (detectorModules+imod)->nadc=myMod->nadc;
myMod=NULL; thisDetector->nChips=myMod->nchip;
} thisDetector->nChans=myMod->nchan/myMod->nchip;
return myMod; thisDetector->nDacs=myMod->ndac;
thisDetector->nAdcs=myMod->nadc;
for (int ichip=0; ichip<thisDetector->nChips; ichip++) {
if (chipregs)
chipregs[ichip+thisDetector->nChips*imod]=myMod->chipregs[ichip];
if (chanregs) {
for (int i=0; i<thisDetector->nChans; i++) {
chanregs[i+ichip*thisDetector->nChans+thisDetector->nChips*thisDetector->nChans*imod]=myMod->chanregs[ichip*thisDetector->nChans+i];
}
}
}
if (dacs) {
for (int i=0; i<thisDetector->nDacs; i++)
dacs[i+imod*thisDetector->nDacs]=myMod->dacs[i];
}
if (adcs) {
for (int i=0; i<thisDetector->nAdcs; i++)
adcs[i+imod*thisDetector->nAdcs]=myMod->adcs[i];
}
(detectorModules+imod)->gain=myMod->gain;
(detectorModules+imod)->offset=myMod->offset;
(detectorModules+imod)->serialnumber=myMod->serialnumber;
(detectorModules+imod)->reg=myMod->reg;
}
}
if ((thisDetector->nGain) && (gainval) && (gain)) {
for (int i=0; i<thisDetector->nGain; i++)
gain[i+imod*thisDetector->nGain]=gainval[i];
}
if ((thisDetector->nOffset) && (offsetval) && (offset)) {
for (int i=0; i<thisDetector->nOffset; i++)
offset[i+imod*thisDetector->nOffset]=offsetval[i];
}
if(gainval) delete[]gainval;
if(offsetval) delete[]offsetval;
} else {
deleteModule(myMod);
myMod=NULL;
}
return myMod;
} }
@ -2958,6 +3051,19 @@ slsDetectorDefs::detectorSettings slsDetector::setSettings( detectorSettings ise
string settingsfname, calfname; string settingsfname, calfname;
string ssettings; string ssettings;
int* gainval=0, *offsetval=0;
if(thisDetector->nGain)
gainval=new int[thisDetector->nGain];
if(thisDetector->nOffset)
offsetval=new int[thisDetector->nOffset];
int ret=0;
if(thisDetector->nGain)
gainval = new int[thisDetector->nGain];
if(thisDetector->nOffset)
offsetval = new int[thisDetector->nOffset];
switch (isettings) { switch (isettings) {
case STANDARD: case STANDARD:
if ( (thisDetector->myDetectorType == MYTHEN) || if ( (thisDetector->myDetectorType == MYTHEN) ||
@ -3068,61 +3174,86 @@ slsDetectorDefs::detectorSettings slsDetector::setSettings( detectorSettings ise
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);
} }
//settings file****
settingsfname=ostfn.str(); settingsfname=ostfn.str();
#ifdef VERBOSE #ifdef VERBOSE
cout << "the settings file name is "<<settingsfname << endl; cout << "the settings file name is "<<settingsfname << endl;
#endif #endif
if (readSettingsFile(settingsfname,thisDetector->myDetectorType, myMod)) { if (!readSettingsFile(settingsfname,thisDetector->myDetectorType, myMod)) {
calfname=oscfn.str(); //if it didnt open, try default settings file
#ifdef VERBOSE ostringstream ostfn_default;
cout << calfname << endl;
#endif
//reads calibration files here!
readCalibrationFile(calfname,myMod->gain, myMod->offset);
setModule(*myMod);
} else {
ostringstream ostfn,oscfn;
switch(thisDetector->myDetectorType){ switch(thisDetector->myDetectorType){
case MOENCH: case MOENCH:
case GOTTHARD: case GOTTHARD:
case PROPIX: case PROPIX:
case JUNGFRAUCTB: case JUNGFRAUCTB:
ostfn << thisDetector->settingsDir << ssettings << ssettings << ".settings"; ostfn_default << thisDetector->settingsDir << ssettings << ssettings << ".settings";
break; break;
case EIGER: case EIGER:
default: default:
ostfn << thisDetector->settingsDir << ssettings << ssettings << ".trim"; ostfn_default << thisDetector->settingsDir << ssettings << ssettings << ".trim";
break; break;
} }
oscfn << thisDetector->calDir << ssettings << ssettings << ".cal"; settingsfname=ostfn_default.str();
calfname=oscfn.str();
settingsfname=ostfn.str();
#ifdef VERBOSE #ifdef VERBOSE
cout << settingsfname << endl; cout << settingsfname << endl;
cout << calfname << endl;
#endif #endif
if (readSettingsFile(settingsfname,thisDetector->myDetectorType, myMod)) { if (!readSettingsFile(settingsfname,thisDetector->myDetectorType, myMod)) {
calfname=oscfn.str(); //if default doesnt work, return error
readCalibrationFile(calfname,myMod->gain, myMod->offset);
setModule(*myMod);
}else{
std::cout << "Could not open settings file" << endl; std::cout << "Could not open settings file" << endl;
setErrorMask((getErrorMask())|(SETTINGS_FILE_NOT_OPEN)); setErrorMask((getErrorMask())|(SETTINGS_FILE_NOT_OPEN));
return thisDetector->currentSettings; return thisDetector->currentSettings;
} }
} }
//calibration file****
calfname=oscfn.str();
#ifdef VERBOSE
cout << "Specific file:"<< calfname << endl;
#endif
//extra gain and offset
if(thisDetector->nGain)
ret = readCalibrationFile(calfname,gainval, offsetval,thisDetector->myDetectorType );
//normal gain and offset inside sls_detector_module
else
ret = readCalibrationFile(calfname,myMod->gain, myMod->offset);
//if it didnt open, try default
if(ret != OK){
ostringstream oscfn_default;
oscfn_default << thisDetector->calDir << ssettings << ssettings << ".cal";
calfname=oscfn_default.str();
#ifdef VERBOSE
cout << "Default file:" << calfname << endl;
#endif
//extra gain and offset
if(thisDetector->nGain)
ret = readCalibrationFile(calfname,gainval, offsetval,thisDetector->myDetectorType );
//normal gain and offset inside sls_detector_module
else
ret = readCalibrationFile(calfname,myMod->gain, myMod->offset);
}
//if default doesnt work, return error
if(ret != OK){
std::cout << "Could not open calibration file" << calfname << endl;
setErrorMask((getErrorMask())|(SETTINGS_FILE_NOT_OPEN));
return thisDetector->currentSettings;
}
//if everything worked, set module****
setModule(*myMod,gainval,offsetval);
} }
} }
deleteModule(myMod); deleteModule(myMod);
if(gainval) delete [] gainval;
if(offsetval) delete [] offsetval;
switch(thisDetector->myDetectorType==MYTHEN){ switch(thisDetector->myDetectorType==MYTHEN){
if (thisDetector->correctionMask&(1<<RATE_CORRECTION)) { if (thisDetector->correctionMask&(1<<RATE_CORRECTION)) {
int isett=getSettings(imod); int isett=getSettings(imod);
@ -4131,6 +4262,7 @@ int slsDetector::setSpeed(speedVariable sp, int value) {
if (ret==FAIL) { if (ret==FAIL) {
controlSocket->ReceiveDataOnly(mess,sizeof(mess)); controlSocket->ReceiveDataOnly(mess,sizeof(mess));
std::cout<< "Detector returned error: " << mess << std::endl; std::cout<< "Detector returned error: " << mess << std::endl;
setErrorMask((getErrorMask())|(COULD_NOT_SET_SPEED_PARAMETERS));
} else { } else {
controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); controlSocket->ReceiveDataOnly(&retval,sizeof(retval));
} }
@ -4399,6 +4531,7 @@ int slsDetector::setReadOutFlags(readOutFlags flag){
if (ret==FAIL) { if (ret==FAIL) {
controlSocket->ReceiveDataOnly(mess,sizeof(mess)); controlSocket->ReceiveDataOnly(mess,sizeof(mess));
std::cout<< "Detector returned error: " << mess << std::endl; std::cout<< "Detector returned error: " << mess << std::endl;
setErrorMask((getErrorMask())|(COULD_NOT_SET_READOUT_FLAGS));
} else { } else {
controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); controlSocket->ReceiveDataOnly(&retval,sizeof(retval));
thisDetector->roFlags=retval; thisDetector->roFlags=retval;
@ -5853,6 +5986,7 @@ int slsDetector::writeSettingsFile(string fname, int imod){
int slsDetector::loadSettingsFile(string fname, int imod) { int slsDetector::loadSettingsFile(string fname, int imod) {
sls_detector_module *myMod=NULL; sls_detector_module *myMod=NULL;
int* g=0; int* o=0;
string fn=fname; string fn=fname;
fn=fname; fn=fname;
int mmin=0, mmax=setNumberOfModules(); int mmin=0, mmax=setNumberOfModules();
@ -5878,7 +6012,7 @@ int slsDetector::loadSettingsFile(string fname, int imod) {
//settings is saved in myMod.reg for all except mythen //settings is saved in myMod.reg for all except mythen
if(thisDetector->myDetectorType!=MYTHEN) if(thisDetector->myDetectorType!=MYTHEN)
myMod->reg=thisDetector->currentSettings; myMod->reg=thisDetector->currentSettings;
setModule(*myMod); setModule(*myMod,g,o);
deleteModule(myMod); deleteModule(myMod);
} else } else
return FAIL; return FAIL;
@ -5955,7 +6089,21 @@ int slsDetector::loadCalibrationFile(string fname, int imod) {
sls_detector_module *myMod=NULL; sls_detector_module *myMod=NULL;
string fn=fname; string fn=fname;
int* gainval=0, *offsetval=0;
if(thisDetector->nGain)
gainval=new int[thisDetector->nGain];
if(thisDetector->nOffset)
offsetval=new int[thisDetector->nOffset];
fn=fname; fn=fname;
if(thisDetector->nGain)
gainval = new int[thisDetector->nGain];
if(thisDetector->nOffset)
offsetval = new int[thisDetector->nOffset];
int mmin=0, mmax=setNumberOfModules(); int mmin=0, mmax=setNumberOfModules();
if (imod>=0) { if (imod>=0) {
mmin=imod; mmin=imod;
@ -5973,10 +6121,21 @@ int slsDetector::loadCalibrationFile(string fname, int imod) {
} }
fn=ostfn.str(); fn=ostfn.str();
if((myMod=getModule(im))){ if((myMod=getModule(im))){
if(readCalibrationFile(fn, myMod->gain, myMod->offset)==FAIL)
return FAIL; //extra gain and offset
setModule(*myMod); if(thisDetector->nGain){
if(readCalibrationFile(fn,gainval, offsetval,thisDetector->myDetectorType)==FAIL)
return FAIL;
} //normal gain and offset inside sls_detector_module
else{
if(readCalibrationFile(fn,myMod->gain, myMod->offset)==FAIL)
return FAIL;
}
setModule(*myMod,gainval,offsetval);
deleteModule(myMod); deleteModule(myMod);
if(gainval) delete[]gainval;
if(offsetval) delete offsetval;
} else } else
return FAIL; return FAIL;
} }
@ -6002,7 +6161,13 @@ int slsDetector::saveCalibrationFile(string fname, int imod) {
else else
ostfn << fname << ".sn" << setfill('0') << setw(3) << hex << getId(MODULE_SERIAL_NUMBER,im); ostfn << fname << ".sn" << setfill('0') << setw(3) << hex << getId(MODULE_SERIAL_NUMBER,im);
if ((myMod=getModule(im))) { if ((myMod=getModule(im))) {
ret=writeCalibrationFile(ostfn.str(), myMod->gain, myMod->offset); //extra gain and offset
if(thisDetector->nGain)
ret=writeCalibrationFile(ostfn.str(),gain, offset,thisDetector->myDetectorType);
//normal gain and offset inside sls_detector_module
else
ret=writeCalibrationFile(ostfn.str(),myMod->gain, myMod->offset);
deleteModule(myMod); deleteModule(myMod);
}else }else
return FAIL; return FAIL;
@ -6540,7 +6705,7 @@ int slsDetector::resetFramesCaught(){
int* slsDetector::readFrameFromReceiver(char* fName, int &acquisitionIndex, int &frameIndex){ int* slsDetector::readFrameFromReceiver(char* fName, int &acquisitionIndex, int &frameIndex, int &subFrameIndex){
int fnum=F_READ_RECEIVER_FRAME; int fnum=F_READ_RECEIVER_FRAME;
int nel=thisDetector->dataBytes/sizeof(int); int nel=thisDetector->dataBytes/sizeof(int);
int* retval=new int[nel]; int* retval=new int[nel];
@ -6567,6 +6732,8 @@ int* slsDetector::readFrameFromReceiver(char* fName, int &acquisitionIndex, int
n=dataSocket->ReceiveDataOnly(fName,MAX_STR_LENGTH); n=dataSocket->ReceiveDataOnly(fName,MAX_STR_LENGTH);
n=dataSocket->ReceiveDataOnly(&acquisitionIndex,sizeof(acquisitionIndex)); n=dataSocket->ReceiveDataOnly(&acquisitionIndex,sizeof(acquisitionIndex));
n=dataSocket->ReceiveDataOnly(&frameIndex,sizeof(frameIndex)); n=dataSocket->ReceiveDataOnly(&frameIndex,sizeof(frameIndex));
if(thisDetector->myDetectorType == EIGER)
n=dataSocket->ReceiveDataOnly(&subFrameIndex,sizeof(subFrameIndex));
n=dataSocket->ReceiveDataOnly(retval,thisDetector->dataBytes); n=dataSocket->ReceiveDataOnly(retval,thisDetector->dataBytes);
#ifdef VERBOSE #ifdef VERBOSE

View File

@ -126,11 +126,17 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
int nDacs; int nDacs;
/** number of adcs per module */ /** number of adcs per module */
int nAdcs; int nAdcs;
/** number of extra gain values*/
int nGain;
/** number of extra offset values */
int nOffset;
/** dynamic range of the detector data */ /** dynamic range of the detector data */
int dynamicRange; int dynamicRange;
/** size of the data that are transfered from the detector */ /** size of the data that are transfered from the detector */
int dataBytes; int dataBytes;
/** corrections to be applied to the data \see ::correctionFlags */ /** corrections to be applied to the data \see ::correctionFlags */
int correctionMask; int correctionMask;
/** threaded processing flag (i.e. if data are processed and written to file in a separate thread) */ /** threaded processing flag (i.e. if data are processed and written to file in a separate thread) */
@ -230,7 +236,10 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
int chipoff; int chipoff;
/** memory offsets for the channel register arrays -trimbits*/ /** memory offsets for the channel register arrays -trimbits*/
int chanoff; int chanoff;
/** memory offsets for the gain register arrays */
int gainoff;
/** memory offsets for the offset register arrays -trimbits*/
int offsetoff;
/* receiver*/ /* receiver*/
@ -894,10 +903,12 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
/** /**
configure chip configure chip
\param module module to be set - must contain correct module number and also channel and chip registers \param module module to be set - must contain correct module number and also channel and chip registers
\param gainval pointer to extra gain values
\param offsetval pointer to extra offset values
\returns current register value \returns current register value
\sa ::sls_detector_module \sa ::sls_detector_module
*/ */
int setModule(sls_detector_module module); int setModule(sls_detector_module module, int* gainval, int* offsetval);
//virtual int setModule(sls_detector_module module); //virtual int setModule(sls_detector_module module);
/** /**
@ -1543,9 +1554,10 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
* @param fName file name of current frame() * @param fName file name of current frame()
* @param acquisitionIndex current acquisition index * @param acquisitionIndex current acquisition index
* @param frameIndex current frame index (for each scan) * @param frameIndex current frame index (for each scan)
* @param subFrameIndex current sub frame index (for 32 bit mode for eiger)
/returns a frame read from recever /returns a frame read from recever
*/ */
int* readFrameFromReceiver(char* fName, int &acquisitionIndex, int &frameIndex); int* readFrameFromReceiver(char* fName, int &acquisitionIndex, int &frameIndex, int &subFrameIndex);
/** Locks/Unlocks the connection to the receiver /** Locks/Unlocks the connection to the receiver
/param lock sets (1), usets (0), gets (-1) the lock /param lock sets (1), usets (0), gets (-1) the lock
@ -1770,6 +1782,10 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
int *chipregs; int *chipregs;
/** pointer to channal registers */ /** pointer to channal registers */
int *chanregs; int *chanregs;
/** pointer to gain values */
int *gain;
/** pointer to offset values */
int *offset;
receiverInterface *thisReceiver; receiverInterface *thisReceiver;

View File

@ -499,9 +499,10 @@ class slsDetectorBase : public virtual slsDetectorDefs, public virtual errorDef
* @param fName file name of current frame() * @param fName file name of current frame()
* @param acquisitionIndex current acquisition index * @param acquisitionIndex current acquisition index
* @param frameIndex current frame index (for each scan) * @param frameIndex current frame index (for each scan)
* @param subFrameIndex current sub frame index (for 32 bit mode for eiger)
/returns a frame read from recever /returns a frame read from recever
*/ */
virtual int* readFrameFromReceiver(char* fName, int &acquisitionIndex, int &frameIndex)=0; virtual int* readFrameFromReceiver(char* fName, int &acquisitionIndex, int &frameIndex, int &subFrameIndex)=0;
/** Sets the read receiver frequency /** Sets the read receiver frequency

View File

@ -268,7 +268,7 @@ int64_t slsDetectorUsers::getThisSoftwareVersion(){
void slsDetectorUsers::registerDataCallback(int( *userCallback)(detectorData*, int, void*), void *pArg){ void slsDetectorUsers::registerDataCallback(int( *userCallback)(detectorData*, int, int, void*), void *pArg){
myDetector->registerDataCallback(userCallback,pArg); myDetector->registerDataCallback(userCallback,pArg);
} }

View File

@ -408,10 +408,10 @@ class slsDetectorUsers
/** /**
@short register calbback for accessing detector final data @short register calbback for accessing detector final data
\param userCallback function for plotting/analyzing the data. Its arguments are the data structure d and the frame number f. \param userCallback function for plotting/analyzing the data. Its arguments are the data structure d and the frame number f, s is for subframe number for eiger for 32 bit mode
*/ */
void registerDataCallback(int( *userCallback)(detectorData* d, int f, void*), void *pArg); void registerDataCallback(int( *userCallback)(detectorData* d, int f, int s, void*), void *pArg);
/** /**
@short register callback for accessing raw data - if the rawDataCallback is registered, no filewriting/postprocessing will be carried on automatically by the software - the raw data are deleted by the software @short register callback for accessing raw data - if the rawDataCallback is registered, no filewriting/postprocessing will be carried on automatically by the software - the raw data are deleted by the software

View File

@ -641,9 +641,10 @@ virtual int resetFramesCaught()=0;
* @param fName file name of current frame() * @param fName file name of current frame()
* @param acquisitionIndex current acquisition index * @param acquisitionIndex current acquisition index
* @param frameIndex current frame index (for each scan) * @param frameIndex current frame index (for each scan)
* @param subFrameIndex current sub frame index (for 32 bit mode for eiger)
/returns a frame read from recever /returns a frame read from recever
*/ */
virtual int* readFrameFromReceiver(char* fName, int &acquisitionIndex, int &frameIndex)=0; virtual int* readFrameFromReceiver(char* fName, int &acquisitionIndex, int &frameIndex, int &subFrameIndex)=0;
/** /**

View File

@ -47,7 +47,6 @@ int energyConversion::readCalibrationFile(string fname, double &gain, double &of
int energyConversion::writeCalibrationFile(string fname, double gain, double offset){ int energyConversion::writeCalibrationFile(string fname, double gain, double offset){
//std::cout<< "Function not yet implemented " << std::endl; //std::cout<< "Function not yet implemented " << std::endl;
ofstream outfile; ofstream outfile;
outfile.open (fname.c_str()); outfile.open (fname.c_str());
// >> i/o operations here << // >> i/o operations here <<
@ -70,66 +69,62 @@ int energyConversion::writeCalibrationFile(string fname, double gain, double off
}; };
int energyConversion::readCalibrationFile(string fname, double *gain, double *offset, detectorType myDetectorType){ int energyConversion::readCalibrationFile(string fname, int *gain, int *offset, detectorType myDetectorType){
string str; string str;
ifstream infile; ifstream infile;
double o,g; double o,g;
int ig=0; int ig=0;
switch (myDetectorType) { switch (myDetectorType) {
case EIGER: case EIGER:
#ifdef VERBOSE #ifdef VERBOSE
std::cout<< "Opening file "<< fname << std::endl; std::cout<< "Opening file "<< fname << std::endl;
#endif #endif
infile.open(fname.c_str(), ios_base::in); infile.open(fname.c_str(), ios_base::in);
if (infile.is_open()) { if (infile.is_open()) {
for (ig=0; ig<4; ig++) {
for (ig=0; ig<4; ig++) { //while ( (getline(infile,str)) > -1) {
//while ( (getline(infile,str)) > -1) { getline(infile,str);
getline(infile,str);
#ifdef VERBOSE #ifdef VERBOSE
std::cout<< str << std::endl; std::cout<< str << std::endl;
#endif #endif
istringstream ssstr(str); istringstream ssstr(str);
ssstr >> o >> g; ssstr >> o >> g;
offset[ig]=o; offset[ig]=(int)(o*1000);
gain[ig]=g; gain[ig]=(int)(g*1000);
// ig++; // ig++;
if (ig>=4) if (ig>=4)
break; break;
} }
infile.close(); infile.close();
cout << "Calibration file loaded: " << fname << endl; cout << "Calibration file loaded: " << fname << endl;
} else { } else {
std::cout<< "Could not open calibration file "<< fname << std::endl; cout << "Could not open calibration file: "<< fname << std::endl;
gain[0]=0.; gain[0]=0;
offset[0]=0.; offset[0]=0;
#ifndef MYROOT #ifndef MYROOT
return FAIL; return FAIL;
#endif #endif
return -1; return -1;
} }
#ifndef MYROOT #ifndef MYROOT
return OK; return OK;
#endif #endif
return 0; return 0;
break; break;
default:
std::cout<< "Writing Calibration Files for this detector not defined\n" << std::endl;
return FAIL;
}
default:
return readCalibrationFile(fname, *gain, *offset);
}
}; };
int energyConversion::writeCalibrationFile(string fname, double *gain, double *offset, detectorType myDetectorType){ int energyConversion::writeCalibrationFile(string fname, int *gain, int *offset, detectorType myDetectorType){
//std::cout<< "Function not yet implemented " << std::endl; //std::cout<< "Function not yet implemented " << std::endl;
ofstream outfile; ofstream outfile;
switch (myDetectorType) { switch (myDetectorType) {
@ -140,7 +135,7 @@ int energyConversion::writeCalibrationFile(string fname, double *gain, double *o
// >> i/o operations here << // >> i/o operations here <<
if (outfile.is_open()) { if (outfile.is_open()) {
for (int ig=0; ig<4; ig++) for (int ig=0; ig<4; ig++)
outfile << offset[ig] << " " << gain[ig] << std::endl; outfile << ((double)offset[ig]/1000) << " " << ((double)gain[ig]/1000) << std::endl;
} else { } else {
std::cout<< "Could not open calibration file "<< fname << " for writing" << std::endl; std::cout<< "Could not open calibration file "<< fname << " for writing" << std::endl;
#ifndef MYROOT #ifndef MYROOT
@ -156,7 +151,8 @@ int energyConversion::writeCalibrationFile(string fname, double *gain, double *o
return 0; return 0;
break; break;
default: default:
return writeCalibrationFile(fname, *gain, *offset); std::cout<< "Writing Calibration Files for this detector not defined\n" << std::endl;
return FAIL;
} }
}; };

View File

@ -54,7 +54,7 @@ class energyConversion
\param gain reference to the gain variable \param gain reference to the gain variable
\offset reference to the offset variable \offset reference to the offset variable
*/ */
static int readCalibrationFile(string fname, double *gain, double *offset, detectorType myDetectorType); static int readCalibrationFile(string fname, int *gain, int *offset, detectorType myDetectorType);
/** /**
writes a calibration file writes a calibration file
@ -62,7 +62,7 @@ class energyConversion
\param gain \param gain
\param offset \param offset
*/ */
static int writeCalibrationFile(string fname, double *gain, double *offset, detectorType myDetectorType); static int writeCalibrationFile(string fname, int *gain, int *offset, detectorType myDetectorType);

View File

@ -138,7 +138,7 @@ void postProcessing::processFrame(int *myData, int delflag, int jctb) {
// cout << "callback arg "<< getCurrentProgress()<< " " << (fname+string(".raw")).c_str() << " " << getTotalNumberOfChannels() << endl; // cout << "callback arg "<< getCurrentProgress()<< " " << (fname+string(".raw")).c_str() << " " << getTotalNumberOfChannels() << endl;
// cout << "DATAREADY 1" <<endl; // cout << "DATAREADY 1" <<endl;
thisData=new detectorData(fdata,NULL,NULL,getCurrentProgress(),(fname+string(".raw")).c_str(),getTotalNumberOfChannels()); thisData=new detectorData(fdata,NULL,NULL,getCurrentProgress(),(fname+string(".raw")).c_str(),getTotalNumberOfChannels());
dataReady(thisData, currentFrameIndex, pCallbackArg); dataReady(thisData, currentFrameIndex, -1, pCallbackArg);
delete thisData; delete thisData;
fdata=NULL; fdata=NULL;
} }
@ -281,7 +281,7 @@ data queue size unlock
// cout << "callback arg "<< getCurrentProgress()<< " " << (fname+ext).c_str() << " " << np << endl; // cout << "callback arg "<< getCurrentProgress()<< " " << (fname+ext).c_str() << " " << np << endl;
//cout << "ADATREADY 2 " << endl; //cout << "ADATREADY 2 " << endl;
thisData=new detectorData(val,err,ang,getCurrentProgress(),(fname+ext).c_str(),np); thisData=new detectorData(val,err,ang,getCurrentProgress(),(fname+ext).c_str(),np);
dataReady(thisData, currentFrameIndex, pCallbackArg); dataReady(thisData, currentFrameIndex, -1, pCallbackArg);
delete thisData; delete thisData;
ang=NULL; ang=NULL;
val=NULL; val=NULL;
@ -500,6 +500,7 @@ void* postProcessing::processData(int delflag) {
int caught = -1; int caught = -1;
int currentAcquisitionIndex = -1; int currentAcquisitionIndex = -1;
int currentFrameIndex = -1; int currentFrameIndex = -1;
int currentSubFrameIndex = -1;
bool newData = false; bool newData = false;
int nthframe = setReadReceiverFrequency(0); int nthframe = setReadReceiverFrequency(0);
@ -633,7 +634,7 @@ void* postProcessing::processData(int delflag) {
strcpy(currentfName,""); strcpy(currentfName,"");
pthread_mutex_lock(&mg); pthread_mutex_lock(&mg);
//int* receiverData = new int [getTotalNumberOfChannels()]; //int* receiverData = new int [getTotalNumberOfChannels()];
int* receiverData = readFrameFromReceiver(currentfName,currentAcquisitionIndex,currentFrameIndex); int* receiverData = readFrameFromReceiver(currentfName,currentAcquisitionIndex,currentFrameIndex,currentSubFrameIndex);
pthread_mutex_unlock(&mg); pthread_mutex_unlock(&mg);
//if detector returned null //if detector returned null
@ -664,7 +665,7 @@ void* postProcessing::processData(int delflag) {
if ((fdata) && (dataReady)){ if ((fdata) && (dataReady)){
// cout << "DATAREADY 3" << endl; // cout << "DATAREADY 3" << endl;
thisData = new detectorData(fdata,NULL,NULL,getCurrentProgress(),currentfName,getTotalNumberOfChannels()); thisData = new detectorData(fdata,NULL,NULL,getCurrentProgress(),currentfName,getTotalNumberOfChannels());
dataReady(thisData, currentFrameIndex, pCallbackArg); dataReady(thisData, currentFrameIndex, currentSubFrameIndex, pCallbackArg);
delete thisData; delete thisData;
fdata = NULL; fdata = NULL;
progress = caught; progress = caught;

View File

@ -238,7 +238,7 @@ s
void ResetPositionIndex(){pthread_mutex_lock(&mp); resetPositionIndex(); pthread_mutex_unlock(&mp);}; void ResetPositionIndex(){pthread_mutex_lock(&mp); resetPositionIndex(); pthread_mutex_unlock(&mp);};
void registerDataCallback(int( *userCallback)(detectorData*, int, void*), void *pArg) {dataReady = userCallback; pCallbackArg = pArg;}; void registerDataCallback(int( *userCallback)(detectorData*, int, int, void*), void *pArg) {dataReady = userCallback; pCallbackArg = pArg;};
void registerRawDataCallback(int( *userCallback)(double*, int, void*), void *pArg) {rawDataReady = userCallback; pRawDataArg = pArg;}; void registerRawDataCallback(int( *userCallback)(double*, int, void*), void *pArg) {rawDataReady = userCallback; pRawDataArg = pArg;};
@ -335,7 +335,7 @@ s
private: private:
double *fdata; double *fdata;
int (*dataReady)(detectorData*,int, void*); int (*dataReady)(detectorData*,int, int,void*);
void *pCallbackArg; void *pCallbackArg;
int (*rawDataReady)(double*,int,void*); int (*rawDataReady)(double*,int,void*);

View File

@ -60,14 +60,21 @@ int setChip(sls_detector_chip myChip);
int getChip(sls_detector_chip *myChip); int getChip(sls_detector_chip *myChip);
#endif #endif
#ifdef EIGERD
int setModule(sls_detector_module myMod, int* gain, int* offset);
int getModule(sls_detector_module *myMod, int* gain, int* offset);
#else
int setModule(sls_detector_module myMod); int setModule(sls_detector_module myMod);
int getModule(sls_detector_module *myMod); int getModule(sls_detector_module *myMod);
#endif
enum detectorSettings setSettings(enum detectorSettings sett, int imod); enum detectorSettings setSettings(enum detectorSettings sett, int imod);
#if defined(MYTHEND) || defined(EIGERD) #if defined(MYTHEND) || defined(EIGERD)
int getThresholdEnergy(int imod); int getThresholdEnergy(int imod);
int setThresholdEnergy(int thr, int imod); int setThresholdEnergy(int ev, int imod);
#endif #endif
int startStateMachine(); int startStateMachine();
@ -118,7 +125,10 @@ int getNumberOfChannelsPerModule();
int getNumberOfChipsPerModule(); int getNumberOfChipsPerModule();
int getNumberOfDACsPerModule(); int getNumberOfDACsPerModule();
int getNumberOfADCsPerModule(); int getNumberOfADCsPerModule();
#ifdef EIGERD
int getNumberOfGainsPerModule();
int getNumberOfOffsetsPerModule();
#endif
enum externalSignalFlag getExtSignal(int signalindex); enum externalSignalFlag getExtSignal(int signalindex);
enum externalSignalFlag setExtSignal(int signalindex, enum externalSignalFlag flag); enum externalSignalFlag setExtSignal(int signalindex, enum externalSignalFlag flag);

View File

@ -1788,11 +1788,15 @@ int get_chip(int file_des) {
} }
int set_module(int file_des) { int set_module(int file_des) {
int retval, n; int retval, n,i;
int ret=OK,ret1=OK; int ret=OK,ret1=OK;
#ifdef SLS_DETECTOR_FUNCTION_LIST #ifdef SLS_DETECTOR_FUNCTION_LIST
sls_detector_module myModule; sls_detector_module myModule;
#ifdef EIGERD
int *myGain = (int*)malloc(getNumberOfGainsPerModule()*sizeof(int));
int *myOffset = (int*)malloc(getNumberOfOffsetsPerModule()*sizeof(int));
#endif
int *myChip=(int*)malloc(getNumberOfChipsPerModule()*sizeof(int)); int *myChip=(int*)malloc(getNumberOfChipsPerModule()*sizeof(int));
int *myChan=(int*)malloc(getNumberOfChannelsPerModule()*sizeof(int)); int *myChan=(int*)malloc(getNumberOfChannelsPerModule()*sizeof(int));
int *myDac=(int*)malloc(getNumberOfDACsPerModule()*sizeof(int)); int *myDac=(int*)malloc(getNumberOfDACsPerModule()*sizeof(int));
@ -1823,7 +1827,16 @@ int set_module(int file_des) {
sprintf(mess,"could not allocate chans\n"); sprintf(mess,"could not allocate chans\n");
ret=FAIL; ret=FAIL;
} }
#ifdef EIGERD
if (!myGain){
sprintf(mess,"could not allocate gains\n");
ret=FAIL;
}
if (!myOffset){
sprintf(mess,"could not allocate offsets\n");
ret=FAIL;
}
#endif
myModule.nchip=getNumberOfChipsPerModule(); myModule.nchip=getNumberOfChipsPerModule();
myModule.nchan=getNumberOfChannelsPerModule(); myModule.nchan=getNumberOfChannelsPerModule();
myModule.ndac=getNumberOfDACsPerModule(); myModule.ndac=getNumberOfDACsPerModule();
@ -1834,17 +1847,25 @@ int set_module(int file_des) {
printf("Setting module\n"); printf("Setting module\n");
#endif #endif
ret=receiveModule(file_des, &myModule); ret=receiveModule(file_des, &myModule);
#ifdef EIGERD
n = receiveData(file_des,myGain,sizeof(int)*getNumberOfGainsPerModule(),INT32);
n = receiveData(file_des,myOffset,sizeof(int)*getNumberOfOffsetsPerModule(),INT32);
#endif
if (ret>=0) if (ret>=0)
ret=OK; ret=OK;
else else
ret=FAIL; ret=FAIL;
#ifdef VERBOSE //#ifdef VERBOSE
printf("module number is %d,register is %d, nchan %d, nchip %d, ndac %d, nadc %d, gain %f, offset %f\n",myModule.module, myModule.reg, myModule.nchan, myModule.nchip, myModule.ndac, myModule.nadc, myModule.gain,myModule.offset); printf("module number is %d,register is %d, nchan %d, nchip %d, ndac %d, nadc %d, gain %f, offset %f\n",myModule.module, myModule.reg, myModule.nchan, myModule.nchip, myModule.ndac, myModule.nadc, myModule.gain,myModule.offset);
#ifdef EIGERD
for(i=0;i<getNumberOfGainsPerModule();i++)
printf("gain[%d]:%d\t%f\n",i,myGain[i],((double)myGain[i]/1000));
for(i=0;i<getNumberOfOffsetsPerModule();i++)
printf("offset[%d]:%d\t%f\n",i,myOffset[i],((double)myOffset[i]/1000));
#endif #endif
//#endif
if (ret==OK) { if (ret==OK) {
@ -1852,7 +1873,12 @@ int set_module(int file_des) {
ret=FAIL; ret=FAIL;
sprintf(mess,"Detector locked by %s\n",lastClientIP); sprintf(mess,"Detector locked by %s\n",lastClientIP);
} else { } else {
retval=setModule(myModule); #ifdef EIGERD
ret=setModule(myModule, myGain, myOffset);
#else
ret=setModule(myModule);
#endif
retval = ret;
} }
} }
#endif #endif
@ -1878,6 +1904,10 @@ int set_module(int file_des) {
free(myChan); free(myChan);
free(myDac); free(myDac);
free(myAdc); free(myAdc);
#ifdef EIGERD
free(myGain);
free(myOffset);
#endif
#endif #endif
return ret; return ret;
} }
@ -1895,6 +1925,10 @@ int get_module(int file_des) {
sls_detector_module myModule; sls_detector_module myModule;
#ifdef SLS_DETECTOR_FUNCTION_LIST #ifdef SLS_DETECTOR_FUNCTION_LIST
#ifdef EIGERD
int *myGain = (int*)malloc(getNumberOfGainsPerModule()*sizeof(int));
int *myOffset = (int*)malloc(getNumberOfOffsetsPerModule()*sizeof(int));
#endif
int *myChip=(int*)malloc(getNumberOfChipsPerModule()*sizeof(int)); int *myChip=(int*)malloc(getNumberOfChipsPerModule()*sizeof(int));
int *myChan=(int*)malloc(getNumberOfChannelsPerModule()*sizeof(int)); int *myChan=(int*)malloc(getNumberOfChannelsPerModule()*sizeof(int));
int *myDac=(int*)malloc(getNumberOfDACsPerModule()*sizeof(int)); int *myDac=(int*)malloc(getNumberOfDACsPerModule()*sizeof(int));
@ -1925,7 +1959,16 @@ int get_module(int file_des) {
sprintf(mess,"could not allocate chans\n"); sprintf(mess,"could not allocate chans\n");
ret=FAIL; ret=FAIL;
} }
#ifdef EIGERD
if (!myGain){
sprintf(mess,"could not allocate gains\n");
ret=FAIL;
}
if (!myOffset){
sprintf(mess,"could not allocate offsets\n");
ret=FAIL;
}
#endif
myModule.ndac=getNumberOfDACsPerModule(); myModule.ndac=getNumberOfDACsPerModule();
myModule.nchip=getNumberOfChipsPerModule(); myModule.nchip=getNumberOfChipsPerModule();
myModule.nchan=getNumberOfChannelsPerModule(); myModule.nchan=getNumberOfChannelsPerModule();
@ -1948,7 +1991,18 @@ int get_module(int file_des) {
if (imod>=0) { if (imod>=0) {
ret=OK; ret=OK;
myModule.module=imod; myModule.module=imod;
#ifdef EIGERD
getModule(&myModule, myGain, myOffset);
#ifdef VERBOSE
for(i=0;i<getNumberOfGainsPerModule();i++)
printf("gain[%d]:%d\t%f\n",i,myGain[i],((double)myGain[i]/1000));
for(i=0;i<getNumberOfOffsetsPerModule();i++)
printf("offset[%d]:%d\t%f\n",i,myOffset[i],((double)myOffset[i]/1000));
#endif
#else
getModule(&myModule); getModule(&myModule);
#endif
#ifdef VERBOSE #ifdef VERBOSE
printf("Returning module %d of register %x\n", imod, myModule.reg); printf("Returning module %d of register %x\n", imod, myModule.reg);
@ -1967,6 +2021,10 @@ int get_module(int file_des) {
if (ret!=FAIL) { if (ret!=FAIL) {
/* send return argument */ /* send return argument */
ret=sendModule(file_des, &myModule); ret=sendModule(file_des, &myModule);
#ifdef EIGERD
n = sendData(file_des,myGain,sizeof(int)*getNumberOfGainsPerModule(),INT32);
n = sendData(file_des,myOffset,sizeof(int)*getNumberOfOffsetsPerModule(),INT32);
#endif
} else { } else {
n += sendData(file_des,mess,sizeof(mess),OTHER); n += sendData(file_des,mess,sizeof(mess),OTHER);
} }
@ -1976,6 +2034,10 @@ int get_module(int file_des) {
free(myChan); free(myChan);
free(myDac); free(myDac);
free(myAdc); free(myAdc);
#ifdef EIGERD
free(myGain);
free(myOffset);
#endif
#endif #endif
/*return ok/fail*/ /*return ok/fail*/
return ret; return ret;
@ -2717,9 +2779,10 @@ int set_readout_flags(int file_des) {
#endif #endif
if (ret==OK) { if (ret==OK) {
if (retval == -1) { if ((retval == -1) || ((arg!=-1)&&((retval&arg)!=arg))){
cprintf(RED,"arg:0x%x, retval:0x%x retval&arg:0x%x\n",(int)arg,(int)retval,retval&arg);
ret=FAIL; ret=FAIL;
sprintf(mess,"Could not change readout flag: should be %d but is %d\n", arg, retval); sprintf(mess,"Could not change readout flag: should be 0x%x but is 0x%x\n", arg, retval);
cprintf(RED, "%s",mess); cprintf(RED, "%s",mess);
}else if (differentClients) }else if (differentClients)
ret=FORCE_UPDATE; ret=FORCE_UPDATE;