new feature, set threshold without uploading trimbits

This commit is contained in:
Dhanya Maliakal 2017-06-27 13:00:38 +02:00
parent b1de501bef
commit 6a80bc5b54
14 changed files with 140 additions and 71 deletions

View File

@ -561,6 +561,15 @@ int receiveModuleGeneral(int file_des, sls_detector_module* myMod, int receiveA
myMod->chipregs=chipptr;
myMod->chanregs=chanptr;
#ifdef EIGERD
//feature to exclude sending of trimbtis, nchips=0,nchans=0 in that case
if(myMod->nchip == 0 && myMod->nchan == 0) {
receiveAll=0;
nchipold=0;
nchanold=0;
}
#endif
nChips=myMod->nchip;
nchipdiff=nChips-nchipold;
if (nchipold!=nChips) {
@ -571,6 +580,7 @@ int receiveModuleGeneral(int file_des, sls_detector_module* myMod, int receiveA
printf("received %d chips\n",nChips);
#endif
nChans=myMod->nchan;
nchandiff=nChans-nchanold;
if (nchanold!=nChans) {

View File

@ -627,6 +627,10 @@ int setModule(sls_detector_module myMod, int delay){
for(i=0;i<myMod.ndac;i++)
setDAC((enum detDacIndex)i,myMod.dacs[i],myMod.module,0,retval);
if(myMod.nchan==0 && myMod.nchip == 0)
cprintf(BLUE,"Setting module without trimbits\n");
else{
cprintf(GREEN,"Setting module with trimbits\n");
//includ gap pixels
unsigned int tt[263680];
int iy,ichip,ix,ip=0,ich=0;
@ -647,6 +651,7 @@ int setModule(sls_detector_module myMod, int delay){
cprintf(BG_RED,"Could not set trimbits\n");
return FAIL;
}
}
return thisSettings;
}
@ -1126,11 +1131,13 @@ int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod){
destMod->serialnumber=srcMod->serialnumber;
}
if ((srcMod->nchip)>(destMod->nchip)) {
//no trimbit feature
if (destMod->nchip && ((srcMod->nchip)>(destMod->nchip))) {
printf("Number of chip of source is larger than number of chips of destination\n");
return FAIL;
}
if ((srcMod->nchan)>(destMod->nchan)) {
//no trimbit feature
if (destMod->nchan && ((srcMod->nchan)>(destMod->nchan))) {
printf("Number of channels of source is larger than number of channels of destination\n");
return FAIL;
}
@ -1164,6 +1171,7 @@ int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod){
if (srcMod->offset>=0)
destMod->offset=srcMod->offset;
if((destMod->nchip!=0) || (destMod->nchan!=0)) {
for (ichip=0; ichip<(srcMod->nchip); ichip++) {
if (*((srcMod->chipregs)+ichip)>=0)
*((destMod->chipregs)+ichip)=*((srcMod->chipregs)+ichip);
@ -1172,6 +1180,12 @@ int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod){
if (*((srcMod->chanregs)+ichan)>=0)
*((destMod->chanregs)+ichan)=*((srcMod->chanregs)+ichan);
}
}
#ifdef VERBOSE
printf("Not Copying trimbits\n");
#endif
for (idac=0; idac<(srcMod->ndac); idac++) {
if (*((srcMod->dacs)+idac)>=0)
*((destMod->dacs)+idac)=*((srcMod->dacs)+idac);

View File

@ -1139,7 +1139,7 @@ int multiSlsDetector::getThresholdEnergy(int pos) {
}
int multiSlsDetector::setThresholdEnergy(int e_eV, int pos, detectorSettings isettings) {
int multiSlsDetector::setThresholdEnergy(int e_eV, int pos, detectorSettings isettings, int tb) {
int posmin, posmax;
int ret=-100;
@ -1160,8 +1160,8 @@ int multiSlsDetector::setThresholdEnergy(int e_eV, int pos, detectorSettings ise
for(int idet=posmin; idet<posmax; idet++){
if(detectors[idet]){
iret[idet]= new int(-1);
Task* task = new Task(new func3_t<int,slsDetector,int,int,detectorSettings,int>(&slsDetector::setThresholdEnergy,
detectors[idet],e_eV,-1,isettings,iret[idet]));
Task* task = new Task(new func4_t<int,slsDetector,int,int,detectorSettings,int,int>(&slsDetector::setThresholdEnergy,
detectors[idet],e_eV,-1,isettings,tb, iret[idet]));
threadpool->add_task(task);
}
}

View File

@ -453,9 +453,10 @@ class multiSlsDetector : public slsDetectorUtils {
\param e_eV threshold in eV
\param imod module number (-1 all)
\param isettings ev. change settings
\param tb 1 to include trimbits, 0 to exclude
\returns current threshold value for imod in ev (-1 failed)
*/
int setThresholdEnergy(int e_eV, int imod=-1, detectorSettings isettings=GET_SETTINGS);
int setThresholdEnergy(int e_eV, int imod=-1, detectorSettings isettings=GET_SETTINGS, int tb=1);
/**
get detector settings

View File

@ -2886,7 +2886,7 @@ int slsDetector::setModule(int reg, int imod){
};
int slsDetector::setModule(sls_detector_module module, int iodelay, int tau, int e_eV, int* gainval, int* offsetval){
int slsDetector::setModule(sls_detector_module module, int iodelay, int tau, int e_eV, int* gainval, int* offsetval, int tb){
int fnum=F_SET_MODULE;
int retval;
@ -2903,6 +2903,11 @@ int slsDetector::setModule(sls_detector_module module, int iodelay, int tau, int
if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (connectControl() == OK){
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
//to exclude trimbits
if(!tb) {
module.nchan=0;
module.nchip=0;
}
sendModule(&module);
//not included in module
@ -2936,16 +2941,21 @@ int slsDetector::setModule(sls_detector_module module, int iodelay, int tau, int
if (ret!=FAIL) {
if (detectorModules) {
if (imod>=0 && imod<thisDetector->nMod[X]*thisDetector->nMod[Y]) {
if(tb) {
(detectorModules+imod)->nchan=module.nchan;
(detectorModules+imod)->nchip=module.nchip;
}
(detectorModules+imod)->ndac=module.ndac;
(detectorModules+imod)->nadc=module.nadc;
if(tb) {
thisDetector->nChips=module.nchip;
thisDetector->nChans=module.nchan/module.nchip;
}
thisDetector->nDacs=module.ndac;
thisDetector->nAdcs=module.nadc;
if(thisDetector->myDetectorType != JUNGFRAU){
if(tb) {
for (int ichip=0; ichip<thisDetector->nChips; ichip++) {
if (chipregs)
chipregs[ichip+thisDetector->nChips*imod]=module.chipregs[ichip];
@ -2956,6 +2966,7 @@ int slsDetector::setModule(sls_detector_module module, int iodelay, int tau, int
}
}
}
}
if (adcs) {
for (int i=0; i<thisDetector->nAdcs; i++)
adcs[i+imod*thisDetector->nAdcs]=module.adcs[i];
@ -3182,11 +3193,11 @@ int slsDetector::getThresholdEnergy(int imod){
return thisDetector->currentThresholdEV;
};
int slsDetector::setThresholdEnergy(int e_eV, int imod, detectorSettings isettings){
int slsDetector::setThresholdEnergy(int e_eV, int imod, detectorSettings isettings, int tb){
//currently only for eiger
if (thisDetector->myDetectorType == EIGER) {
setThresholdEnergyAndSettings(e_eV,isettings);
setThresholdEnergyAndSettings(e_eV,isettings,tb);
return thisDetector->currentThresholdEV;
}
@ -3226,7 +3237,7 @@ int slsDetector::setThresholdEnergy(int e_eV, int imod, detectorSettings isetti
int slsDetector::setThresholdEnergyAndSettings(int e_eV, detectorSettings isettings) {
int slsDetector::setThresholdEnergyAndSettings(int e_eV, detectorSettings isettings, int tb) {
//if settings provided, use that, else use the shared memory variable
detectorSettings is = ((isettings != GET_SETTINGS) ? isettings: thisDetector->currentSettings);
@ -3292,7 +3303,7 @@ int slsDetector::setThresholdEnergyAndSettings(int e_eV, detectorSettings isetti
#endif
//read the files
myMod=createModule();
if (NULL == readSettingsFile(settingsfname,thisDetector->myDetectorType, iodelay, tau, myMod)) {
if (NULL == readSettingsFile(settingsfname,thisDetector->myDetectorType, iodelay, tau, myMod, tb)) {
if(myMod)deleteModule(myMod);
return FAIL;
}
@ -3327,13 +3338,13 @@ int slsDetector::setThresholdEnergyAndSettings(int e_eV, detectorSettings isetti
int tau1 = -1; //not included in the module
int iodelay2 = -1; //not included in the module
int tau2 = -1; //not included in the module
if (NULL == readSettingsFile(settingsfname1,thisDetector->myDetectorType, iodelay1, tau1, myMod1)) {
if (NULL == readSettingsFile(settingsfname1,thisDetector->myDetectorType, iodelay1, tau1, myMod1, tb)) {
setErrorMask((getErrorMask())|(SETTINGS_FILE_NOT_OPEN));
deleteModule(myMod1);
deleteModule(myMod2);
return FAIL;
}
if (NULL == readSettingsFile(settingsfname2,thisDetector->myDetectorType, iodelay2, tau2, myMod2)) {
if (NULL == readSettingsFile(settingsfname2,thisDetector->myDetectorType, iodelay2, tau2, myMod2, tb)) {
setErrorMask((getErrorMask())|(SETTINGS_FILE_NOT_OPEN));
deleteModule(myMod1);
deleteModule(myMod2);
@ -3349,7 +3360,7 @@ int slsDetector::setThresholdEnergyAndSettings(int e_eV, detectorSettings isetti
iodelay = iodelay1;
//interpolate module
myMod = interpolateTrim(thisDetector->myDetectorType, myMod1, myMod2, e_eV, trim1, trim2);
myMod = interpolateTrim(thisDetector->myDetectorType, myMod1, myMod2, e_eV, trim1, trim2, tb);
if (myMod == NULL) {
printf("Could not interpolate, different dac values in files\n");
setErrorMask((getErrorMask())|(SETTINGS_NOT_SET));
@ -3365,7 +3376,7 @@ int slsDetector::setThresholdEnergyAndSettings(int e_eV, detectorSettings isetti
myMod->module=0;
myMod->reg=thisDetector->currentSettings;
setModule(*myMod, iodelay, tau, e_eV, 0, 0);
setModule(*myMod, iodelay, tau, e_eV, 0, 0, tb);
deleteModule(myMod);
if (getSettings(-1) != is){
printf( "Could not set settings in detector \n" );

View File

@ -953,10 +953,11 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
\param e_eV threashold in eV (detector specific)
\param gainval pointer to extra gain values
\param offsetval pointer to extra offset values
\param tb 1 to include trimbits, 0 to exclude (used for eiger)
\returns current register value
\sa ::sls_detector_module
*/
int setModule(sls_detector_module module, int iodelay, int tau, int e_eV, int* gainval=0, int* offsetval=0);
int setModule(sls_detector_module module, int iodelay, int tau, int e_eV, int* gainval=0, int* offsetval=0, int tb=1);
//virtual int setModule(sls_detector_module module);
/**
@ -987,17 +988,19 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
\param e_eV threshold in eV
\param imod module number (-1 all)
\param isettings ev. change settings
\param tb 1 to include trimbits, 0 to exclude
\returns current threshold value for imod in ev (-1 failed)
*/
int setThresholdEnergy(int e_eV, int imod=-1, detectorSettings isettings=GET_SETTINGS);
int setThresholdEnergy(int e_eV, int imod=-1, detectorSettings isettings=GET_SETTINGS, int tb=1);
/**
set threshold energy
\param e_eV threshold in eV
\param isettings ev. change settings
\param tb 1 to include trimbits, 0 to exclude
\returns OK if successful, else FAIL
*/
int setThresholdEnergyAndSettings(int e_eV, detectorSettings isettings);
int setThresholdEnergyAndSettings(int e_eV, detectorSettings isettings, int tb=1);
/**
get detector settings

View File

@ -210,7 +210,7 @@ class slsDetectorActions : public virtual slsDetectorBase
/* *\/ */
/* virtual detectorType getDetectorsType(int pos=-1)=0; */
virtual int setThresholdEnergy(int, int im=-1, detectorSettings isettings=GET_SETTINGS)=0;
virtual int setThresholdEnergy(int, int im=-1, detectorSettings isettings=GET_SETTINGS, int tb=1)=0;
virtual int setChannel(int64_t, int ich=-1, int ichip=-1, int imod=-1)=0;

View File

@ -429,7 +429,7 @@ class slsDetectorBase : public virtual slsDetectorDefs, public virtual errorDef
virtual externalCommunicationMode setExternalCommunicationMode(externalCommunicationMode pol=GET_EXTERNAL_COMMUNICATION_MODE)=0;
int setTimingMode(int i=-1){return slsDetectorUsers::getTimingMode( externalCommunicationType( setExternalCommunicationMode(externalCommunicationType( slsDetectorUsers::getTimingMode(i) ) ) ) );};
virtual int setThresholdEnergy(int e_eV, int imod, detectorSettings isettings=GET_SETTINGS)=0;
virtual int setThresholdEnergy(int e_eV, int imod, detectorSettings isettings=GET_SETTINGS, int tb=1)=0;
int setThresholdEnergy(int e_eV){return setThresholdEnergy(e_eV,-1);};

View File

@ -552,6 +552,10 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) {
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSettings;
i++;
descrToFuncMap[i].m_pFuncName="thresholdnotb"; //
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSettings;
i++;
descrToFuncMap[i].m_pFuncName="trimbits"; //
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSettings;
i++;
@ -3289,10 +3293,10 @@ string slsDetectorCommand::cmdSettings(int narg, char *args[], int action) {
return myDet->getDetectorSettings(myDet->getSettings());
} else if (cmd=="threshold") {
if (action==PUT_ACTION) {
detectorType type = myDet->getDetectorsType();
if (!sscanf(args[1],"%d",&val)) {
return string("invalid threshold value");
}
detectorType type = myDet->getDetectorsType();
if (type != EIGER || (type == EIGER && narg<=2)) {
myDet->setThresholdEnergy(val);
} else {
@ -3304,6 +3308,25 @@ string slsDetectorCommand::cmdSettings(int narg, char *args[], int action) {
}
sprintf(ans,"%d",myDet->getThresholdEnergy());
return string(ans);
} else if (cmd=="thresholdnotb") {
if (action==PUT_ACTION) {
if (!sscanf(args[1],"%d",&val)) {
return string("invalid threshold value");
}
detectorType type = myDet->getDetectorsType();
if (type != EIGER)
return string("not implemented for this detector");
if (narg<=2) {
myDet->setThresholdEnergy(val, -1, GET_SETTINGS, 0);
} else {
detectorSettings sett= myDet->getDetectorSettings(string(args[2]));
if(sett == -1)
return string("invalid settings value");
myDet->setThresholdEnergy(val, -1, sett, 0);
}
}
sprintf(ans,"%d",myDet->getThresholdEnergy());
return string(ans);
} else if (cmd=="trimbits") {
if (narg>=2) {
string sval=string(args[1]);
@ -3386,7 +3409,8 @@ string slsDetectorCommand::helpSettings(int narg, char *args[], int action) {
if (action==PUT_ACTION || action==HELP_ACTION) {
os << "settings s \n sets the settings of the detector - can be standard, fast, highgain, dynamicgain, lowgain, mediumgain, veryhighgain"
"lownoise, dynamichg0,fixgain1,fixgain2,forceswitchg1, forceswitchg2"<< std::endl;
os << "threshold eV\n sets the detector threshold in eV"<< std::endl;
os << "threshold eV [sett]\n sets the detector threshold in eV. If sett is provided for eiger, uses settings sett"<< std::endl;
os << "thresholdnotb eV [sett]\n sets the detector threshold in eV without loading trimbits. If sett is provided for eiger, uses settings sett"<< std::endl;
os << "trimbits fname\n loads the trimfile fname to the detector. If no extension is specified, the serial number of each module will be attached."<< std::endl;
os << "trim:mode fname\n trims the detector according to mode (can be noise, beam, improve, fix) and saves the resulting trimbits to file fname."<< std::endl;
os << "trimval i \n sets all the trimbits to i" << std::endl;

View File

@ -421,7 +421,7 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing {
// double* convertAngles(){return convertAngles(currentPosition);};
// virtual double* convertAngles(double pos)=0;
virtual int setThresholdEnergy(int, int im=-1, detectorSettings isettings=GET_SETTINGS)=0;
virtual int setThresholdEnergy(int, int im=-1, detectorSettings isettings=GET_SETTINGS, int tb=1)=0;
virtual int setChannel(int64_t, int ich=-1, int ichip=-1, int imod=-1)=0;
virtual double getRateCorrectionTau()=0;

View File

@ -138,7 +138,7 @@ int energyConversion::writeCalibrationFile(string fname, int *gain, int *offset)
slsDetectorDefs::sls_detector_module* energyConversion::interpolateTrim(detectorType myDetectorType, sls_detector_module* a, sls_detector_module* b, const int energy, const int e1, const int e2){
slsDetectorDefs::sls_detector_module* energyConversion::interpolateTrim(detectorType myDetectorType, sls_detector_module* a, sls_detector_module* b, const int energy, const int e1, const int e2, int tb){
// only implemented for eiger currently (in terms of which dacs)
if(myDetectorType != EIGER) {
printf("Interpolation of Trim values not implemented for this detector!\n");
@ -168,8 +168,10 @@ slsDetectorDefs::sls_detector_module* energyConversion::interpolateTrim(detector
}
//Interpolate all trimbits
if(tb) {
for (int i = 0; i<myMod->nchan; i++)
myMod->chanregs[i] = linearInterpolation(energy, e1, e2, a->chanregs[i], b->chanregs[i]);
}
return myMod;
}
@ -180,7 +182,7 @@ slsDetectorDefs::sls_detector_module* energyConversion::interpolateTrim(detector
/* I/O */
slsDetectorDefs::sls_detector_module* energyConversion::readSettingsFile(string fname, detectorType myDetectorType, int& iodelay, int& tau, sls_detector_module* myMod){
slsDetectorDefs::sls_detector_module* energyConversion::readSettingsFile(string fname, detectorType myDetectorType, int& iodelay, int& tau, sls_detector_module* myMod, int tb){
@ -372,13 +374,14 @@ slsDetectorDefs::sls_detector_module* energyConversion::readSettingsFile(string
infile.read((char*) myMod->dacs,sizeof(dacs_t)*(myMod->ndac));
infile.read((char*)&iodelay,sizeof(iodelay));
infile.read((char*)&tau,sizeof(tau));
infile.read((char*) myMod->chanregs,sizeof(int)*(myMod->nchan));
#ifdef VERBOSE
for(int i=0;i<myMod->ndac;i++)
printf( "dac %d:%d \n", i, myMod->dacs[i] );
printf( "iodelay:%d \n", iodelay );
printf( "tau:%d \n", tau );
#endif
if(tb) {
infile.read((char*) myMod->chanregs,sizeof(int)*(myMod->nchan));
if(infile.eof()){
printf( "Error, could not load trimbits end of file reached: %s \n\n", myfname.c_str() );
if (nflag)
@ -386,6 +389,7 @@ slsDetectorDefs::sls_detector_module* energyConversion::readSettingsFile(string
return NULL;
}
}
infile.close();
strcpy(settingsFile,fname.c_str());
printf("Settings file loaded: %s\n",settingsFile);

View File

@ -88,9 +88,10 @@ class energyConversion
\param energy energy to trim at
\param e1 reference trim value
\param e2 reference trim value
\param tb 1 to include trimbits, 0 to exclude (used for eiger)
\returns the pointer to the module structure with interpolated values or NULL if error
*/
sls_detector_module* interpolateTrim(detectorType myDetectorType, sls_detector_module* a, sls_detector_module* b, const int energy, const int e1, const int e2);
sls_detector_module* interpolateTrim(detectorType myDetectorType, sls_detector_module* a, sls_detector_module* b, const int energy, const int e1, const int e2, int tb=1);
@ -103,10 +104,11 @@ class energyConversion
\param iodelay io delay (detector specific)
\param tau tau (detector specific)
\param myMod pointer to the module structure which has to be set. <BR> If it is NULL a new module structure will be created
\param tb 1 to include trimbits, 0 to exclude (used for eiger)
\returns the pointer to myMod or NULL if reading the file failed
*/
sls_detector_module* readSettingsFile(string fname, detectorType myDetectorType, int& iodelay, int& tau, sls_detector_module* myMod=NULL);
sls_detector_module* readSettingsFile(string fname, detectorType myDetectorType, int& iodelay, int& tau, sls_detector_module* myMod=NULL, int tb=1);
/**
writes a trim/settings file

View File

@ -129,8 +129,8 @@ public:
Task(func2_t <char*,slsDetector,networkParameter,string,string>* t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(t),m12(0),m13(0){};
/* Return: void, Param: none */
Task(func00_t <void,slsDetector>* t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0),m12(t),m13(0){};
/* Return: int, Param: int,int,detectorSettings */
Task(func3_t <int,slsDetector,int,int,detectorSettings,int>* t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0),m12(0),m13(t){};
/* Return: int, Param: int,int,detectorSettings,int */
Task(func4_t <int,slsDetector,int,int,detectorSettings,int,int>* t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0),m12(0),m13(t){};
@ -178,7 +178,7 @@ private:
/* Return: void, Param: none */
func00_t <void,slsDetector>* m12;
/* Return: int, Param: int,int,detectorSettings */
func3_t <int,slsDetector,int,int,detectorSettings,int>* m13;
func4_t <int,slsDetector,int,int,detectorSettings,int,int>* m13;
};