sorted out problem with CPU read out

This commit is contained in:
2016-12-22 17:24:53 +01:00
parent 3eea80a121
commit 987aeda6fb
13 changed files with 982 additions and 1010 deletions

View File

@ -801,7 +801,7 @@ int slsDetector::initializeDetectorSize(detectorType type) {
//update?!?!?!?
if(thisDetector->myDetectorType==JUNGFRAUCTB) {
cout << "here2" << endl;
// cout << "here2" << endl;
getTotalNumberOfChannels();
//thisDetector->nChan[X]=32;
//thisDetector->nChans=thisDetector->nChan[X]*thisDetector->nChan[Y];
@ -1703,8 +1703,9 @@ int slsDetector::getTotalNumberOfChannels() {
}
thisDetector->nChans=thisDetector->nChan[X];
thisDetector->dataBytes=thisDetector->nChans*thisDetector->nChips*thisDetector->nMods*2*thisDetector->timerValue[SAMPLES_JCTB];
cout << "Total number of channels is "<< thisDetector->nChans*thisDetector->nChips*thisDetector->nMods << " data bytes is " << thisDetector->dataBytes << endl;
}
} else
cout << "det type is "<< thisDetector->myDetectorType << endl;
cout << "Total number of channels is "<< thisDetector->nChans*thisDetector->nChips*thisDetector->nMods << " data bytes is " << thisDetector->dataBytes << endl;
return thisDetector->nChans*thisDetector->nChips*thisDetector->nMods;
};
@ -3928,9 +3929,9 @@ int* slsDetector::getDataFromDetector(int *retval){
n=controlSocket->ReceiveDataOnly(retval,thisDetector->dataBytes);
//#ifdef VERBOSE
#ifdef VERBOSE
std::cout<< "Received "<< n << " data bytes" << std::endl;
//#endif
#endif
if (n!=thisDetector->dataBytes) {
std::cout<< "wrong data size received from detector: received " << n << " but expected " << thisDetector->dataBytes << std::endl;
thisDetector->stoppedFlag=1;
@ -3940,8 +3941,13 @@ int* slsDetector::getDataFromDetector(int *retval){
}
return NULL;
}
// for (int ib=0; ib<thisDetector->dataBytes/8; ib++)
// cout << ((*(((u_int64_t*)retval)+ib))>>17&1) ;
}
// cout << "get data returning " << endl;
// cout << endl;
return retval;
};
@ -3956,8 +3962,8 @@ int* slsDetector::readAll(){
int fnum=F_READ_ALL;
int* retval; // check what we return!
int i=0;
#ifdef VERBOSE
int i=0;
std::cout<< "Reading all frames "<< std::endl;
#endif
if (thisDetector->onlineFlag==ONLINE_FLAG) {
@ -3965,23 +3971,18 @@ int* slsDetector::readAll(){
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
while ((retval=getDataFromDetector())){
#ifdef VERBOSE
i++;
#ifdef VERBOSE
std::cout<< i << std::endl;
//#else
//std::cout << "-" << flush ;
#endif
#endif
dataQueue.push(retval);
// std::cout<< "pushed" << std::endl;
}
disconnectControl();
}
}
#ifdef VERBOSE
#ifdef VERBOSE
std::cout<< "received "<< i<< " frames" << std::endl;
//#else
// std::cout << std::endl;
#endif
#endif
return dataQueue.front(); // check what we return!
};
@ -4019,19 +4020,21 @@ int* slsDetector::startAndReadAll(){
int* retval;
//#ifdef VERBOSE
#ifdef VERBOSE
int i=0;
#endif
//#endif
startAndReadAllNoWait();
//#ifdef VERBOSE
// std::cout<< "started" << std::endl;
//#endif
while ((retval=getDataFromDetector())){
#ifdef VERBOSE
#ifdef VERBOSE
i++;
std::cout<< i << std::endl;
//#else
//std::cout<< "-" << flush;
#endif
#endif
dataQueue.push(retval);
//std::cout<< "pushed" << std::endl;
@ -5029,14 +5032,17 @@ int slsDetector::executeTrimming(trimMode mode, int par1, int par2, int imod){
double* slsDetector::decodeData(int *datain, int &nn, double *fdata) {
double *dataout;
if (fdata) {
dataout=fdata;
// printf("not allocating fdata!\n");
} else {
double *dataout;
if (fdata) {
dataout=fdata;
// printf("not allocating fdata!\n");
if (thisDetector->myDetectorType==JUNGFRAUCTB) nn=thisDetector->dataBytes/2;
} else {
if (thisDetector->myDetectorType==JUNGFRAUCTB) {
dataout=new double[thisDetector->dataBytes/2];
nn=thisDetector->dataBytes/2;
dataout=new double[nn];
// std::cout<< "nn is "<< nn << std::endl;
} else {
dataout=new double[thisDetector->nChans*thisDetector->nChips*thisDetector->nMods];
nn=thisDetector->nChans*thisDetector->nChips*thisDetector->nMods;
@ -5044,30 +5050,31 @@ double* slsDetector::decodeData(int *datain, int &nn, double *fdata) {
// printf("allocating fdata!\n");
}
const int bytesize=8;
int ival=0;
char *ptr=(char*)datain;
char iptr;
int nbits=thisDetector->dynamicRange;
int nch=thisDetector->nChans*thisDetector->nChips*thisDetector->nMods;
int ipos=0, ichan=0, ibyte;
if (thisDetector->timerValue[PROBES_NUMBER]==0) {
if (thisDetector->myDetectorType==JUNGFRAUCTB) {
for (ichan=0; ichan<thisDetector->dataBytes/2; ichan++) {
const int bytesize=8;
int ival=0;
char *ptr=(char*)datain;
char iptr;
int nbits=thisDetector->dynamicRange;
int nch=thisDetector->nChans*thisDetector->nChips*thisDetector->nMods;
int ipos=0, ichan=0, ibyte;
if (thisDetector->timerValue[PROBES_NUMBER]==0) {
if (thisDetector->myDetectorType==JUNGFRAUCTB) {
for (ichan=0; ichan<nn; ichan++) {
// // }
dataout[ichan]=*((u_int16_t*)ptr);
ptr+=2;
}
} else {
std::cout<< "decoded "<< ichan << " channels" << std::endl;
} else {
switch (nbits) {
case 1:
for (ibyte=0; ibyte<thisDetector->dataBytes; ibyte++) {
iptr=ptr[ibyte]&0x1;
iptr=ptr[ibyte];//&0x1;
for (ipos=0; ipos<8; ipos++) {
// dataout[ibyte*2+ichan]=((iptr&((0xf)<<ichan))>>ichan)&0xf;
ival=(iptr>>(ipos))&0x1;
@ -5078,7 +5085,7 @@ double* slsDetector::decodeData(int *datain, int &nn, double *fdata) {
break;
case 4:
for (ibyte=0; ibyte<thisDetector->dataBytes; ibyte++) {
iptr=ptr[ibyte]&0xff;
iptr=ptr[ibyte];
for (ipos=0; ipos<2; ipos++) {
// dataout[ibyte*2+ichan]=((iptr&((0xf)<<ichan))>>ichan)&0xf;
ival=(iptr>>(ipos*4))&0xf;
@ -5096,36 +5103,32 @@ double* slsDetector::decodeData(int *datain, int &nn, double *fdata) {
case 16:
for (ichan=0; ichan<nch; ichan++) {
// dataout[ichan]=0;
ival=0;
for (ibyte=0; ibyte<2; ibyte++) {
iptr=ptr[ichan*2+ibyte];
ival|=((iptr<<(ibyte*bytesize))&(0xff<<(ibyte*bytesize)));
}
dataout[ichan]=ival;
// ival=0;
// for (ibyte=0; ibyte<2; ibyte++) {
// iptr=ptr[ichan*2+ibyte];
// ival|=((iptr<<(ibyte*bytesize))&(0xff<<(ibyte*bytesize)));
// }
dataout[ichan]=*((u_int16_t*)ptr);
ptr+=2;
}
break;
default:
if(thisDetector->myDetectorType == MYTHEN){
for (ichan=0; ichan<nch; ichan++) {
ival=datain[ichan]&0xffffff;
dataout[ichan]=ival;
}
}
for (ichan=0; ichan<nch; ichan++) {
dataout[ichan]=datain[ichan];
}
int mask=0xffffffff;
if(thisDetector->myDetectorType == MYTHEN) mask=0xffffff;
for (ichan=0; ichan<nch; ichan++) {
dataout[ichan]=datain[ichan]&mask;
}
}
}
} else {
for (ichan=0; ichan<nch; ichan++) {
dataout[ichan]=datain[ichan];
}
}
}
} else {
for (ichan=0; ichan<nch; ichan++) {
dataout[ichan]=datain[ichan];
}
}
#ifdef VERBOSE
std::cout<< "decoded "<< ichan << " channels" << std::endl;
#endif
//#ifdef VERBOSE
//#endif
return dataout;
}

View File

@ -787,6 +787,10 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) {
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDAC;
i++;
descrToFuncMap[i].m_pFuncName="v_limit"; //
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDAC;
i++;
/* r/w timers */
descrToFuncMap[i].m_pFuncName="temp_adc"; //
@ -3816,6 +3820,8 @@ string slsDetectorCommand::cmdDAC(int narg, char *args[], int action) {
dac=V_POWER_IO;
else if (cmd== "v_chip")
dac=V_POWER_CHIP;
else if (cmd== "v_limit")
dac=V_LIMIT;
else
return string("cannot decode dac ")+cmd;
@ -3849,7 +3855,7 @@ string slsDetectorCommand::cmdDAC(int narg, char *args[], int action) {
sprintf(answer,"%f",myDet->setDAC(-1,dac,mode));
#endif
if(mode)
strcat(answer,"mV");
strcat(answer," mV");
return string(answer);
}
@ -4007,7 +4013,7 @@ string slsDetectorCommand::cmdADC(int narg, char *args[], int action) {
return string("cannot set ")+cmd;
if (sscanf(args[0],"adc:%d",&idac)==1) {
printf("chiptestboard!\n");
// printf("chiptestboard!\n");
adc=(dacIndex)(idac+1000);
} else if (cmd=="temp_adc")
adc=TEMPERATURE_ADC;

View File

@ -174,8 +174,8 @@ int slsDetectorUtils::acquire(int delflag){
//resets frames caught in receiver
if(receiver){
pthread_mutex_lock(&mg); //cout << "lock"<< endl;
resetFramesCaught();
pthread_mutex_unlock(&mg);//cout << "unlock"<< endl;
resetFramesCaught();
pthread_mutex_unlock(&mg);//cout << "unlock"<< endl;
}
@ -269,7 +269,7 @@ int slsDetectorUtils::acquire(int delflag){
aclog->addStep(getCurrentPosition(), getCurrentFileName());
if (eclog)
eclog->addStep(setDAC(-1,THRESHOLD,0), getCurrentFileName());
eclog->addStep(setDAC(-1,THRESHOLD,0), getCurrentFileName());
if (*correctionMask&(1<< I0_NORMALIZATION)) {
@ -344,7 +344,7 @@ int slsDetectorUtils::acquire(int delflag){
} else
break;
while (dataQueueSize()) usleep(100000);
// cout << "mglock " << endl;;
pthread_mutex_lock(&mg); //cout << "lock"<< endl;
// cout << "done " << endl;;