diff --git a/slsDetectorSoftware/commonFiles/sls_detector_defs.h b/slsDetectorSoftware/commonFiles/sls_detector_defs.h index 29c624b8d..1c911c9d5 100755 --- a/slsDetectorSoftware/commonFiles/sls_detector_defs.h +++ b/slsDetectorSoftware/commonFiles/sls_detector_defs.h @@ -140,6 +140,7 @@ typedef struct { double offset; /**< is the module offset (V) */ } sls_detector_module; + /** @short structure for a region of interest diff --git a/slsDetectorSoftware/eigerDetectorServer/FebControl.c b/slsDetectorSoftware/eigerDetectorServer/FebControl.c index bd318d60a..b24cc374a 100644 --- a/slsDetectorSoftware/eigerDetectorServer/FebControl.c +++ b/slsDetectorSoftware/eigerDetectorServer/FebControl.c @@ -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_subFrameMode; -unsigned int Feb_Control_photon_energy_eV; - unsigned int Feb_Control_nimages; double Feb_Control_exposure_time_in_sec; 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; } - +/* not called anywhere**/ int Feb_Control_ReadSetUpFile(unsigned int module_num, char* file_name){ printf("Reading Setup file for module number:%d\n",module_num); char line[100]; @@ -486,14 +484,14 @@ int Feb_Control_ReadSetUpFile(unsigned int module_num, char* file_name){ } Feb_Control_SetHighVoltage(f0); } - +/* else if(!strcmp("photon_energy",str)){ if(sscanf (line,"%s %f", str,&f0) < 2){ printf("Error reading photon_energy\n"); exit(0); } Feb_Control_SetPhotonEnergy(f0); - } + }*/ else if(!strcmp("dynamic_range",str)){ if(sscanf (line,"%s %d", str,&i0) < 2){ @@ -591,32 +589,6 @@ unsigned int Feb_Control_GetNHalfModules(){ 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){ 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); diff --git a/slsDetectorSoftware/eigerDetectorServer/FebControl.h b/slsDetectorSoftware/eigerDetectorServer/FebControl.h index b72103e1c..3c0e62760 100644 --- a/slsDetectorSoftware/eigerDetectorServer/FebControl.h +++ b/slsDetectorSoftware/eigerDetectorServer/FebControl.h @@ -121,8 +121,6 @@ int Feb_Control_GetModuleNumber(); int Feb_Control_SetHighVoltage(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_SetIDelays1(unsigned int module_num, unsigned int chip_pos, unsigned int ndelay_units); diff --git a/slsDetectorSoftware/eigerDetectorServer/bin/eigerDetectorServer b/slsDetectorSoftware/eigerDetectorServer/bin/eigerDetectorServer index 1a2700d2b..45564168e 100755 Binary files a/slsDetectorSoftware/eigerDetectorServer/bin/eigerDetectorServer and b/slsDetectorSoftware/eigerDetectorServer/bin/eigerDetectorServer differ diff --git a/slsDetectorSoftware/eigerDetectorServer/slsDetectorFunctionList.c b/slsDetectorSoftware/eigerDetectorServer/slsDetectorFunctionList.c index 17f1889f0..edffb9be0 100644 --- a/slsDetectorSoftware/eigerDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorSoftware/eigerDetectorServer/slsDetectorFunctionList.c @@ -26,7 +26,8 @@ int *detectorChips=NULL; int *detectorChans=NULL; dacs_t *detectorDacs=NULL; dacs_t *detectorAdcs=NULL; - +int* detectorGain = NULL; +int* detectorOffset = NULL; int eiger_highvoltage = 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"};; 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; @@ -80,12 +83,16 @@ int initDetector(){ detectorChans=malloc(n*NCHIP*NCHAN*sizeof(int)); detectorDacs=malloc(n*NDAC*sizeof(dacs_t)); detectorAdcs=malloc(n*NADC*sizeof(dacs_t)); + detectorGain=malloc(n*NGAIN*sizeof(int)); + detectorOffset=malloc(n*NOFFSET*sizeof(int)); #ifdef VERBOSE 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("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("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 for (imod=0; imoddacs=detectorDacs+imod*NDAC; @@ -102,6 +109,10 @@ int initDetector(){ (detectorModules+imod)->reg=0; /* initialize registers, dacs, retrieve sn, adc values etc */ } + for(i=0;indac;i++) setDAC((enum detDacIndex)i,default_dac_values[i],(detectorModules)->module,0,retval); - //setting default measurement parameters setTimer(FRAME_NUMBER,1); setTimer(ACQUISITION_TIME,1E9); setTimer(SUBFRAME_ACQUISITION_TIME,DEFAULT_SUBFRAME_EXPOSURE_VAL); setTimer(FRAME_PERIOD,1E9); setDynamicRange(16); - setThresholdEnergy(8000,0); + eiger_photonenergy = -1; setReadOutFlags(NONPARALLEL); setSpeed(0,1);//clk_devider,half speed 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 i; + //#ifdef VERBOSE printf("Setting module with settings %d\n",myMod.reg); //#endif - int i; - for(i=0;i= 0){ + eiger_photonenergy = ev; + //calculate thrvalues for dacs + for(i=0;inChip[Y]=1; thisDetector->nDacs=6; thisDetector->nAdcs=0; + thisDetector->nGain=0; + thisDetector->nOffset=0; thisDetector->nModMax[X]=24; thisDetector->nModMax[Y]=1; thisDetector->dynamicRange=24; @@ -544,6 +566,8 @@ int slsDetector::initializeDetectorSize(detectorType type) { thisDetector->nChip[Y]=1; thisDetector->nDacs=6; thisDetector->nAdcs=0; + thisDetector->nGain=0; + thisDetector->nOffset=0; thisDetector->nModMax[X]=6; thisDetector->nModMax[Y]=1; thisDetector->dynamicRange=24; @@ -555,6 +579,8 @@ int slsDetector::initializeDetectorSize(detectorType type) { thisDetector->nChip[Y]=1; thisDetector->nDacs=8; thisDetector->nAdcs=5; + thisDetector->nGain=0; + thisDetector->nOffset=0; thisDetector->nModMax[X]=1; thisDetector->nModMax[Y]=1; thisDetector->dynamicRange=16; @@ -566,6 +592,8 @@ int slsDetector::initializeDetectorSize(detectorType type) { thisDetector->nChip[Y]=1; thisDetector->nDacs=8; thisDetector->nAdcs=5; + thisDetector->nGain=0; + thisDetector->nOffset=0; thisDetector->nModMax[X]=1; thisDetector->nModMax[Y]=1; thisDetector->dynamicRange=16; @@ -577,6 +605,8 @@ int slsDetector::initializeDetectorSize(detectorType type) { thisDetector->nChip[Y]=1; thisDetector->nDacs=8; thisDetector->nAdcs=1; + thisDetector->nGain=0; + thisDetector->nOffset=0; thisDetector->nModMax[X]=1; thisDetector->nModMax[Y]=1; thisDetector->dynamicRange=16; @@ -588,6 +618,8 @@ int slsDetector::initializeDetectorSize(detectorType type) { thisDetector->nChip[Y]=1; thisDetector->nDacs=16; thisDetector->nAdcs=1; + thisDetector->nGain=0; + thisDetector->nOffset=0; thisDetector->nModMax[X]=1; thisDetector->nModMax[Y]=1; thisDetector->dynamicRange=16; @@ -599,6 +631,8 @@ int slsDetector::initializeDetectorSize(detectorType type) { thisDetector->nChip[Y]=1; thisDetector->nDacs=16; thisDetector->nAdcs=0; + thisDetector->nGain=4; + thisDetector->nOffset=4; thisDetector->nModMax[X]=1; thisDetector->nModMax[Y]=1; thisDetector->dynamicRange=16; @@ -610,6 +644,8 @@ int slsDetector::initializeDetectorSize(detectorType type) { thisDetector->nChip[Y]=0; thisDetector->nDacs=0; thisDetector->nAdcs=0; + thisDetector->nGain=0; + thisDetector->nOffset=0; thisDetector->nModMax[X]=0; thisDetector->nModMax[Y]=0; thisDetector->dynamicRange=32; @@ -725,7 +761,8 @@ int slsDetector::initializeDetectorSize(detectorType type) { thisDetector->adcoff=thisDetector->dacoff+sizeof(dacs_t)*thisDetector->nDacs*thisDetector->nModsMax; thisDetector->chipoff=thisDetector->adcoff+sizeof(dacs_t)*thisDetector->nAdcs*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?!?!?!? @@ -745,6 +782,8 @@ int slsDetector::initializeDetectorSize(detectorType type) { adcs=(dacs_t*)(goff+thisDetector->adcoff); chipregs=(int*)(goff+thisDetector->chipoff); chanregs=(int*)(goff+thisDetector->chanoff); + gain=(int*)(goff+thisDetector->gainoff); + offset=(int*)(goff+thisDetector->offsetoff); if (thisDetector->alreadyExisting==0) { /** if thisDetector is new, initialize its structures \sa initializeDetectorStructure(); */ initializeDetectorStructure(); @@ -864,6 +903,18 @@ int slsDetector::initializeDetectorStructure() { for (int ichan=0; ichannChans*thisDetector->nChips; ichan++) { *(chanregs+ichan+thisDetector->nChips*thisDetector->nChans*imod)=-1; } + + /** initializes the gain values to 0 */ + for (int igain=0; igainnGain; igain++) { + *(gain+igain+thisDetector->nGain*imod)=0; + } + + + /** initializes the offset values to 0 */ + for (int ioffset=0; ioffsetnOffset; ioffset++) { + *(offset+ioffset+thisDetector->nOffset*imod)=0; + } + /** initialize gain and offset to -1 */ thisMod->gain=-1.; thisMod->offset=-1.; @@ -910,7 +961,7 @@ slsDetectorDefs::sls_detector_module* slsDetector::createModule(detectorType t) nm=1; //modules/detector nc=4*1; //chips nd=16; //dacs - na=0; //use for gain???? + na=0; break; case MOENCH: nch=160*160; @@ -2554,6 +2605,8 @@ slsDetectorDefs::sls_detector_chip slsDetector::getChip(int ichip, int imod){ int slsDetector::setModule(int reg, int imod){ sls_detector_module myModule; + int* g=0; + int* o=0; #ifdef VERBOSE std::cout << "slsDetector set module " << std::endl; @@ -2622,16 +2675,14 @@ int slsDetector::setModule(int reg, int imod){ ads[i]=-1; myModule.adcs=ads; } - ret=setModule(myModule); + ret=setModule(myModule,g,o); } return ret; }; - - -int slsDetector::setModule(sls_detector_module module){ +int slsDetector::setModule(sls_detector_module module, int* gainval, int* offsetval){ int fnum=F_SET_MODULE; int retval; @@ -2649,6 +2700,13 @@ int slsDetector::setModule(sls_detector_module module){ if (connectControl() == OK){ controlSocket->SendDataOnly(&fnum,sizeof(fnum)); 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)); if (ret!=FAIL) { controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); @@ -2700,6 +2758,16 @@ int slsDetector::setModule(sls_detector_module module){ (detectorModules+imod)->reg=module.reg; } } + + if ((thisDetector->nGain) && (gainval) && (gain)) { + for (int i=0; inGain; i++) + gain[i+imod*thisDetector->nGain]=gainval[i]; + } + + if ((thisDetector->nOffset) && (offsetval) && (offset)) { + for (int i=0; inOffset; i++) + offset[i+imod*thisDetector->nOffset]=offsetval[i]; + } } #ifdef VERBOSE @@ -2709,106 +2777,131 @@ int slsDetector::setModule(sls_detector_module module){ return retval; }; + + + + slsDetectorDefs::sls_detector_module *slsDetector::getModule(int imod){ #ifdef VERBOSE - std::cout << "slsDetector get module " << std::endl; + std::cout << "slsDetector get module " << std::endl; #endif - int fnum=F_GET_MODULE; - sls_detector_module *myMod=createModule(); + int fnum=F_GET_MODULE; + 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 chipreg[thisDetector->nChips]; - //double dac[thisDetector->nDacs], adc[thisDetector->nAdcs]; + // int chanreg[thisDetector->nChans*thisDetector->nChips]; + //int chipreg[thisDetector->nChips]; + //double dac[thisDetector->nDacs], adc[thisDetector->nAdcs]; - int ret=FAIL; - char mess[100]; - // int n; + int ret=FAIL; + char mess[100]; + // int n; #ifdef VERBOSE - std::cout<< "getting module " << imod << std::endl; + std::cout<< "getting module " << imod << std::endl; #endif - myMod->module=imod; - // myMod.nchan=thisDetector->nChans*thisDetector->nChips; - //myMod.chanregs=chanreg; - //myMod.nchip=thisDetector->nChips; - //myMod.chipregs=chipreg; - //myMod.ndac=thisDetector->nDacs; - //myMod.dacs=dac; - //myMod.ndac=thisDetector->nAdcs; - //myMod.dacs=adc; + myMod->module=imod; + // myMod.nchan=thisDetector->nChans*thisDetector->nChips; + //myMod.chanregs=chanreg; + //myMod.nchip=thisDetector->nChips; + //myMod.chipregs=chipreg; + //myMod.ndac=thisDetector->nDacs; + //myMod.dacs=dac; + //myMod.ndac=thisDetector->nAdcs; + //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); - - - 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); - } else { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - } - controlSocket->Disconnect(); - if (ret==FORCE_UPDATE) - updateDetector(); - } - } - - - if (ret!=FAIL) { - if (detectorModules) { - if (imod>=0 && imodnMod[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; ichipnChips; ichip++) { - if (chipregs) - chipregs[ichip+thisDetector->nChips*imod]=myMod->chipregs[ichip]; - - if (chanregs) { - for (int i=0; inChans; i++) { - chanregs[i+ichip*thisDetector->nChans+thisDetector->nChips*thisDetector->nChans*imod]=myMod->chanregs[ichip*thisDetector->nChans+i]; - } - } - } - if (dacs) { - for (int i=0; inDacs; i++) - dacs[i+imod*thisDetector->nDacs]=myMod->dacs[i]; - } - if (adcs) { - for (int i=0; inAdcs; i++) - adcs[i+imod*thisDetector->nAdcs]=myMod->adcs[i]; + //extra gain and offset - eiger + if(thisDetector->nGain) + controlSocket->ReceiveDataOnly(gainval,sizeof(int)*thisDetector->nGain); + if(thisDetector->nOffset) + controlSocket->ReceiveDataOnly(offsetval,sizeof(int)*thisDetector->nOffset); + } else { + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + } + controlSocket->Disconnect(); + if (ret==FORCE_UPDATE) + updateDetector(); + } } - (detectorModules+imod)->gain=myMod->gain; - (detectorModules+imod)->offset=myMod->offset; - (detectorModules+imod)->serialnumber=myMod->serialnumber; - (detectorModules+imod)->reg=myMod->reg; - } - } - } else { - deleteModule(myMod); - myMod=NULL; - } - return myMod; + + if (ret!=FAIL) { + if (detectorModules) { + if (imod>=0 && imodnMod[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; ichipnChips; ichip++) { + if (chipregs) + chipregs[ichip+thisDetector->nChips*imod]=myMod->chipregs[ichip]; + + if (chanregs) { + for (int i=0; inChans; i++) { + chanregs[i+ichip*thisDetector->nChans+thisDetector->nChips*thisDetector->nChans*imod]=myMod->chanregs[ichip*thisDetector->nChans+i]; + } + } + } + if (dacs) { + for (int i=0; inDacs; i++) + dacs[i+imod*thisDetector->nDacs]=myMod->dacs[i]; + } + if (adcs) { + for (int i=0; inAdcs; 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; inGain; i++) + gain[i+imod*thisDetector->nGain]=gainval[i]; + } + + if ((thisDetector->nOffset) && (offsetval) && (offset)) { + for (int i=0; inOffset; 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 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) { case STANDARD: 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); } + + //settings file**** settingsfname=ostfn.str(); #ifdef VERBOSE cout << "the settings file name is "<myDetectorType, myMod)) { - calfname=oscfn.str(); -#ifdef VERBOSE - cout << calfname << endl; -#endif - - //reads calibration files here! - - - readCalibrationFile(calfname,myMod->gain, myMod->offset); - setModule(*myMod); - - - - } else { - ostringstream ostfn,oscfn; + if (!readSettingsFile(settingsfname,thisDetector->myDetectorType, myMod)) { + //if it didnt open, try default settings file + ostringstream ostfn_default; switch(thisDetector->myDetectorType){ case MOENCH: case GOTTHARD: case PROPIX: case JUNGFRAUCTB: - ostfn << thisDetector->settingsDir << ssettings << ssettings << ".settings"; + ostfn_default << thisDetector->settingsDir << ssettings << ssettings << ".settings"; break; case EIGER: default: - ostfn << thisDetector->settingsDir << ssettings << ssettings << ".trim"; + ostfn_default << thisDetector->settingsDir << ssettings << ssettings << ".trim"; break; } - oscfn << thisDetector->calDir << ssettings << ssettings << ".cal"; - calfname=oscfn.str(); - settingsfname=ostfn.str(); + settingsfname=ostfn_default.str(); #ifdef VERBOSE cout << settingsfname << endl; - cout << calfname << endl; #endif - if (readSettingsFile(settingsfname,thisDetector->myDetectorType, myMod)) { - calfname=oscfn.str(); - readCalibrationFile(calfname,myMod->gain, myMod->offset); - setModule(*myMod); - }else{ + if (!readSettingsFile(settingsfname,thisDetector->myDetectorType, myMod)) { + //if default doesnt work, return error std::cout << "Could not open settings file" << endl; setErrorMask((getErrorMask())|(SETTINGS_FILE_NOT_OPEN)); 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); + if(gainval) delete [] gainval; + if(offsetval) delete [] offsetval; + switch(thisDetector->myDetectorType==MYTHEN){ if (thisDetector->correctionMask&(1<myDetectorType!=MYTHEN) myMod->reg=thisDetector->currentSettings; - setModule(*myMod); + setModule(*myMod,g,o); deleteModule(myMod); } else return FAIL; @@ -5955,7 +6087,21 @@ int slsDetector::loadCalibrationFile(string fname, int imod) { sls_detector_module *myMod=NULL; 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; + + if(thisDetector->nGain) + gainval = new int[thisDetector->nGain]; + if(thisDetector->nOffset) + offsetval = new int[thisDetector->nOffset]; + + int mmin=0, mmax=setNumberOfModules(); if (imod>=0) { mmin=imod; @@ -5973,10 +6119,21 @@ int slsDetector::loadCalibrationFile(string fname, int imod) { } fn=ostfn.str(); if((myMod=getModule(im))){ - if(readCalibrationFile(fn, myMod->gain, myMod->offset)==FAIL) - return FAIL; - setModule(*myMod); + + //extra gain and offset + 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); + if(gainval) delete[]gainval; + if(offsetval) delete offsetval; } else return FAIL; } @@ -6002,7 +6159,13 @@ int slsDetector::saveCalibrationFile(string fname, int imod) { else ostfn << fname << ".sn" << setfill('0') << setw(3) << hex << getId(MODULE_SERIAL_NUMBER,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); }else return FAIL; diff --git a/slsDetectorSoftware/slsDetector/slsDetector.h b/slsDetectorSoftware/slsDetector/slsDetector.h index 3ad0841ad..85112f551 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.h +++ b/slsDetectorSoftware/slsDetector/slsDetector.h @@ -126,11 +126,17 @@ class slsDetector : public slsDetectorUtils, public energyConversion { int nDacs; /** number of adcs per module */ int nAdcs; + /** number of extra gain values*/ + int nGain; + /** number of extra offset values */ + int nOffset; /** dynamic range of the detector data */ int dynamicRange; /** size of the data that are transfered from the detector */ int dataBytes; + + /** corrections to be applied to the data \see ::correctionFlags */ int correctionMask; /** 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; /** memory offsets for the channel register arrays -trimbits*/ int chanoff; - + /** memory offsets for the gain register arrays */ + int gainoff; + /** memory offsets for the offset register arrays -trimbits*/ + int offsetoff; /* receiver*/ @@ -894,10 +903,12 @@ class slsDetector : public slsDetectorUtils, public energyConversion { /** configure chip \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 \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); /** @@ -1770,6 +1781,10 @@ class slsDetector : public slsDetectorUtils, public energyConversion { int *chipregs; /** pointer to channal registers */ int *chanregs; + /** pointer to gain values */ + int *gain; + /** pointer to offset values */ + int *offset; receiverInterface *thisReceiver; diff --git a/slsDetectorSoftware/slsDetectorAnalysis/energyConversion.cpp b/slsDetectorSoftware/slsDetectorAnalysis/energyConversion.cpp index 9999c5a30..818ab8399 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/energyConversion.cpp +++ b/slsDetectorSoftware/slsDetectorAnalysis/energyConversion.cpp @@ -47,7 +47,6 @@ int energyConversion::readCalibrationFile(string fname, double &gain, double &of int energyConversion::writeCalibrationFile(string fname, double gain, double offset){ //std::cout<< "Function not yet implemented " << std::endl; ofstream outfile; - outfile.open (fname.c_str()); // >> 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; - ifstream infile; - double o,g; - int ig=0; - switch (myDetectorType) { - case EIGER: + string str; + ifstream infile; + double o,g; + int ig=0; + switch (myDetectorType) { + case EIGER: #ifdef VERBOSE - std::cout<< "Opening file "<< fname << std::endl; + std::cout<< "Opening file "<< fname << std::endl; #endif - infile.open(fname.c_str(), ios_base::in); - if (infile.is_open()) { - - for (ig=0; ig<4; ig++) { - //while ( (getline(infile,str)) > -1) { - getline(infile,str); + infile.open(fname.c_str(), ios_base::in); + if (infile.is_open()) { + for (ig=0; ig<4; ig++) { + //while ( (getline(infile,str)) > -1) { + getline(infile,str); #ifdef VERBOSE - std::cout<< str << std::endl; + std::cout<< str << std::endl; #endif - istringstream ssstr(str); - ssstr >> o >> g; - offset[ig]=o; - gain[ig]=g; - // ig++; - if (ig>=4) - break; - } - infile.close(); - cout << "Calibration file loaded: " << fname << endl; - } else { - std::cout<< "Could not open calibration file "<< fname << std::endl; - gain[0]=0.; - offset[0]=0.; + istringstream ssstr(str); + ssstr >> o >> g; + offset[ig]=(int)(o*1000); + gain[ig]=(int)(g*1000); + // ig++; + if (ig>=4) + break; + } + infile.close(); + cout << "Calibration file loaded: " << fname << endl; + } else { + cout << "Could not open calibration file: "<< fname << std::endl; + gain[0]=0; + offset[0]=0; #ifndef MYROOT - return FAIL; + return FAIL; #endif - return -1; - } + return -1; + } #ifndef MYROOT - return OK; + return OK; #endif - return 0; - break; - - - - - default: - return readCalibrationFile(fname, *gain, *offset); - } + return 0; + break; + default: + std::cout<< "Writing Calibration Files for this detector not defined\n" << std::endl; + return FAIL; + } }; -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; ofstream outfile; switch (myDetectorType) { @@ -140,7 +135,7 @@ int energyConversion::writeCalibrationFile(string fname, double *gain, double *o // >> i/o operations here << if (outfile.is_open()) { 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 { std::cout<< "Could not open calibration file "<< fname << " for writing" << std::endl; #ifndef MYROOT @@ -156,7 +151,8 @@ int energyConversion::writeCalibrationFile(string fname, double *gain, double *o return 0; break; default: - return writeCalibrationFile(fname, *gain, *offset); + std::cout<< "Writing Calibration Files for this detector not defined\n" << std::endl; + return FAIL; } }; diff --git a/slsDetectorSoftware/slsDetectorAnalysis/energyConversion.h b/slsDetectorSoftware/slsDetectorAnalysis/energyConversion.h index 6242601b5..2768632ba 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/energyConversion.h +++ b/slsDetectorSoftware/slsDetectorAnalysis/energyConversion.h @@ -54,7 +54,7 @@ class energyConversion \param gain reference to the gain 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 @@ -62,7 +62,7 @@ class energyConversion \param gain \param offset */ - static int writeCalibrationFile(string fname, double *gain, double *offset, detectorType myDetectorType); + static int writeCalibrationFile(string fname, int *gain, int *offset, detectorType myDetectorType); diff --git a/slsDetectorSoftware/slsDetectorServer/slsDetectorFunctionList.h b/slsDetectorSoftware/slsDetectorServer/slsDetectorFunctionList.h index 14a0dc2ea..e15b673dd 100644 --- a/slsDetectorSoftware/slsDetectorServer/slsDetectorFunctionList.h +++ b/slsDetectorSoftware/slsDetectorServer/slsDetectorFunctionList.h @@ -60,14 +60,21 @@ int setChip(sls_detector_chip myChip); int getChip(sls_detector_chip *myChip); #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 getModule(sls_detector_module *myMod); +#endif + enum detectorSettings setSettings(enum detectorSettings sett, int imod); #if defined(MYTHEND) || defined(EIGERD) int getThresholdEnergy(int imod); -int setThresholdEnergy(int thr, int imod); +int setThresholdEnergy(int ev, int imod); #endif int startStateMachine(); @@ -118,7 +125,10 @@ int getNumberOfChannelsPerModule(); int getNumberOfChipsPerModule(); int getNumberOfDACsPerModule(); int getNumberOfADCsPerModule(); - +#ifdef EIGERD +int getNumberOfGainsPerModule(); +int getNumberOfOffsetsPerModule(); +#endif enum externalSignalFlag getExtSignal(int signalindex); enum externalSignalFlag setExtSignal(int signalindex, enum externalSignalFlag flag); diff --git a/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.c b/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.c index 17b11eece..870bd9d3d 100755 --- a/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.c +++ b/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.c @@ -1788,11 +1788,15 @@ int get_chip(int file_des) { } int set_module(int file_des) { - int retval, n; + int retval, n,i; int ret=OK,ret1=OK; #ifdef SLS_DETECTOR_FUNCTION_LIST 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 *myChan=(int*)malloc(getNumberOfChannelsPerModule()*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"); 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.nchan=getNumberOfChannelsPerModule(); myModule.ndac=getNumberOfDACsPerModule(); @@ -1834,17 +1847,25 @@ int set_module(int file_des) { printf("Setting module\n"); #endif 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) ret=OK; else 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); +#ifdef EIGERD + for(i=0;i=0) { ret=OK; myModule.module=imod; +#ifdef EIGERD + getModule(&myModule, myGain, myOffset); +#ifdef VERBOSE + for(i=0;i