flatfield directory field added to shared memory - Server works with newest firmware versions

git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@22 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
bergamaschi
2011-01-28 13:24:03 +00:00
parent 9f64dd01d8
commit f882a61802
18 changed files with 709 additions and 314 deletions

View File

@ -12,7 +12,7 @@ SRC_CLNT= slsDetector/slsDetector.cpp MySocketTCP/MySocketTCP.cxx usersFunctions
SRC_MYTHEN_SVC = mythenDetectorServer/server.c mythenDetectorServer/server_funcs.c commonFiles/communication_funcs.c mythenDetectorServer/firmware_funcs.c mythenDetectorServer/mcb_funcs.c mythenDetectorServer/trimming_funcs.c mythenDetectorServer/sharedmemory.c SRC_MYTHEN_SVC = mythenDetectorServer/server.c mythenDetectorServer/server_funcs.c commonFiles/communication_funcs.c mythenDetectorServer/firmware_funcs.c mythenDetectorServer/mcb_funcs.c mythenDetectorServer/trimming_funcs.c mythenDetectorServer/sharedmemory.c
all: package mythenServer doc all: package mythenServer doc picassoServer
doc: $(SRC_H) $(SRC_CLNT) doc: $(SRC_H) $(SRC_CLNT)
doxygen doxy.config doxygen doxy.config
@ -21,17 +21,47 @@ doc: $(SRC_H) $(SRC_CLNT)
mythenServer: $(SRC_MYTHEN_SVC) mythenServer: $(SRC_MYTHEN_SVC)
gcc $(SRC_MYTHEN_SVC) $(CFLAGS) $(FLAGS) $(INCLUDES) -ImythenDetectorServer -D VIRTUAL -lm -D MCB_FUNCS $(CXX) $(SRC_MYTHEN_SVC) $(CFLAGS) $(FLAGS) $(INCLUDES) -ImythenDetectorServer -D VIRTUAL -lm -D MCB_FUNCS
mv a.out bin/mythenDetectorServer mv a.out bin/mythenDetectorServer
picassoServer: $(SRC_MYTHEN_SVC)
$(CXX) $(SRC_MYTHEN_SVC) $(CFLAGS) $(FLAGS) $(INCLUDES) -ImythenDetectorServer -D VIRTUAL -lm -D MCB_FUNCS -DPICASSOD
mv a.out bin/picassoDetectorServer
package: $(SRC_CLNT) package: $(SRC_CLNT)
gcc -fPIC -g -o objs/slsDetector.o -c -Wall slsDetector/slsDetector.cpp $(INCLUDES) $(CXX) -fPIC -g -o objs/slsDetector.o -c -Wall slsDetector/slsDetector.cpp $(INCLUDES) $(FLAGS)
gcc -fPIC -g -o objs/eigerDetector.o -c -Wall eigerDetector/eigerDetector.cpp $(INCLUDES) # $(CXX) -fPIC -g -o objs/eigerDetector.o -c -Wall eigerDetector/eigerDetector.cpp $(INCLUDES) $(FLAGS)
gcc -fPIC -g -o objs/usersFunctions.o -c -Wall usersFunctions/usersFunctions.c $(INCLUDES) $(CXX) -fPIC -g -o objs/mythenDetector.o -c -Wall mythenDetector/mythenDetector.cpp $(INCLUDES) $(FLAGS)
gcc -fPIC -g -o objs/MySocketTCP.o -c -Wall MySocketTCP/MySocketTCP.cxx $(INCLUDES) $(CXX) -fPIC -g -o objs/usersFunctions.o -c -Wall usersFunctions/usersFunctions.c $(INCLUDES) $(FLAGS)
gcc -shared -Wl,-soname,libSlsDetector.so.1 -o bin/libSlsDetector.so.1.0.1 objs/slsDetector.o objs/eigerDetector.o objs/usersFunctions.o objs/MySocketTCP.o -lc $(INCLUDES) $(CXX) -fPIC -g -o objs/MySocketTCP.o -c -Wall MySocketTCP/MySocketTCP.cxx $(INCLUDES) $(FLAGS)
$(CXX) -shared -Wl,-soname,libSlsDetector.so.1 -o bin/libSlsDetector.so.1.0.1 objs/slsDetector.o objs/mythenDetector.o objs/usersFunctions.o objs/MySocketTCP.o -lc $(INCLUDES) $(FLAGS)
cd bin && ln -sf libSlsDetector.so.1.0.1 libSlsDetector.so
ar rcs bin/libSlsDetector.a objs/slsDetector.o objs/mythenDetector.o objs/usersFunctions.o objs/MySocketTCP.o
clean: clean:
rm bin/* core objs/* rm -rf bin/* core objs/* docs/*
#-------------------------------------------------------------------------------
lib: package
# added install target, HBl
install_lib: lib
$(shell test -d $(DESTDIR) || mkdir -p $(DESTDIR))
cp -P bin/* $(DESTDIR)
install_inc:
$(shell test -d $(DESTDIR) || mkdir -p $(DESTDIR))
cp -P ../slsDetectorSoftware/MySocketTCP/MySocketTCP.h $(DESTDIR)
cp -P ../slsDetectorSoftware/eigerDetector/eigerDetector.h $(DESTDIR)
cp -P ../slsDetectorSoftware/mythenDetector/mythenDetector.h $(DESTDIR)
cp -P ../slsDetectorSoftware/slsDetector/slsDetector.h $(DESTDIR)
cp -P ../slsDetectorSoftware/commonFiles/sls_detector_defs.h $(DESTDIR)
cp -P ../slsDetectorSoftware/usersFunctions/usersFunctions.h $(DESTDIR)
install_doc:
$(shell test -d $(DESTDIR) || mkdir -p $(DESTDIR))
cp -Pr docs/* $(DESTDIR)

View File

@ -153,23 +153,14 @@ int MySocketTCP::Connect(){
cout << "fd " << file_des << endl; cout << "fd " << file_des << endl;
#endif #endif
} else { } else {
socketDescriptor = socket(AF_INET, SOCK_STREAM,0); //tcp if (socketDescriptor<=0)
socketDescriptor = socket(AF_INET, SOCK_STREAM,0); //tcp
// SetTimeOut(10);
if (socketDescriptor < 0){ if (socketDescriptor < 0){
cerr << "Can not create socket "<<endl; cerr << "Can not create socket "<<endl;
file_des = socketDescriptor; file_des = socketDescriptor;
} else { } else {
struct timeval tout;
tout.tv_sec = 10;
tout.tv_usec = 0;
if(::setsockopt(socketDescriptor, SOL_SOCKET, SO_RCVTIMEO, &tout, sizeof(struct timeval)) <0)
{
cerr << "Error in setsockopt SO_RCVTIMEO" << endl;
}
if(::setsockopt(socketDescriptor, SOL_SOCKET, SO_SNDTIMEO, &tout, sizeof(struct timeval)) < 0)
{
cerr << "Error in setsockopt SO_RCVTIMEO" << endl;
}
if(connect(socketDescriptor,(struct sockaddr *) &serverAddress,sizeof(serverAddress))<0){ if(connect(socketDescriptor,(struct sockaddr *) &serverAddress,sizeof(serverAddress))<0){
cerr << "Can not connect to socket "<<endl; cerr << "Can not connect to socket "<<endl;
file_des = -1; file_des = -1;
@ -183,8 +174,31 @@ int MySocketTCP::Connect(){
} }
int MySocketTCP::SetTimeOut(int ts){
if (ts<=0)
return -1;
//cout << "socketdescriptor "<< socketDescriptor << endl;
struct timeval tout;
tout.tv_sec = 0;
tout.tv_usec = 0;
if(::setsockopt(socketDescriptor, SOL_SOCKET, SO_RCVTIMEO, &tout, sizeof(struct timeval)) <0)
{
cerr << "Error in setsockopt SO_RCVTIMEO "<< 0 << endl;
}
tout.tv_sec = ts;
tout.tv_usec = 0;
if(::setsockopt(socketDescriptor, SOL_SOCKET, SO_SNDTIMEO, &tout, sizeof(struct timeval)) < 0)
{
cerr << "Error in setsockopt SO_SNDTIMEO " << ts << endl;
}
return 0;
}

View File

@ -64,6 +64,8 @@ class MySocketTCP{
int Connect(); //establish connection a Disconnect should always follow int Connect(); //establish connection a Disconnect should always follow
void Disconnect(); //free connection void Disconnect(); //free connection
/** Set the socket timeout ts is in seconds */
int SetTimeOut(int ts);
//The following two functions will connectioned->send/receive->disconnect //The following two functions will connectioned->send/receive->disconnect
int SendData(void* buf,int length);//length in characters int SendData(void* buf,int length);//length in characters

View File

@ -16,7 +16,7 @@ const int send_rec_max_size=SEND_REC_MAX_SIZE;
extern int errno; extern int errno;
//struct sockaddr_in address; //struct sockaddr_in address;
//#define VERY_VERBOSE //#define VERBOSE
int bindSocket(unsigned short int port_number) { int bindSocket(unsigned short int port_number) {
@ -276,9 +276,6 @@ int sendDataOnly(void* buf,int length) {
return write(file_des, buf, length); return write(file_des, buf, length);
#ifdef VERBOSE
// printf("sent %d Bytes\n", total_sent);
#endif
} }
@ -336,6 +333,7 @@ int sendChip(sls_detector_chip *myChip) {
int sendModule(sls_detector_module *myMod) { int sendModule(sls_detector_module *myMod) {
int ts=0; int ts=0;
int idac;
int nChips=myMod->nchip; int nChips=myMod->nchip;
int nChans=myMod->nchan; int nChans=myMod->nchan;
int nAdcs=myMod->nadc; int nAdcs=myMod->nadc;
@ -347,6 +345,8 @@ int sendModule(sls_detector_module *myMod) {
ts+= sendDataOnly(myMod->dacs,sizeof(float)*nDacs); ts+= sendDataOnly(myMod->dacs,sizeof(float)*nDacs);
#ifdef VERBOSE #ifdef VERBOSE
printf("dacs %d of size %d sent\n",myMod->module, ts); printf("dacs %d of size %d sent\n",myMod->module, ts);
for (idac=0; idac< nDacs; idac++)
printf("dac %d is %d\n",idac,myMod->dacs[idac]);
#endif #endif
ts+= sendDataOnly(myMod->adcs,sizeof(float)*nAdcs); ts+= sendDataOnly(myMod->adcs,sizeof(float)*nAdcs);
#ifdef VERBOSE #ifdef VERBOSE

View File

@ -5,7 +5,7 @@
typedef float float32_t; typedef float float32_t;
typedef int int32_t; typedef int int32_t;
/** /**
\file sls_detector_defs.h \file sls_detector_defs.h
@ -298,7 +298,8 @@ enum timerIndex {
DELAY_AFTER_TRIGGER, /**< delay between trigger and start of exposure or readout (in triggered mode) */ DELAY_AFTER_TRIGGER, /**< delay between trigger and start of exposure or readout (in triggered mode) */
GATES_NUMBER, /**< number of gates per frame (in gated mode) */ GATES_NUMBER, /**< number of gates per frame (in gated mode) */
PROBES_NUMBER, /**< number of probe types in pump-probe mode */ PROBES_NUMBER, /**< number of probe types in pump-probe mode */
CYCLES_NUMBER /**< number of cycles: total number of acquisitions is number or frames*number of cycles */ CYCLES_NUMBER, /**< number of cycles: total number of acquisitions is number or frames*number of cycles */
PROGRESS /**< fraction of measurement elapsed - only get! */
}; };
/** /**

View File

@ -148,6 +148,14 @@ string mythenDetector::executeLine(int narg, char *args[], int action) {
return string("none"); return string("none");
} }
} }
} else if (var=="ffdir") {
if (action==PUT_ACTION) {
sval=string(args[1]);
if (sval=="none")
sval="";
setFlatFieldCorrectionDir(sval);
}
return string(getFlatFieldCorrectionDir());
} else if (var=="ratecorr") { } else if (var=="ratecorr") {
if (action==PUT_ACTION) { if (action==PUT_ACTION) {
sscanf(args[1],"%f",&fval); sscanf(args[1],"%f",&fval);
@ -367,7 +375,8 @@ string mythenDetector::executeLine(int narg, char *args[], int action) {
//setNumberOfModules(ival); //setNumberOfModules(ival);
} else } else
ival=GET_FLAG; ival=GET_FLAG;
sprintf(answer,"%d",setNumberOfModules(ival)); setNumberOfModules(ival);
sprintf(answer,"%d",setNumberOfModules(GET_FLAG));
return string(answer); return string(answer);
} else if (var=="maxmod") { } else if (var=="maxmod") {
if (action==PUT_ACTION) { if (action==PUT_ACTION) {
@ -376,8 +385,12 @@ string mythenDetector::executeLine(int narg, char *args[], int action) {
sprintf(answer,"%d",getMaxNumberOfModules()); sprintf(answer,"%d",getMaxNumberOfModules());
return string(answer); return string(answer);
} else if (var.find("extsig")==0) { } else if (var.find("extsig")==0) {
if (var.size()<=7)
return string("syntax is extsig:i where signal is signal number");
istringstream vvstr(var.substr(7)); istringstream vvstr(var.substr(7));
vvstr >> ival; vvstr >> ival;
if (vvstr.fail())
return string("syntax is extsig:i where signal is signal number");
externalSignalFlag flag=GET_EXTERNAL_SIGNAL_FLAG, ret; externalSignalFlag flag=GET_EXTERNAL_SIGNAL_FLAG, ret;
if (action==PUT_ACTION) { if (action==PUT_ACTION) {
sval=string(args[1]); sval=string(args[1]);
@ -436,9 +449,13 @@ string mythenDetector::executeLine(int narg, char *args[], int action) {
if (action==PUT_ACTION) { if (action==PUT_ACTION) {
return string("cannot set"); return string("cannot set");
} }
if (var.size()<=13)
return string("syntax is modulenumber:i where is is module number");
istringstream vvstr(var.substr(13)); istringstream vvstr(var.substr(13));
vvstr >> ival; vvstr >> ival;
cout << var.substr(13) << endl; if (vvstr.fail())
return string("syntax is modulenumber:i where is is module number");
//cout << var.substr(13) << endl;
sprintf(answer,"%llx",getId(MODULE_SERIAL_NUMBER,ival)); sprintf(answer,"%llx",getId(MODULE_SERIAL_NUMBER,ival));
return string(answer); return string(answer);
} else if (var=="moduleversion") { } else if (var=="moduleversion") {
@ -478,11 +495,16 @@ string mythenDetector::executeLine(int narg, char *args[], int action) {
if (action==PUT_ACTION) { if (action==PUT_ACTION) {
return string("cannot set "); return string("cannot set ");
} }
cout << var.substr(9) << endl; if (var.size()<=9)
return string("syntax is digitest:i where i is the module number");
istringstream vvstr(var.substr(9)); istringstream vvstr(var.substr(9));
vvstr >> ival; vvstr >> ival;
if (vvstr.fail())
return string("syntax is digitest:i where i is the module number");
sprintf(answer,"%x",digitalTest(CHIP_TEST, ival)); sprintf(answer,"%x",digitalTest(CHIP_TEST, ival));
return string(answer); return string(answer);
} else if (var=="bustest") { } else if (var=="bustest") {
if (action==PUT_ACTION) { if (action==PUT_ACTION) {
return string("cannot set "); return string("cannot set ");
@ -529,7 +551,7 @@ string mythenDetector::executeLine(int narg, char *args[], int action) {
} }
//timers //timers
else if (var=="exptime") { else if (var=="exptime") {
if (action==PUT_ACTION) { if (action==PUT_ACTION) {
sscanf(args[1],"%f",&fval);// in seconds! sscanf(args[1],"%f",&fval);// in seconds!
setTimer(ACQUISITION_TIME,(int64_t)(fval*1E+9)); setTimer(ACQUISITION_TIME,(int64_t)(fval*1E+9));
@ -558,34 +580,77 @@ string mythenDetector::executeLine(int narg, char *args[], int action) {
sprintf(answer,"%lld",setTimer(GATES_NUMBER)); sprintf(answer,"%lld",setTimer(GATES_NUMBER));
return string(answer); return string(answer);
} else if (var=="frames") { } else if (var=="frames") {
if (action==PUT_ACTION) { if (action==PUT_ACTION) {
sscanf(args[1],"%d",&ival); sscanf(args[1],"%d",&ival);
setTimer(FRAME_NUMBER,ival); setTimer(FRAME_NUMBER,ival);
} }
sprintf(answer,"%lld",setTimer(FRAME_NUMBER)); sprintf(answer,"%lld",setTimer(FRAME_NUMBER));
return string(answer); return string(answer);
} else if (var=="cycles") { } else if (var=="cycles") {
if (action==PUT_ACTION) { if (action==PUT_ACTION) {
sscanf(args[1],"%d",&ival); sscanf(args[1],"%d",&ival);
setTimer(CYCLES_NUMBER,ival); setTimer(CYCLES_NUMBER,ival);
} }
sprintf(answer,"%lld",setTimer(CYCLES_NUMBER)); sprintf(answer,"%lld",setTimer(CYCLES_NUMBER));
return string(answer); return string(answer);
} else if (var=="probes") {
} else if (var=="probes") {
if (action==PUT_ACTION) { if (action==PUT_ACTION) {
sscanf(args[1],"%d",&ival); sscanf(args[1],"%d",&ival);
setTimer(PROBES_NUMBER,ival); setTimer(PROBES_NUMBER,ival);
} }
sprintf(answer,"%lld",setTimer(PROBES_NUMBER)); sprintf(answer,"%lld",setTimer(PROBES_NUMBER));
return string(answer); return string(answer);
} }
else if (var=="dr") {
else if (var=="exptimel") {
if (action==PUT_ACTION) {
sprintf(answer,"Cannot set\n");
} else
sprintf(answer,"%f",(float)getTimeLeft(ACQUISITION_TIME)*1E-9);
return string(answer);
} else if (var=="periodl") {
if (action==PUT_ACTION) {
sprintf(answer,"Cannot set\n");
} else
sprintf(answer,"%f",(float)getTimeLeft(FRAME_PERIOD)*1E-9);
return string(answer);
} else if (var=="delayl") {
if (action==PUT_ACTION) {
sprintf(answer,"Cannot set\n");
} else
sprintf(answer,"%f",(float)getTimeLeft(DELAY_AFTER_TRIGGER)*1E-9);
return string(answer);
} else if (var=="gatesl") {
if (action==PUT_ACTION) {
sprintf(answer,"Cannot set\n");
} else
sprintf(answer,"%f",(float)getTimeLeft(GATES_NUMBER));
return string(answer);
} else if (var=="framesl") {
if (action==PUT_ACTION) {
sprintf(answer,"Cannot set\n");
} else
sprintf(answer,"%f",(float)getTimeLeft(FRAME_NUMBER)+2);
return string(answer);
} else if (var=="cyclesl") {
if (action==PUT_ACTION) {
sprintf(answer,"Cannot set\n");
} else
sprintf(answer,"%f",(float)getTimeLeft(CYCLES_NUMBER)+2);
return string(answer);
} else if (var=="progress") {
if (action==PUT_ACTION) {
sprintf(answer,"Cannot set\n");
} else
sprintf(answer,"%f",(float)getTimeLeft(PROGRESS));
return string(answer);
}
else if (var=="dr") {
if (action==PUT_ACTION) { if (action==PUT_ACTION) {
sscanf(args[1],"%d",&ival); sscanf(args[1],"%d",&ival);
setDynamicRange(ival); setDynamicRange(ival);
} }
sprintf(answer,"%d",setDynamicRange()); sprintf(answer,"%d",setDynamicRange());
return string(answer); return string(answer);
@ -621,10 +686,10 @@ string mythenDetector::executeLine(int narg, char *args[], int action) {
} }
} else if (var=="trimbits") { } else if (var=="trimbits") {
if (narg>=2) { if (narg>=2) {
std::cout<< " writing trimfile " << std::endl;
int nm=setNumberOfModules(GET_FLAG,X)*setNumberOfModules(GET_FLAG,Y); int nm=setNumberOfModules(GET_FLAG,X)*setNumberOfModules(GET_FLAG,Y);
sls_detector_module *myMod=NULL; sls_detector_module *myMod=NULL;
sval=string(args[1]); sval=string(args[1]);
std::cout<< " trimfile " << sval << std::endl;
for (int im=0; im<nm; im++) { for (int im=0; im<nm; im++) {
ostringstream ostfn, oscfn; ostringstream ostfn, oscfn;
@ -640,9 +705,11 @@ string mythenDetector::executeLine(int narg, char *args[], int action) {
if (sval.find('.',sval.length()-7)<string::npos) if (sval.find('.',sval.length()-7)<string::npos)
ostfn << ".sn" << setfill('0') << setw(3) << hex << getId(MODULE_SERIAL_NUMBER, im); ostfn << ".sn" << setfill('0') << setw(3) << hex << getId(MODULE_SERIAL_NUMBER, im);
myMod=readTrimFile(ostfn.str()); myMod=readTrimFile(ostfn.str());
myMod->module=im; if (myMod) {
setModule(*myMod); myMod->module=im;
deleteModule(myMod); setModule(*myMod);
deleteModule(myMod);
} //else cout << "myMod NULL" << endl;
} }
} }
} }
@ -652,6 +719,9 @@ string mythenDetector::executeLine(int narg, char *args[], int action) {
if (action==GET_ACTION) { if (action==GET_ACTION) {
trimMode mode=NOISE_TRIMMING; trimMode mode=NOISE_TRIMMING;
int par1=0, par2=0; int par1=0, par2=0;
if (var.size()<=5)
return string("trim:mode fname");
if (var.substr(5)=="noise") { if (var.substr(5)=="noise") {
// par1 is countlim; par2 is nsigma // par1 is countlim; par2 is nsigma
mode=NOISE_TRIMMING; mode=NOISE_TRIMMING;
@ -808,6 +878,8 @@ string mythenDetector::helpLine( int action) {
os << std::endl; os << std::endl;
os << "threshold ev \t Sets detector threshold in eV. Should be half of the beam energy. It is precise only if the detector is calibrated"<< std::endl; os << "threshold ev \t Sets detector threshold in eV. Should be half of the beam energy. It is precise only if the detector is calibrated"<< std::endl;
os << std::endl; os << std::endl;
os << "vthreshold dacu\t sets the detector threshold in dac units (0-1024). The energy is approx 800-15*keV" << std::endl;
os << std::endl;
os << "exptime t \t Sets the exposure time per frame (in s)"<< std::endl; os << "exptime t \t Sets the exposure time per frame (in s)"<< std::endl;
os << std::endl; os << std::endl;
os << "period t \t Sets the frames period (in s)"<< std::endl; os << "period t \t Sets the frames period (in s)"<< std::endl;
@ -826,6 +898,8 @@ string mythenDetector::helpLine( int action) {
os << std::endl; os << std::endl;
os << "flags mode \t Sets the readout flags - can be none or storeinram"<< std::endl; os << "flags mode \t Sets the readout flags - can be none or storeinram"<< std::endl;
os << std::endl; os << std::endl;
os << "ffdir dir \t Sets the default directory where the flat field are located"<< std::endl;
os << std::endl;
os << "flatfield fname \t Sets the flatfield file name - none disable flat field corrections"<< std::endl; os << "flatfield fname \t Sets the flatfield file name - none disable flat field corrections"<< std::endl;
os << std::endl; os << std::endl;
os << "ratecorr t \t Sets the rate corrections with dead time t ns (0 unsets, -1 uses default dead time for chosen settings"<< std::endl; os << "ratecorr t \t Sets the rate corrections with dead time t ns (0 unsets, -1 uses default dead time for chosen settings"<< std::endl;
@ -844,6 +918,8 @@ string mythenDetector::helpLine( int action) {
os << std::endl; os << std::endl;
os << "threaded b \t sets whether the postprocessing and file writing of the data is done in a separate thread (0 sequencial, 1 threaded). Please remeber to set the threaded mode if you acquire long real time measurements and/or use the storeinram option otherwise you risk to lose your data"<< std::endl; os << "threaded b \t sets whether the postprocessing and file writing of the data is done in a separate thread (0 sequencial, 1 threaded). Please remeber to set the threaded mode if you acquire long real time measurements and/or use the storeinram option otherwise you risk to lose your data"<< std::endl;
os << std::endl; os << std::endl;
os << "online b\t sets the detector in online (1) or offline (0) state " << std::endl;
os << std::endl;
} else if (action==GET_ACTION) { } else if (action==GET_ACTION) {
os << "help \t This help " << std::endl; os << "help \t This help " << std::endl;
@ -855,7 +931,7 @@ string mythenDetector::helpLine( int action) {
os << std::endl; os << std::endl;
os << "parameters fname\t writes the main detector parameters for the measuremen tin the file " << std::endl; os << "parameters fname\t writes the main detector parameters for the measuremen tin the file " << std::endl;
os << std::endl; os << std::endl;
os << "setup rootname\t writes the complete detector setup (including configuration, trimbits, flat field coefficients, badchannels etc.) is a set of files for which the extension is automatically generated " << std::endl; os << "setup rootname\t writes the complete detector setup (including configuration, trimbits, flat field coefficients, badchannels etc.) in a set of files for which the extension is automatically generated " << std::endl;
os << std::endl; os << std::endl;
os << "hostname \t Gets the detector hostname (or IP address) " << std::endl; os << "hostname \t Gets the detector hostname (or IP address) " << std::endl;
os << std::endl; os << std::endl;
@ -901,7 +977,7 @@ string mythenDetector::helpLine( int action) {
os << std::endl; os << std::endl;
os << "\t 12 ro_trigger_out_falling_edge" << std::endl; os << "\t 12 ro_trigger_out_falling_edge" << std::endl;
os << std::endl; os << std::endl;
os << "modulenumber\t Gets the module serial number " << std::endl; os << "modulenumber:i \t Gets the serial number of module i" << std::endl;
os << std::endl; os << std::endl;
os << "moduleversion\t Gets the module version " << std::endl; os << "moduleversion\t Gets the module version " << std::endl;
os << std::endl; os << std::endl;
@ -913,7 +989,7 @@ string mythenDetector::helpLine( int action) {
os << std::endl; os << std::endl;
os << "thisversion\t Gets the version of this software" << std::endl; os << "thisversion\t Gets the version of this software" << std::endl;
os << std::endl; os << std::endl;
os << "digitest\t Makes a digital test of the detector. Returns 0 if it succeeds " << std::endl; os << "digitest:i\t Makes a digital test of the detector module i. Returns 0 if it succeeds " << std::endl;
os << std::endl; os << std::endl;
os << "bustest\t Makes a test of the detector bus. Returns 0 if it succeeds " << std::endl; os << "bustest\t Makes a test of the detector bus. Returns 0 if it succeeds " << std::endl;
os << std::endl; os << std::endl;
@ -922,11 +998,15 @@ string mythenDetector::helpLine( int action) {
os << std::endl; os << std::endl;
os << "threshold\t Gets detector threshold in eV. It is precise only if the detector is calibrated"<< std::endl; os << "threshold\t Gets detector threshold in eV. It is precise only if the detector is calibrated"<< std::endl;
os << std::endl; os << std::endl;
os << "exptime\t Gets the exposure time per frame (in ns)"<< std::endl; os << "vthreshold \t Gets the detector threshold in dac units (0-1024). The energy is approx 800-15*keV" << std::endl;
os << std::endl; os << std::endl;
os << "period \t Gets the frames period (in ns)"<< std::endl;
os << "exptime\t Gets the exposure time per frame (in s)"<< std::endl;
os << std::endl; os << std::endl;
os << "delay \t Gets the delay after trigger (in ns)"<< std::endl; os << "period \t Gets the frames period (in s)"<< std::endl;
os << std::endl;
os << "delay \t Gets the delay after trigger (in s)"<< std::endl;
os << std::endl; os << std::endl;
os << "gates \t Gets the number of gates per frame"<< std::endl; os << "gates \t Gets the number of gates per frame"<< std::endl;
os << std::endl; os << std::endl;
@ -935,6 +1015,30 @@ string mythenDetector::helpLine( int action) {
os << "cycles \t Gets the number of cycles (e.g. number of triggers)"<< std::endl; os << "cycles \t Gets the number of cycles (e.g. number of triggers)"<< std::endl;
os << std::endl; os << std::endl;
os << "probes \t Gets the number of probes to accumulate (max 3)"<< std::endl; os << "probes \t Gets the number of probes to accumulate (max 3)"<< std::endl;
os << "exptimel\t Gets the exposure time left in the current frame (in s)"<< std::endl;
os << std::endl;
os << "periodl \t Gets the period left in the current frame (in s)"<< std::endl;
os << std::endl;
os << "delayl \t Gets the delay after current trigger left (in s)"<< std::endl;
os << std::endl;
os << "gatesl \t Gets the number of gates left in the current frame"<< std::endl;
os << std::endl;
os << "framesl \t Gets the number of frames left (after the current trigger)"<< std::endl;
os << std::endl;
os << "cyclesl \t Gets the number of cycles left (e.g. number of triggers)"<< std::endl;
//os << std::endl;
//os << "progress \t Gets acquisition progress - to be implemented"<< std::endl;
os << std::endl; os << std::endl;
os << "dr \t Gets the dynamic range"<< std::endl; os << "dr \t Gets the dynamic range"<< std::endl;
os << std::endl; os << std::endl;
@ -942,6 +1046,8 @@ string mythenDetector::helpLine( int action) {
os << "\t mode can be:\t noise\t beam\t improve\t fix\t offline "<< std::endl; os << "\t mode can be:\t noise\t beam\t improve\t fix\t offline "<< std::endl;
os << "Check that the start conditions are OK!!!"<< std::endl; os << "Check that the start conditions are OK!!!"<< std::endl;
os << std::endl; os << std::endl;
os << "ffdir \t Returns the default directory where the flat field are located"<< std::endl;
os << std::endl;
os << "flatfield fname \t returns wether the flat field corrections are enabled and if so writes the coefficients to the specified filename. If fname is none it is not written"<< std::endl; os << "flatfield fname \t returns wether the flat field corrections are enabled and if so writes the coefficients to the specified filename. If fname is none it is not written"<< std::endl;
os << std::endl; os << std::endl;
os << "ratecorr \t returns wether teh rate corrections are enabled and what is the dead time used in ns"<< std::endl; os << "ratecorr \t returns wether teh rate corrections are enabled and what is the dead time used in ns"<< std::endl;
@ -959,7 +1065,9 @@ string mythenDetector::helpLine( int action) {
os << "positions \t returns the number of positions at which the detector is moved during the acquisition and their values"<< std::endl; os << "positions \t returns the number of positions at which the detector is moved during the acquisition and their values"<< std::endl;
os << std::endl; os << std::endl;
os << "threaded \t gets whether the postprocessing and file writing of the data is done in a separate thread (0 sequencial, 1 threaded). Check that it is set to 1 if you acquire long real time measurements and/or use the storeinram option otherwise you risk to lose your data"<< std::endl; os << "threaded \t gets whether the postprocessing and file writing of the data is done in a separate thread (0 sequencial, 1 threaded). Check that it is set to 1 if you acquire long real time measurements and/or use the storeinram option otherwise you risk to lose your data"<< std::endl;
os << std::endl; os << std::endl;
os << "online \t gets the detector online (1) or offline (0) state " << std::endl;
os << std::endl;
} }
@ -1082,6 +1190,7 @@ int mythenDetector::writeConfigurationFile(string const fname){
"trimdir",\ "trimdir",\
"trimen",\ "trimen",\
"outdir",\ "outdir",\
"ffdir",\
"nmod",\ "nmod",\
"badchannels",\ "badchannels",\
"angconv",\ "angconv",\
@ -1091,7 +1200,7 @@ int mythenDetector::writeConfigurationFile(string const fname){
"waitstates",\ "waitstates",\
"setlength",\ "setlength",\
"clkdivider"}; "clkdivider"};
int nvar=14; int nvar=15;
ofstream outfile; ofstream outfile;
int iv=0; int iv=0;
char *args[100]; char *args[100];
@ -1253,6 +1362,7 @@ int mythenDetector::retrieveDetectorSetup(string fname1, int level){
if (level==2) { if (level==2) {
fname=fname1+string(".config"); fname=fname1+string(".config");
readConfigurationFile(fname); readConfigurationFile(fname);
//cout << "config file read" << endl;
fname=fname1+string(".det"); fname=fname1+string(".det");
} else } else
fname=fname1; fname=fname1;
@ -1454,7 +1564,7 @@ int mythenDetector::retrieveDetectorSetup(string fname1, int level){
strcpy(thisDetector->trimFile,fname.c_str()); strcpy(thisDetector->trimFile,fname.c_str());
return myMod; return myMod;
} else { } else {
std::cout<< "could not open file " << std::endl; std::cout<< "could not open file " << myfname<< std::endl;
if (nflag) if (nflag)
deleteModule(myMod); deleteModule(myMod);
return NULL; return NULL;
@ -1635,6 +1745,10 @@ int mythenDetector::readDataFile(string fname, float *data, float *err, float *a
if (ang==NULL) { if (ang==NULL) {
ssstr >> ichan >> fdata; ssstr >> ichan >> fdata;
ich=ichan; ich=ichan;
if (!ssstr.good()) {
interrupt=1;
break;
}
if (ich!=iline) if (ich!=iline)
std::cout<< "Channel number " << ichan << " does not match with line number " << iline << " " << dataformat << std::endl; std::cout<< "Channel number " << ichan << " does not match with line number " << iline << " " << dataformat << std::endl;
} else { } else {

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)
CFLAGS+= -Wall -DC_ONLY -DMCB_FUNCS -DVERBOSE CFLAGS+= -Wall -DC_ONLY -DMCB_FUNCS
#-DVERBOSE
#-DVERYVERBOSE #-DVERYVERBOSE
#-Werror #-Werror

View File

@ -1 +1 @@
/afs/psi.ch/project/mythen/slsDetectorSoftware/commonFiles/communication_funcs.c /afs/psi.ch/project/mythen/newMythenSoftware/slsDetectorSoftware/commonFiles/communication_funcs.c

View File

@ -1 +1 @@
/afs/psi.ch/project/mythen/slsDetectorSoftware/commonFiles/communication_funcs.h /afs/psi.ch/project/mythen/newMythenSoftware/slsDetectorSoftware/commonFiles/communication_funcs.h

View File

@ -37,6 +37,10 @@ int *ram_values=NULL;
char *now_ptr=NULL; char *now_ptr=NULL;
int ram_size=0; int ram_size=0;
int64_t totalTime=1;
u_int32_t progressMask=0;
int ififostart, ififostop, ififostep, ififo; int ififostart, ififostop, ififostep, ififo;
@ -182,18 +186,21 @@ u_int32_t getSetLength() {
u_int32_t setWaitStates(int d1) { u_int32_t setWaitStates(int d1) {
u_int32_t c; u_int32_t c;
int d=d1-2; int d=d1-2;
//int d=d1-3;
char cmd[100]; char cmd[100];
sprintf(cmd,"bus -a 0xb0000000 -w 0x%x0008",d1); if (d1<=0xf) {
c=bus_r(SPEED_REG); sprintf(cmd,"bus -a 0xb0000000 -w 0x%x0008",d1);
bus_w(SPEED_REG,(d<<WAIT_STATES_OFFSET)|(c&~(WAIT_STATES_MASK))); c=bus_r(SPEED_REG);
system(cmd); bus_w(SPEED_REG,(d<<WAIT_STATES_OFFSET)|(c&~(WAIT_STATES_MASK)));
return ((bus_r(SPEED_REG)& WAIT_STATES_MASK)>>WAIT_STATES_OFFSET); system(cmd);
}
return ((bus_r(SPEED_REG)& WAIT_STATES_MASK)>>WAIT_STATES_OFFSET)+2;
} }
u_int32_t getWaitStates() { u_int32_t getWaitStates() {
u_int32_t clk_div; u_int32_t clk_div;
clk_div=((bus_r(SPEED_REG)& WAIT_STATES_MASK)>>WAIT_STATES_OFFSET); clk_div=((bus_r(SPEED_REG)& WAIT_STATES_MASK)>>WAIT_STATES_OFFSET);
return clk_div; return clk_div+2;
} }
@ -247,8 +254,6 @@ int getExtSignal(int d) {
int off=d*SIGNAL_OFFSET; int off=d*SIGNAL_OFFSET;
int mode=((bus_r(EXT_SIGNAL_REG)&(SIGNAL_MASK<<off))>>off); int mode=((bus_r(EXT_SIGNAL_REG)&(SIGNAL_MASK<<off))>>off);
if (mode<RO_TRIGGER_OUT_FALLING_EDGE) if (mode<RO_TRIGGER_OUT_FALLING_EDGE)
return modes[mode]; return modes[mode];
else else
@ -366,18 +371,18 @@ u_int32_t testFpga(void) {
//fixed pattern //fixed pattern
val=bus_r(FIX_PATT_REG); val=bus_r(FIX_PATT_REG);
if (val==FIXED_PATT_VAL) { if (val==FIXED_PATT_VAL) {
printf("fixed pattern ok!! %x\n",val); printf("fixed pattern ok!! %08x\n",val);
} else { } else {
printf("fixed pattern wrong!! %x\n",val); printf("fixed pattern wrong!! %08x\n",val);
result=FAIL; result=FAIL;
// return FAIL; // return FAIL;
} }
//FPGA code version //FPGA code version
val=bus_r(FPGA_VERSION_REG)&0x00ffffff; val=bus_r(FPGA_VERSION_REG)&0x00ffffff;
if (val>=(FPGA_VERSION_VAL&0x00ffffff)) { if (val>=(FPGA_VERSION_VAL&0x00ffffff)) {
printf("FPGA version ok!! %x\n",val); printf("FPGA version ok!! %06x\n",val);
} else { } else {
printf("FPGA version too old! %x\n",val); printf("FPGA version too old! %06x\n",val);
return FAIL; return FAIL;
} }
//dummy register //dummy register
@ -387,7 +392,7 @@ u_int32_t testFpga(void) {
if (val==0xF0F0F0F0) { if (val==0xF0F0F0F0) {
printf("FPGA dummy register ok!! %x\n",val); printf("FPGA dummy register ok!! %x\n",val);
} else { } else {
printf("FPGA dummy register wrong!! %x\n",val); printf("FPGA dummy register wrong!! %x instead of 0xF0F0F0F0 \n",val);
result=FAIL; result=FAIL;
// return FAIL; // return FAIL;
} }
@ -398,7 +403,7 @@ u_int32_t testFpga(void) {
if (val==0x0F0F0F0F) { if (val==0x0F0F0F0F) {
printf("FPGA dummy register ok!! %x\n",val); printf("FPGA dummy register ok!! %x\n",val);
} else { } else {
printf("FPGA dummy register wrong!! %x\n",val); printf("FPGA dummy register wrong!! %x instead of 0x0F0F0F0F \n",val);
result=FAIL; result=FAIL;
// return FAIL; // return FAIL;
} }
@ -423,10 +428,12 @@ int getNModBoard() {
int nmodboard; int nmodboard;
u_int32_t val; u_int32_t val;
val=bus_r(FPGA_VERSION_REG)&0xff000000; val=bus_r(FPGA_VERSION_REG)&0xff000000;
printf("version register %08x\n",val);
nmodboard=val >> 24; nmodboard=val >> 24;
#ifdef VERY_VERBOSE //#ifdef VERY_VERBOSE
printf("The board hosts %d modules\n",nmodboard); printf("The board hosts %d modules\n",nmodboard);
#endif //#endif
nModBoard=nmodboard; nModBoard=nmodboard;
//getNModBoard()=nmodboard; //getNModBoard()=nmodboard;
return nmodboard; return nmodboard;
@ -439,26 +446,28 @@ int setNMod(int n) {
int imod; int imod;
int rval; int rval;
int reg; int reg;
int nf=0;
int shiftfifo=SHIFTFIFO; int shiftfifo=SHIFTFIFO;
int ntot=getNModBoard(); int ntot=getNModBoard();
if (getProbes()==0) {
switch (dynamicRange) { switch (dynamicRange) {
case 16: case 16:
shiftfifo=SHIFTFIFO-1; shiftfifo=SHIFTFIFO-1;
break; break;
case 8: case 8:
shiftfifo=SHIFTFIFO-2; shiftfifo=SHIFTFIFO-2;
break; break;
case 4: case 4:
shiftfifo=SHIFTFIFO-3; shiftfifo=SHIFTFIFO-3;
break; break;
case 1: case 1:
shiftfifo=SHIFTFIFO-5; shiftfifo=SHIFTFIFO-5;
break; break;
default: default:
shiftfifo=SHIFTFIFO;
}
} else
shiftfifo=SHIFTFIFO; shiftfifo=SHIFTFIFO;
}
#ifdef VERBOSE #ifdef VERBOSE
@ -466,80 +475,77 @@ int setNMod(int n) {
#endif #endif
if (n>0 && n<=ntot) { if (n>0 && n<=ntot) {
nModX=n; nModX=n;
// dataBytes=nModX*nModY*NCHIP*NCHAN*dynamicRange/8;
//allocateRAM();
/* should enable all fifos*/
/* // bus_w(FIFO_CNTRL_REG_OFF+(ALLFIFO<<SHIFTFIFO), FIFO_RESET_BIT | FIFO_DISABLE_TOGGLE_BIT);
bus_w(FIFO_CNTRL_REG_OFF+(ALLFIFO<<shiftfifo), FIFO_RESET_BIT | FIFO_DISABLE_TOGGLE_BIT);
#ifdef VERBOSE
printf("a %08x r %08x\n",FIFO_CNTRL_REG_OFF+(ALLFIFO<<shiftfifo),FIFO_RESET_BIT | FIFO_DISABLE_TOGGLE_BIT);
for (ififo=0; ififo<ntot*NCHIP; ififo++) {
printf("%d %08x\n",ififo,bus_r(FIFO_COUNTR_REG_OFF+(ififo<<shiftfifo)));
}
#endif
ifste=dynamicRange/32;
ifsta=nModX*NCHIP*ifste;
ifsto=ntot*NCHIP*ifste;
*/
/*d isable the fifos relative to the unused modules */ /*d isable the fifos relative to the unused modules */
for (ififo=0; ififo<ntot*NCHIP; ififo++) { for (ififo=0; ififo<ntot*NCHIP; ififo++) {
//for (ififo=ifsta; ififo<ifsto; ififo+=ifste) {
//fifocntrl[ififo]=FIFO_DISABLE_TOGGLE_BIT;
reg=bus_r(FIFO_COUNTR_REG_OFF+(ififo<<shiftfifo)); reg=bus_r(FIFO_COUNTR_REG_OFF+(ififo<<shiftfifo));
#ifdef VERBOSE
printf("Fifo %d is %x",ififo,reg);
#endif
if (ififo<n*NCHIP) { if (ififo<n*NCHIP) {
if (reg&FIFO_DISABLED_BIT) if (reg&FIFO_DISABLED_BIT) {
bus_w(FIFO_CNTRL_REG_OFF+(ififo<<shiftfifo), FIFO_DISABLE_TOGGLE_BIT); bus_w(FIFO_CNTRL_REG_OFF+(ififo<<shiftfifo), FIFO_DISABLE_TOGGLE_BIT);
} else {
if ((reg&FIFO_DISABLED_BIT)==0)
bus_w(FIFO_CNTRL_REG_OFF+(ififo<<shiftfifo), FIFO_DISABLE_TOGGLE_BIT);
}
#ifdef VERBOSE #ifdef VERBOSE
printf(" done %x\n",bus_r(FIFO_COUNTR_REG_OFF+(ififo<<shiftfifo))); if (bus_r(FIFO_COUNTR_REG_OFF+(ififo<<shiftfifo))&FIFO_DISABLED_BIT) {
printf("Fifo %d is %x (nm %d nc %d addr %08x)",ififo,reg, (reg&FIFO_NM_MASK)>>FIFO_NM_OFF, (reg&FIFO_NC_MASK)>>FIFO_NC_OFF, FIFO_COUNTR_REG_OFF+(ififo<<shiftfifo));
printf(" enabling %08x\n",bus_r(FIFO_COUNTR_REG_OFF+(ififo<<shiftfifo)));
}
#endif #endif
}
//#ifdef VERBOSE
//else printf(" unmodified ",ififo,reg);
//#endif
} else {
if ((reg&FIFO_ENABLED_BIT)) {
bus_w(FIFO_CNTRL_REG_OFF+(ififo<<shiftfifo), FIFO_DISABLE_TOGGLE_BIT);
#ifdef VERBOSE
if ((bus_r(FIFO_COUNTR_REG_OFF+(ififo<<shiftfifo))&FIFO_ENABLED_BIT)) {
printf("Fifo %d is %x (nm %d nc %d addr %08x)",ififo,reg, (reg&FIFO_NM_MASK)>>FIFO_NM_OFF, (reg&FIFO_NC_MASK)>>FIFO_NC_OFF, FIFO_COUNTR_REG_OFF+(ififo<<shiftfifo));
printf(" disabling %08x\n",bus_r(FIFO_COUNTR_REG_OFF+(ififo<<shiftfifo)));
}
#endif
}
//#ifdef VERBOSE
//else printf(" unmodified ",ififo,reg);
//#endif
}
//#ifdef VERBOSE
//printf(" done %x\n",bus_r(FIFO_COUNTR_REG_OFF+(ififo<<shiftfifo)));
//#endif
} }
} }
// ifste=dynamicRange/32; // ifste=dynamicRange/32;
nModX=0; nModX=0;
nf=0;
for (imod=0; imod<ntot; imod++) { for (imod=0; imod<ntot; imod++) {
rval=0; rval=0;
for (ififo=imod*NCHIP; ififo<(imod+1)*NCHIP; ififo++) {// for (ififo=imod*NCHIP; ififo<(imod+1)*NCHIP; ififo++) {
//for (ififo=imod*NCHIP*ifste; ififo<(imod+1)*NCHIP*ifste; ififo+=ifste) { bus_w(FIFO_CNTRL_REG_OFF+(ififo<<shiftfifo), FIFO_RESET_BIT);
if ((bus_r(FIFO_COUNTR_REG_OFF+(ififo<<shiftfifo))&FIFO_DISABLED_BIT)==0){ #ifdef VERBOSE
printf("%08x ",(bus_r(FIFO_COUNTR_REG_OFF+(ififo<<shiftfifo))));
#endif
if ((bus_r(FIFO_COUNTR_REG_OFF+(ififo<<shiftfifo))&FIFO_ENABLED_BIT)){
rval=1; // checks if at least one fifo of the module is enabled rval=1; // checks if at least one fifo of the module is enabled
#ifdef VERBOSE #ifdef VERBOSE
printf("%x Fifo %d is enabled\n",(bus_r(FIFO_COUNTR_REG_OFF+(ififo<<shiftfifo))), ififo); printf("Fifo %d is enabled\n",ififo);
#endif #endif
nf++;
} }
#ifdef VERBOSE #ifdef VERBOSE
else printf("%x Fifo %d is disabled\n",(bus_r(FIFO_COUNTR_REG_OFF+(ififo<<shiftfifo))),ififo); else printf("Fifo %d is disabled\n",ififo);
#endif #endif
} }
if (rval) { if (rval) {
nModX++; nModX++;
#ifdef VERBOSE #ifdef VERBOSE
printf("Module %d is enabled --total %d\n",imod,nModX ); printf("Module %d is enabled --total %d (%d fifos)\n",imod,nModX,nf );
#endif #endif
} }
#ifdef VERBOSE #ifdef VERBOSE
else printf("Module %d is disabled --total %d\n",imod,nModX ); else printf("Module %d is disabled --total %d (%d fifos)\n",imod,nModX,nf );
#endif #endif
} }
#ifdef VERBOSE #ifdef VERBOSE
printf("There are %d modules enabled\n",nModX); printf("There are %d modules enabled (%d fifos)\n",nModX, nf);
#endif #endif
// dataBytes=nModX*nModY*NCHIP*NCHAN*dynamicRange/8;
// allocateRAM();
getDynamicRange(); getDynamicRange();
return nModX; return nModX;
@ -591,10 +597,9 @@ int64_t getFrames(){
int64_t setExposureTime(int64_t value){ int64_t setExposureTime(int64_t value){
/* time is in ns */ /* time is in ns */
if (value!=-1) { if (value!=-1)
value*=(1E-9*CLK_FREQ); value*=(1E-9*CLK_FREQ);
} return set64BitReg(value,SET_EXPTIME_LSB_REG, SET_EXPTIME_MSB_REG)/(1E-9*CLK_FREQ);
return set64BitReg(value,SET_EXPTIME_LSB_REG, SET_EXPTIME_MSB_REG)/(1E-9*CLK_FREQ);
} }
int64_t getExposureTime(){ int64_t getExposureTime(){
@ -614,6 +619,9 @@ int64_t setPeriod(int64_t value){
if (value!=-1) { if (value!=-1) {
value*=(1E-9*CLK_FREQ); value*=(1E-9*CLK_FREQ);
} }
return set64BitReg(value,SET_PERIOD_LSB_REG, SET_PERIOD_MSB_REG)/(1E-9*CLK_FREQ); return set64BitReg(value,SET_PERIOD_LSB_REG, SET_PERIOD_MSB_REG)/(1E-9*CLK_FREQ);
} }
@ -644,6 +652,7 @@ int64_t getTrains(){
int64_t setProbes(int64_t value){ int64_t setProbes(int64_t value){
int ow; int ow;
int nm=setNMod(-1);
switch (getDynamicRange()) { switch (getDynamicRange()) {
case 32: case 32:
ow=1; ow=1;
@ -652,25 +661,45 @@ int64_t setProbes(int64_t value){
ow=2; ow=2;
break; break;
case 8: case 8:
ow=4; ow=3;
break; break;
case 4: case 4:
ow=8; ow=4;
break; break;
case 1: case 1:
ow=5; ow=5;
break;
default: default:
ow=1; ow=1;
} }
if (value>=0) { if (value>=0) {
setCSregister(ALLMOD); setCSregister(ALLMOD);
initChipWithProbes(0, ow,value, ALLMOD); initChipWithProbes(0, ow,value, ALLMOD);
putout("0000000000000000",ALLMOD); putout("0000000000000000",ALLMOD);
setNMod(nm);
getDynamicRange(); // needed to change dataBytes
} }
return getProbes(); return getProbes();
} }
int64_t setProgress() {
//????? eventually call after setting the registers
}
int64_t getProgress() {
//should be done in firmware!!!!
}
int64_t getProbes(){ int64_t getProbes(){
u_int32_t shiftin=bus_r(GET_SHIFT_IN_REG); u_int32_t shiftin=bus_r(GET_SHIFT_IN_REG);
u_int32_t np=(shiftin >>PROBES_OFF) & PROBES_MASK; u_int32_t np=(shiftin >>PROBES_OFF) & PROBES_MASK;
@ -729,6 +758,9 @@ u_int32_t runState(void) {
write_status_sm("Running"); write_status_sm("Running");
else else
write_status_sm("Stopped"); write_status_sm("Stopped");
#endif
#ifdef VERBOSE
printf("status %08x\n",s);
#endif #endif
return s; return s;
} }
@ -836,7 +868,7 @@ u_int32_t fifoReadCounter(int fifonum)
rval=bus_r(FIFO_COUNTR_REG_OFF+(fifonum<<shiftfifo)); rval=bus_r(FIFO_COUNTR_REG_OFF+(fifonum<<shiftfifo));
#ifdef VERBOSE #ifdef VERBOSE
printf("FIFO %d contains %x words\n",fifonum, rval); //printf("FIFO %d contains %x words\n",fifonum, rval);
#endif #endif
return rval; return rval;
} }
@ -861,6 +893,7 @@ u_int32_t* fifo_read_event()
#ifdef VERBOSE #ifdef VERBOSE
int ichip; int ichip;
int ichan;
#endif #endif
#ifdef VIRTUAL #ifdef VIRTUAL
return NULL; return NULL;
@ -868,43 +901,65 @@ u_int32_t* fifo_read_event()
#ifdef VERYVERBOSE #ifdef VERYVERBOSE
printf("before looping\n"); printf("before looping\n");
for (ichip=0; ichip<nModBoard*NCHIP; ichip++) { for (ichip=0; ichip<nModBoard*NCHIP; ichip++) {
fifoReadCounter(ichip); if ((fifoReadCounter(ichip)&FIFO_COUNTER_MASK)%128)
printf("FIFO %d contains %d words\n",ichip,(fifoReadCounter(ichip)&FIFO_COUNTER_MASK));
} }
#endif #endif
while(bus_r(LOOK_AT_ME_REG)==0) { while(bus_r(LOOK_AT_ME_REG)==0) {
//#ifdef VERYVERBOSE #ifdef VERYVERBOSE
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) { if (bus_r(LOOK_AT_ME_REG)==0) {
#ifdef VERBOSE #ifdef VERBOSE
printf("no frame found %x status %x\n", bus_r(LOOK_AT_ME_REG),runState()); printf("no frame found - exiting ");
#ifdef VERYVERBOSE
for (ichip=0; ichip<nModBoard*NCHIP; ichip++) { printf("%08x %08x\n", runState(), bus_r(LOOK_AT_ME_REG));
fifoReadCounter(ichip); /* for (ichip=0; ichip<nModBoard*NCHIP; ichip++) {
} if ((fifoReadCounter(ichip)&FIFO_COUNTER_MASK)%128)
#endif printf("FIFO %d contains %d words\n",ichip,(fifoReadCounter(ichip)&FIFO_COUNTER_MASK));
}
*/
#endif #endif
return NULL; return NULL;
} else { } else {
#ifdef VERYVERBOSE
printf("no frame found %x status %x\n", bus_r(LOOK_AT_ME_REG),runState());
#endif
break; break;
} }
} }
} }
#ifdef VERBOSE #ifdef VERYVERBOSE
printf("before readout\n"); printf("before readout %08x %08x\n", runState(), bus_r(LOOK_AT_ME_REG));
for (ichip=0; ichip<nModBoard*NCHIP; ichip++) { for (ichip=0; ichip<nModBoard*NCHIP; ichip++) {
fifoReadCounter(ichip); if ((fifoReadCounter(ichip)&FIFO_COUNTER_MASK)%128)
printf("FIFO %d contains %d words\n",ichip,(fifoReadCounter(ichip)&FIFO_COUNTER_MASK));
} }
#endif #endif
memcpy(now_ptr, values, dataBytes); memcpy(now_ptr, values, dataBytes);
#ifdef VERBOSE /*
#ifdef VERBOSE
for (ichip=0;ichip<dataBytes/4; ichip++) {
now_ptr[ichip*4]=values[ichip];
#ifdef VERBOSE
if (((fifoReadCounter(ichip/128)&FIFO_COUNTER_MASK)+(ichip%128))>128)
printf("chip %d ch %d %d\n",ichip/128, ichip%128, (fifoReadCounter(ichip/128)&FIFO_COUNTER_MASK));
#endif
}
//#endif
*/
#ifdef VERYVERBOSE
printf("Copying to ptr %x %d\n",now_ptr, dataBytes); printf("Copying to ptr %x %d\n",now_ptr, dataBytes);
#endif #endif
#ifdef VERYVERBOSE #ifdef VERYVERBOSE
printf("after readout\n"); printf("after readout %08x %08x\n", runState(), bus_r(LOOK_AT_ME_REG));
for (ichip=0; ichip<nModBoard*NCHIP; ichip++) { for (ichip=0; ichip<nModBoard*NCHIP; ichip++) {
fifoReadCounter(ichip); if ((fifoReadCounter(ichip)&FIFO_COUNTER_MASK)%128)
printf("FIFO %d contains %d words\n",ichip,(fifoReadCounter(ichip)&FIFO_COUNTER_MASK));
} }
#endif #endif
if (storeInRAM>0) { if (storeInRAM>0) {
@ -1023,9 +1078,10 @@ int getDynamicRange() {
int dr; int dr;
u_int32_t shiftin=bus_r(GET_SHIFT_IN_REG); u_int32_t shiftin=bus_r(GET_SHIFT_IN_REG);
u_int32_t outmux=(shiftin >> OUTMUX_OFF) & OUTMUX_MASK; u_int32_t outmux=(shiftin >> OUTMUX_OFF) & OUTMUX_MASK;
u_int32_t probes=(shiftin >> PROBES_OFF) & PROBES_MASK;
#ifdef VERYVERBOSE #ifdef VERYVERBOSE
printf("%08x ",shiftin); printf("%08x ",shiftin);
printf("outmux==%02x\n",outmux); printf("outmux=%02x probes=%d\n",outmux,probes);
#endif #endif
switch (outmux) { switch (outmux) {
@ -1045,7 +1101,14 @@ int getDynamicRange() {
dr=32; dr=32;
} }
dynamicRange=dr; dynamicRange=dr;
dataBytes=nModX*nModY*NCHIP*NCHAN*dynamicRange/8; if (probes==0) {
dataBytes=nModX*nModY*NCHIP*NCHAN*dynamicRange/8;
} else {
dataBytes=nModX*nModY*NCHIP*NCHAN*4;///
}
#ifdef VERBOSE
printf("Number of data bytes %d - probes %d dr %d\n", dataBytes, probes, dr);
#endif
if (allocateRAM()==OK) { if (allocateRAM()==OK) {
; ;
} else } else
@ -1059,6 +1122,7 @@ int testBus() {
u_int32_t j, i; u_int32_t j, i;
char cmd[100]; char cmd[100];
u_int32_t val=0x0; u_int32_t val=0x0;
int ifail=OK;
// printf("%s\n",cmd); // printf("%s\n",cmd);
// system(cmd); // system(cmd);
i=0; i=0;
@ -1066,18 +1130,20 @@ int testBus() {
while (i<10000000) { while (i<10000000) {
// val=bus_r(FIX_PATT_REG); // val=bus_r(FIX_PATT_REG);
bus_w(DUMMY_REG,val); bus_w(DUMMY_REG,val);
bus_w(FIX_PATT_REG,0x0); bus_w(FIX_PATT_REG,0);
j=bus_r(DUMMY_REG); j=bus_r(DUMMY_REG);
if (i%10000==1) //if (i%10000==1)
printf("value 0x%x\n",j);
if (j!=val){ if (j!=val){
printf("read wrong value %x instead of %x\n",j, val); printf("%d : read wrong value %08x instead of %08x\n",i,j, val);
return FAIL; ifail++;
} //return FAIL;
}// else
// printf("%d : value OK 0x%08x\n",i,j);
val+=0xbbbbb; val+=0xbbbbb;
i++; i++;
} }
return OK; return ifail;
} }

View File

@ -75,6 +75,11 @@ int64_t getTrains();
int64_t setProbes(int64_t value); int64_t setProbes(int64_t value);
int64_t getProbes(); int64_t getProbes();
int64_t getProgress();
int64_t setProgress();
u_int32_t runBusy(void); u_int32_t runBusy(void);
u_int32_t runState(void); u_int32_t runState(void);
u_int32_t dataPresent(void); u_int32_t dataPresent(void);

View File

@ -52,9 +52,10 @@ int initDetector() {
int imod; int imod;
// sls_detector_module *myModule; // sls_detector_module *myModule;
int n=getNModBoard(); int n=getNModBoard();
#ifdef VERBOSE nModX=n;
//#ifdef VERBOSE
printf("Board is for %d modules\n",n); printf("Board is for %d modules\n",n);
#endif //#endif
detectorModules=malloc(n*sizeof(sls_detector_module)); detectorModules=malloc(n*sizeof(sls_detector_module));
detectorChips=malloc(n*NCHIP*sizeof(int)); detectorChips=malloc(n*NCHIP*sizeof(int));
@ -1446,9 +1447,8 @@ int initChipWithProbes(int obe, int ow,int nprobes, int imod){
int im, ichip; int im, ichip;
int chipmi, chipma, modmi, modma; int chipmi, chipma, modmi, modma;
int64_t regval, dum; int64_t regval=0, dum;
int omask; int omask;
switch (ow) { switch (ow) {
case 2: case 2:
omask=2; omask=2;
@ -1466,10 +1466,16 @@ int initChipWithProbes(int obe, int ow,int nprobes, int imod){
omask=0;//1; omask=0;//1;
break; break;
} }
regval=(omask<<OUTMUX_OFFSET)|(nprobes<<PROBES_OFFSET)|(obe<<OUTBUF_OFFSET); #ifdef VERBOSE
printf("\n \n \n",regval);
printf("initChip ow=%d omask=%d probes=%d\n",ow, omask,nprobes);
#endif
regval|=(omask<<OUTMUX_OFFSET);
regval|=(nprobes<<PROBES_OFFSET);
regval|=(obe<<OUTBUF_OFFSET);
#ifdef VERBOSE #ifdef VERBOSE
printf("initChip: shift in will be %08x\n",regval); printf("initChip : shift in will be %08x\n",regval);
#endif #endif
/* clearing shift in register */ /* clearing shift in register */
@ -1909,6 +1915,7 @@ int testShiftIn(int imod) {
} }
putout("0000000000000000", ALLMOD); putout("0000000000000000", ALLMOD);
printf("Shift in module %d : %d errors\n", imod,result);
if (result) if (result)
return 1; return 1;
else else
@ -1922,7 +1929,7 @@ int testShiftOut(int imod) {
printf("testing shift out for module %d\n", imod); printf("testing shift out for module %d\n", imod);
setCSregister(254); setCSregister(ALLMOD);
for (i=0; i<24; i++) { for (i=0; i<24; i++) {
if (dum & 1<<i) { if (dum & 1<<i) {
putout("0100010000000000",ALLMOD); putout("0100010000000000",ALLMOD);
@ -1962,6 +1969,7 @@ int testShiftOut(int imod) {
putout("0010010000000000",ALLMOD); putout("0010010000000000",ALLMOD);
} }
putout("0000000000000000", ALLMOD); putout("0000000000000000", ALLMOD);
printf("Shift out module %d : %d errors\n", imod,result);
if (result) if (result)
return 1; return 1;
else else
@ -2010,7 +2018,8 @@ int testShiftStSel(int imod) {
putout("0010011000000000",ALLMOD); putout("0010011000000000",ALLMOD);
} }
putout("0000011000000000",ALLMOD); putout("0000011000000000",ALLMOD);
printf("Shift stsel module %d : %d errors\n", imod,result);
if (result) if (result)
return 1; return 1;
else else
@ -2103,7 +2112,7 @@ int testExtPulse(int imod) {
int testExtPulseMux(int imod, int ow) { int testExtPulseMux(int imod, int ow) {
int i, ichan, ichip, result=0, ind; int i, ichan, ichip, result=0, ind, chipr=0;
int *values, *v1; int *values, *v1;
int vright,v; int vright,v;
int nbit_mask=0xffffff; int nbit_mask=0xffffff;
@ -2157,19 +2166,25 @@ int testExtPulseMux(int imod, int ow) {
return 1; return 1;
} }
for (ichip=0; ichip<NCHIP; ichip++) { for (ichip=0; ichip<NCHIP; ichip++) {
chipr=0;
for (ichan=0; ichan<NCHAN; ichan++) { for (ichan=0; ichan<NCHAN; ichan++) {
ind=ichan+(ichip+imod*NCHIP)*NCHAN; ind=ichan+(ichip+imod*NCHIP)*NCHAN;
v=values[ind]; v=values[ind];
vright=(ichan*(ichip+1))&nbit_mask; vright=(ichan*(ichip+1))&nbit_mask;
if (v!=vright) { if (v!=vright) {
result++; result++;
printf("Counter test mux %d mode: channel %d (%x) read %d instead of %d\n",ow, ichan+(ichip+imod*NCHIP)*NCHAN, ind, v, vright); chipr++;
printf("Counter test mux %d mode: channel %d chip %d read %d instead of %d\n",ow, ichan+(ichip+imod*NCHIP)*NCHAN, ichip, v, vright);
//break; //break;
} }
//printf("\n"); //printf("\n");
} }
if (chipr)
printf("Test Counter module %d chip%d mux %d: %d errors\n", imod,ichip, ow,chipr);
} }
free(values); free(values);
if (result)
printf("Test Counter module %d mux %d: %d errors\n", imod,ow,result);
if (result) if (result)
return 1; return 1;
@ -2180,7 +2195,7 @@ int testExtPulseMux(int imod, int ow) {
int testDataInOutMux(int imod, int ow, int num) { int testDataInOutMux(int imod, int ow, int num) {
int ichan, ichip, result=0, ind; int ichan, ichip, result=0, chipr=0, ind;
int vright,v; int vright,v;
int nbit_mask=0xffffff; int nbit_mask=0xffffff;
int *values, *v1; int *values, *v1;
@ -2226,18 +2241,23 @@ int testDataInOutMux(int imod, int ow, int num) {
return 1; return 1;
} }
for (ichip=0; ichip<NCHIP; ichip++) { for (ichip=0; ichip<NCHIP; ichip++) {
chipr=0;
for (ichan=0; ichan<NCHAN; ichan++) { for (ichan=0; ichan<NCHAN; ichan++) {
ind=ichan+(ichip+imod*NCHIP)*NCHAN; ind=ichan+(ichip+imod*NCHIP)*NCHAN;
v=values[ind]; v=values[ind];
if (v!=vright) { if (v!=vright) {
result++; result++;
printf("Counter test mux %d mode: channel %d (%x) read %d instead of %d\n",ow, ichan+(ichip+imod*NCHIP)*NCHAN, ind, v, vright); chipr++;
printf("DataInOut test mux %d mode: channel %d chip %d read %d instead of %d\n",ow, ichan+(ichip+imod*NCHIP)*NCHAN, ichip, v, vright);
//break; //break;
} }
//printf("\n"); //printf("\n");
} }
if (chipr)
printf("Test DatInOut module %d chip %d mux %d: %d errors\n", imod,ichip, ow,chipr);
} }
if (result)
printf("Test DatInOut module %d mux %d: %d errors\n", imod,ow,result);
free(values); free(values);
if (result) if (result)
return 1; return 1;
@ -2426,6 +2446,7 @@ int testOutMux(int imod) {
putout("0000000000000000",ALLMOD); putout("0000000000000000",ALLMOD);
} }
printf("Test OutMux module %d : %d errors\n", imod,result);
if (result) if (result)
return 1; return 1;
else else
@ -2544,6 +2565,7 @@ int testFpgaMux(int imod) {
putout("0000000000000000",ALLMOD); putout("0000000000000000",ALLMOD);
} }
printf("Test FpgaMux module %d : %d errors\n", imod,result);
if (result) if (result)
return 1; return 1;
else else

View File

@ -104,11 +104,16 @@
#define ALL_FIFO_EMPTY_BIT 0x00010000 // data ready #define ALL_FIFO_EMPTY_BIT 0x00010000 // data ready
/* for fifo status register */ /* for fifo status register */
#define FIFO_DISABLED_BIT 0x81000000 #define FIFO_ENABLED_BIT 0x80000000
#define FIFO_DISABLED_BIT 0x01000000
#define FIFO_ERROR_BIT 0x08000000 #define FIFO_ERROR_BIT 0x08000000
#define FIFO_EMPTY_BIT 0x04000000 #define FIFO_EMPTY_BIT 0x04000000
#define FIFO_DATA_READY_BIT 0x02000000 #define FIFO_DATA_READY_BIT 0x02000000
#define FIFO_COUNTER_MASK 0x00ffffff #define FIFO_COUNTER_MASK 0x000001ff
#define FIFO_NM_MASK 0x00e00000
#define FIFO_NM_OFF 21
#define FIFO_NC_MASK 0x001ffe00
#define FIFO_NC_OFF 9
/* for config register */ /* for config register */

View File

@ -589,19 +589,36 @@ int digital_test(int fnum) {
#endif #endif
retval=0; retval=0;
#ifdef MCB_FUNCS #ifdef MCB_FUNCS
if (testShiftIn(imod)) retval|=(1<<(ibit++)); if (testShiftIn(imod)) retval|=(1<<(ibit));
if (testShiftOut(imod)) retval|=(1<<(ibit++)); ibit++;
if (testShiftStSel(imod)) retval|=(1<<(ibit++)); if (testShiftOut(imod)) retval|=(1<<(ibit));
ibit++;
if (testShiftStSel(imod)) retval|=(1<<(ibit));
ibit++;
//if ( testDataInOut(0x123456, imod)) retval|=(1<<(ibit++)); //if ( testDataInOut(0x123456, imod)) retval|=(1<<(ibit++));
//if ( testExtPulse(imod)) retval|=(1<<(ibit++)); //if ( testExtPulse(imod)) retval|=(1<<(ibit++));
// for (ow=0; ow<6; ow++) // for (ow=0; ow<6; ow++)
for (ow=0; ow<5; ow++) // ow=1;
if (testDataInOutMux(imod, ow, 0x789abc)) retval|=(1<<ibit++); //#ifndef PICASSOD
for (ow=0; ow<5; ow++) {
//#endif
if (testDataInOutMux(imod, ow, 0x789abc)) retval|=(1<<ibit);
ibit++;
}
//for (ow=0; ow<6; ow++) //for (ow=0; ow<6; ow++)
for (ow=0; ow<5; ow++) // ow=1;
if (testExtPulseMux(imod, ow)) retval|=(1<<ibit++); //#ifndef PICASSOD
if ( testOutMux(imod)) retval|=(1<<(ibit++)); for (ow=0; ow<5; ow++) {
if (testFpgaMux(imod)) retval|=(1<<(ibit++)); //#endif
if (testExtPulseMux(imod, ow)) retval|=(1<<ibit);
ibit++;
}
//#ifndef PICASSOD
if ( testOutMux(imod)) retval|=(1<<(ibit));
ibit++;
if (testFpgaMux(imod)) retval|=(1<<(ibit));
ibit++;
//#endif
#endif #endif
break; break;
@ -1670,7 +1687,13 @@ int read_frame(int fnum) {
printf("Sending ptr %x %d\n",dataretval, dataBytes); printf("Sending ptr %x %d\n",dataretval, dataBytes);
#endif #endif
sendDataOnly(&dataret,sizeof(dataret)); sendDataOnly(&dataret,sizeof(dataret));
#ifdef VERBOSE
n=sendDataOnly(dataretval,dataBytes);
printf("sent %d bytes\n",n);
#else
sendDataOnly(dataretval,dataBytes); sendDataOnly(dataretval,dataBytes);
#endif
return OK; return OK;
} else { } else {
//might add delay???? //might add delay????
@ -1892,7 +1915,7 @@ int get_time_left(int fnum) {
int64_t retval; int64_t retval;
int ret=OK; int ret=OK;
sprintf(mess,"can't set timer\n"); sprintf(mess,"can't get timer\n");
n = receiveDataOnly(&ind,sizeof(ind)); n = receiveDataOnly(&ind,sizeof(ind));
if (n < 0) { if (n < 0) {
sprintf(mess,"Error reading from socket\n"); sprintf(mess,"Error reading from socket\n");
@ -1928,6 +1951,9 @@ int get_time_left(int fnum) {
case CYCLES_NUMBER: case CYCLES_NUMBER:
retval=getTrains(); retval=getTrains();
break; break;
case PROGRESS:
retval=getProgress();
break;
default: default:
ret=FAIL; ret=FAIL;
sprintf(mess,"timer index unknown %d\n",ind); sprintf(mess,"timer index unknown %d\n",ind);

View File

@ -1 +1 @@
/afs/psi.ch/project/mythen/slsDetectorSoftware/commonFiles/sls_detector_defs.h /afs/psi.ch/project/mythen/newMythenSoftware/slsDetectorSoftware/commonFiles/sls_detector_defs.h

View File

@ -47,10 +47,13 @@ int slsDetector::initSharedMemory(detectorType type, int id) {
sz=sizeof(sharedSlsDetector)+nm*(2*nch*nc*sizeof(float)+sizeof(sls_detector_module)+sizeof(int)*nc+sizeof(float)*nd+sizeof(int)*nch*nc); sz=sizeof(sharedSlsDetector)+nm*(2*nch*nc*sizeof(float)+sizeof(sls_detector_module)+sizeof(int)*nc+sizeof(float)*nd+sizeof(int)*nch*nc);
#ifdef VERBOSE
std::cout<<"Size of shared memory is "<< sz << std::endl;
#endif
shm_id = shmget(mem_key,sz,IPC_CREAT | 0666); // allocate shared memory shm_id = shmget(mem_key,sz,IPC_CREAT | 0666); // allocate shared memory
if (shm_id < 0) { if (shm_id < 0) {
std::cout<<"*** shmget error (server) ***"<< std::endl; std::cout<<"*** shmget error (server) ***"<< shm_id << std::endl;
return shm_id; return shm_id;
} }
@ -89,15 +92,28 @@ int slsDetector::freeSharedMemory() {
} }
slsDetector::slsDetector(detectorType type, int id): slsDetector::slsDetector(detectorType type, int id):
thisDetector(NULL),
detId(0),
shmId(-1),
controlSocket(NULL), controlSocket(NULL),
stopSocket(NULL), stopSocket(NULL),
dataSocket(NULL), dataSocket(NULL),
shmId(-1), currentPosition(0),
detId(0), currentPositionIndex(0),
thisDetector(NULL), currentI0(0),
badChannelMask(NULL), mergingBins(NULL),
detectorModules(NULL) mergingCounts(NULL),
mergingErrors(NULL),
mergingMultiplicity(NULL),
ffcoefficients(NULL),
fferrors(NULL),
detectorModules(NULL),
dacs(NULL),
adcs(NULL),
chipregs(NULL),
chanregs(NULL),
badChannelMask(NULL)
{ {
while (shmId<0) { while (shmId<0) {
/**Initlializes shared memory \sa initSharedMemory /**Initlializes shared memory \sa initSharedMemory
@ -170,7 +186,7 @@ int slsDetector::initializeDetectorSize(detectorType type) {
thisDetector->nMod[Y]=thisDetector->nModMax[Y]; thisDetector->nMod[Y]=thisDetector->nModMax[Y];
thisDetector->nMods=thisDetector->nModsMax; thisDetector->nMods=thisDetector->nModsMax;
/** calculates the expected data size */ /** calculates the expected data size */
if (thisDetector->dynamicRange==24) if (thisDetector->dynamicRange==24 || thisDetector->timerValue[PROBES_NUMBER]>0)
thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*4; thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*4;
else else
thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*thisDetector->dynamicRange/8; thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*thisDetector->dynamicRange/8;
@ -193,6 +209,8 @@ int slsDetector::initializeDetectorSize(detectorType type) {
thisDetector->tDead=0; thisDetector->tDead=0;
/** sets bad channel list file to none */ /** sets bad channel list file to none */
strcpy(thisDetector->badChanFile,"none"); strcpy(thisDetector->badChanFile,"none");
/** sets flat field correction directory */
strcpy(thisDetector->flatFieldDir,getenv("HOME"));
/** sets flat field correction file */ /** sets flat field correction file */
strcpy(thisDetector->flatFieldFile,"none"); strcpy(thisDetector->flatFieldFile,"none");
/** set number of bad chans to 0*/ /** set number of bad chans to 0*/
@ -263,7 +281,7 @@ int slsDetector::initializeDetectorSize(detectorType type) {
int slsDetector::initializeDetectorStructure() { int slsDetector::initializeDetectorStructure() {
sls_detector_module *thisMod; sls_detector_module *thisMod;
char *ptr, *p1, *p2; char *p2;
p2=(char*)thisDetector; p2=(char*)thisDetector;
/** for each of the detector modules up to the maximum number which can be installed initlialize the sls_detector_module structure \sa ::sls_detector_module*/ /** for each of the detector modules up to the maximum number which can be installed initlialize the sls_detector_module structure \sa ::sls_detector_module*/
@ -312,6 +330,7 @@ int slsDetector::initializeDetectorStructure() {
thisMod->gain=-1.; thisMod->gain=-1.;
thisMod->offset=-1.; thisMod->offset=-1.;
} }
return 0;
} }
sls_detector_module* slsDetector::createModule() { sls_detector_module* slsDetector::createModule() {
@ -371,6 +390,7 @@ int slsDetector::sendModule(sls_detector_module *myMod) {
ts+=controlSocket->SendDataOnly(myMod->adcs,sizeof(float)*(myMod->nadc)); ts+=controlSocket->SendDataOnly(myMod->adcs,sizeof(float)*(myMod->nadc));
ts+=controlSocket->SendDataOnly(myMod->chipregs,sizeof(int)*(myMod->nchip)); ts+=controlSocket->SendDataOnly(myMod->chipregs,sizeof(int)*(myMod->nchip));
ts+=controlSocket->SendDataOnly(myMod->chanregs,sizeof(int)*(myMod->nchan)); ts+=controlSocket->SendDataOnly(myMod->chanregs,sizeof(int)*(myMod->nchan));
return ts;
} }
int slsDetector::receiveChannel(sls_detector_channel *myChan) { int slsDetector::receiveChannel(sls_detector_channel *myChan) {
@ -565,12 +585,23 @@ int slsDetector::setTCPSocket(string const name, int const control_port, int con
#endif #endif
} }
if (retval!=FAIL) { if (retval!=FAIL) {
if (controlSocket->Connect()<0) {
controlSocket->SetTimeOut(5);
thisDetector->onlineFlag=OFFLINE_FLAG;
retval=FAIL;
#ifdef VERBOSE #ifdef VERBOSE
std::cout<< "online!" << std::endl; std::cout<< "offline!" << std::endl;
#endif #endif
thisDetector->onlineFlag=ONLINE_FLAG; } else {
thisDetector->onlineFlag=ONLINE_FLAG;
controlSocket->SetTimeOut(100);
controlSocket->Disconnect();
#ifdef VERBOSE
std::cout<< "online!" << std::endl;
#endif
}
} else { } else {
thisDetector->onlineFlag=OFFLINE_FLAG; thisDetector->onlineFlag=OFFLINE_FLAG;
#ifdef VERBOSE #ifdef VERBOSE
std::cout<< "offline!" << std::endl; std::cout<< "offline!" << std::endl;
#endif #endif
@ -673,7 +704,6 @@ int slsDetector::setDetectorType(detectorType const type){
char mess[100]; char mess[100];
strcpy(mess,"dummy"); strcpy(mess,"dummy");
int ret=FAIL;
#ifdef VERBOSE #ifdef VERBOSE
std::cout<< std::endl; std::cout<< std::endl;
@ -800,14 +830,15 @@ int slsDetector::setNumberOfModules(int n, dimension d){
} else { } else {
ret=OK; ret=OK;
if (n==GET_FLAG) if (n==GET_FLAG)
retval=thisDetector->nMod[d]; ;
else { else {
if (n<=0 || n>thisDetector->nModMax[d]) { if (n<=0 || n>thisDetector->nModMax[d]) {
retval=thisDetector->nMod[d];
ret=FAIL; ret=FAIL;
} else } else {
retval=thisDetector->nMod[d]; thisDetector->nMod[d]=n;
}
} }
retval=thisDetector->nMod[d];
} }
#ifdef VERBOSE #ifdef VERBOSE
std::cout<< "Number of modules in dimension "<< d <<" is " << retval << std::endl; std::cout<< "Number of modules in dimension "<< d <<" is " << retval << std::endl;
@ -821,7 +852,12 @@ int slsDetector::setNumberOfModules(int n, dimension d){
if (dr==24) if (dr==24)
dr=32; dr=32;
thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*dr/8; if (thisDetector->timerValue[PROBES_NUMBER]==0) {
thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*dr/8;
} else {
thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*4;
}
#ifdef VERBOSE #ifdef VERBOSE
std::cout<< "Data size is " << thisDetector->dataBytes << std::endl; std::cout<< "Data size is " << thisDetector->dataBytes << std::endl;
std::cout<< "nModX " << thisDetector->nMod[X] << " nModY " << thisDetector->nMod[Y] << " nChips " << thisDetector->nChips << " nChans " << thisDetector->nChans<< " dr " << dr << std::endl; std::cout<< "nModX " << thisDetector->nMod[X] << " nModY " << thisDetector->nMod[Y] << " nChips " << thisDetector->nChips << " nChans " << thisDetector->nChans<< " dr " << dr << std::endl;
@ -941,6 +977,12 @@ enum externalSignalFlag {
} }
#endif #endif
return retval; return retval;
}; };
/* /*
@ -1042,35 +1084,41 @@ int64_t slsDetector::getId( idMode mode, int imod){
else else
std::cout<< "Getting id type "<< mode << std::endl; std::cout<< "Getting id type "<< mode << std::endl;
#endif #endif
if (thisDetector->onlineFlag==ONLINE_FLAG) { if (mode==THIS_SOFTWARE_VERSION) {
if (controlSocket) { ret=OK;
if (controlSocket->Connect()>=0) { retval=thisSoftwareVersion;
controlSocket->SendDataOnly(&fnum,sizeof(fnum)); } else {
controlSocket->SendDataOnly(&mode,sizeof(mode)); if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (mode==MODULE_SERIAL_NUMBER) if (controlSocket) {
controlSocket->SendDataOnly(&imod,sizeof(imod)); if (controlSocket->Connect()>=0) {
controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); controlSocket->SendDataOnly(&fnum,sizeof(fnum));
if (ret==OK) controlSocket->SendDataOnly(&mode,sizeof(mode));
controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); if (mode==MODULE_SERIAL_NUMBER)
else { controlSocket->SendDataOnly(&imod,sizeof(imod));
controlSocket->ReceiveDataOnly(mess,sizeof(mess)); controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
std::cout<< "Detector returned error: " << mess << std::endl; if (ret==OK)
} controlSocket->ReceiveDataOnly(&retval,sizeof(retval));
controlSocket->Disconnect(); else {
controlSocket->ReceiveDataOnly(mess,sizeof(mess));
std::cout<< "Detector returned error: " << mess << std::endl;
}
controlSocket->Disconnect();
} else
ret=FAIL;
} else {
ret=FAIL;
} }
} }
} else {
ret=FAIL;
} }
if (ret==FAIL) { if (ret==FAIL) {
std::cout<< "Get id failed " << std::endl; std::cout<< "Get id failed " << std::endl;
return ret; return ret;
} else { } else {
#ifdef VERBOSE #ifdef VERBOSE
if (mode==MODULE_SERIAL_NUMBER) if (mode==MODULE_SERIAL_NUMBER)
std::cout<< "Id of "<< imod <<" is " << hex <<retval << setbase(10) << std::endl; std::cout<< "Id of "<< imod <<" is " << hex <<retval << setbase(10) << std::endl;
else else
std::cout<< "Id "<< mode <<" is " << hex <<retval << setbase(10) << std::endl; std::cout<< "Id "<< mode <<" is " << hex <<retval << setbase(10) << std::endl;
#endif #endif
return retval; return retval;
} }
@ -1576,7 +1624,7 @@ int slsDetector::setChip(int reg, int ichip, int imod){
int chregs[thisDetector->nChans]; int chregs[thisDetector->nChans];
int mmin=imod, mmax=imod+1, chimin=ichip, chimax=ichip+1; int mmin=imod, mmax=imod+1, chimin=ichip, chimax=ichip+1;
int ret; int ret=FAIL;
if (imod==-1) { if (imod==-1) {
mmin=0; mmin=0;
mmax=thisDetector->nModsMax; mmax=thisDetector->nModsMax;
@ -1715,7 +1763,7 @@ int slsDetector::setChip(sls_detector_chip chip){
*/ */
int slsDetector::setModule(int reg, int imod){ int slsDetector::setModule(int reg, int imod){
sls_detector_module myModule, *mptr; sls_detector_module myModule;
#ifdef VERBOSE #ifdef VERBOSE
std::cout << "slsDetector set module " << std::endl; std::cout << "slsDetector set module " << std::endl;
@ -1724,7 +1772,7 @@ int slsDetector::setModule(int reg, int imod){
int chiregs[thisDetector->nChips]; int chiregs[thisDetector->nChips];
float das[thisDetector->nDacs], ads[thisDetector->nAdcs]; float das[thisDetector->nDacs], ads[thisDetector->nAdcs];
int mmin=imod, mmax=imod+1; int mmin=imod, mmax=imod+1;
int ret; int ret=FAIL;
if (imod==-1) { if (imod==-1) {
mmin=0; mmin=0;
@ -1884,7 +1932,7 @@ sls_detector_module *slsDetector::getModule(int imod){
sls_detector_module *myMod=createModule(); sls_detector_module *myMod=createModule();
char *ptr, *goff=(char*)thisDetector; //char *ptr, *goff=(char*)thisDetector;
// int chanreg[thisDetector->nChans*thisDetector->nChips]; // int chanreg[thisDetector->nChans*thisDetector->nChips];
//int chipreg[thisDetector->nChips]; //int chipreg[thisDetector->nChips];
@ -1892,7 +1940,7 @@ sls_detector_module *slsDetector::getModule(int imod){
int ret=FAIL; int ret=FAIL;
char mess[100]; char mess[100];
int n; // int n;
#ifdef VERBOSE #ifdef VERBOSE
std::cout<< "getting module " << imod << std::endl; std::cout<< "getting module " << imod << std::endl;
@ -2313,7 +2361,7 @@ int slsDetector::startReadOut(){
int* slsDetector::readFrame(){ int* slsDetector::readFrame(){
int fnum=F_READ_FRAME, n; int fnum=F_READ_FRAME;
int* retval=NULL; int* retval=NULL;
#ifdef VERBOSE #ifdef VERBOSE
@ -2365,9 +2413,9 @@ int* slsDetector::getDataFromDetector(){
} else { } else {
n=controlSocket->ReceiveDataOnly(retval,thisDetector->dataBytes); n=controlSocket->ReceiveDataOnly(retval,thisDetector->dataBytes);
#ifdef VERBOSE //#ifdef VERBOSE
std::cout<< "Received "<< n << " data bytes" << std::endl; std::cout<< "Received "<< n << " data bytes" << std::endl;
#endif //#endif
if (n!=thisDetector->dataBytes) { if (n!=thisDetector->dataBytes) {
std::cout<< "wrong data size received: received " << n << " but expected " << thisDetector->dataBytes << std::endl; std::cout<< "wrong data size received: received " << n << " but expected " << thisDetector->dataBytes << std::endl;
thisDetector->stoppedFlag=1; thisDetector->stoppedFlag=1;
@ -2384,10 +2432,8 @@ int* slsDetector::getDataFromDetector(){
int* slsDetector::readAll(){ int* slsDetector::readAll(){
int fnum=F_READ_ALL, n; int fnum=F_READ_ALL;
int* retval; // check what we return! int* retval; // check what we return!
int ret=OK;
char mess[100];
int i=0; int i=0;
#ifdef VERBOSE #ifdef VERBOSE
@ -2397,7 +2443,7 @@ int* slsDetector::readAll(){
if (controlSocket) { if (controlSocket) {
if (controlSocket->Connect()>=0) { if (controlSocket->Connect()>=0) {
controlSocket->SendDataOnly(&fnum,sizeof(fnum)); controlSocket->SendDataOnly(&fnum,sizeof(fnum));
while (retval=getDataFromDetector()){ while ((retval=getDataFromDetector())){
i++; i++;
#ifdef VERBOSE #ifdef VERBOSE
// std::cout<< i << std::endl; // std::cout<< i << std::endl;
@ -2421,18 +2467,18 @@ int* slsDetector::startAndReadAll(){
int* retval; int* retval;
int i=0; int i=0;
startAndReadAllNoWait(); startAndReadAllNoWait();
while (retval=getDataFromDetector()){ while ((retval=getDataFromDetector())){
i++; i++;
#ifdef VERBOSE //#ifdef VERBOSE
// std::cout<< i << std::endl; std::cout<< i << std::endl;
#endif //#endif
dataQueue.push(retval); dataQueue.push(retval);
} }
controlSocket->Disconnect(); controlSocket->Disconnect();
#ifdef VERBOSE //#ifdef VERBOSE
std::cout<< "recieved "<< i<< " frames" << std::endl; std::cout<< "recieved "<< i<< " frames" << std::endl;
#endif //#endif
return dataQueue.front(); // check what we return! return dataQueue.front(); // check what we return!
/* while ((retval=getDataFromDetectorNoWait())) /* while ((retval=getDataFromDetectorNoWait()))
i++; i++;
@ -2449,10 +2495,6 @@ int* slsDetector::startAndReadAll(){
int slsDetector::startAndReadAllNoWait(){ int slsDetector::startAndReadAllNoWait(){
int fnum= F_START_AND_READ_ALL; int fnum= F_START_AND_READ_ALL;
int* retval;
int ret=OK;
char mess[100];
int i=0;
#ifdef VERBOSE #ifdef VERBOSE
std::cout<< "Starting and reading all frames "<< std::endl; std::cout<< "Starting and reading all frames "<< std::endl;
@ -2582,6 +2624,11 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t){
#ifdef VERBOSE #ifdef VERBOSE
std::cout<< "Timer set to "<< thisDetector->timerValue[index] << "ns" << std::endl; std::cout<< "Timer set to "<< thisDetector->timerValue[index] << "ns" << std::endl;
#endif #endif
if (index==PROBES_NUMBER) {
setDynamicRange();
//cout << "Changing probes: data size = " << thisDetector->dataBytes <<endl;
}
return thisDetector->timerValue[index]; return thisDetector->timerValue[index];
}; };
@ -2661,19 +2708,34 @@ int64_t slsDetector::getTimeLeft(timerIndex index){
std::cout<< "Getting timer "<< index << std::endl; std::cout<< "Getting timer "<< index << std::endl;
#endif #endif
if (thisDetector->onlineFlag==ONLINE_FLAG) { if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (controlSocket) { // if (controlSocket) {
if (controlSocket->Connect()>=0) { // if (controlSocket->Connect()>=0) {
controlSocket->SendDataOnly(&fnum,sizeof(fnum)); // controlSocket->SendDataOnly(&fnum,sizeof(fnum));
controlSocket->SendDataOnly(&index,sizeof(index)); // controlSocket->SendDataOnly(&index,sizeof(index));
controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); // controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
// if (ret!=OK) {
// controlSocket->ReceiveDataOnly(mess,sizeof(mess));
// std::cout<< "Detector returned error: " << mess << std::endl;
// } else {
// controlSocket->ReceiveDataOnly(&retval,sizeof(retval));
// // thisDetector->timerValue[index]=retval;
// }
// controlSocket->Disconnect();
// }
// }
if (stopSocket) {
if (stopSocket->Connect()>=0) {
stopSocket->SendDataOnly(&fnum,sizeof(fnum));
stopSocket->SendDataOnly(&index,sizeof(index));
stopSocket->ReceiveDataOnly(&ret,sizeof(ret));
if (ret!=OK) { if (ret!=OK) {
controlSocket->ReceiveDataOnly(mess,sizeof(mess)); stopSocket->ReceiveDataOnly(mess,sizeof(mess));
std::cout<< "Detector returned error: " << mess << std::endl; std::cout<< "Detector returned error: " << mess << std::endl;
} else { } else {
controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); stopSocket->ReceiveDataOnly(&retval,sizeof(retval));
// thisDetector->timerValue[index]=retval; // thisDetector->timerValue[index]=retval;
} }
controlSocket->Disconnect(); stopSocket->Disconnect();
} }
} }
} }
@ -2720,7 +2782,13 @@ int slsDetector::setDynamicRange(int n){
} }
if (ret==OK && retval>0) { if (ret==OK && retval>0) {
thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*retval/8; /* checking the number of probes to chose the data size */
if (thisDetector->timerValue[PROBES_NUMBER]==0) {
thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*retval/8;
} else {
thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*4;
}
if (retval==32) if (retval==32)
thisDetector->dynamicRange=24; thisDetector->dynamicRange=24;
else else
@ -2808,7 +2876,7 @@ enum trimMode {
int slsDetector::executeTrimming(trimMode mode, int par1, int par2, int imod){ int slsDetector::executeTrimming(trimMode mode, int par1, int par2, int imod){
int fnum= F_EXECUTE_TRIMMING; int fnum= F_EXECUTE_TRIMMING;
int retval; int retval=FAIL;
char mess[100]; char mess[100];
int ret=OK; int ret=OK;
int arg[3]; int arg[3];
@ -2851,7 +2919,6 @@ int slsDetector::executeTrimming(trimMode mode, int par1, int par2, int imod){
float* slsDetector::decodeData(int *datain) { float* slsDetector::decodeData(int *datain) {
float *dataout=new float[thisDetector->nChans*thisDetector->nChips*thisDetector->nMods]; float *dataout=new float[thisDetector->nChans*thisDetector->nChips*thisDetector->nMods];
const char one=1;
const int bytesize=8; const int bytesize=8;
int ival=0; int ival=0;
@ -2860,55 +2927,58 @@ float* slsDetector::decodeData(int *datain) {
int nbits=thisDetector->dynamicRange; int nbits=thisDetector->dynamicRange;
int ipos=0, ichan=0, ibyte; int ipos=0, ichan=0, ibyte;
int nch, boff=0; if (thisDetector->timerValue[PROBES_NUMBER]==0) {
switch (nbits) {
switch (nbits) { case 1:
case 1: for (ibyte=0; ibyte<thisDetector->dataBytes; ibyte++) {
for (ibyte=0; ibyte<thisDetector->dataBytes; ibyte++) { iptr=ptr[ibyte]&0x1;
iptr=ptr[ibyte]&0x1; for (ipos=0; ipos<8; ipos++) {
for (ipos=0; ipos<8; ipos++) { // dataout[ibyte*2+ichan]=((iptr&((0xf)<<ichan))>>ichan)&0xf;
// dataout[ibyte*2+ichan]=((iptr&((0xf)<<ichan))>>ichan)&0xf;
ival=(iptr>>(ipos))&0x1; ival=(iptr>>(ipos))&0x1;
dataout[ichan]=ival; dataout[ichan]=ival;
ichan++; ichan++;
} }
} }
break; break;
case 4: case 4:
for (ibyte=0; ibyte<thisDetector->dataBytes; ibyte++) { for (ibyte=0; ibyte<thisDetector->dataBytes; ibyte++) {
iptr=ptr[ibyte]&0xff; iptr=ptr[ibyte]&0xff;
for (ipos=0; ipos<2; ipos++) { for (ipos=0; ipos<2; ipos++) {
// dataout[ibyte*2+ichan]=((iptr&((0xf)<<ichan))>>ichan)&0xf; // dataout[ibyte*2+ichan]=((iptr&((0xf)<<ichan))>>ichan)&0xf;
ival=(iptr>>(ipos*4))&0xf; ival=(iptr>>(ipos*4))&0xf;
dataout[ichan]=ival;
ichan++;
}
}
break;
case 8:
for (ichan=0; ichan<thisDetector->dataBytes; ichan++) {
ival=ptr[ichan]&0xff;
dataout[ichan]=ival;
}
break;
case 16:
for (ichan=0; ichan<thisDetector->nChans*thisDetector->nChips*thisDetector->nMods; 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;
}
break;
default:
for (ichan=0; ichan<thisDetector->nChans*thisDetector->nChips*thisDetector->nMods; ichan++) {
ival=datain[ichan]&0xffffff;
dataout[ichan]=ival; dataout[ichan]=ival;
ichan++;
} }
} }
break; } else {
case 8:
for (ichan=0; ichan<thisDetector->dataBytes; ichan++) {
ival=ptr[ichan]&0xff;
dataout[ichan]=ival;
}
break;
case 16:
for (ichan=0; ichan<thisDetector->nChans*thisDetector->nChips*thisDetector->nMods; ichan++) { for (ichan=0; ichan<thisDetector->nChans*thisDetector->nChips*thisDetector->nMods; ichan++) {
// dataout[ichan]=0; dataout[ichan]=datain[ichan];
ival=0;
for (ibyte=0; ibyte<2; ibyte++) {
iptr=ptr[ichan*2+ibyte];
ival|=((iptr<<(ibyte*bytesize))&(0xff<<(ibyte*bytesize)));
}
dataout[ichan]=ival;
}
break;
default:
for (ichan=0; ichan<thisDetector->nChans*thisDetector->nChips*thisDetector->nMods; ichan++) {
ival=datain[ichan]&0xffffff;
dataout[ichan]=ival;
} }
} }
/* /*
@ -2953,15 +3023,16 @@ float* slsDetector::decodeData(int *datain) {
*/ */
int slsDetector::setFlatFieldCorrection(string fname){ int slsDetector::setFlatFieldCorrection(string fname){
int interrupt=0;
float data[thisDetector->nModMax[X]*thisDetector->nModMax[Y]*thisDetector->nChans*thisDetector->nChips]; float data[thisDetector->nModMax[X]*thisDetector->nModMax[Y]*thisDetector->nChans*thisDetector->nChips];
float err[thisDetector->nModMax[X]*thisDetector->nModMax[Y]*thisDetector->nChans*thisDetector->nChips]; //float err[thisDetector->nModMax[X]*thisDetector->nModMax[Y]*thisDetector->nChans*thisDetector->nChips];
float xmed[thisDetector->nModMax[X]*thisDetector->nModMax[Y]*thisDetector->nChans*thisDetector->nChips]; float xmed[thisDetector->nModMax[X]*thisDetector->nModMax[Y]*thisDetector->nChans*thisDetector->nChips];
int nmed=0; int nmed=0;
int im=0; int im=0;
int nch; int nch;
thisDetector->nBadFF=0; thisDetector->nBadFF=0;
char ffffname[MAX_STR_LENGTH*2];
if (fname=="") { if (fname=="") {
#ifdef VERBOSE #ifdef VERBOSE
std::cout<< "disabling flat field correction" << std::endl; std::cout<< "disabling flat field correction" << std::endl;
@ -2972,7 +3043,8 @@ int slsDetector::setFlatFieldCorrection(string fname){
#ifdef VERBOSE #ifdef VERBOSE
std::cout<< "Setting flat field correction from file " << fname << std::endl; std::cout<< "Setting flat field correction from file " << fname << std::endl;
#endif #endif
nch=readDataFile(fname,data); sprintf(ffffname,"%s/%s",thisDetector->flatFieldDir,fname.c_str());
nch=readDataFile(string(ffffname),data);
if (nch>0) { if (nch>0) {
strcpy(thisDetector->flatFieldFile,fname.c_str()); strcpy(thisDetector->flatFieldFile,fname.c_str());
for (int ichan=0; ichan<nch; ichan++) { for (int ichan=0; ichan<nch; ichan++) {
@ -3157,7 +3229,7 @@ int slsDetector::getRateCorrection(){
int slsDetector::rateCorrect(float datain, float errin, float &dataout, float &errout, float tau, float t){ int slsDetector::rateCorrect(float datain, float errin, float &dataout, float &errout, float tau, float t){
float data; // float data;
float e; float e;
dataout=(datain*exp(tau*datain/t)); dataout=(datain*exp(tau*datain/t));
@ -3171,6 +3243,7 @@ int slsDetector::getRateCorrection(){
errout=e*dataout*sqrt((1/(datain*datain)+tau*tau/(t*t))); errout=e*dataout*sqrt((1/(datain*datain)+tau*tau/(t*t)));
else else
errout=1.; errout=1.;
return 0;
}; };
@ -3178,7 +3251,7 @@ int slsDetector::getRateCorrection(){
int slsDetector::rateCorrect(float* datain, float *errin, float* dataout, float *errout){ int slsDetector::rateCorrect(float* datain, float *errin, float* dataout, float *errout){
float tau=thisDetector->tDead; float tau=thisDetector->tDead;
float t=thisDetector->timerValue[ACQUISITION_TIME]; float t=thisDetector->timerValue[ACQUISITION_TIME];
float data; // float data;
float e; float e;
if (thisDetector->correctionMask&(1<<RATE_CORRECTION)) { if (thisDetector->correctionMask&(1<<RATE_CORRECTION)) {
#ifdef VERBOSE #ifdef VERBOSE
@ -3195,7 +3268,7 @@ int slsDetector::rateCorrect(float* datain, float *errin, float* dataout, float
} }
} }
return 0;
}; };
@ -3328,7 +3401,7 @@ int slsDetector::fillBadChannelMask() {
badChannelMask=NULL; badChannelMask=NULL;
} }
} }
return thisDetector->nBadFF;
} }

View File

@ -135,7 +135,6 @@ class slsDetector {
typedef struct sharedSlsDetector { typedef struct sharedSlsDetector {
/** already existing flag. If the detector does not yet exist (alreadyExisting=0) the sharedMemory will be created, otherwise it will simly be linked */ /** already existing flag. If the detector does not yet exist (alreadyExisting=0) the sharedMemory will be created, otherwise it will simly be linked */
int alreadyExisting; int alreadyExisting;
/*
/** online flag - is set if the detector is connected, unset if socket connection is not possible */ /** online flag - is set if the detector is connected, unset if socket connection is not possible */
int onlineFlag; int onlineFlag;
@ -204,6 +203,8 @@ typedef struct sharedSlsDetector {
int threadedProcessing; int threadedProcessing;
/** dead time (in ns) for rate corrections */ /** dead time (in ns) for rate corrections */
float tDead; float tDead;
/** directory where the flat field files are stored */
char flatFieldDir[MAX_STR_LENGTH];
/** file used for flat field corrections */ /** file used for flat field corrections */
char flatFieldFile[MAX_STR_LENGTH]; char flatFieldFile[MAX_STR_LENGTH];
/** number of bad channels from bad channel list */ /** number of bad channels from bad channel list */
@ -284,7 +285,7 @@ typedef struct sharedSlsDetector {
//slsDetector(string const fname); //slsDetector(string const fname);
// ~slsDetector(){while(dataQueue.size()>0){}}; // ~slsDetector(){while(dataQueue.size()>0){}};
/** destructor */ /** destructor */
~slsDetector(){}; virtual ~slsDetector(){};
/** sets the onlineFlag /** sets the onlineFlag
@ -566,7 +567,12 @@ typedef struct sharedSlsDetector {
\sa angleConversionConstant mythenDetector::writeAngularConversion \sa angleConversionConstant mythenDetector::writeAngularConversion
*/ */
virtual int writeAngularConversion(string fname="")=0; virtual int writeAngularConversion(string fname="")=0;
/** Returns the number of channels per chip */
int getNChans(){return thisDetector->nChans;}; //
/** Returns the number of chips per module */
int getNChips(){return thisDetector->nChips;}; //
/* Communication to server */ /* Communication to server */
@ -620,7 +626,7 @@ typedef struct sharedSlsDetector {
\param d dimension \param d dimension
\returns current number of modules in direction d \returns current number of modules in direction d
*/ */
int setNumberOfModules(int n, dimension d=X); // if n=GET_FLAG returns the number of installed modules int setNumberOfModules(int n=GET_FLAG, dimension d=X); // if n=GET_FLAG returns the number of installed modules
/* /*
returns the instrinsic size of the detector (maxmodx, maxmody, nchans, nchips, ndacs returns the instrinsic size of the detector (maxmodx, maxmody, nchans, nchips, ndacs
@ -1057,6 +1063,17 @@ s
\returns 0 if ff correction disabled, >0 otherwise \returns 0 if ff correction disabled, >0 otherwise
*/ */
int getFlatFieldCorrection(float *corr=NULL, float *ecorr=NULL); int getFlatFieldCorrection(float *corr=NULL, float *ecorr=NULL);
/**
get flat field corrections file directory
\returns flat field correction file directory
*/
char *getFlatFieldCorrectionDir(){return thisDetector->flatFieldDir;};
/**
set flat field corrections file directory
\param flat field correction file directory
*/
void setFlatFieldCorrectionDir(string dir){strcpy(thisDetector->flatFieldDir,dir.c_str());};
/** /**
get flat field corrections file name get flat field corrections file name
@ -1326,6 +1343,8 @@ s
protected: protected:
static const int64_t thisSoftwareVersion=0x20110113;
/** /**
address of the detector structure in shared memory address of the detector structure in shared memory
*/ */

View File

@ -1,7 +1,9 @@
#include "usersFunctions.h" #include "usersFunctions.h"
#include <math.h> #include <math.h>
#include <stdio.h>
float pos; float pos;
float i0=0;
/* /*
contains the conversion channel-angle for a module channel contains the conversion channel-angle for a module channel
@ -11,7 +13,8 @@ float pos;
float angle(int ichan, float encoder, float totalOffset, float conv_r, float center, float offset, float tilt, int direction) { float angle(int ichan, float encoder, float totalOffset, float conv_r, float center, float offset, float tilt, int direction) {
(void) offset; // to avoid warning: unused parameter
(void) tilt; // to avoid warning: unused parameter
float ang; float ang;
ang=180./PI*(center*conv_r+atan((float)(ichan-center)*conv_r))+encoder+totalOffset; ang=180./PI*(center*conv_r+atan((float)(ichan-center)*conv_r))+encoder+totalOffset;
@ -23,25 +26,39 @@ float angle(int ichan, float encoder, float totalOffset, float conv_r, float cen
/* reads the encoder and returns the position */ /* reads the encoder and returns the position */
float get_position() { float get_position() {
#ifdef VERBOSE
printf("Getting motor position \n");
#endif
return pos; return pos;
} }
/* moves the encoder to position p */ /* moves the encoder to position p */
int go_to_position(float p) { int go_to_position(float p) {
#ifdef VERBOSE
printf("Setting motor position \n");
#endif
pos=p; pos=p;
return pos;
} }
/* moves the encoder to position p without waiting */ /* moves the encoder to position p without waiting */
int go_to_position_no_wait(float p) { int go_to_position_no_wait(float p) {
#ifdef VERBOSE
printf("Setting motor position no wait \n");
#endif
pos=p; pos=p;
return pos;
} }
/* reads I0 and returns the intensity */ /* reads I0 and returns the intensity */
float get_i0() { float get_i0() {
return 100.; #ifdef VERBOSE
printf("Getting I0 readout \n");
#endif
return i0++;
} }