Solved problem with MYTHEN readout

git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@820 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
bergamaschi
2014-04-17 14:23:42 +00:00
parent a79046162f
commit 2609e249ab
7 changed files with 77 additions and 33 deletions

View File

@ -13,7 +13,8 @@ INSTMODE= 0777
SRCS= server.c server_funcs.c communication_funcs.c firmware_funcs.c mcb_funcs.c trimming_funcs.c sharedmemory.c SRCS= server.c server_funcs.c communication_funcs.c firmware_funcs.c mcb_funcs.c trimming_funcs.c sharedmemory.c
OBJS= $(SRCS:%.c=%.o) OBJS= $(SRCS:%.c=%.o)
VFLAGS= -DVERBOSE VFLAGS=
#-DVERBOSE
#-DVERYVERBOSE #-DVERYVERBOSE
CFLAGS+= -Wall -DC_ONLY -DMCB_FUNCS -DDACS_INT $(VFLAGS) CFLAGS+= -Wall -DC_ONLY -DMCB_FUNCS -DDACS_INT $(VFLAGS)
#-Werror #-Werror

View File

@ -298,7 +298,9 @@ u_int32_t setExtSignal(int d, enum externalSignalFlag mode) {
u_int32_t setFPGASignal(int d, enum externalSignalFlag mode) { u_int32_t setFPGASignal(int d, enum externalSignalFlag mode) {
int modes[]={EXT_SIG_OFF, EXT_GATE_IN_ACTIVEHIGH, EXT_GATE_IN_ACTIVELOW,EXT_TRIG_IN_RISING,EXT_TRIG_IN_FALLING,EXT_RO_TRIG_IN_RISING, EXT_RO_TRIG_IN_FALLING,EXT_GATE_OUT_ACTIVEHIGH, EXT_GATE_OUT_ACTIVELOW, EXT_TRIG_OUT_RISING, EXT_TRIG_OUT_FALLING, EXT_RO_TRIG_OUT_RISING, EXT_RO_TRIG_OUT_FALLING}; int modes[]={SIGNAL_OFF, GATE_IN_ACTIVE_HIGH, GATE_IN_ACTIVE_LOW,TRIGGER_IN_RISING_EDGE, TRIGGER_IN_FALLING_EDGE,RO_TRIGGER_IN_RISING_EDGE, RO_TRIGGER_IN_FALLING_EDGE, GATE_OUT_ACTIVE_HIGH, GATE_OUT_ACTIVE_LOW, TRIGGER_OUT_RISING_EDGE, TRIGGER_OUT_FALLING_EDGE, RO_TRIGGER_OUT_RISING_EDGE,RO_TRIGGER_OUT_FALLING_EDGE};
// int modes[]={EXT_SIG_OFF, EXT_GATE_IN_ACTIVEHIGH, EXT_GATE_IN_ACTIVELOW,EXT_TRIG_IN_RISING,EXT_TRIG_IN_FALLING,EXT_RO_TRIG_IN_RISING, EXT_RO_TRIG_IN_FALLING,EXT_GATE_OUT_ACTIVEHIGH, EXT_GATE_OUT_ACTIVELOW, EXT_TRIG_OUT_RISING, EXT_TRIG_OUT_FALLING, EXT_RO_TRIG_OUT_RISING, EXT_RO_TRIG_OUT_FALLING};
u_int32_t c; u_int32_t c;
int off=d*SIGNAL_OFFSET; int off=d*SIGNAL_OFFSET;
@ -383,7 +385,7 @@ int setTiming(int ti) {
int g=-1, t=-1, rot=-1; int g=-1, t=-1, rot=-1;
int i; int i;
printf("*********************************Setting timing mode %d!\n", ti);
switch (ti) { switch (ti) {
case AUTO_TIMING: case AUTO_TIMING:
timingMode=ti; timingMode=ti;
@ -425,6 +427,7 @@ int setTiming(int ti) {
case GATE_FIX_NUMBER: case GATE_FIX_NUMBER:
timingMode=ti; timingMode=ti;
printf("*********************************Setting gating!\n");
// if one of the signals is configured to be trigger, set it and unset possible gates // if one of the signals is configured to be trigger, set it and unset possible gates
for (i=0; i<4; i++) { for (i=0; i<4; i++) {
if (signals[i]==RO_TRIGGER_IN_RISING_EDGE || signals[i]==RO_TRIGGER_IN_FALLING_EDGE) if (signals[i]==RO_TRIGGER_IN_RISING_EDGE || signals[i]==RO_TRIGGER_IN_FALLING_EDGE)
@ -1148,6 +1151,8 @@ u_int32_t fifo_full(void)
u_int32_t* fifo_read_event() u_int32_t* fifo_read_event()
{ {
int ir=0;
#ifdef VERBOSE #ifdef VERBOSE
int ichip; int ichip;
int ichan; int ichan;
@ -1167,24 +1172,33 @@ u_int32_t* fifo_read_event()
printf("Waiting for data status %x\n",runState()); printf("Waiting for data status %x\n",runState());
#endif #endif
if (runBusy()==0) { if (runBusy()==0) {
if (bus_r(LOOK_AT_ME_REG)==0) { /* for (ir=0; ir<100; ir++) { */
#ifdef VERBOSE /* //usleep(100); */
printf("no frame found - exiting "); /* //printf("check %d\n", ir); */
/* if (runBusy()==1) */
printf("%08x %08x\n", runState(), bus_r(LOOK_AT_ME_REG)); /* break; */
/* for (ichip=0; ichip<nModBoard*NCHIP; ichip++) { /* } */
if ((fifoReadCounter(ichip)&FIFO_COUNTER_MASK)%128) /* if (ir==100) { */
printf("FIFO %d contains %d words\n",ichip,(fifoReadCounter(ichip)&FIFO_COUNTER_MASK)); if (bus_r(LOOK_AT_ME_REG)==0) {
} //#ifdef VERBOSE
*/ printf("no frame found - exiting ");
#endif
return NULL; printf("%08x %08x\n", runState(), bus_r(LOOK_AT_ME_REG));
} else { // for (ichip=0; ichip<nModBoard*NCHIP; ichip++) {
// if ((fifoReadCounter(ichip)&FIFO_COUNTER_MASK)%128)
// printf("FIFO %d contains %d words\n",ichip,(fifoReadCounter(ichip)&FIFO_COUNTER_MASK));
// }
//#endif
return NULL;
} else {
#ifdef VERYVERBOSE #ifdef VERYVERBOSE
printf("no frame found %x status %x\n", bus_r(LOOK_AT_ME_REG),runState()); printf("no frame found %x status %x\n", bus_r(LOOK_AT_ME_REG),runState());
#endif #endif
break; break;
} }
/* } else */
/* printf("run busy error workaround %d \n", ir); */
} }
} }
#ifdef VERYVERBOSE #ifdef VERYVERBOSE

View File

@ -3147,7 +3147,6 @@ string slsDetectorCommand::cmdRegister(int narg, char *args[], int action) {
sprintf(answer,"%x",myDet->writeRegister(addr,myDet->readRegister(addr)| 1<<n)); sprintf(answer,"%x",myDet->writeRegister(addr,myDet->readRegister(addr)| 1<<n));
if (cmd=="clearbit") if (cmd=="clearbit")
sprintf(answer,"%x",myDet->writeRegister(addr,myDet->readRegister(addr) & ~(1<<n))); sprintf(answer,"%x",myDet->writeRegister(addr,myDet->readRegister(addr) & ~(1<<n)));
} }

View File

@ -330,9 +330,9 @@ void slsDetectorUtils::acquire(int delflag){
cout << "check data queue size " << endl; cout << "check data queue size " << endl;
#endif #endif
/*while (dataQueueSize()){ /*while (dataQueueSize()){
#ifdef VERBOSE //#ifdef VERBOSE
cout << "AAAAAAAAA check data queue size " << endl; cout << "AAAAAAAAA check data queue size " << endl;
#endif //#endif
usleep(100000); usleep(100000);
}*/ }*/

View File

@ -240,17 +240,24 @@ TH1F* energyCalibration::createMedianHistogram(TH2F* h2, int ch0, int nch) {
TH1F *h1=NULL; TH1F *h1=NULL;
double val=-1; double val=-1;
double me=0;
h1=new TH1F("median","Median",h2->GetYaxis()->GetNbins(),h2->GetYaxis()->GetXmin(),h2->GetYaxis()->GetXmax()); h1=new TH1F("median","Median",h2->GetYaxis()->GetNbins(),h2->GetYaxis()->GetXmin(),h2->GetYaxis()->GetXmax());
for (int ib=0; ib<h1->GetXaxis()->GetNbins(); ib++) { for (int ib=0; ib<h1->GetXaxis()->GetNbins(); ib++) {
me=0;
for (int ich=0; ich<nch; ich++) { for (int ich=0; ich<nch; ich++) {
x[ich]=h2->GetBinContent(ch0+ich+1,ib+1); x[ich]=h2->GetBinContent(ch0+ich+1,ib+1);
me+=x[ich];
} }
cout << ib << " calculating median ch0=" << ch0 << " nch=" << nch << endl;
val=energyCalibrationFunctions::median(x, nch); val=energyCalibrationFunctions::median(x, nch);
cout << "median=" << val << " mean= " << me/nch << endl;
h1->SetBinContent(ib+1,val); h1->SetBinContent(ib+1,val);
} }
delete [] x;
return h1; return h1;

View File

@ -7,6 +7,7 @@
#include "usersFunctions.h" #include "usersFunctions.h"
#endif #endif
//#define VERBOSE
static void* startProcessData(void *n){\ static void* startProcessData(void *n){\
postProcessing *myDet=(postProcessing*)n;\ postProcessing *myDet=(postProcessing*)n;\
@ -38,9 +39,9 @@ postProcessing::postProcessing(): expTime(NULL), ang(NULL), val(NULL), err(NULL)
pRawDataArg = 0; pRawDataArg = 0;
#ifdef VERBOSE //#ifdef VERBOSE
registerDataCallback(&defaultDataReadyFunc, NULL); // registerDataCallback(&defaultDataReadyFunc, NULL);
#endif //#endif
#ifdef EXTPP #ifdef EXTPP
registerRawDataCallback(&defaultRawDataReadyFunc, NULL); registerRawDataCallback(&defaultRawDataReadyFunc, NULL);
#endif #endif
@ -82,18 +83,18 @@ void postProcessing::processFrame(int *myData, int delflag) {
/** decode data */ /** decode data */
// if (getDetectorsType()==MYTHEN) { // if (getDetectorsType()==MYTHEN) {
fdata=decodeData(myData, fdata); fdata=decodeData(myData, fdata);
#ifdef VERBOSE #ifdef VERBOSE
cout << "decode"<< endl; cout << "decode"<< endl;
#endif #endif
//} else // } else
// fdata=NULL; // fdata=NULL;
if (rawDataReady) { if (rawDataReady) {
#ifdef VERBOSE #ifdef VERBOSE
cout << "raw data ready..." << endl; cout << "raw data ready..." << endl;
#endif #endif
rawDataReady(fdata,numberOfChannels, pRawDataArg); rawDataReady(fdata,numberOfChannels, pRawDataArg);
#ifdef VERBOSE #ifdef VERBOSE
cout << "done" << endl; cout << "done" << endl;
@ -128,7 +129,8 @@ void postProcessing::processFrame(int *myData, int delflag) {
#endif #endif
} }
if ((*correctionMask) & ~(1<<WRITE_FILE)) { if ((*correctionMask) & ~((1<<WRITE_FILE) | (1<<OVERWRITE_FILE))) {
// cout << "cmask is not 0: " << *correctionMask << " - " << ((*correctionMask) & (1<<I0_NORMALIZATION)) << "-" << ((*correctionMask) & (1<<OVERWRITE_FILE)) << endl;
doProcessing(fdata,delflag, fname); doProcessing(fdata,delflag, fname);
} else } else
if (dataReady){ if (dataReady){
@ -232,7 +234,22 @@ void postProcessing::doProcessing(double *lfdata, int delflag, string fname) {
#ifdef VERBOSE #ifdef VERBOSE
cout << "add frame" << endl; cout << "add frame" << endl;
#endif #endif
/**ot them
start processing
prog incremented
decode
fname is //run_f0_0
??????????????????????????????????????????? do processing - data size is 30720
arrays allocated
npos is 0
exptime is 10.00
init dataset
add frame
data queue size lock
data queue size unlock
**/
addFrame(lfdata,currentPosition, currentI0, t, fname, 0); addFrame(lfdata,currentPosition, currentI0, t, fname, 0);
// cout << "++++++++++++++++++++" << GetCurrentPositionIndex() << " " << npos << " " << positionFinished() << " " << dataQueueSize() << endl; // cout << "++++++++++++++++++++" << GetCurrentPositionIndex() << " " << npos << " " << positionFinished() << " " << dataQueueSize() << endl;
if ((GetCurrentPositionIndex()>=npos && dataQueueSize()) || npos<2) { if ((GetCurrentPositionIndex()>=npos && dataQueueSize()) || npos<2) {
@ -393,7 +410,7 @@ void* postProcessing::processData(int delflag) {
while((queuesize=dataQueueSize())>0) { while((queuesize=dataQueueSize())>0) {
/** Pop data queue */ /** Pop data queue */
#ifdef VERBOSE #ifdef VERBOSE
cout << "data found"<< endl<<endl;; cout << "data foun"<< endl<<endl;;
#endif #endif
myData=dataQueueFront(); // get the data from the queue myData=dataQueueFront(); // get the data from the queue
@ -404,12 +421,18 @@ void* postProcessing::processData(int delflag) {
if (myData) { if (myData) {
processFrame(myData,delflag); processFrame(myData,delflag);
} }
#ifdef VERBOSE
cout << "frame processed"<< endl;
#endif
} }
/** IF detector acquisition is done, let the acquire() thread know to finish up and force join thread */ /** IF detector acquisition is done, let the acquire() thread know to finish up and force join thread */
if(acquiringDone){ if(acquiringDone){
sem_post(&sem_queue); sem_post(&sem_queue);
} // cout << "Sem posted" << endl;
} //else
// cout << "Sem not posted" << endl;
/* IF THERE ARE NO DATA look if acquisition is finished */ /* IF THERE ARE NO DATA look if acquisition is finished */
if (checkJoinThread()) { if (checkJoinThread()) {