still updating slsdetector.cpp

This commit is contained in:
2018-10-26 17:40:18 +02:00
parent cf87b6ca83
commit 33ac63d14a
16 changed files with 1501 additions and 2523 deletions

View File

@ -24,7 +24,6 @@ const char* dac_names[16] = {"SvP","Vtr","Vrf","Vrs","SvN","Vtgstv","Vcmp_ll","V
int default_tau_from_file= -1;
enum detectorSettings thisSettings;
sls_detector_module *detectorModules=NULL;
int *detectorChips=NULL;
int *detectorChans=NULL;
int *detectorDacs=NULL;
int *detectorAdcs=NULL;
@ -383,26 +382,24 @@ void allocateDetectorStructureMemory() {
//Allocation of memory
detectorModules=malloc(sizeof(sls_detector_module));
detectorChips=malloc(NCHIP*sizeof(int));
detectorChans=malloc(NCHIP*NCHAN*sizeof(int));
detectorDacs=malloc(NDAC*sizeof(int));
detectorAdcs=malloc(NADC*sizeof(int));
FILE_LOG(logDEBUG5, ("modules from 0x%x to 0x%x\n",detectorModules, detectorModules));
FILE_LOG(logDEBUG5, ("chips from 0x%x to 0x%x\n",detectorChips, detectorChips));
FILE_LOG(logDEBUG5, ("chans from 0x%x to 0x%x\n",detectorChans, detectorChans));
FILE_LOG(logDEBUG5, ("dacs from 0x%x to 0x%x\n",detectorDacs, detectorDacs));
FILE_LOG(logDEBUG5, ("adcs from 0x%x to 0x%x\n",detectorAdcs, detectorAdcs));
(detectorModules)->dacs=detectorDacs;
(detectorModules)->adcs=detectorAdcs;
(detectorModules)->chipregs=detectorChips;
(detectorModules)->chanregs=detectorChans;
(detectorModules)->ndac=NDAC;
(detectorModules)->nadc=NADC;
(detectorModules)->nchip=NCHIP;
(detectorModules)->nchan=NCHIP*NCHAN;
(detectorModules)->gain=0;
(detectorModules)->offset=0;
(detectorModules)->reg=0;
(detectorModules)->iodelay=0;
(detectorModules)->tau=0;
(detectorModules)->eV=0;
thisSettings = UNINITIALIZED;
// if trimval requested, should return -1 to acknowledge unknown
@ -805,63 +802,123 @@ int64_t getTimeLeft(enum timerIndex ind) {
/* parameters - channel, chip, module, settings */
/* parameters - channel, module, settings */
int setModule(sls_detector_module myMod, int delay) {
int retval[2];
int i;
int setModule(sls_detector_module myMod, char* mess) {
FILE_LOG(logINFO, ("Setting module with settings %d\n",myMod.reg));
//copy module locally (module number, serial number, gain offset,
//dacs (pointless), trimbit values(if needed)
if (detectorModules)
if (copyModule(detectorModules,&myMod) == FAIL)
return FAIL;
// settings
setSettings( (enum detectorSettings)myMod.reg);
//copy module locally (module number, serial number
//dacs (pointless), trimbit values(if needed)
if (detectorModules) {
if (copyModule(detectorModules,&myMod) == FAIL) {
sprintf(mess, "Could not copy module\n");
FILE_LOG(logERROR, (mess));
setSettings(UNDEFINED);
FILE_LOG(logERROR, ("Settings has been changed to undefined\n"));
return FAIL;
}
}
// iodelay
if (setIODelay(delay)!= delay) {
FILE_LOG(logERROR, ("Could not set iodelay %d\n", delay));
if (setIODelay(myMod.iodelay)!= myMod.iodelay) {
sprintf(mess, "Could not set module. Could not set iodelay %d\n", myMod.iodelay);
FILE_LOG(logERROR, (mess));
setSettings(UNDEFINED);
FILE_LOG(logERROR, ("Settings has been changed to undefined\n"));
return FAIL;
}
// dacs
for(i=0;i<myMod.ndac;i++)
setDAC((enum DACINDEX)i,myMod.dacs[i],0,retval);
// threshold
if (myMod.eV >= 0)
setThresholdEnergy(myMod.eV);
else {
// (loading a random trim file) (dont return fail)
setSettings(UNDEFINED);
FILE_LOG(logERROR, ("Settings has been changed to undefined (random trim file)\n"));
}
// dacs
{
int i = 0;
int retval[2] = {0, 0};
for(i = 0; i < myMod.ndac; ++i) {
setDAC((enum DACINDEX)i, myMod.dacs[i] , 0, retval);
if (myMod.dacs[i] != retval[0]) {
sprintf(mess, "Could not set module. Could not set dac %d\n", i);
FILE_LOG(logERROR, (mess));
setSettings(UNDEFINED);
FILE_LOG(logERROR, ("Settings has been changed to undefined\n"));
return FAIL;
}
}
}
// trimbits
#ifndef VIRTUAL
if (myMod.nchan==0 && myMod.nchip == 0) {
if (myMod.nchan == 0) {
FILE_LOG(logINFO, ("Setting module without trimbits\n"));
} else {
FILE_LOG(logINFO, ("Setting module with trimbits\n"));
//includ gap pixels
unsigned int tt[263680];
int iy,ichip,ix,ip=0,ich=0;
for(iy=0;iy<256;iy++) {
for (ichip=0; ichip<4; ichip++) {
for(ix=0;ix<256;ix++) {
tt[ip++]=myMod.chanregs[ich++];
int iy, ichip, ix, ip = 0, ich = 0;
for (iy = 0; iy < 256; ++iy) {
for (ichip = 0; ichip < 4; ++ichip) {
for (ix = 0; ix < 256; ++ix) {
tt[ip++] = myMod.chanregs[ich++];
}
if (ichip<3) {
tt[ip++]=0;
tt[ip++]=0;
if (ichip < 3) {
tt[ip++] = 0;
tt[ip++] = 0;
}
}
}
//set trimbits
if (!Feb_Control_SetTrimbits(Feb_Control_GetModuleNumber(),tt)) {
FILE_LOG(logERROR, ("Could not set trimbits\n"));
if (!Feb_Control_SetTrimbits(Feb_Control_GetModuleNumber(), tt)) {
sprintf(mess, "Could not set module. Could not set trimbits\n");
FILE_LOG(logERROR, (mess));
setSettings(UNDEFINED);
FILE_LOG(logERROR, ("Settings has been changed to undefined (random trim file)\n"));
return FAIL;
}
}
//rate correction
//switch off rate correction: no value read from load settings)
if (myMod.tau == -1) {
if (getRateCorrectionEnable()) {
setRateCorrection(0);
sprintf(mess,"Cannot set module. Cannot set Rate correction. "
"No default tau provided. Deactivating Rate Correction\n");
FILE_LOG(logERROR, (mess));
setSettings(UNDEFINED);
FILE_LOG(logERROR, ("Settings has been changed to undefined (random trim file)\n"));
return FAIL;
}
}
//normal tau value (only if enabled)
else {
setDefaultSettingsTau_in_nsec(myMod.tau);
if (getRateCorrectionEnable()) {
int64_t retvalTau = setRateCorrection(myMod.tau);
if (myMod.tau != retvalTau) {
sprintf(mess, "Cannot set module. Could not set rate correction\n");
FILE_LOG(logERROR, (mess));
setSettings(UNDEFINED);
FILE_LOG(logERROR, ("Settings has been changed to undefined (random trim file)\n"));
return FAIL;
}
}
}
#endif
return thisSettings;
return OK;
}
@ -882,13 +939,13 @@ int getModule(sls_detector_module *myMod) {
tt = Feb_Control_GetTrimbits();
//exclude gap pixels
int iy,ichip,ix,ip=0,ich=0;
for(iy=0;iy<256;iy++) {
for (ichip=0; ichip<4; ichip++) {
for(ix=0;ix<256;ix++) {
myMod->chanregs[ich++]=tt[ip++];
int iy, ichip, ix, ip = 0, ich = 0;
for (iy = 0; iy < 256; ++iy) {
for (ichip = 0; ichip < 4; ++ichip) {
for (ix = 0; ix < 256; ++iy) {
myMod->chanregs[ich++] = tt[ip++];
}
if (ichip<3) {
if (ichip < 3) {
ip++;
ip++;
}
@ -1728,7 +1785,7 @@ void readFrame(int *ret, char *mess) {
int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod) {
int ichip, idac, ichan, iadc;
int idac, ichan, iadc;
int ret=OK;
FILE_LOG(logDEBUG5, ("Copying module %x to module %x\n",srcMod,destMod));
@ -1738,11 +1795,6 @@ int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod) {
destMod->serialnumber=srcMod->serialnumber;
}
//no trimbit feature
if (destMod->nchip && ((srcMod->nchip)>(destMod->nchip))) {
FILE_LOG(logINFO, ("Number of chip of source is larger than number of chips of destination\n"));
return FAIL;
}
//no trimbit feature
if (destMod->nchan && ((srcMod->nchan)>(destMod->nchan))) {
FILE_LOG(logINFO, ("Number of channels of source is larger than number of channels of destination\n"));
return FAIL;
@ -1758,7 +1810,6 @@ int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod) {
FILE_LOG(logDEBUG5, ("DACs: src %d, dest %d\n",srcMod->ndac,destMod->ndac));
FILE_LOG(logDEBUG5, ("ADCs: src %d, dest %d\n",srcMod->nadc,destMod->nadc));
FILE_LOG(logDEBUG5, ("Chips: src %d, dest %d\n",srcMod->nchip,destMod->nchip));
FILE_LOG(logDEBUG5, ("Chans: src %d, dest %d\n",srcMod->nchan,destMod->nchan));
destMod->ndac=srcMod->ndac;
destMod->nadc=srcMod->nadc;
@ -1766,23 +1817,22 @@ int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod) {
destMod->nchan=srcMod->nchan;
if (srcMod->reg>=0)
destMod->reg=srcMod->reg;
if (srcMod->iodelay>=0)
destMod->iodelay=srcMod->iodelay;
if (srcMod->tau>=0)
destMod->tau=srcMod->tau;
if (srcMod->eV>=0)
destMod->eV=srcMod->eV;
FILE_LOG(logDEBUG5, ("Copying register %x (%x)\n",destMod->reg,srcMod->reg ));
if (srcMod->gain>=0)
destMod->gain=srcMod->gain;
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);
}
if (destMod->nchan!=0) {
for (ichan=0; ichan<(srcMod->nchan); ichan++) {
if (*((srcMod->chanregs)+ichan)>=0)
*((destMod->chanregs)+ichan)=*((srcMod->chanregs)+ichan);
}
}
else FILE_LOG(logINFO, ("Not Copying trimbits\n"));
for (idac=0; idac<(srcMod->ndac); idac++) {
if (*((srcMod->dacs)+idac)>=0) {
*((destMod->dacs)+idac)=*((srcMod->dacs)+idac);
@ -1811,8 +1861,6 @@ int getNumberOfChips() {return NCHIP;}
int getNumberOfDACs() {return NDAC;}
int getNumberOfADCs() {return NADC;}
int getNumberOfChannelsPerChip() {return NCHAN;}
int getNumberOfGains() {return NGAIN;}
int getNumberOfOffsets() {return NOFFSET;}

View File

@ -49,8 +49,6 @@ enum {E_PARALLEL, E_NON_PARALLEL, E_SAFE};
#define NCHIP (4)
#define NADC (0)
#define NDAC (16)
#define NGAIN (0)
#define NOFFSET (0)
#define TEN_GIGA_BUFFER_SIZE (4112)

View File

@ -351,64 +351,36 @@ int receiveDataOnly(int file_des, void* buf,int length) {
int sendModule(int file_des, sls_detector_module *myMod) {
return sendModuleGeneral(file_des, myMod, 1);
}
int sendModuleGeneral(int file_des, sls_detector_module *myMod, int sendAll) {
int ts = 0, n = 0;
int nChips = myMod->nchip;
int nChans = myMod->nchan;
int nAdcs = myMod->nadc;
int nDacs = myMod->ndac;
// send module structure
n = sendData(file_des,&(myMod->serialnumber),sizeof(myMod->serialnumber),INT32);
if (!n) return -1; ts += n;
n = sendData(file_des,&(myMod->nchan),sizeof(myMod->nchan),INT32);
n = sendData(file_des,&(myMod->nchan), sizeof(myMod->nchan), INT32);
if (!n) return -1; ts += n;
n = sendData(file_des,&(myMod->nchip),sizeof(myMod->nchip),INT32);
n = sendData(file_des,&(myMod->nchip), sizeof(myMod->nchip), INT32);
if (!n) return -1; ts += n;
n = sendData(file_des,&(myMod->ndac),sizeof(myMod->ndac),INT32);
n = sendData(file_des,&(myMod->ndac), sizeof(myMod->ndac), INT32);
if (!n) return -1; ts += n;
n = sendData(file_des,&(myMod->nadc),sizeof(myMod->nadc),INT32);
n = sendData(file_des,&(myMod->nadc), sizeof(myMod->nadc), INT32);
if (!n) return -1; ts += n;
n = sendData(file_des,&(myMod->reg),sizeof(myMod->reg),INT32);
n = sendData(file_des,&(myMod->reg), sizeof(myMod->reg), INT32);
if (!n) return -1; ts += n;
n = sendData(file_des,&(myMod->gain), sizeof(myMod->gain),OTHER);
n = sendData(file_des,&(myMod->iodelay), sizeof(myMod->iodelay), INT32);
if (!n) return -1; ts += n;
n = sendData(file_des,&(myMod->offset), sizeof(myMod->offset),OTHER);
n = sendData(file_des,&(myMod->tau), sizeof(myMod->tau), INT32);
if (!n) return -1; ts += n;
FILE_LOG(logDEBUG5, ("module of size %d sent\n",ts));
// send dac
n = sendData(file_des,myMod->dacs,sizeof(int)*nDacs,INT32);
n = sendData(file_des,&(myMod->eV), sizeof(myMod->eV), INT32);
if (!n) return -1; ts += n;
FILE_LOG(logDEBUG5, ("dacs of size %d sent\n",ts));
{
int idac;
for (idac = 0; idac < nDacs; idac++)
FILE_LOG(logDEBUG5, ("dac %d is %d\n",idac,(int)myMod->dacs[idac]));
}
// send adc
n = sendData(file_des,myMod->adcs,sizeof(int)*nAdcs,INT32);
// dacs
n = sendData(file_des,myMod->dacs, sizeof(int)*(myMod->ndac), INT32);
if (!n) return -1; ts += n;
FILE_LOG(logDEBUG5, ("adcs of size %d sent\n", ts));
// some detectors dont require sending all trimbits etc.
if(sendAll) {
// chips
n = sendData(file_des,myMod->chipregs,sizeof(int)*nChips,INT32);
if (!n) return -1; ts += n;
FILE_LOG(logDEBUG5, ("chips of size %d sent\n", ts));
// channels
n = sendData(file_des,myMod->chanregs,sizeof(int)*nChans,INT32);
FILE_LOG(logDEBUG5, ("chans of size %d sent - %d\n", ts, myMod->nchan));
if (!n) return -1; ts += n;
}
// adcs
n = sendData(file_des,myMod->adcs, sizeof(int)*(myMod->nadc), INT32);
if (!n) return -1; ts += n;
// channels
#ifdef EIGERD
n = sendData(file_des,myMod->chanregs, sizeof(int) * (myMod->nchan), INT32);
if (!n) return -1; ts += n;
#endif
FILE_LOG(logDEBUG5, ("module of size %d sent register %x\n", ts, myMod->reg));
return ts;
}
@ -416,149 +388,57 @@ int sendModuleGeneral(int file_des, sls_detector_module *myMod, int sendAll) {
int receiveModule(int file_des, sls_detector_module* myMod) {
return receiveModuleGeneral(file_des,myMod,1);
}
int receiveModuleGeneral(int file_des, sls_detector_module* myMod, int receiveAll) {
int ts = 0, n = 0;
int *dacptr = myMod->dacs;
int *adcptr = myMod->adcs;
int *chipptr = myMod->chipregs, *chanptr = myMod->chanregs;
int nChips, nchipold = myMod->nchip, nchipdiff;
int nChans, nchanold = myMod->nchan, nchandiff;
int nDacs, ndold = myMod->ndac, ndacdiff;
int nAdcs, naold = myMod->nadc, nadcdiff;
n = receiveData(file_des,&(myMod->serialnumber),sizeof(myMod->serialnumber),INT32);
if (!n) return -1; ts += n;
n = receiveData(file_des,&(myMod->nchan),sizeof(myMod->nchan),INT32);
if (!n) return -1; ts += n;
n = receiveData(file_des,&(myMod->nchip),sizeof(myMod->nchip),INT32);
if (!n) return -1; ts += n;
n = receiveData(file_des,&(myMod->ndac),sizeof(myMod->ndac),INT32);
if (!n) return -1; ts += n;
n = receiveData(file_des,&(myMod->nadc),sizeof(myMod->nadc),INT32);
if (!n) return -1; ts += n;
n = receiveData(file_des,&(myMod->reg),sizeof(myMod->reg),INT32);
if (!n) return -1; ts += n;
n = receiveData(file_des,&(myMod->gain), sizeof(myMod->gain),OTHER);
if (!n) return -1; ts += n;
n = receiveData(file_des,&(myMod->offset), sizeof(myMod->offset),OTHER);
if (!n) return -1; ts += n;
myMod->dacs = dacptr;
myMod->adcs = adcptr;
myMod->chipregs = chipptr;
myMod->chanregs = chanptr;
int nDacs = myMod->ndac;
int nAdcs = myMod->nadc;
#ifdef EIGERD
//exclude sending of trimbtis, nchips = 0,nchans = 0 in that case
if(myMod->nchip == 0 && myMod->nchan == 0) {
receiveAll = 0;
nchipold = 0;
nchanold = 0;
}
int nChans = myMod->nchan; // can be zero for no trimbits
#endif
nChips = myMod->nchip;
nchipdiff = nChips-nchipold;
if (nchipold != nChips) {
FILE_LOG(logERROR, ("received wrong number of chips\n"));
n = receiveData(file_des,&(myMod->serialnumber), sizeof(myMod->serialnumber), INT32);
if (!n) return -1; ts += n;
n = receiveData(file_des,&(myMod->nchan), sizeof(myMod->nchan), INT32);
if (!n) return -1; ts += n;
n = receiveData(file_des,&(myMod->nchip), sizeof(myMod->nchip), INT32);
if (!n) return -1; ts += n;
n = receiveData(file_des,&(myMod->ndac), sizeof(myMod->ndac), INT32);
if (!n) return -1; ts += n;
n = receiveData(file_des,&(myMod->nadc), sizeof(myMod->nadc), INT32);
if (!n) return -1; ts += n;
n = receiveData(file_des,&(myMod->reg), sizeof(myMod->reg), INT32);
if (!n) return -1; ts += n;
n = receiveData(file_des,&(myMod->iodelay), sizeof(myMod->iodelay), INT32);
if (!n) return -1; ts += n;
n = receiveData(file_des,&(myMod->tau), sizeof(myMod->tau), INT32);
if (!n) return -1; ts += n;
n = receiveData(file_des,&(myMod->eV), sizeof(myMod->eV), INT32);
if (!n) return -1; ts += n;
// dacs
if (nDacs != (myMod->ndac)) {
FILE_LOG(logERROR, ("received wrong number of dacs. "
"Expected %d, got %d\n", nDacs, myMod->ndac));
return 0;
}
else
FILE_LOG(logDEBUG5, ("received %d chips\n",nChips));
nChans = myMod->nchan;
nchandiff = nChans-nchanold;
if (nchanold != nChans) {
FILE_LOG(logERROR, ("received wrong number of channels\n"));
n = receiveData(file_des,&(myMod->dacs), sizeof(int) * (myMod->ndac), INT32);
if (!n) return -1; ts += n;
// adcs
if (nAdcs != (myMod->nadc)) {
FILE_LOG(logERROR, ("received wrong number of adcs. "
"Expected %d, got %d\n", nAdcs, myMod->nadc));
return 0;
}
else
FILE_LOG(logDEBUG5, ("received %d chans\n",nChans));
nDacs = myMod->ndac;
ndacdiff = nDacs-ndold;
if (ndold != nDacs) {
FILE_LOG(logERROR, ("received wrong number of dacs\n"));
}
else
FILE_LOG(logDEBUG5, ("received %d dacs\n",nDacs));
nAdcs = myMod->nadc;
nadcdiff = nAdcs-naold;
if (naold != nAdcs) {
FILE_LOG(logERROR, ("received wrong number of adcs\n"));
}
else
FILE_LOG(logDEBUG5, ("received %d adcs\n",nAdcs));
if (ndacdiff <= 0) {
n = receiveData(file_des,myMod->dacs, sizeof(int)*nDacs,INT32);
if (!n) return -1; ts += n;
FILE_LOG(logDEBUG5, ("dacs received\n"));
int id;
for (id = 0; id<nDacs; id++)
FILE_LOG(logDEBUG5, ("dac %d val %d\n",id, (int)myMod->dacs[id]));
} else {
dacptr = (int*)malloc(ndacdiff*sizeof(int));
myMod->ndac = ndold;
n = receiveData(file_des,myMod->dacs, sizeof(int)*ndold,INT32);
if (!n) return -1; ts += n;
n = receiveData(file_des,dacptr, sizeof(int)*ndacdiff,INT32);
if (!n) return -1; ts += n;
free(dacptr);
return FAIL;
}
if (nadcdiff <= 0) {
n = receiveData(file_des,myMod->adcs, sizeof(int)*nAdcs,INT32);
if (!n) return -1; ts += n;
FILE_LOG(logDEBUG5, ("adcs received\n"));
} else {
adcptr = (int*)malloc(nadcdiff*sizeof(int));
myMod->nadc = naold;
n = receiveData(file_des,myMod->adcs, sizeof(int)*naold,INT32);
if (!n) return -1; ts += n;
n = receiveData(file_des,adcptr, sizeof(int)*nadcdiff,INT32);
if (!n) return -1; ts += n;
free(adcptr);
return FAIL;
}
// some detectors dont require sending all trimbits etc.
if(receiveAll){
if (nchipdiff <= 0) {
n = receiveData(file_des,myMod->chipregs, sizeof(int)*nChips,INT32);
if (!n) return -1; ts += n;
FILE_LOG(logDEBUG5, ("chips received\n"));
} else {
chipptr = (int*)malloc(nchipdiff*sizeof(int));
myMod->nchip = nchipold;
n = receiveData(file_des,myMod->chipregs, sizeof(int)*nchipold,INT32);
if (!n) return -1; ts += n;
n = receiveData(file_des,chipptr, sizeof(int)*nchipdiff,INT32);
if (!n) return -1; ts += n;
free(chipptr);
return FAIL;
}
if (nchandiff <= 0) {
n = receiveData(file_des,myMod->chanregs, sizeof(int)*nChans,INT32);
if (!n) return -1; ts += n;
FILE_LOG(logDEBUG5, ("chans received\n"));
} else {
chanptr = (int*)malloc(nchandiff*sizeof(int));
myMod->nchan = nchanold;
n = receiveData(file_des,myMod->chanregs, sizeof(int)*nchanold,INT32);
if (!n) return -1; ts += n;
n = receiveData(file_des,chanptr, sizeof(int)*nchandiff,INT32);
if (!n) return -1; ts += n;
free(chanptr);
return FAIL;
}
n = receiveData(file_des,&(myMod->adcs), sizeof(int) * (myMod->nadc), INT32);
if (!n) return -1; ts += n;
// channels
#ifdef EIGERD
if (((myMod->nchan) != 0 ) || // no trimbits
(nChans != (myMod->nchan))) { // with trimbits
FILE_LOG(logERROR, ("received wrong number of channels. "
"Expected %d, got %d\n", nChans, (myMod->nchan)));
return 0;
}
n = receiveData(file_des,&(myMod->chanregs), sizeof(int) * (myMod->nchan), INT32);
if (!n) return -1; ts += n;
#endif
FILE_LOG(logDEBUG5, ("received module of size %d register %x\n",ts,myMod->reg));
return ts;
}

View File

@ -38,9 +38,7 @@ int sendDataOnly(int file_des, void* buf,int length);
int receiveDataOnly(int file_des, void* buf,int length);
int sendModule(int file_des, sls_detector_module *myMod);
int sendModuleGeneral(int file_des, sls_detector_module *myMod, int sendAll);
int receiveModule(int file_des, sls_detector_module* myMod);
int receiveModuleGeneral(int file_des, sls_detector_module* myMod, int receiveAll);
/**
* Servers sets and prints error message for locked server

View File

@ -102,12 +102,7 @@ int64_t getTimeLeft(enum timerIndex ind);
// parameters - module, settings
#ifdef EIGERD
int setModule(sls_detector_module myMod, int delay);
#else
int setModule(sls_detector_module myMod);
#endif
int setModule(sls_detector_module myMod, char* mess);
int getModule(sls_detector_module *myMod);
enum detectorSettings setSettings(enum detectorSettings sett);
enum detectorSettings getSettings();
@ -233,10 +228,6 @@ int getTotalNumberOfChannels();
int getNumberOfChips();
int getNumberOfDACs();
int getNumberOfADCs();
#ifdef EIGERD
int getNumberOfGains();
int getNumberOfOffsets();
#endif
int getNumberOfChannelsPerChip();

View File

@ -156,7 +156,6 @@ const char* getFunctionName(enum detFuncs func) {
case F_LOAD_IMAGE: return "F_LOAD_IMAGE";
case F_READ_COUNTER_BLOCK: return "F_READ_COUNTER_BLOCK";
case F_RESET_COUNTER_BLOCK: return "F_RESET_COUNTER_BLOCK";
case F_CALIBRATE_PEDESTAL: return "F_CALIBRATE_PEDESTAL";
case F_ENABLE_TEN_GIGA: return "F_ENABLE_TEN_GIGA";
case F_SET_ALL_TRIMBITS: return "F_SET_ALL_TRIMBITS";
case F_SET_CTB_PATTERN: return "F_SET_CTB_PATTERN";
@ -221,7 +220,6 @@ void function_table() {
flist[F_LOAD_IMAGE] = &load_image;
flist[F_READ_COUNTER_BLOCK] = &read_counter_block;
flist[F_RESET_COUNTER_BLOCK] = &reset_counter_block;
flist[F_CALIBRATE_PEDESTAL] = &calibrate_pedestal;
flist[F_ENABLE_TEN_GIGA] = &enable_ten_giga;
flist[F_SET_ALL_TRIMBITS] = &set_all_trimbits;
flist[F_SET_CTB_PATTERN] = &set_ctb_pattern;
@ -304,7 +302,7 @@ int M_nofunc(int file_des) {
memset(mess, 0, sizeof(mess));
// to receive any arguments
int n = 0;
int n = 1;
while (n > 0)
n = receiveData(file_des,mess,MAX_STR_LENGTH,OTHER);
@ -320,7 +318,7 @@ int M_nofuncMode(int file_des) {
memset(mess, 0, sizeof(mess));
// to receive any arguments
int n = 0;
int n = 1;
while (n > 0)
n = receiveData(file_des,mess,MAX_STR_LENGTH,OTHER);
@ -836,112 +834,83 @@ int read_register(int file_des) {
int set_module(int file_des) {
ret = OK;
memset(mess, 0, sizeof(mess));
int retval = -1;
enum detectorSettings retval = -1;
sls_detector_module module;
int *myDac = NULL;
int *myAdc = NULL;
int *myChip = NULL;
int *myChan = NULL;
#ifdef EIGERD
int ioDelay = -1;
int tau = -1;
int eV = -1;
#endif
module.dacs = NULL;
module.adcs = NULL;
module.chanregs = NULL;
// allocate to receive arguments
// infinite loop to break out when FAIL or a final OK
while(1) {
// allocate dacs
myDac = (int*)malloc(getNumberOfDACs() * sizeof(int));
// error
if (getNumberOfDACs() > 0 && myDac == NULL) {
ret = FAIL;
sprintf(mess, "Could not allocate dacs\n");
FILE_LOG(logERROR,(mess));
break;
}
// allocate dacs
myDac = (int*)malloc(getNumberOfDACs() * sizeof(int));
// error
if (getNumberOfDACs() > 0 && myDac == NULL) {
ret = FAIL;
sprintf(mess, "Could not allocate dacs\n");
FILE_LOG(logERROR,(mess));
} else
module.dacs = myDac;
// allocate adcs
// allocate adcs
if (ret == OK) {
myAdc = (int*)malloc(getNumberOfADCs() * sizeof(int));
// error
if (getNumberOfADCs() > 0 && myAdc == NULL) {
ret = FAIL;
sprintf(mess,"Could not allocate adcs\n");
FILE_LOG(logERROR,(mess));
break;
}
module.adcs=myAdc;
} else
module.adcs = myAdc;
}
// no need to allocate chips and chans for jungfrau, too much memory
#ifdef JUNGFRAUD
module.chipregs = NULL;
module.chanregs = NULL;
#else
// allocate chips
myChip = (int*)malloc(getNumberOfChips() * sizeof(int));
if (getNumberOfChips() > 0 && myChip == NULL) {
ret = FAIL;
sprintf(mess,"Could not allocate chips\n");
FILE_LOG(logERROR,(mess));
break;
}
module.chipregs = myChip;
// allocate chans
// allocate chans
#ifdef EIGERD
if (ret == OK) {
myChan = (int*)malloc(getTotalNumberOfChannels() * sizeof(int));
if (getTotalNumberOfChannels() > 0 && myChan == NULL) {
ret = FAIL;
sprintf(mess,"Could not allocate chans\n");
FILE_LOG(logERROR,(mess));
break;
}
module.chanregs=myChan;
} else
module.chanregs = myChan;
}
#endif
// receive arguments
if (ret == OK) {
module.nchip = getNumberOfChips();
module.nchan = getTotalNumberOfChannels();
module.ndac = getNumberOfDACs();
module.nadc = getNumberOfADCs();
// receive arguments (0 to partially receive module without trimbits
if (receiveModuleGeneral(file_des, &module, (myDetectorType == JUNGFRAU) ? 0 : 1) < 0) {
if (myChip != NULL) free(myChip);
if (myChan != NULL) free(myChan);
int ts = receiveModule(file_des, &module);
if (ts < 0) {
if (myChan != NULL) free(myChan);
if (myDac != NULL) free(myDac);
if (myAdc != NULL) free(myAdc);
return printSocketReadError();
}
FILE_LOG(logDEBUG5, ("module register is %d, nchan %d, nchip %d, "
"ndac %d, nadc %d, gain %f, offset %f\n",
"ndac %d, nadc %d, iodelay %d, tau %d, eV %d\n",
module.reg, module.nchan, module.nchip,
module.ndac, module.nadc, module.gain,module.offset));
#ifdef EIGERD
int args[3] = {-1, -1};
if (receiveData(file_des, args, sizeof(args), INT32) < 0) {
if (myChip != NULL) free(myChip);
if (myChan != NULL) free(myChan);
if (myDac != NULL) free(myDac);
if (myAdc != NULL) free(myAdc);
return printSocketReadError();
}
ioDelay = args[0];
tau = args[1];
eV = args[2];
FILE_LOG(logDEBUG5, ("ioDelay: %d, tau: d, ev:%d\n", ioDelay, tau, eV));
#endif
module.ndac, module.nadc, module.iodelay, module.tau, module.eV));
// should at least have a dac
if (ts <= sizeof(sls_detector_module)) {
ret = FAIL;
sprintf(mess, "Cannot set module. Received incorrect number of dacs or adcs or channels\n");
FILE_LOG(logERROR,(mess));
}
}
// receive all arguments
if (ret == FAIL) {
int n = 0;
int n = 1;
while (n > 0)
n = receiveData(file_des, mess, MAX_STR_LENGTH, OTHER);
}
// only set
else if (Server_VerifyLock() != FAIL) {
// check index
@ -972,52 +941,12 @@ int set_module(int file_des) {
break;
}
// set
#ifndef EIGERD
retval = setModule(module);
validate(module.reg, retval, "set module (settings)", 0);
// eiger
#else
//set dacs, trimbits and iodelay
ret = setModule(module, ioDelay);
//set threshhold
if (eV >= 0)
setThresholdEnergy(eV);
else {
//changes settings to undefined (loading a random trim file)
setSettings(UNDEFINED);
FILE_LOG(logERROR, ("Settings has been changed to undefined "
"(random trim file)\n"));
}
//rate correction
//switch off rate correction: no value read from load calib/load settings)
if (tau == -1) {
if (getRateCorrectionEnable()) {
setRateCorrection(0);
ret = FAIL;
sprintf(mess,"Cannot set module. Cannot set Rate correction. "
"No default tau provided. Deactivating Rate Correction\n");
FILE_LOG(logERROR, (mess));
}
}
//normal tau value (only if enabled)
else {
setDefaultSettingsTau_in_nsec(tau);
if (getRateCorrectionEnable()) {
int64_t retvalTau = setRateCorrection(tau);
if (tau != retvalTau) {
ret = FAIL;
sprintf(mess, "Cannot set module. Could not set rate correction\n");
FILE_LOG(logERROR, (mess));
}
}
}
ret = setModule(module, mess);
retval = getSettings();
#endif
validate(module.reg, (int)retval, "set module (settings)", 0);
FILE_LOG(logDEBUG5, ("Settings: %d\n", retval));
}
if (myChip != NULL) free(myChip);
if (myChan != NULL) free(myChan);
if (myChan != NULL) free(myChan);
if (myDac != NULL) free(myDac);
if (myAdc != NULL) free(myAdc);
return Server_SendResult(file_des, INT32, 1, &retval, sizeof(retval));
@ -1026,70 +955,55 @@ int set_module(int file_des) {
int get_module(int file_des) {
ret = OK;
memset(mess, 0, sizeof(mess));
sls_detector_module module;
int *myDac = NULL;
int *myAdc = NULL;
int *myChip = NULL;
int *myChan = NULL;
module.dacs = NULL;
module.adcs = NULL;
module.chanregs = NULL;
// allocate to send arguments
// infinite loop to break out when FAIL or a final OK
while(1) {
// allocate dacs
myDac = (int*)malloc(getNumberOfDACs() * sizeof(int));
// error
if (getNumberOfDACs() > 0 && myDac == NULL) {
ret = FAIL;
sprintf(mess, "Could not allocate dacs\n");
FILE_LOG(logERROR,(mess));
break;
}
// allocate dacs
myDac = (int*)malloc(getNumberOfDACs() * sizeof(int));
// error
if (getNumberOfDACs() > 0 && myDac == NULL) {
ret = FAIL;
sprintf(mess, "Could not allocate dacs\n");
FILE_LOG(logERROR,(mess));
} else
module.dacs = myDac;
// allocate adcs
// allocate adcs
if (ret == OK) {
myAdc = (int*)malloc(getNumberOfADCs() * sizeof(int));
// error
if (getNumberOfADCs() > 0 && myAdc == NULL) {
ret = FAIL;
sprintf(mess,"Could not allocate adcs\n");
FILE_LOG(logERROR,(mess));
break;
}
module.adcs=myAdc;
} else
module.adcs=myAdc;
}
// no need to allocate chips and chans for jungfrau, too much memory
#ifdef JUNGFRAUD
module.chipregs = NULL;
module.chanregs = NULL;
#else
// allocate chips
myChip = (int*)malloc(getNumberOfChips() * sizeof(int));
if (getNumberOfChips() > 0 && myChip == NULL) {
ret = FAIL;
sprintf(mess,"Could not allocate chips\n");
FILE_LOG(logERROR,(mess));
break;
}
module.chipregs = myChip;
// allocate chans
// allocate chans
#ifdef EIGERD
if (ret == OK) {
myChan = (int*)malloc(getTotalNumberOfChannels() * sizeof(int));
if (getTotalNumberOfChannels() > 0 && myChan == NULL) {
ret = FAIL;
sprintf(mess,"Could not allocate chans\n");
FILE_LOG(logERROR,(mess));
break;
}
module.chanregs=myChan;
} else
module.chanregs=myChan;
}
#endif
// get module
if (ret == OK) {
module.nchip = getNumberOfChips();
module.nchan = getTotalNumberOfChannels();
module.ndac = getNumberOfDACs();
@ -1105,10 +1019,9 @@ int get_module(int file_des) {
// send module, 0 is to receive partially (without trimbits etc)
if (ret != FAIL) {
ret = sendModuleGeneral(file_des, &module, (myDetectorType == JUNGFRAU) ? 0 : 1);
ret = sendModule(file_des, &module);
}
if (myChip != NULL) free(myChip);
if (myChan != NULL) free(myChan);
if (myChan != NULL) free(myChan);
if (myDac != NULL) free(myDac);
if (myAdc != NULL) free(myAdc);
return ret;
@ -2014,7 +1927,6 @@ int load_image(int file_des) {
ret = OK;
memset(mess, 0, sizeof(mess));
int args[2] = {-1, -1};
int retval = -1;
if (receiveData(file_des, args, sizeof(args), INT32) < 0)
return printSocketReadError();
@ -2039,10 +1951,9 @@ int load_image(int file_des) {
switch (index) {
case DARK_IMAGE :
case GAIN_IMAGE :
retval = loadImage(index, ImageVals);
FILE_LOG(logDEBUG5, ("Loading image retval: %d\n", retval));
if (retval == -1) {
ret = FAIL;
ret = loadImage(index, ImageVals);
FILE_LOG(logDEBUG5, ("Loading image ret: %d\n", ret));
if (ret == FAIL) {
sprintf(mess, "Could not load image\n");
FILE_LOG(logERROR,(mess));
}
@ -2053,7 +1964,7 @@ int load_image(int file_des) {
}
}
#endif
return Server_SendResult(file_des, INT32, 1, &retval, sizeof(retval));
return Server_SendResult(file_des, INT32, 1, NULL, 0);
}
@ -2096,8 +2007,6 @@ int reset_counter_block(int file_des) {
ret = OK;
memset(mess, 0, sizeof(mess));
int startACQ = -1;
char retval[dataBytes];
memset(retval, 0, dataBytes);
if (receiveData(file_des, &startACQ, sizeof(startACQ), INT32) < 0)
return printSocketReadError();
@ -2109,7 +2018,7 @@ int reset_counter_block(int file_des) {
// only set
if (Server_VerifyLock() != FAIL) {
ret = resetCounterBlock(startACQ, retval);
ret = resetCounterBlock(startACQ);
if (ret == FAIL) {
strcpy(mess, "Could not reset counter block\n");
FILE_LOG(logERROR, (mess));
@ -2123,27 +2032,6 @@ int reset_counter_block(int file_des) {
int calibrate_pedestal(int file_des) {
ret = OK;
memset(mess, 0, sizeof(mess));
int frames = -1;
int retval = -1;
if (receiveData(file_des, &frames, sizeof(frames), INT32) < 0)
return printSocketReadError();
FILE_LOG(logDEBUG5, ("Calibrate pedestal, frames: %d\n", frames));
functionNotImplemented();
return Server_SendResult(file_des, INT32, 1, &retval, sizeof(retval));
}
int enable_ten_giga(int file_des) {
ret = OK;
memset(mess, 0, sizeof(mess));
@ -2215,12 +2103,12 @@ int set_ctb_pattern(int file_des) {
int write_adc_register(int file_des) {
ret = OK;
memset(mess, 0, sizeof(mess));
int args[2] = {-1, -1};
uint32_t args[2] = {-1, -1};
if (receiveData(file_des, args, sizeof(args), INT32) < 0)
return printSocketReadError();
int addr = args[0];
int val = args[1];
uint32_t addr = args[0];
uint32_t val = args[1];
FILE_LOG(logDEBUG5, ("Writing 0x%x to ADC Register 0x%x\n", val, addr));
#ifndef JUNGFRAUD
@ -2484,7 +2372,7 @@ int program_fpga(int file_des) {
FILE_LOG(logDEBUG5, ("Programming FPGA\n"));
#ifndef JUNGFRAUD
//to receive any arguments
int n = 0;
int n = 1;
while (n > 0)
n = receiveData(file_des,mess,MAX_STR_LENGTH,OTHER);
functionNotImplemented();
@ -2708,7 +2596,7 @@ int prepare_acquisition(int file_des) {
// stop server
int threshold_temp(int file_des) {
ret = OK;
memset(mess, 0, sizeof(mess));
@ -2738,11 +2626,11 @@ int threshold_temp(int file_des) {
}
}
#endif
return Server_SendResult(file_des, INT32, 1, &retval, sizeof(retval));
return Server_SendResult(file_des, INT32, 0, &retval, sizeof(retval));
}
// stop server
int temp_control(int file_des) {
ret = OK;
memset(mess, 0, sizeof(mess));
@ -2763,12 +2651,12 @@ int temp_control(int file_des) {
validate(arg, retval, "set temperature control", 0);
}
#endif
return Server_SendResult(file_des, INT32, 1, &retval, sizeof(retval));
return Server_SendResult(file_des, INT32, 0, &retval, sizeof(retval));
}
// stop server
int temp_event(int file_des) {
ret = OK;
memset(mess, 0, sizeof(mess));
@ -2789,7 +2677,7 @@ int temp_event(int file_des) {
validate(arg, retval, "set temperature event", 0);
}
#endif
return Server_SendResult(file_des, INT32, 1, &retval, sizeof(retval));
return Server_SendResult(file_des, INT32, 0, &retval, sizeof(retval));
}

View File

@ -2196,14 +2196,7 @@ int multiSlsDetector::writeAdcRegister(int addr, int val, int detPos) {
// multi
auto r = parallelCall(&slsDetector::writeAdcRegister, addr, val);
if (sls::allEqual(r))
return r.front();
// can't have different values
FILE_LOG(logERROR) << "Error: Different Values for function writeAdcRegister "
"(write 0x" << std::hex << val << " to addr 0x" << std::hex << addr << std::dec << ")";
setErrorMask(getErrorMask() | MULTI_HAVE_DIFFERENT_VALUES);
return -1;
return sls::allEqualTo(r, static_cast<int>(OK)) ? OK : FAIL;
}
@ -2458,33 +2451,22 @@ int multiSlsDetector::setAutoComparatorDisableMode(int ival, int detPos) {
}
int multiSlsDetector::getChanRegs(double* retval, bool fromDetector, int detPos) {
int multiSlsDetector::getChanRegs(double* retval, int detPos) {
int offset = 0;
std::vector<int> r;
for (auto& d : detectors) {
int nch = d->getTotalNumberOfChannels();
double result[nch];
r.push_back(d->getChanRegs(result, fromDetector));
r.push_back(d->getChanRegs(result));
memcpy(retval + offset, result, nch * sizeof(double));
}
return sls::minusOneIfDifferent(r);
}
int multiSlsDetector::calibratePedestal(int frames, int detPos) {
// single
if (detPos >= 0) {
return detectors[detPos]->calibratePedestal(frames);
}
// multi
auto r = parallelCall(&slsDetector::calibratePedestal, frames);
return sls::minusOneIfDifferent(r);
}
int multiSlsDetector::setRateCorrection(int t, int detPos) {
int multiSlsDetector::setRateCorrection(int64_t t, int detPos) {
// single
if (detPos >= 0) {
return detectors[detPos]->setRateCorrection(t);
@ -2496,7 +2478,7 @@ int multiSlsDetector::setRateCorrection(int t, int detPos) {
}
int multiSlsDetector::getRateCorrection(int detPos) {
int64_t multiSlsDetector::getRateCorrection(int detPos) {
// single
if (detPos >= 0) {
return detectors[detPos]->getRateCorrection();
@ -2508,15 +2490,14 @@ int multiSlsDetector::getRateCorrection(int detPos) {
}
int multiSlsDetector::printReceiverConfiguration(int detPos) {
void multiSlsDetector::printReceiverConfiguration(int detPos) {
// single
if (detPos >= 0) {
return detectors[detPos]->printReceiverConfiguration();
}
// multi
auto r = parallelCall(&slsDetector::printReceiverConfiguration);
return sls::allEqualTo(r, static_cast<int>(OK)) ? OK : FAIL;
parallelCall(&slsDetector::printReceiverConfiguration);
}

View File

@ -1153,21 +1153,10 @@ public:
/**
* Returns the trimbits from the detector's shared memmory (Mythen, Eiger)
* @param retval is the array with the trimbits
* @param fromDetector is true if the trimbits shared memory have to be
* uploaded from detector
* @param detPos -1 for all detectors in list or specific detector position
* @returns total number of channels for the detector
*/
int getChanRegs(double* retval,bool fromDetector, int detPos = -1);
/**
* Calibrate Pedestal (ChipTestBoard)
* Starts acquisition, calibrates pedestal and writes to fpga
* @param frames number of frames
* @param detPos -1 for all detectors in list or specific detector position
* @returns number of frames
*/
int calibratePedestal(int frames = 0, int detPos = -1);
int getChanRegs(double* retval, int detPos = -1);
/**
* Set Rate correction ( Eiger)
@ -1177,21 +1166,20 @@ public:
* @param detPos -1 for all detectors in list or specific detector position
* @returns 0 if rate correction disabled, >0 otherwise
*/
int setRateCorrection(int t=0, int detPos = -1);
int setRateCorrection(int64_t t = 0, int detPos = -1);
/**
* Get rate correction ( Eiger)
* @param detPos -1 for all detectors in list or specific detector position
* @returns 0 if rate correction disabled, > 0 otherwise (ns)
*/
int getRateCorrection(int detPos = -1);
int64_t getRateCorrection(int detPos = -1);
/**
* Prints receiver configuration
* @param detPos -1 for all detectors in list or specific detector position
* @returns OK or FAIL
*/
int printReceiverConfiguration(int detPos = -1);
void printReceiverConfiguration(int detPos = -1);
/**
* Sets up receiver socket if online and sets the flag

File diff suppressed because it is too large Load Diff

View File

@ -32,8 +32,6 @@ typedef struct detParameterList {
int nChipY;
int nDacs;
int nAdcs;
int nGain;
int nOffset;
int dynamicRange;
int nGappixelsX;
int nGappixelsY;
@ -112,12 +110,6 @@ private:
/** 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;
@ -158,18 +150,9 @@ private:
/** memory offsets for the adc arrays */
int adcoff;
/** memory offsets for the chip register arrays */
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;
/** ip address/hostname of the receiver for client control via TCP */
char receiver_hostname[MAX_STR_LENGTH];
@ -622,12 +605,10 @@ public:
* Writes a trim/settings file for module number
* the values will be read from the current detector structure
* @param fname name of the file to be written
* @param iodelay io delay (detector specific)
* @param tau tau (detector specific)
* @returns OK or FAIL if the file could not be written
* \sa ::sls_detector_module sharedSlsDetector mythenDetector::writeSettingsFile(string, int)
*/
int writeSettingsFile(std::string fname, int iodelay, int tau);
int writeSettingsFile(std::string fname);
/**
* Get detector settings
@ -1073,11 +1054,11 @@ public:
/**
* Gets counter memory block in detector (Gotthard)
* @param arg counter memory block from detector
* @param image counter memory block from detector
* @param startACQ 1 to start acquisition afterwards, else 0
* @returns OK or FAIL
*/
int getCounterBlock(short int arg[],int startACQ=0);
int getCounterBlock(short int image[],int startACQ=0);
/**
* Resets counter in detector
@ -1276,10 +1257,8 @@ public:
/**
* Returns the trimbits from the detector's shared memmory (Mythen, Eiger)
* Returns the trimbits from the detector's shared memmory (Eiger)
* @param retval is the array with the trimbits
* @param fromDetector is true if the trimbits shared memory have to be
* uploaded from detector
* @returns total number of channels for the detector
*/
int getChanRegs(double* retval,bool fromDetector);
@ -1289,17 +1268,11 @@ public:
* Called for loading trimbits and settings settings to the detector
* @param module module to be set - must contain correct module number and
* also channel and chip registers
* @param iodelay iodelay (detector specific)
* @param tau tau (detector specific)
* @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 ok or fail
* \sa ::sls_detector_module
*/
int setModule(sls_detector_module module, int iodelay, int tau, int e_eV,
int* gainval=0, int* offsetval=0, int tb=1);
int setModule(sls_detector_module module, int tb = 1);
/**
@ -1308,14 +1281,6 @@ public:
*/
sls_detector_module *getModule();
/**
* Calibrate Pedestal (ChipTestBoard)
* Starts acquisition, calibrates pedestal and writes to fpga
* @param frames number of frames
* @returns number of frames
*/
int calibratePedestal(int frames = 0);
/**
* Set Rate correction (Mythen, Eiger)
* @param t dead time in ns - if 0 disable correction,
@ -1323,19 +1288,19 @@ public:
* for current settings
* @returns 0 if rate correction disabled, >0 otherwise
*/
int setRateCorrection(int t=0);
int setRateCorrection(int64_t t = 0);
/**
* Get rate correction Eiger)
* @returns 0 if rate correction disabled, > 0 otherwise
*/
int getRateCorrection();
int64_t getRateCorrection();
/**
* Prints receiver configuration
* @returns OK or FAIL
* #param level print level
*/
int printReceiverConfiguration();
void printReceiverConfiguration(int level = logINFO);
/**
* Checks if receiver is online and set flag
@ -1824,28 +1789,21 @@ private:
/**
* reads a trim/settings file
* @param fname name of the file to be read
* @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(std::string fname,
int& iodelay, int& tau,
sls_detector_module* myMod=NULL, int tb=1);
sls_detector_module* readSettingsFile(std::string fname, sls_detector_module* myMod=NULL, int tb=1);
/**
* writes a trim/settings file
* @param fname name of the file to be written
* @param mod module structure which has to be written to file
* @param iodelay io delay (detector specific)
* @param tau tau (detector specific)
* @returns OK or FAIL if the file could not be written
*/
int writeSettingsFile(std::string fname,
sls_detector_module mod, int iodelay, int tau);
int writeSettingsFile(std::string fname, sls_detector_module mod);
/** slsDetector Id or position in the detectors list */
@ -1884,17 +1842,8 @@ private:
/** pointer to adc valuse in shared memory */
int *adcs;
/** pointer to chip registers in shared memory */
int *chipregs;
/** pointer to channal registers in shared memory */
int *chanregs;
/** pointer to gain values in shared memory */
int *gain;
/** pointer to offset values in shared memory */
int *offset;
};
#endif

View File

@ -924,14 +924,6 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) {
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSettings;
++i;
/*! \page settings
- <b>pedestal [i]</b> starts acquisition for i frames, calculates pedestal and writes back to fpga. Used in GOTTHARD only. Only put! \c Returns \c (int)
*/
descrToFuncMap[i].m_pFuncName="pedestal"; //
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSettings;
++i;
/* pots */
/*! \page settings
@ -2725,16 +2717,16 @@ string slsDetectorCommand::cmdRateCorr(int narg, char *args[], int action, int d
if (action==HELP_ACTION) {
return helpRateCorr(action);
}
int fval;
int64_t ival;
char answer[1000];
myDet->setOnline(ONLINE_FLAG, detPos);
if (action==PUT_ACTION) {
sscanf(args[1],"%d",&fval);
myDet->setRateCorrection(fval, detPos);
sscanf(args[1],"%lld",&ival);
myDet->setRateCorrection(ival, detPos);
}
sprintf(answer,"%d",myDet->getRateCorrection(detPos));
sprintf(answer,"%lld",myDet->getRateCorrection(detPos));
return string(answer);
}
@ -3549,15 +3541,6 @@ string slsDetectorCommand::cmdSettings(int narg, char *args[], int action, int d
}
sprintf(ans,"%d",myDet->setAllTrimbits(-1, detPos));
return ans;
} else if (cmd=="pedestal") {
if (action==GET_ACTION)
return string("cannot get");
if (sscanf(args[1],"%d",&val)){
sprintf(ans,"%d",myDet->calibratePedestal(val, detPos));
return string(ans);
}else
return string("cannot parse frame number")+cmd;
}
return string("unknown settings command ")+cmd;
@ -3574,8 +3557,6 @@ string slsDetectorCommand::helpSettings(int action) {
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 << "trimval i \n sets all the trimbits to i" << std::endl;
os << "pedestal i \n starts acquisition for i frames, calculates pedestal and writes back to fpga."<< std::endl;
}
if (action==GET_ACTION || action==HELP_ACTION) {
os << "settings \n gets the settings of the detector"<< std::endl;

View File

@ -55,7 +55,7 @@ class slsReceiverImplementation: private virtual slsDetectorDefs {
/*
* Get detector hostname
* @return NULL or hostname or NULL if uninitialized (max of 1000 characters)
* @return hostname (max of 1000 characters)
*/
char *getDetectorHostname() const;
@ -80,13 +80,13 @@ class slsReceiverImplementation: private virtual slsDetectorDefs {
fileFormat getFileFormat() const;
/**
* Get File Name Prefix (without frame index, file index and extension (_d0_f000000000000_8.raw))
* @return NULL or file name prefix (max of 1000 characters)
* @return file name prefix
*/
char *getFileName() const;
/**
* Get File Path
* @return NULL or file path (max of 1000 characters)
* @return file path
*/
char *getFilePath() const;
@ -162,7 +162,7 @@ class slsReceiverImplementation: private virtual slsDetectorDefs {
/**
* Get Ehernet Interface
* @ethernet interface. eg. eth0 or "" if listening to all (max of 1000 characters)
* @ethernet interface. eg. eth0 or "" if listening to all
*/
char *getEthernetInterface() const;

View File

@ -146,15 +146,7 @@ int slsReceiverImplementation::getDetectorPositionId() const{
char *slsReceiverImplementation::getDetectorHostname() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
//not initialized
if(!strlen(detHostname))
return NULL;
char* output = new char[MAX_STR_LENGTH]();
strcpy(output,detHostname);
//freed by calling function
return output;
return detHostname;
}
int slsReceiverImplementation::getFlippedData(int axis) const{
@ -177,28 +169,12 @@ slsDetectorDefs::fileFormat slsReceiverImplementation::getFileFormat() const{
char *slsReceiverImplementation::getFileName() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
//not initialized
if(!strlen(fileName))
return NULL;
char* output = new char[MAX_STR_LENGTH]();
strcpy(output,fileName);
//freed by calling function
return output;
return fileName;
}
char *slsReceiverImplementation::getFilePath() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
//not initialized
if(!strlen(filePath))
return NULL;
char* output = new char[MAX_STR_LENGTH]();
strcpy(output,filePath);
//freed by calling function
return output;
return filePath;
}
uint64_t slsReceiverImplementation::getFileIndex() const{
@ -296,11 +272,7 @@ uint32_t slsReceiverImplementation::getUDPPortNumber2() const{
char *slsReceiverImplementation::getEthernetInterface() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
char* output = new char[MAX_STR_LENGTH]();
strcpy(output,eth);
//freed by calling function
return output;
return eth;
}
@ -397,21 +369,12 @@ uint32_t slsReceiverImplementation::getStreamingPort() const{
char *slsReceiverImplementation::getStreamingSourceIP() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
char* output = new char[MAX_STR_LENGTH]();
strcpy(output,streamingSrcIP);
//freed by calling function
return output;
return streamingSrcIP;
}
char *slsReceiverImplementation::getAdditionalJsonHeader() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
char* output = new char[MAX_STR_LENGTH]();
memset(output, 0, MAX_STR_LENGTH);
strcpy(output,additionalJsonHeader);
//freed by calling function
return output;
return additionalJsonHeader;
}
uint32_t slsReceiverImplementation::getUDPSocketBufferSize() const {

View File

@ -370,6 +370,7 @@ int slsReceiverTCPIPInterface::lock_receiver() {
int slsReceiverTCPIPInterface::get_last_client_ip() {
ret = OK;
memset(mess, 0, sizeof(mess));
return interface->Server_SendResult(true, ret,mySock->lastClientIP, sizeof(mySock->lastClientIP));
}
@ -446,97 +447,82 @@ int slsReceiverTCPIPInterface::update_client() {
int slsReceiverTCPIPInterface::send_update() {
int ind = -1;
char defaultVal[MAX_STR_LENGTH] = {0};
char* path = NULL;
char path[MAX_STR_LENGTH] = {0};
int n = 0;
n += mySock->SendDataOnly(mySock->lastClientIP,sizeof(mySock->lastClientIP));
// filepath
path = receiver->getFilePath();
if (path == NULL)
n += mySock->SendDataOnly(defaultVal,MAX_STR_LENGTH);
else {
n += mySock->SendDataOnly(path,MAX_STR_LENGTH);
delete[] path;
}
n += mySock->SendDataOnly(path, sizeof(path));
// filename
path = receiver->getFileName();
if(path == NULL)
n += mySock->SendDataOnly(defaultVal,MAX_STR_LENGTH);
else {
n += mySock->SendDataOnly(path,MAX_STR_LENGTH);
delete[] path;
}
n += mySock->SendDataOnly(path, sizeof(path));
// index
ind=receiver->getFileIndex();
n += mySock->SendDataOnly(&ind,sizeof(ind));
n += mySock->SendDataOnly(&ind, sizeof(ind));
//file format
ind=(int)receiver->getFileFormat();
n += mySock->SendDataOnly(&ind,sizeof(ind));
n += mySock->SendDataOnly(&ind, sizeof(ind));
//frames per file
ind=(int)receiver->getFramesPerFile();
n += mySock->SendDataOnly(&ind,sizeof(ind));
n += mySock->SendDataOnly(&ind, sizeof(ind));
//frame discard policy
ind=(int)receiver->getFrameDiscardPolicy();
n += mySock->SendDataOnly(&ind,sizeof(ind));
n += mySock->SendDataOnly(&ind, sizeof(ind));
//frame padding
ind=(int)receiver->getFramePaddingEnable();
n += mySock->SendDataOnly(&ind,sizeof(ind));
n += mySock->SendDataOnly(&ind, sizeof(ind));
// file write enable
ind=(int)receiver->getFileWriteEnable();
n += mySock->SendDataOnly(&ind,sizeof(ind));
n += mySock->SendDataOnly(&ind, sizeof(ind));
// file overwrite enable
ind=(int)receiver->getOverwriteEnable();
n += mySock->SendDataOnly(&ind,sizeof(ind));
n += mySock->SendDataOnly(&ind, sizeof(ind));
// gap pixels
ind=(int)receiver->getGapPixelsEnable();
n += mySock->SendDataOnly(&ind,sizeof(ind));
n += mySock->SendDataOnly(&ind, sizeof(ind));
// streaming frequency
ind=(int)receiver->getStreamingFrequency();
n += mySock->SendDataOnly(&ind,sizeof(ind));
n += mySock->SendDataOnly(&ind, sizeof(ind));
// streaming port
ind=(int)receiver->getStreamingPort();
n += mySock->SendDataOnly(&ind,sizeof(ind));
n += mySock->SendDataOnly(&ind, sizeof(ind));
// streaming source ip
path = receiver->getStreamingSourceIP();
mySock->SendDataOnly(path,MAX_STR_LENGTH);
if (path != NULL)
delete[] path;
n += mySock->SendDataOnly(path, sizeof(path));
// additional json header
path = receiver->getAdditionalJsonHeader();
mySock->SendDataOnly(path,MAX_STR_LENGTH);
if (path != NULL)
delete[] path;
n += mySock->SendDataOnly(path, sizeof(path));
// data streaming enable
ind=(int)receiver->getDataStreamEnable();
n += mySock->SendDataOnly(&ind,sizeof(ind));
n += mySock->SendDataOnly(&ind, sizeof(ind));
// activate
ind=(int)receiver->getActivate();
n += mySock->SendDataOnly(&ind,sizeof(ind));
n += mySock->SendDataOnly(&ind, sizeof(ind));
// deactivated padding enable
ind=(int)receiver->getDeactivatedPadding();
n += mySock->SendDataOnly(&ind,sizeof(ind));
n += mySock->SendDataOnly(&ind, sizeof(ind));
// silent mode
ind=(int)receiver->getSilentMode();
n += mySock->SendDataOnly(&ind,sizeof(ind));
n += mySock->SendDataOnly(&ind, sizeof(ind));
if (!lockStatus)
strcpy(mySock->lastClientIP,mySock->thisClientIP);
@ -617,7 +603,7 @@ int slsReceiverTCPIPInterface::set_detector_type(){
int slsReceiverTCPIPInterface::set_detector_hostname() {
memset(mess, 0, sizeof(mess));
char hostname[MAX_STR_LENGTH] = {0};
char* retval = NULL;
char retval[MAX_STR_LENGTH] = {0};
// get args, return if socket crashed, ret is fail if receiver is not null
if (interface->Server_ReceiveArg(ret, mess, hostname,MAX_STR_LENGTH, true, receiver) == FAIL)
@ -633,20 +619,14 @@ int slsReceiverTCPIPInterface::set_detector_hostname() {
}
// get
retval = receiver->getDetectorHostname();
if(retval == NULL) {
if (strlen(retval)) {
ret = FAIL;
cprintf(RED, "Could not set hostname to %s\n", hostname);
sprintf(mess, "hostname not set\n");
FILE_LOG(logERROR) << mess;
}
}
interface->Server_SendResult(true, ret,
retval, (retval == NULL) ? 0 : MAX_STR_LENGTH, mess);
if(retval != NULL)
delete[] retval;
return ret;
return interface->Server_SendResult(true, ret, retval, MAX_STR_LENGTH, mess);
}
@ -1048,7 +1028,7 @@ int slsReceiverTCPIPInterface::stop_receiver(){
int slsReceiverTCPIPInterface::set_file_dir() {
memset(mess, 0, sizeof(mess));
char fPath[MAX_STR_LENGTH] = {0};
char* retval=NULL;
char retval[MAX_STR_LENGTH] = {0};
// get args, return if socket crashed, ret is fail if receiver is not null
if (interface->Server_ReceiveArg(ret, mess, fPath, sizeof(fPath), true, receiver) == FAIL)
@ -1062,22 +1042,15 @@ int slsReceiverTCPIPInterface::set_file_dir() {
}
// get
retval = receiver->getFilePath();
if (retval == NULL || (strlen(fPath) && strcasecmp(fPath, retval))) {
if ((!strlen(retval)) || (strlen(fPath) && strcasecmp(fPath, retval))) {
ret = FAIL;
strcpy(mess,"receiver file path does not exist\n");
FILE_LOG(logERROR) << mess;
}
if (retval != NULL) {
} else
FILE_LOG(logDEBUG1) << "file path:" << retval;
}
}
interface->Server_SendResult(true, ret, retval, (retval == NULL) ? 0 : MAX_STR_LENGTH, mess);
if(retval != NULL)
delete[] retval;
return ret;
return interface->Server_SendResult(true, ret, retval, MAX_STR_LENGTH, mess);
}
@ -1085,7 +1058,7 @@ int slsReceiverTCPIPInterface::set_file_dir() {
int slsReceiverTCPIPInterface::set_file_name() {
memset(mess, 0, sizeof(mess));
char fName[MAX_STR_LENGTH] = {0};
char* retval = NULL;
char retval[MAX_STR_LENGTH] = {0};
// get args, return if socket crashed, ret is fail if receiver is not null
if (interface->Server_ReceiveArg(ret, mess, fName, sizeof(fName), true, receiver) == FAIL)
@ -1099,22 +1072,15 @@ int slsReceiverTCPIPInterface::set_file_name() {
}
// get
retval = receiver->getFileName();
if(retval == NULL) {
if (strlen(retval)) {
ret = FAIL;
strcpy(mess, "file name is empty\n");
FILE_LOG(logERROR) << mess;
}
if (retval != NULL) {
} else
FILE_LOG(logDEBUG1) << "file name:" << retval;
}
}
interface->Server_SendResult(true, ret, retval, (retval == NULL) ? 0 : MAX_STR_LENGTH, mess);
if(retval != NULL)
delete[] retval;
return ret;
return interface->Server_SendResult(true, ret, retval, MAX_STR_LENGTH, mess);
}
@ -1624,7 +1590,7 @@ int slsReceiverTCPIPInterface::set_streaming_port() {
int slsReceiverTCPIPInterface::set_streaming_source_ip() {
memset(mess, 0, sizeof(mess));
char arg[MAX_STR_LENGTH] = {0};
char* retval=NULL;
char retval[MAX_STR_LENGTH] = {0};
// get args, return if socket crashed, ret is fail if receiver is not null
if (interface->Server_ReceiveArg(ret, mess, arg, MAX_STR_LENGTH, true, receiver) == FAIL)
@ -1642,13 +1608,7 @@ int slsReceiverTCPIPInterface::set_streaming_source_ip() {
FILE_LOG(logDEBUG1) << "streaming source ip:" << retval;
}
interface->Server_SendResult(true,
ret, retval, (retval == NULL) ? 0 : MAX_STR_LENGTH, mess);
if(retval != NULL)
delete[] retval;
return ret;
return interface->Server_SendResult(true, ret, retval, MAX_STR_LENGTH, mess);
}
@ -1758,7 +1718,7 @@ int slsReceiverTCPIPInterface::restream_stop(){
int slsReceiverTCPIPInterface::set_additional_json_header() {
memset(mess, 0, sizeof(mess));
char arg[MAX_STR_LENGTH] = {0};
char* retval=NULL;
char retval[MAX_STR_LENGTH] = {0};
// get args, return if socket crashed, ret is fail if receiver is not null
if (interface->Server_ReceiveArg(ret, mess, arg, sizeof(arg), true, receiver) == FAIL)
@ -1776,12 +1736,7 @@ int slsReceiverTCPIPInterface::set_additional_json_header() {
FILE_LOG(logDEBUG1) << "additional json header:" << retval;
}
interface->Server_SendResult(true, ret, retval, MAX_STR_LENGTH, mess);
if (retval != NULL)
delete[] retval;
return ret;
return interface->Server_SendResult(true, ret, retval, MAX_STR_LENGTH, mess);
}

View File

@ -240,16 +240,13 @@ public:
int nchip; /**< is the number of chips on the module */
int ndac; /**< is the number of dacs on the module */
int nadc; /**< is the number of adcs on the module */
int reg; /**< is the module register (e.g. dynamic range?)
\see moduleRegisterBit */
int reg; /**< is the module register settings (gain level) */
int iodelay; /**< iodelay */
int tau; /**< tau */
int eV; /**< threshold energy */
int *dacs; /**< is the pointer to the array of the dac values (in V) */
int *adcs; /**< is the pointer to the array of the adc values (in V) FLAT_FIELD_CORRECTION*/
int *chipregs; /**< is the pointer to the array of the chip registers
\see ::chipRegisterBit */
int *chanregs; /**< is the pointer to the array of the channel registers
\see ::channelRegisterBit */
double gain; /**< is the module gain (V/keV) */
double offset; /**< is the module offset (V) */
int *adcs; /**< is the pointer to the array of the adc values (in V) */
int *chanregs; /**< is the pointer to the array of the channel registers */
} sls_detector_module;

View File

@ -45,7 +45,6 @@ enum detFuncs{
F_LOAD_IMAGE, /**< Loads Dark/Gain image to the Gotthard detector */
F_READ_COUNTER_BLOCK, /**< reads the counter block memory for gotthard */
F_RESET_COUNTER_BLOCK, /**< resets the counter block memory for gotthard */
F_CALIBRATE_PEDESTAL, /**< starts acquistion, calibrates pedestal and write back to fpga */
F_ENABLE_TEN_GIGA, /**< enable 10Gbe */
F_SET_ALL_TRIMBITS, /** < set all trimbits to this value */
F_SET_CTB_PATTERN, /** < loads a pattern in the CTB */
@ -160,7 +159,6 @@ static const char* getFunctionNameFromEnum(enum detFuncs func) {
case F_LOAD_IMAGE: return "F_LOAD_IMAGE";
case F_READ_COUNTER_BLOCK: return "F_READ_COUNTER_BLOCK";
case F_RESET_COUNTER_BLOCK: return "F_RESET_COUNTER_BLOCK";
case F_CALIBRATE_PEDESTAL: return "F_CALIBRATE_PEDESTAL";
case F_ENABLE_TEN_GIGA: return "F_ENABLE_TEN_GIGA";
case F_SET_ALL_TRIMBITS: return "F_SET_ALL_TRIMBITS";
case F_SET_CTB_PATTERN: return "F_SET_CTB_PATTERN";