changes in the software structure debugged

git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@131 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
bergamaschi 2012-02-24 13:14:58 +00:00
parent e0368c69ee
commit c2a24e2c73
14 changed files with 2403 additions and 1041 deletions

View File

@ -1,11 +1,11 @@
CFLAGS= -DC_ONLY
FLAGS=-DVERBOSE
#FLAGS=-DVERBOSE
INCLUDES= -IcommonFiles -IslsDetector -IMySocketTCP -IusersFunctions -ImultiSlsDetector -IslsDetectorUtils -IslsDetectorCommand
#-I eigerDetector -ImythenDetector -IgotthardDetector
#EPICSFLAGS=-D EPICS -I/usr/local/epics/base/include/ -I /usr/local/epics/base/include/os/Linux/ -L /usr/local/epics/base/lib/SL5-x86/ -Wl,-R/usr/local/epics/base/lib/SL5-x86 -lca -lCom
SRC_CLNT= slsDetector/slsDetector.cpp MySocketTCP/MySocketTCP.cxx usersFunctions/usersFunctions.c multiSlsDetector/multiSlsDetector.cpp slsDetector/slsDetectorUtils.cpp slsDetector/slsDetectorCommand.cpp
SRC_CLNT= slsDetector/slsDetector.cpp MySocketTCP/MySocketTCP.cpp usersFunctions/usersFunctions.c multiSlsDetector/multiSlsDetector.cpp slsDetector/slsDetectorUtils.cpp slsDetector/slsDetectorCommand.cpp
#mythenDetector/mythenDetector.cpp eigerDetector/eigerDetector.cpp gotthardDetector/gotthardDetector.cpp
SRC_MYTHEN_SVC = mythenDetectorServer/server.c mythenDetectorServer/server_funcs.c mythenDetectorServer/communication_funcs.c mythenDetectorServer/firmware_funcs.c mythenDetectorServer/mcb_funcs.c mythenDetectorServer/trimming_funcs.c
#mythenDetectorServer/sharedmemory.c
@ -35,16 +35,14 @@ package: $(SRC_CLNT)
$(CXX) -fPIC -g -o objs/multiSlsDetector.o -c -Wall multiSlsDetector/multiSlsDetector.cpp $(INCLUDES) $(FLAGS)
$(CXX) -fPIC -g -o objs/usersFunctions.o -c -Wall usersFunctions/usersFunctions.c $(INCLUDES) $(FLAGS) $(EPICSFLAGS)
$(CXX) -fPIC -g -o objs/MySocketTCP.o -c -Wall MySocketTCP/MySocketTCP.cpp $(INCLUDES) $(FLAGS)
# $(CXX) -fPIC -g -o objs/multiSDetector.o -c -Wall multiSlsDetector/multiSlsDetector.cpp $(INCLUDES) $(FLAGS)
# $(CXX) -shared -Wl,-soname,libSlsDetector.so.1 -o libSlsDetector.so.1.0.1 objs/slsDetector.o objs/usersFunctions.o objs/MySocketTCP.o objs/multiSDetector.o -lc $(INCLUDES) $(FLAGS) $(EPICSFLAGS)
$(CXX) -shared -Wl,-soname,libSlsDetector.so.1 -o libSlsDetector.so.1.0.1 objs/slsDetector.o objs/slsDetectorUtils.o objs/slsDetectorCommand.o objs/multiSlsDetector.o objs/usersFunctions.o objs/MySocketTCP.o -lc $(INCLUDES) $(FLAGS) $(EPICSFLAGS)
#objs/mythenDetector.o objs/gotthardDetector.o
ln -sf libSlsDetector.so libSlsDetector.so.1.0.1
ln -sf libSlsDetector.so.1 libSlsDetector.so
#objs/mythenDetector.o objs/gotthardDetector.o
ln -sf libSlsDetector.so libSlsDetector.so.1
ln -sf libSlsDetector.so libSlsDetector.so.1.0.1
ar rcs libSlsDetector.a objs/slsDetector.o objs/usersFunctions.o objs/MySocketTCP.o objs/multiSlsDetector.o objs/slsDetectorUtils.o objs/slsDetectorCommand.o
clean:
rm -rf libSlsDetector.so.1.0.1 libSlsDetector.so core objs/* docs/*
rm -rf libSlsDetector.so.1 libSlsDetector.so.1.0.1 libSlsDetector.so core objs/* docs/*
#-------------------------------------------------------------------------------
lib: package
@ -53,14 +51,12 @@ lib: package
# added install target, HBl
install_lib: lib
$(shell test -d $(DESTDIR) || mkdir -p $(DESTDIR))
cp -P libSlsDetector.so.1.0.1 libSlsDetector.so $(DESTDIR)
cp -P libSlsDetector.so.1.0.1 libSlsDetector.so libSlsDetector.so.1 $(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/gotthardDetector/gotthardDetector.h $(DESTDIR)
cp -P ../slsDetectorSoftware/slsDetector/slsDetectorBase.h $(DESTDIR)
cp -P ../slsDetectorSoftware/slsDetector/slsDetector.h $(DESTDIR)
cp -P ../slsDetectorSoftware/slsDetector/slsDetectorUtils.h $(DESTDIR)
cp -P ../slsDetectorSoftware/slsDetector/slsDetectorCommand.h $(DESTDIR)

View File

@ -8,6 +8,7 @@
#include <stdio.h>
#include <errno.h>
#include <sys/time.h>
@ -18,6 +19,13 @@ extern int errno;
char dummyClientIP[INET_ADDRSTRLEN];
fd_set readset, tempset;
int isock=0, maxfd;
int myport=-1;
//struct sockaddr_in address;
//#define VERBOSE
@ -30,6 +38,23 @@ int bindSocket(unsigned short int port_number) {
//int file_des;
//file_des= -1;
if (myport==port_number)
return -10;
socketDescriptor = socket(AF_INET, SOCK_STREAM,0); //tcp
//socketDescriptor = socket(PF_INET, SOCK_STREAM, 0);
@ -59,12 +84,22 @@ int bindSocket(unsigned short int port_number) {
socketDescriptor=-1;
} else {
listen(socketDescriptor, 5);
if (listen(socketDescriptor, 5)==0) {
if (isock==0) {
FD_ZERO(&readset);
}
FD_SET(socketDescriptor, &readset);
isock++;
maxfd = socketDescriptor;
printf ("%d port %d fd %d\n",isock, port_number,socketDescriptor);
myport=port_number;
} else
printf("error on listen");
}
}
@ -88,94 +123,124 @@ int getServerError(int socketDescriptor)
int acceptConnection(int socketDescriptor) {
int j;
struct sockaddr_in addressC;
int file_des=-1;
struct timeval tv;
int result;
//socklen_t address_length;
size_t address_length=sizeof(struct sockaddr_in);
// if(file_des>0) return file_des;
if (socketDescriptor<0)
return -1;
memcpy(&tempset, &readset, sizeof(tempset));
tv.tv_sec = 10000000;
tv.tv_usec = 0;
result = select(maxfd + 1, &tempset, NULL, NULL, &tv);
if (result == 0) {
printf("select() timed out!\n");
} else if (result < 0 && errno != EINTR) {
printf("Error in select(): %s\n", strerror(errno));
} else if (result > 0) {
printf("select returned!\n");
for (j=0; j<maxfd+1; j++) {
if (FD_ISSET(j, &tempset)) {
printf("fd %d is set\n",j);
FD_CLR(j, &tempset);
#ifndef C_ONLY
if(is_a_server){ //server; the server will wait for the clients connection
#endif
if (socketDescriptor>0) {
//if ((file_des = accept(socketDescriptor,(struct sockaddr *) &address, &address_length)) < 0) {
if ((file_des = accept(socketDescriptor,(struct sockaddr *) &addressC, &address_length)) < 0) {
printf("Error: with server accept, connection refused %d\n", errno);
switch(errno) {
case EWOULDBLOCK:
printf("ewouldblock eagain\n");
break;
case EBADF:
printf("ebadf\n");
break;
case ECONNABORTED:
if ((file_des = accept(j,(struct sockaddr *) &addressC, &address_length)) < 0) {
printf("Error in accept(): %s\n", strerror(errno));
printf("Error: with server accept, connection refused %d\n", errno);
switch(errno) {
case EWOULDBLOCK:
printf("ewouldblock eagain\n");
break;
case EBADF:
printf("ebadf\n");
break;
case ECONNABORTED:
printf("econnaborted\n");
break;
case EFAULT:
printf("efault\n");
break;
case EINTR:
printf("eintr\n");
break;
case EFAULT:
printf("efault\n");
break;
case EINTR:
printf("eintr\n");
break;
case EINVAL:
printf("einval\n");
break;
case EMFILE:
printf("emfile\n");
break;
case ENFILE:
printf("enfile\n");
case EMFILE:
printf("emfile\n");
break;
case ENFILE:
printf("enfile\n");
break;
case ENOTSOCK:
printf("enotsock\n");
break;
case EOPNOTSUPP:
printf("eOPNOTSUPP\n");
case EOPNOTSUPP:
printf("eOPNOTSUPP\n");
break;
case ENOBUFS:
printf("ENOBUFS\n");
break;
case ENOMEM:
printf("ENOMEM\n");
break;
case ENOSR:
printf("ENOSR\n");
case ENOBUFS:
printf("ENOBUFS\n");
break;
case ENOMEM:
printf("ENOMEM\n");
break;
case ENOSR:
printf("ENOSR\n");
break;
case EPROTO:
printf("EPROTO\n");
break;
default:
printf("unknown error\n");
}
default:
printf("unknown error\n");
}
// should remove descriptor
socketDescriptor=-1;
} else {
inet_ntop(AF_INET, &(addressC.sin_addr), dummyClientIP, INET_ADDRSTRLEN);
printf("connection accepted %d\n",file_des);
FD_SET(file_des, &readset);
maxfd = (maxfd < file_des)?file_des:maxfd;
}
}
}
}
/* for (j=0; j<maxfd+1; j++) { */
/* if (FD_ISSET(j, &tempset)) { */
/* printf("%d is set!\n",j); */
/* ///////////executes the function!!!! */
socketDescriptor=-1;
}
inet_ntop(AF_INET, &(addressC.sin_addr), dummyClientIP, INET_ADDRSTRLEN);
/* } // end if (FD_ISSET(j, &tempset)) */
/* } // end for (j=0;...) */
/* } // end else if (result > 0) */
// struct sockaddr_in
//{
//short int sin_family; /* Famyly of the address*/
//unsigned short int sin_port; /* Port */
//struct in_addr sin_addr; /* Network address */
//unsigned char sin_zero[8]; /* Same size of struct sockaddr */
//};
}
return file_des;
return file_des;
}
@ -185,14 +250,11 @@ int acceptConnection(int socketDescriptor) {
void closeConnection(int file_des) {
//fflush(stdout);
//printf("Closing file_des %d\n", file_des);
//sleep(1);
#ifdef VERY_VERBOSE
#endif
if(file_des>=0)
close(file_des);
file_des=-1;
if(file_des>=0)
close(file_des);
FD_CLR(file_des, &readset);
}
void exitServer(int socketDescriptor) {
@ -201,7 +263,9 @@ void exitServer(int socketDescriptor) {
#ifdef VERY_VERBOSE
printf("Closing server\n");
#endif
FD_CLR(socketDescriptor, &readset);
socketDescriptor=-1;
isock--;
}

View File

@ -147,9 +147,9 @@ enum networkParameter {
SERVER_MAC /**< server MAC */
};
/**
/**
type of action performed (for text client)
*/
*/
enum {GET_ACTION, PUT_ACTION, READOUT_ACTION, HELP_ACTION};
/** online flags enum \sa setOnline*/
@ -158,18 +158,6 @@ enum {GET_ONLINE_FLAG=-1, /**< returns wether the detector is in online or offli
ONLINE_FLAG =1/**< detector in online state (i.e. communication to the detector updating the local structure) */
};
/** synchronization of the various detectors (should be set for each detector individually?!?!?) */
enum synchronizationMode {
GET_SYNCHRONIZATION_MODE=-1, /**< the multidetector will return its synchronization mode */
NONE, /**< all detectors are independent (no cabling) */
MASTER_GATES, /**< the master gates the other detectors */
MASTER_TRIGGERS, /**< the master triggers the other detectors */
SLAVE_STARTS_WHEN_MASTER_STOPS /**< the slave acquires when the master finishes, to avoid deadtime */
};
/**
flags to get (or set) the size of the detector
*/
@ -423,18 +411,36 @@ enum correctionFlags {
ANGULAR_CONVERSION,/**< angular conversion is calculated */
I0_NORMALIZATION
};
/** port type */
enum portType {
CONTROL_PORT, /**< control port */
STOP_PORT, /**<stop port */
DATA_PORT /**< data port */
};
enum image {
/** hierarchy in multi-detector structure, if any */
enum masterFlags {
GET_MASTER=-1, /**< return master flag */
NO_MASTER, /**< no master/slave hierarchy defined */
IS_MASTER, /**<is master */
IS_SLAVE /**< is slave */
};
/** synchronization in a multidetector structure, if any */
enum synchronizationMode {
GET_SYNCHRONIZATION_MODE=-1, /**< the multidetector will return its synchronization mode */
NONE, /**< all detectors are independent (no cabling) */
MASTER_GATES, /**< the master gates the other detectors */
MASTER_TRIGGERS, /**< the master triggers the other detectors */
SLAVE_STARTS_WHEN_MASTER_STOPS /**< the slave acquires when the master finishes, to avoid deadtime */
};
enum imageType {
DARK_IMAGE, /**< dark image */
GAIN_IMAGE /**< gain image */
};
/**
function indexes to call on the server
@ -527,12 +533,18 @@ enum {
F_UPDATE_CLIENT, /**< Returns all the important parameters to update the shared memory of the client */
F_CONFIGURE_MAC, /**< Configures MAC for Gotthard readout */
F_LOAD_IMAGE, /**< Loads Dark/Gain image to the Gotthard detector */
// multi detector structures
F_SET_MASTER, /**< sets master/slave flag for multi detector structures */
F_SET_SYNCHRONIZATION_MODE /**< sets master/slave synchronization mode for multidetector structures */
F_LOAD_IMAGE /**< Loads Dark/Gain image to the Gotthard detector */
/* Always append functions hereafter!!! */
};
@ -551,5 +563,14 @@ typedef struct {
} angleConversionConstant;
enum angleConversionParameter {
ANGULAR_DIRECTION, /**< angular direction of the diffractometer */
GLOBAL_OFFSET, /**< global offset of the diffractometer */
FINE_OFFSET, /**< fine offset of the diffractometer */
BIN_SIZE /**< angular bin size */
};
#endif

View File

@ -152,6 +152,8 @@ multiSlsDetector::multiSlsDetector(int id) : slsDetectorUtils(), shmId(-1)
thisMultiDetector->binSize=0;
thisMultiDetector->stoppedFlag=0;
thisMultiDetector->threadedProcessing=1;
thisMultiDetector->actionMask=0;
@ -983,24 +985,53 @@ int* multiSlsDetector::getDataFromDetector() {
int n;
int* retval=new int[nel];
int *retdet, *p=retval;
int nodata=1, nodatadet=-1;;
for (int id=0; id<thisMultiDetector->numberOfDetectors; id++) {
if (detectors[id]) {
retdet=detectors[id]->getDataFromDetector();
n=detectors[id]->getDataBytes();
if (retdet) {
n=detectors[id]->getDataBytes();
nodata=0;
#ifdef VERBOSE
cout << "Detector " << id << " returned " << n << " bytes " << endl;
#endif
memcpy(p,retdet,n);
#ifdef VERBOSE
cout << "Copied to pointer "<< p << endl;
#endif
delete [] retdet;
p+=n/sizeof(int);
} else {
nodatadet=id;
cout << "Detector " << id << " does not have data left " << endl;
delete [] retval;
return NULL;
}
break;
}
p+=n/sizeof(int);
}
}
if (nodatadet>=0) {
for (int id=0; id<thisMultiDetector->numberOfDetectors; id++) {
if (id!=nodatadet) {
if (detectors[id]) {
#ifdef VERBOSE
cout << "Stopping detector "<< id << endl;
#endif
detectors[id]->stopAcquisition();
while ((retdet=detectors[id]->getDataFromDetector())) {
#ifdef VERBOSE
cout << "Detector "<< id << " still sent data " << endl;
#endif
delete [] retdet;
}
}
}
}
delete [] retval;
return NULL;
}
return retval;
};
@ -1023,7 +1054,9 @@ int* multiSlsDetector::readFrame(){
p+=n/sizeof(int);
} else {
#ifdef VERBOSE
cout << "Detector " << id << " does not have data left " << endl;
#endif
delete [] retval;
return NULL;
}
@ -1079,7 +1112,11 @@ int* multiSlsDetector::readAll(){
int* multiSlsDetector::startAndReadAll(){
/** Thread for each detector?!?!?! */
#ifdef VERBOSE
cout << "Start and read all " << endl;
#endif
int* retval;
int i=0;
if (thisMultiDetector->onlineFlag==ONLINE_FLAG) {
@ -1088,9 +1125,9 @@ int* multiSlsDetector::startAndReadAll(){
while ((retval=getDataFromDetector())){
i++;
//#ifdef VERBOSE
#ifdef VERBOSE
std::cout<< i << std::endl;
//#endif
#endif
dataQueue.push(retval);
}
@ -1102,9 +1139,9 @@ int* multiSlsDetector::startAndReadAll(){
}
//#ifdef VERBOSE
#ifdef VERBOSE
std::cout<< "recieved "<< i<< " frames" << std::endl;
//#endif
#endif
return dataQueue.front(); // check what we return!
@ -1613,12 +1650,6 @@ int multiSlsDetector::getFlatFieldCorrection(float *corr, float *ecorr) {
int multiSlsDetector::flatFieldCorrect(float datain, float errin, float &dataout, float &errout, float ffcoefficient, float fferr){
return flatFieldCorrect(datain, errin, dataout, errout, ffcoefficient, fferr);
};
@ -1709,13 +1740,6 @@ int multiSlsDetector::getRateCorrection(){
int multiSlsDetector::rateCorrect(float datain, float errin, float &dataout, float &errout, float tau, float t){
return rateCorrect(datain, errin, dataout, errout, tau, t);
};
int multiSlsDetector::rateCorrect(float* datain, float *errin, float* dataout, float *errout){
int ichdet=0;
@ -2499,7 +2523,7 @@ int multiSlsDetector::setNumberOfModules(int p, dimension d) {
nt-=nm;
}
}
ret+=detectors[idet]->setDynamicRange(nm);
ret+=detectors[idet]->setNumberOfModules(nm);
thisMultiDetector->dataBytes+=detectors[idet]->getDataBytes();
thisMultiDetector->numberOfChannels+=detectors[idet]->getNChans()*detectors[idet]->getNChips()*detectors[idet]->getNMods();
}
@ -2509,28 +2533,40 @@ int multiSlsDetector::setNumberOfModules(int p, dimension d) {
}
int multiSlsDetector::decodeNMod(int i, int &id, int &im) {
#ifdef VERBOSE
cout << " Module " << i << " belongs to detector ";
#endif
if (i<0 || i>=setNumberOfModules()) {
id=-1;
im=-1;
#ifdef VERBOSE
cout << id << " position " << im << endl;
#endif
return -1;
}
int nm;
for (int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++) {
if (detectors[idet]) {
nm=detectors[idet]->setNumberOfModules();
nm=detectors[idet]->getNMods();
if (nm>i) {
id=idet;
im=i;
#ifdef VERBOSE
cout << id << " position " << im << endl;
#endif
return im;
} else {
i-=nm;
}
}
}
id=-1;
im=-1;
#ifdef VERBOSE
cout << id << " position " << im << endl;
#endif
return -1;
@ -2670,9 +2706,436 @@ int multiSlsDetector::readRegister(int addr){
};
int multiSlsDetector::readConfigurationFile(string const fname){};
int multiSlsDetector::writeConfigurationFile(string const fname){};
int multiSlsDetector::dumpDetectorSetup(string const fname, int level){};
int multiSlsDetector::retrieveDetectorSetup(string const fname, int level){};
int multiSlsDetector::readConfigurationFile(string const fname){
char ext[100];
string ans;
string str;
ifstream infile;
int iargval;
int interrupt=0;
char *args[100];
for (int ia=0; ia<100; ia++) {
args[ia]=new char[1000];
}
string sargname, sargval;
int iline=0;
std::cout<< "config file name "<< fname << std::endl;
infile.open(fname.c_str(), ios_base::in);
if (infile.is_open()) {
while (infile.good() and interrupt==0) {
sargname="none";
sargval="0";
getline(infile,str);
iline++;
#ifdef VERBOSE
std::cout<< str << std::endl;
#endif
if (str.find('#')!=string::npos) {
#ifdef VERBOSE
std::cout<< "Line is a comment " << std::endl;
std::cout<< str << std::endl;
#endif
continue;
} else if (str.length()<2) {
#ifdef VERBOSE
std::cout<< "Empty line " << std::endl;
#endif
continue;
} else {
istringstream ssstr(str);
iargval=0;
while (ssstr.good()) {
ssstr >> sargname;
//if (ssstr.good()) {
#ifdef VERBOSE
std::cout<< iargval << " " << sargname << std::endl;
#endif
strcpy(args[iargval],sargname.c_str());
iargval++;
//}
}
ans=executeLine(iargval,args,PUT_ACTION);
#ifdef VERBOSE
std::cout<< ans << std::endl;
#endif
}
iline++;
}
infile.close();
for (int i=0; i<thisMultiDetector->numberOfDetectors; i++) {
sprintf(ext,".det%d",i);
if (detectors[i]) {
detectors[i]->readConfigurationFile(fname+string(ext));
}
}
} else {
std::cout<< "Error opening configuration file " << fname << " for reading" << std::endl;
return FAIL;
}
#ifdef VERBOSE
std::cout<< "Read configuration file of " << iline << " lines" << std::endl;
#endif
return iline;
};
int multiSlsDetector::writeConfigurationFile(string const fname){
string names[]={ \
"hostname", \
"master", \
"sync", \
"caldir", \
"settingsdir", \
"trimen", \
"outdir", \
"ffdir", \
"headerbefore", \
"headerafter", \
"headerbeforepar", \
"headerafterpar", \
"nmod", \
"badchannels", \
"angconv", \
"globaloff", \
"binsize", \
"threaded" };
int nvar=18;
char ext[100];
int iv=0;
char *args[100];
for (int ia=0; ia<100; ia++) {
args[ia]=new char[1000];
}
ofstream outfile;
int ret;
outfile.open(fname.c_str(),ios_base::out);
if (outfile.is_open()) {
for (iv=0; iv<nvar; iv++) {
strcpy(args[0],names[iv].c_str());
outfile << names[iv] << " " << executeLine(1,args,GET_ACTION) << std::endl;
}
outfile.close();
for (int i=0; i<thisMultiDetector->numberOfDetectors; i++) {
sprintf(ext,".det%d",i);
if (detectors[i]) {
detectors[i]->writeConfigurationFile(fname+string(ext));
}
}
}
else {
std::cout<< "Error opening configuration file " << fname << " for writing" << std::endl;
return FAIL;
}
#ifdef VERBOSE
std::cout<< "wrote " <<ret << " lines to configuration file " << std::endl;
#endif
return iv;
};
int multiSlsDetector::dumpDetectorSetup(string const fname, int level){
string names[]={
"fname",\
"index",\
"flags",\
"dr",\
"settings",\
"threshold",\
"exptime",\
"period",\
"delay",\
"gates",\
"frames",\
"cycles",\
"probes",\
"fineoff",\
"ratecorr",\
"startscript",\
"startscriptpar",\
"stopscript",\
"stopscriptpar",\
"scriptbefore",\
"scriptbeforepar",\
"scriptafter",\
"scriptafterpar",\
"headerbefore",\
"headerbeforepar",\
"headerafter",\
"headerafterpar",\
"scan0script",\
"scan0par",\
"scan0prec",\
"scan0steps",\
"scan1script",\
"scan1par",\
"scan1prec",\
"scan1steps",\
"flatfield",\
"badchannels",\
"angconv"
};
int nvar=38;
char ext[100];
int iv=0;
string fname1;
ofstream outfile;
char *args[2];
for (int ia=0; ia<2; ia++) {
args[ia]=new char[1000];
}
int nargs;
if (level==2)
nargs=2;
else
nargs=1;
if (level==2) {
fname1=fname+string(".config");
writeConfigurationFile(fname1);
fname1=fname+string(".det");
} else
fname1=fname;
outfile.open(fname1.c_str(),ios_base::out);
if (outfile.is_open()) {
for (iv=0; iv<nvar-5; iv++) {
strcpy(args[0],names[iv].c_str());
outfile << names[iv] << " " << executeLine(1,args,GET_ACTION) << std::endl;
}
strcpy(args[0],names[iv].c_str());
if (level==2) {
fname1=fname+string(".ff");
strcpy(args[1],fname1.c_str());
}
outfile << names[iv] << " " << executeLine(nargs,args,GET_ACTION) << std::endl;
iv++;
strcpy(args[0],names[iv].c_str());
if (level==2) {
fname1=fname+string(".bad");
strcpy(args[1],fname1.c_str());
}
outfile << names[iv] << " " << executeLine(nargs,args,GET_ACTION) << std::endl;
iv++;
strcpy(args[0],names[iv].c_str());
if (level==2) {
fname1=fname+string(".angoff");
strcpy(args[1],fname1.c_str());
}
outfile << names[iv] << " " << executeLine(nargs,args,GET_ACTION) << std::endl;
iv++;
outfile.close();
for (int i=0; i<thisMultiDetector->numberOfDetectors; i++) {
sprintf(ext,".det%d",i);
if (detectors[i]) {
detectors[i]->dumpDetectorSetup(fname+string(ext), level);
}
}
}
else {
std::cout<< "Error opening parameters file " << fname1 << " for writing" << std::endl;
return FAIL;
}
#ifdef VERBOSE
std::cout<< "wrote " <<iv << " lines to "<< fname1 << std::endl;
#endif
return 0;
};
int multiSlsDetector::retrieveDetectorSetup(string const fname1, int level){
char ext[100];
string fname;
string str;
ifstream infile;
int iargval;
int interrupt=0;
char *args[2];
for (int ia=0; ia<2; ia++) {
args[ia]=new char[1000];
}
string sargname, sargval;
int iline=0;
if (level==2) {
fname=fname1+string(".config");
readConfigurationFile(fname);
//cout << "config file read" << endl;
fname=fname1+string(".det");
} else
fname=fname1;
infile.open(fname.c_str(), ios_base::in);
if (infile.is_open()) {
while (infile.good() and interrupt==0) {
sargname="none";
sargval="0";
getline(infile,str);
iline++;
#ifdef VERBOSE
std::cout<< str << std::endl;
#endif
if (str.find('#')!=string::npos) {
#ifdef VERBOSE
std::cout<< "Line is a comment " << std::endl;
std::cout<< str << std::endl;
#endif
continue;
} else {
istringstream ssstr(str);
iargval=0;
while (ssstr.good()) {
ssstr >> sargname;
// if (ssstr.good()) {
strcpy(args[iargval],sargname.c_str());
#ifdef VERBOSE
std::cout<< args[iargval] << std::endl;
#endif
iargval++;
// }
}
if (level==2) {
executeLine(iargval,args,PUT_ACTION);
} else {
if (string(args[0])==string("flatfield"))
;
else if (string(args[0])==string("badchannels"))
;
else if (string(args[0])==string("angconv"))
;
else if (string(args[0])==string("trimbits"))
;
else
executeLine(iargval,args,PUT_ACTION);
}
}
iline++;
}
infile.close();
for (int i=0; i<thisMultiDetector->numberOfDetectors; i++) {
sprintf(ext,".det%d",i);
if (detectors[i]) {
detectors[i]->retrieveDetectorSetup(fname1+string(ext), level);
}
}
} else {
std::cout<< "Error opening " << fname << " for reading" << std::endl;
return FAIL;
}
#ifdef VERBOSE
std::cout<< "Read " << iline << " lines" << std::endl;
#endif
return iline;
};
int multiSlsDetector::loadImageToDetector(imageType t, string s) {
}
int multiSlsDetector::testFunction(int times) {
}

View File

@ -194,14 +194,8 @@ class multiSlsDetector : public slsDetectorUtils {
using slsDetectorUtils::setBadChannelCorrection;
using slsDetectorUtils::readAngularConversion;
using slsDetectorUtils::writeAngularConversion;
using slsDetectorUtils::resetMerging;
using slsDetectorUtils::finalizeMerging;
using slsDetectorUtils::addToMerging;
using slsDetectorUtils::readDataFile;
using slsDetectorUtils::writeDataFile;
using slsDetectorUtils::createFileName;
/**
/*
@short Structure allocated in shared memory to store detector settings and be accessed in parallel by several applications (take care of possible conflicts!)
*/
@ -719,7 +713,7 @@ class multiSlsDetector : public slsDetectorUtils {
\param fferr erro on ffcoefficient
\returns 0
*/
int flatFieldCorrect(float datain, float errin, float &dataout, float &errout, float ffcoefficient, float fferr);
// int flatFieldCorrect(float datain, float errin, float &dataout, float &errout, float ffcoefficient, float fferr);
/**
flat field correct data
@ -743,7 +737,7 @@ class multiSlsDetector : public slsDetectorUtils {
\param t acquisition time (in ns)
\returns 0
*/
int rateCorrect(float datain, float errin, float &dataout, float &errout, float tau, float t);
// int rateCorrect(float datain, float errin, float &dataout, float &errout, float tau, float t);
/**
rate correct data
@ -755,43 +749,6 @@ class multiSlsDetector : public slsDetectorUtils {
*/
int rateCorrect(float* datain, float *errin, float* dataout, float *errout);
/* /\** */
/* pure virtual function */
/* sets the arrays of the merged data to 0. NB The array should be created with size >= 360./getBinSize(); */
/* \param mp already merged postions */
/* \param mv already merged data */
/* \param me already merged errors (squared sum) */
/* \param mm multiplicity of merged arrays */
/* \returns OK or FAIL */
/* \sa mythenDetector::resetMerging */
/* *\/ */
/* int resetMerging(float *mp, float *mv,float *me, int *mm) ; */
/* /\** */
/* pure virtual function */
/* merge dataset */
/* \param p1 angular positions of dataset */
/* \param v1 data */
/* \param e1 errors */
/* \param mp already merged postions */
/* \param mv already merged data */
/* \param me already merged errors (squared sum) */
/* \param mm multiplicity of merged arrays */
/* \sa mythenDetector::addToMerging */
/* *\/ */
/* int addToMerging(float *p1, float *v1, float *e1, float *mp, float *mv,float *me, int *mm); */
/* /\** pure virtual function */
/* calculates the "final" positions, data value and errors for the emrged data */
/* \param mp already merged postions */
/* \param mv already merged data */
/* \param me already merged errors (squared sum) */
/* \param mm multiplicity of merged arrays */
/* \returns FAIL or the number of non empty bins (i.e. points belonging to the pattern) */
/* \sa mythenDetector::finalizeMerging */
/* *\/ */
/* int finalizeMerging(float *mp, float *mv,float *me, int *mm); */
/**
turns off server
*/
@ -919,6 +876,23 @@ class multiSlsDetector : public slsDetectorUtils {
int setReadOutFlags(readOutFlags flag=GET_READOUT_FLAGS);
externalCommunicationMode setExternalCommunicationMode(externalCommunicationMode pol=GET_EXTERNAL_COMMUNICATION_MODE);
/**
Loads dark image or gain image to the detector
\param index can be DARK_IMAGE or GAIN_IMAGE
\fname file name to load data from
\returns OK or FAIL
*/
int loadImageToDetector(imageType index,string const fname);
/**
Test function
\param times number of repetitions
\returns repetition when it fails
*/
int testFunction(int times=0);
protected:
@ -935,67 +909,6 @@ class multiSlsDetector : public slsDetectorUtils {
/**
data queue
*/
queue<int*> dataQueue;
/**
queue containing the postprocessed data
*/
queue<detectorData*> finalDataQueue;
/**
current position of the detector
*/
float currentPosition;
/**
current position index of the detector
*/
int currentPositionIndex;
/**
I0 measured
*/
float currentI0;
/**
current scan variable of the detector
*/
float currentScanVariable[MAX_SCAN_LEVELS];
/**
current scan variable index of the detector
*/
int currentScanIndex[MAX_SCAN_LEVELS];
/** merging bins */
float *mergingBins;
/** merging counts */
float *mergingCounts;
/** merging errors */
float *mergingErrors;
/** merging multiplicity */
int *mergingMultiplicity;
};

View File

@ -68,14 +68,16 @@ int main(int argc, char *argv[])
#ifdef VERY_VERBOSE
printf("Conenction accepted\n");
#endif
retval=decode_function(fd);
//#ifdef VERY_VERBOSE
printf("function executed\n");
//#endif
closeConnection(fd);
if (fd>0) {
retval=decode_function(fd);
//#ifdef VERY_VERBOSE
printf("function executed\n");
//#endif
closeConnection(fd);
#ifdef VERY_VERBOSE
printf("connection closed\n");
printf("connection closed\n");
#endif
}
}
exitServer(sockfd);

View File

@ -2580,6 +2580,11 @@ int set_port(int file_des) {
ret=FAIL;
sprintf(mess,"Could not bind port %d\n", p_number);
printf("Could not bind port %d\n", p_number);
if (sd==-10) {
sprintf(mess,"Port %d already set\n", p_number);
printf("Port %d already set\n", p_number);
}
}
n = sendDataOnly(file_des,&ret,sizeof(ret));

View File

@ -577,7 +577,8 @@ int slsDetector::initializeDetectorSize(detectorType type) {
/** set binsize*/
thisDetector->binSize=0;
thisDetector->stoppedFlag=0;
thisDetector->threadedProcessing=1;
thisDetector->actionMask=0;
@ -961,6 +962,8 @@ int slsDetector::setTCPSocket(string const name, int const control_port, int con
#ifdef VERBOSE
std::cout<< "Could not connect Control socket " << thisName << " " << thisCP << std::endl;
#endif
delete controlSocket;
controlSocket=NULL;
retval=FAIL;
}
#ifdef VERYVERBOSE
@ -974,6 +977,8 @@ int slsDetector::setTCPSocket(string const name, int const control_port, int con
#ifdef VERBOSE
std::cout<< "Could not connect Stop socket "<<thisName << " " << thisSP << std::endl;
#endif
delete stopSocket;
stopSocket=NULL;
retval=FAIL;
}
#ifdef VERYVERBOSE
@ -987,6 +992,12 @@ int slsDetector::setTCPSocket(string const name, int const control_port, int con
#ifdef VERBOSE
std::cout<< "Could not connect Data socket "<<thisName << " " << thisDP << std::endl;
#endif
delete dataSocket;
dataSocket=NULL;
retval=FAIL;
}
#ifdef VERYVERBOSE
@ -998,6 +1009,8 @@ int slsDetector::setTCPSocket(string const name, int const control_port, int con
if (controlSocket->Connect()<0) {
controlSocket->SetTimeOut(5);
thisDetector->onlineFlag=OFFLINE_FLAG;
delete controlSocket;
controlSocket=NULL;
retval=FAIL;
#ifdef VERBOSE
std::cout<< "offline!" << std::endl;
@ -3329,34 +3342,64 @@ int slsDetector::setPort(portType index, int num){
int retval;
uint64_t ut;
char mess[100];
int ret=OK;
int ret=FAIL;
int n=0;
MySocketTCP *s;
if (num>1024) {
switch(index) {
case CONTROL_PORT:
s=controlSocket;
retval=thisDetector->controlPort;
#ifdef VERBOSE
cout << "s="<< s<< endl;
cout << thisDetector->controlPort<< " " << thisDetector->dataPort << " " << thisDetector->stopPort << endl;
#endif
if (s==NULL) {
#ifdef VERBOSE
cout << "s=NULL"<< endl;
cout << thisDetector->controlPort<< " " << thisDetector->dataPort << " " << thisDetector->stopPort << endl;
#endif
setTCPSocket("",DEFAULT_PORTNO);
}
if (controlSocket) {
s=controlSocket;
} else {
#ifdef VERBOSE
cout << "still cannot connect!"<< endl;
cout << thisDetector->controlPort<< " " << thisDetector->dataPort << " " << thisDetector->stopPort << endl;
#endif
setTCPSocket("",retval);
}
break;
case DATA_PORT:
s=dataSocket;
retval=thisDetector->dataPort;
if (s==NULL) setTCPSocket("",-1,-1,DEFAULT_PORTNO+2);
if (dataSocket) s=dataSocket;
else setTCPSocket("",-1,-1,retval);
break;
case STOP_PORT:
s=stopSocket;
retval=thisDetector->stopPort;
if (s==NULL) setTCPSocket("",-1,DEFAULT_PORTNO+1);
if (stopSocket) s=stopSocket;
else setTCPSocket("",-1,retval);
break;
default:
s=NULL;
}
if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (s) {
if (s->Connect()>=0) {
s->SendDataOnly(&fnum,sizeof(fnum));
if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (s) {
if (s->Connect()>=0) {
s->SendDataOnly(&fnum,sizeof(fnum));
s->SendDataOnly(&index,sizeof(index));
n=s->SendDataOnly(&num,sizeof(num));
s->ReceiveDataOnly(&ret,sizeof(ret));
@ -3367,9 +3410,32 @@ int slsDetector::setPort(portType index, int num){
s->ReceiveDataOnly(&retval,sizeof(retval));
}
s->Disconnect();
}
}
}
if (ret!=FAIL) {
switch(index) {
case CONTROL_PORT:
thisDetector->controlPort=retval;
break;
case DATA_PORT:
thisDetector->dataPort=retval;
break;
case STOP_PORT:
thisDetector->stopPort=retval;
break;
default:
;
}
#ifdef VERBOSE
cout << "ret is ok" << endl;
#endif
} else {
switch(index) {
case CONTROL_PORT:
thisDetector->controlPort=num;
@ -3383,54 +3449,29 @@ int slsDetector::setPort(portType index, int num){
default:
;
}
return num;
}
} else {
switch(index) {
case CONTROL_PORT:
thisDetector->controlPort=num;
break;
case DATA_PORT:
thisDetector->dataPort=num;
break;
case STOP_PORT:
thisDetector->stopPort=num;
break;
default:
;
}
return num;
}
if (ret!=FAIL) {
}
switch(index) {
case CONTROL_PORT:
thisDetector->controlPort=retval;
retval=thisDetector->controlPort;
break;
case DATA_PORT:
thisDetector->dataPort=retval;
retval=thisDetector->dataPort;
break;
case STOP_PORT:
thisDetector->stopPort=retval;
break;
retval=thisDetector->stopPort;
break;
default:
;
retval=-1;
}
// setTCPSocket();
}
// setTCPSocket();
#ifdef VERBOSE
cout << thisDetector->controlPort<< " " << thisDetector->dataPort << " " << thisDetector->stopPort << endl;
#endif
return retval;
@ -4540,51 +4581,51 @@ int slsDetector:: writeAngularConversion(ofstream &ofs) {
}
int slsDetector::loadImageToDetector(int index,string const fname){
int retval;
int fnum=F_LOAD_IMAGE;
int ret=FAIL;
char mess[100];
short int arg[1280];
int slsDetector::loadImageToDetector(imageType index,string const fname){
int retval;
int fnum=F_LOAD_IMAGE;
int ret=FAIL;
char mess[100];
short int arg[1280];
#ifdef VERBOSE
std::cout<< std::endl<< "Loading ";
if(!index)
std::cout<<"Dark";
else
std::cout<<"Gain";
std::cout<<" image from file " << fname << std::endl;
std::cout<< std::endl<< "Loading ";
if(!index)
std::cout<<"Dark";
else
std::cout<<"Gain";
std::cout<<" image from file " << fname << std::endl;
#endif
if(readDataFile(fname,arg)){
std::cout<< "Could not open file "<< fname << std::endl;
return -1;
if(readDataFile(fname,arg)){
std::cout<< "Could not open file "<< fname << std::endl;
return -1;
}
if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (controlSocket) {
if (controlSocket->Connect()>=0) {
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
controlSocket->SendDataOnly(&index,sizeof(index));
controlSocket->SendDataOnly(arg,sizeof(arg));
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
if (ret!=FAIL)
controlSocket->ReceiveDataOnly(&retval,sizeof(retval));
else {
controlSocket->ReceiveDataOnly(mess,sizeof(mess));
std::cout<< "Detector returned error: " << mess << std::endl;
}
if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (controlSocket) {
if (controlSocket->Connect()>=0) {
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
controlSocket->SendDataOnly(&index,sizeof(index));
controlSocket->SendDataOnly(arg,sizeof(arg));
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
if (ret!=FAIL)
controlSocket->ReceiveDataOnly(&retval,sizeof(retval));
else {
controlSocket->ReceiveDataOnly(mess,sizeof(mess));
std::cout<< "Detector returned error: " << mess << std::endl;
}
controlSocket->Disconnect();
if (ret==FORCE_UPDATE)
updateDetector();
}
}
}
if (ret==FAIL) {
std::cout<< "failed " << std::endl;
return -1;
}
return 0;
controlSocket->Disconnect();
if (ret==FORCE_UPDATE)
updateDetector();
}
}
}
if (ret==FAIL) {
std::cout<< "failed " << std::endl;
return -1;
}
return 0;
}
@ -4643,6 +4684,36 @@ int slsDetector::readConfigurationFile(string const fname){
std::cout<< "config file name "<< fname << std::endl;
infile.open(fname.c_str(), ios_base::in);
if (infile.is_open()) {
iline=readConfigurationFile(infile);
infile.close();
} else {
std::cout<< "Error opening configuration file " << fname << " for reading" << std::endl;
return FAIL;
}
#ifdef VERBOSE
std::cout<< "Read configuration file of " << iline << " lines" << std::endl;
#endif
return iline;
}
int slsDetector::readConfigurationFile(ifstream &infile){
string ans;
string str;
int iargval;
int interrupt=0;
char *args[100];
for (int ia=0; ia<100; ia++) {
args[ia]=new char[1000];
}
string sargname, sargval;
int iline=0;
while (infile.good() and interrupt==0) {
sargname="none";
sargval="0";
@ -4682,24 +4753,51 @@ int slsDetector::readConfigurationFile(string const fname){
}
iline++;
}
infile.close();
} else {
std::cout<< "Error opening configuration file " << fname << " for reading" << std::endl;
return FAIL;
}
#ifdef VERBOSE
std::cout<< "Read configuration file of " << iline << " lines" << std::endl;
#endif
return iline;
}
int slsDetector::writeConfigurationFile(string const fname){
ofstream outfile;
int ret;
outfile.open(fname.c_str(),ios_base::out);
if (outfile.is_open()) {
ret=writeConfigurationFile(outfile);
outfile.close();
}
else {
std::cout<< "Error opening configuration file " << fname << " for writing" << std::endl;
return FAIL;
}
#ifdef VERBOSE
std::cout<< "wrote " <<ret << " lines to configuration file " << std::endl;
#endif
return ret;
}
int slsDetector::writeConfigurationFile(ofstream &outfile){
int nvar;
string names[]={ \
"hostname", \
"port", \
"dataport", \
"stopport", \
"caldir", \
"settingsdir", \
"trimen", \
@ -4720,21 +4818,17 @@ int slsDetector::writeConfigurationFile(string const fname){
"clkdivider"};
switch (thisDetector->myDetectorType) {
case MYTHEN:
names[2]="trimdir";
break;
case GOTTHARD:
names[3]="outdir";
names[4]="clientip";
names[5]="clientmac";
names[6]="servermac";
nvar=7;
nvar=10;
break;
default:
nvar=19;
nvar=22;
}
ofstream outfile;
int iv=0;
char *args[100];
for (int ia=0; ia<100; ia++) {
@ -4742,32 +4836,32 @@ int slsDetector::writeConfigurationFile(string const fname){
}
outfile.open(fname.c_str(),ios_base::out);
if (outfile.is_open()) {
for (iv=0; iv<nvar; iv++) {
strcpy(args[0],names[iv].c_str());
outfile << names[iv] << " " << executeLine(1,args,GET_ACTION) << std::endl;
}
outfile.close();
for (iv=0; iv<nvar; iv++) {
strcpy(args[0],names[iv].c_str());
outfile << names[iv] << " " << executeLine(1,args,GET_ACTION) << std::endl;
}
else {
std::cout<< "Error opening configuration file " << fname << " for writing" << std::endl;
return FAIL;
}
#ifdef VERBOSE
std::cout<< "wrote " <<iv << " lines to configuration file " << std::endl;
#endif
return iv;
}
/*
It should be possible to dump all the settings of the detector (including trimbits, threshold energy, gating/triggering, acquisition time etc.
in a file and retrieve it for repeating the measurement with identicals ettings, if necessary
in a file and retrieve it for repeating the measurement with identicals settings, if necessary
*/
int slsDetector::dumpDetectorSetup(string fname, int level){
int slsDetector::dumpDetectorSetup(string const fname, int level){
string names[]={
"fname",\
"index",\
@ -4983,6 +5077,34 @@ int slsDetector::retrieveDetectorSetup(string fname1, int level){
/* I/O */
@ -4990,10 +5112,12 @@ int slsDetector::retrieveDetectorSetup(string fname1, int level){
int nflag=0;
if (myMod==NULL) {
myMod=createModule();
nflag=1;
}
string myfname;
string str;
ifstream infile;
@ -5143,11 +5267,13 @@ int slsDetector::retrieveDetectorSetup(string fname1, int level){
infile.close();
strcpy(thisDetector->settingsFile,fname.c_str());
return myMod;
} else {
std::cout<< "could not open settings file " << myfname << std::endl;
if (nflag)
deleteModule(myMod);
return NULL;
}
@ -5289,7 +5415,7 @@ int slsDetector::saveSettingsFile(string fname, int imod) {
ostfn << fname << ".sn" << setfill('0') << setw(3) << hex << getId(MODULE_SERIAL_NUMBER, im);
if ((myMod=getModule(im))) {
ret=writeSettingsFile(ostfn.str(),*myMod);
deleteModule(myMod);
deleteModule(myMod);
}
}
return ret;
@ -5297,45 +5423,45 @@ int slsDetector::saveSettingsFile(string fname, int imod) {
int slsDetector::testFunction(int times) {
int val = 0,i,oldval=0;
runStatus s;
for(i=0;i<times;i++){
std::cout<<std::endl<<dec<<i+1<<": \t";
usleep(2000000);
startAcquisition();
s = getRunStatus();
if(s==IDLE){
std::cout<<"NOTTT WORKED"<<std::endl;
exit(-1);
}
else if (s==RUNNING){
while(s==RUNNING){
usleep(20);
val=readRegister(0x25);
if(val!=oldval)
std::cout<<hex<<val<<"\t";
if(val){
if((val&0x100)||(val&0x200)||(val&0x400))
s = getRunStatus();
else{
std::cout<<"\nStuck status.Exit\n";
exit(-1);
}
}
else
break;
oldval=val;
}
}
else{
std::cout<<"\nWeird Status.Exit\n";
exit(-1);
}
int val = 0,i,oldval=0;
runStatus s;
for(i=0;i<times;i++){
std::cout<<std::endl<<dec<<i+1<<": \t";
usleep(2000000);
startAcquisition();
s = getRunStatus();
if(s==IDLE){
std::cout<<"NOTTT WORKED"<<std::endl;
exit(-1);
}
else if (s==RUNNING){
while(s==RUNNING){
usleep(20);
val=readRegister(0x25);
if(val!=oldval)
std::cout<<hex<<val<<"\t";
if(val){
if((val&0x100)||(val&0x200)||(val&0x400))
s = getRunStatus();
else{
std::cout<<"\nStuck status.Exit\n";
exit(-1);
}
}
std::cout<<std::endl;
return 0;
else
break;
oldval=val;
}
}
else{
std::cout<<"\nWeird Status.Exit\n";
exit(-1);
}
}
std::cout<<std::endl;
return 0;
}

View File

@ -5,24 +5,8 @@
#define SLS_DETECTOR_H
#include "MySocketTCP.h"
/* #include <iostream> */
/* #include <fstream> */
/* #include <iomanip> */
/* #include <cstring> */
/* #include <string> */
/* #include <sstream> */
/* #include <queue> */
/* extern "C" { */
/* #include <pthread.h> */
/* } */
/* #include <fcntl.h> */
/* #include <unistd.h> */
/* #include <sys/stat.h> */
/* #include <sys/types.h> */
/* #include <sys/uio.h> */
//#include "sls_detector_defs.h"
#include "slsDetectorUtils.h"
//#include "slsDetectorCommand.h"
@ -285,17 +269,15 @@ typedef struct sharedSlsDetector {
using slsDetectorUtils::getDetectorType;
using slsDetectorUtils::flatFieldCorrect;
using slsDetectorUtils::rateCorrect;
using slsDetectorUtils::setBadChannelCorrection;
using slsDetectorUtils::readAngularConversion;
using slsDetectorUtils::writeAngularConversion;
using slsDetectorUtils::resetMerging;
using slsDetectorUtils::finalizeMerging;
using slsDetectorUtils::addToMerging;
using slsDetectorUtils::readDataFile;
using slsDetectorUtils::writeDataFile;
using slsDetectorUtils::createFileName;
/** (default) constructor
\param type is needed to define the size of the detector shared memory 9defaults to GENERIC i.e. the largest shared memory needed by any slsDetector is allocated
@ -318,11 +300,8 @@ typedef struct sharedSlsDetector {
//slsDetector(string const fname);
// ~slsDetector(){while(dataQueue.size()>0){}};
/** destructor */
~slsDetector();//{ disconnect_channels();};
//virtual ~slsDetector();//{ disconnect_channels();};
~slsDetector();
/** sets the onlineFlag
\param off can be: <BR> GET_ONLINE_FLAG, returns wether the detector is in online or offline state;<BR> OFFLINE_FLAG, detector in offline state (i.e. no communication to the detector - using only local structure - no data acquisition possible!);<BR> ONLINE_FLAG detector in online state (i.e. communication to the detector updating the local structure) */
int setOnline(int const online=GET_ONLINE_FLAG);
/** returns if the detector already existed
@ -340,38 +319,51 @@ typedef struct sharedSlsDetector {
int configureMAC();
/**
Purely virtual function
Should be implemented in the specific detector class
/sa mythenDetector::readConfigurationFile
Reads the configuration file fname
\param fname file name
\returns OK or FAIL
*/
int readConfigurationFile(string const fname);
// virtual int readConfigurationFile(string const fname);
int readConfigurationFile(string const fname);
int readConfigurationFile(ifstream &infile);
/**
Purely virtual function
Should be implemented in the specific detector class
/sa mythenDetector::writeConfigurationFile
Writes the configuration file fname
\param fname file name
\returns OK or FAIL
*/
int writeConfigurationFile(string const fname);
//virtual int writeConfigurationFile(string const fname);
/*
It should be possible to dump all the settings of the detector (including trimbits, threshold energy, gating/triggering, acquisition time etc.
in a file and retrieve it for repeating the measurement with identicals ettings, if necessary
*/
int writeConfigurationFile(ofstream &outfile);
/**
Purely virtual function
Should be implemented in the specific detector class
/sa mythenDetector::dumpDetectorSetup
Saves the detector setup to file
\param fname file to write to
\param level if 2 reads also trimbits, flat field, angular correction etc. and writes them to files with automatically added extension
\returns OK or FAIL
*/
int dumpDetectorSetup(string const fname, int level=0);
//virtual int dumpDetectorSetup(string const fname, int level=0);
/**
Purely virtual function
Should be implemented in the specific detector class
/sa mythenDetector::retrieveDetectorSetup
Loads the detector setup from file
\param fname file to read from
\param level if 2 reads also reads trimbits, angular conversion coefficients etc. from files with default extensions as generated by dumpDetectorSetup
\returns OK or FAIL
*/
int retrieveDetectorSetup(string const fname, int level=0);
//virtual int retrieveDetectorSetup(string const fname, int level=0);
/**
configure the socket communication and initializes the socket instances
@ -430,9 +422,21 @@ typedef struct sharedSlsDetector {
/** disconnect from the stop port */
int disconnectStop();
/**
sets the network parameters
\param i network parameter type can be CLIENT_IP, CLIENT_MAC, SERVER_MAC
\param s value to be set
\returns parameter
*/
char* setNetworkParameter(networkParameter index, string value);
/**
gets the network parameters
\param i network parameter type can be CLIENT_IP, CLIENT_MAC, SERVER_MAC
\returns parameter
*/
char* getNetworkParameter(networkParameter index);
/* I/O */
@ -467,6 +471,8 @@ typedef struct sharedSlsDetector {
\sa sharedSlsDetector
*/
int getTrimEn(int *en=NULL) {if (en) {for (int ien=0; ien<thisDetector->nTrimEn; ien++) en[ien]=thisDetector->trimEnergies[ien];} return (thisDetector->nTrimEn);};
/** sets the number of trim energies and their value \sa sharedSlsDetector
\param nen number of energies
\param en array of energies
@ -528,11 +534,21 @@ typedef struct sharedSlsDetector {
};
/** loads the modules settings/trimbits reading from a file - file name extension is automatically generated! */
int loadSettingsFile(string fname, int nmod=0);
/** loads the modules settings/trimbits reading from a file
\param fname file name . If not specified, extension is automatically generated!
\param imod module number, -1 means all modules
\returns OK or FAIL
*/
int loadSettingsFile(string fname, int imod=-1);
/** gets the modules settings/trimbits and writes them to file - file name extension is automatically generated! */
int saveSettingsFile(string fname, int nmod=0);
/** saves the modules settings/trimbits writing to a file
\param fname file name . Axtension is automatically generated!
\param imod module number, -1 means all modules
\returns OK or FAIL
*/
int saveSettingsFile(string fname, int imod=-1);
/**
@ -1139,7 +1155,6 @@ typedef struct sharedSlsDetector {
/**
pure virtual function
set angular conversion
\param fname file with angular conversion constants ("" disable)
\returns 0 if angular conversion disabled, >0 otherwise
@ -1238,12 +1253,7 @@ typedef struct sharedSlsDetector {
*/
int exitServer();
/** pure virtual function
function for processing data
/param delflag if 1 the data are processed, written to file and then deleted. If 0 they are added to the finalDataQueue
\sa mythenDetector::processData
*/
// void* processData(int delflag=1); // thread function
/** Allocates the memory for a sls_detector_module structure and initializes it
\returns myMod the pointer to the allocate dmemory location
@ -1257,19 +1267,6 @@ typedef struct sharedSlsDetector {
void deleteModule(sls_detector_module *myMod);
/** pure virtual function
performs the complete acquisition and data processing
moves the detector to next position <br>
starts and reads the detector <br>
reads the IC (if required) <br>
reads the encoder (iof required for angualr conversion) <br>
processes the data (flat field, rate, angular conversion and merging ::processData())
/param delflag if 1 the data are processed, written to file and then deleted. If 0 they are added to the finalDataQueue
\sa mythenDetector::acquire()
*/
//void acquire(int delflag=1);
/** calcualtes the total number of steps of the acquisition.
called when number of frames, number of cycles, number of positions and scan steps change
*/
@ -1306,10 +1303,6 @@ typedef struct sharedSlsDetector {
*/
int getDetectorId(int i=-1) {return detId;};
/**
Receives a data frame from the detector socket
\returns pointer to the data (or NULL if failed)
@ -1317,16 +1310,24 @@ typedef struct sharedSlsDetector {
*/
int* getDataFromDetector();
/**
Loads dark image or gain image to the detector
\param index is 0 for dark image and 1 for gain image
\fname file name to load data from
/** returns if the detector is Master, slave or nothing
\param flag can be GET_MASTER, NO_MASTER, IS_MASTER, IS_SLAVE
\returns master flag of the detector
*/
int loadImageToDetector(int index,string const fname);
masterFlags setMaster(masterFlags flag){};
/**
Sets/gets the synchronization mode of the various detectors
\param sync syncronization mode
\returns current syncronization mode
*/
synchronizationMode setSynchronization(synchronizationMode sync=GET_SYNCHRONIZATION_MODE){};
int loadImageToDetector(imageType index,string const fname);
protected:
@ -1335,10 +1336,6 @@ typedef struct sharedSlsDetector {
*/
sharedSlsDetector *thisDetector;
// /**
// \sa setOnline
// */
//int onlineFlag;
/**
detector ID
@ -1432,10 +1429,6 @@ typedef struct sharedSlsDetector {
/* /\** mutex to synchronize threads *\/ */
/* pthread_mutex_t mp; */

View File

@ -0,0 +1,811 @@
#ifndef SLS_DETECTOR_BASE_H
#define SLS_DETECTOR_BASE_H
#include "sls_detector_defs.h"
#include <string>
using namespace std;
/**
This class contains the functions accessible by the users to control the slsDetectors (both multiSlsDetector and slsDetector)
*/
class slsDetectorBase {
public:
/** default constructor */
slsDetectorBase(){};
/** virtual destructor */
virtual ~slsDetectorBase(){};
/** sets the onlineFlag
\param off can be: <BR> GET_ONLINE_FLAG, returns wether the detector is in online or offline state;<BR> OFFLINE_FLAG, detector in offline state (i.e. no communication to the detector - using only local structure - no data acquisition possible!);<BR> ONLINE_FLAG detector in online state (i.e. communication to the detector updating the local structure)
\returns ONLINE_FLAG or OFFLINE_FLAG
*/
virtual int setOnline(int const online=GET_ONLINE_FLAG)=0;
/** performs a complete acquisition including scansand data processing
moves the detector to next position <br>
starts and reads the detector <br>
reads the IC (if required) <br>
reads the encoder (iof required for angualr conversion) <br>
processes the data (flat field, rate, angular conversion and merging ::processData())
\param delflag 0 leaves the data in the final data queue
\returns nothing
*/
virtual void acquire(int delflag)=0;
/**
asks and receives all data from the detector and puts them in a data queue
\returns pointer to the front of the queue or NULL.
\sa getDataFromDetector dataQueue
*/
virtual int* readAll()=0;
/**
asks and receives a data frame from the detector and puts it in the data queue
\returns pointer to the data or NULL.
\sa getDataFromDetector
*/
virtual int* readFrame()=0;
/** processes the data
\param delflag 0 leaves the data in the final data queue
\returns nothing
*/
virtual void* processData(int delflag)=0;
/**
start detector acquisition
\returns OK/FAIL
*/
virtual int startAcquisition()=0;
/**
stop detector acquisition
\returns OK/FAIL
*/
virtual int stopAcquisition()=0;
/**
get run status
\returns status mask
*/
virtual runStatus getRunStatus()=0;
/** Frees the shared memory - should not be used except for debugging*/
virtual int freeSharedMemory()=0;
/** adds the detector with ID id in postion pos
\param id of the detector to be added (should already exist!)
\param pos position where it should be added (normally at the end of the list (default to -1)
\returns the actual number of detectors or -1 if it failed (always for slsDetector)
*/
virtual int addSlsDetector(int id, int pos=-1){return -1;};
/** adds the detector name in position pos
\param name of the detector to be added (should already exist in shared memory or at least be online)
\param pos position where it should be added (normally at the end of the list (default to -1)
\return the actual number of detectors or -1 if it failed (always for slsDetector)
*/
virtual int addSlsDetector(char* name, int pos=-1){return -1;};
/**
removes the detector in position pos from the multidetector
\param pos position of the detector to be removed from the multidetector system (defaults to -1 i.e. last detector)
\returns the actual number of detectors or -1 if it failed (always for slsDetector)
*/
virtual int removeSlsDetector(int pos=-1){return -1;};
/**removes the detector in position pos from the multidetector
\param name is the name of the detector
\returns the actual number of detectors or -1 if it failed (always for slsDetector)
*/
virtual int removeSlsDetector(char* name){return -1;};
/** returns the detector hostname
\param pos position in the multi detector structure (is -1 returns concatenated hostnames divided by a +)
\retruns hostname
*/
virtual string getHostname(int pos=-1)=0;
/** sets the detector hostname
\param name hostname
\param pos position in the multi detector structure (is -1 expects concatenated hostnames divided by a +)
\returns hostname
*/
virtual string setHostname(char* name, int pos=-1)=0;
/** Gets the detector id (shared memory id) of an slsDetector
\param i position in the multiSlsDetector structure
\return id or -1 if FAIL
*/
virtual int getDetectorId(int i=-1) =0;
/** Sets the detector id (shared memory id) of an slsDetector in a multiSlsDetector structure
\param ival id to be set
\param i position in the multiSlsDetector structure
\return id or -1 if FAIL (e.g. in case of an slsDetector)
*/
virtual int setDetectorId(int ival, int i=-1){return -1;};
/** sets/gets position of the master in a multi detector structure
\param i position of the detector in the multidetector structure
\returns position of the master in a multi detector structure (-1 no master or always in slsDetector)
*/
virtual int setMaster(int i=-1){return -1;};
/**
Sets/gets the synchronization mode of the various detectors
\param sync syncronization mode
\returns current syncronization mode
*/
virtual synchronizationMode setSynchronization(synchronizationMode sync=GET_SYNCHRONIZATION_MODE)=0;
/**
Turns off the server - do not use except for debugging!
*/
virtual int exitServer()=0;
/**
returns the detector trimbit/settings directory
*/
virtual char* getSettingsDir()=0;
/** sets the detector trimbit/settings directory */
virtual char* setSettingsDir(string s)=0;
/**
returns the location of the calibration files
*/
virtual char* getCalDir()=0;
/**
sets the location of the calibration files
*/
virtual char* setCalDir(string s)=0;
/**
returns the default output files path
*/
virtual char* getFilePath()=0;
/**
sets the default output files path
\param s file path
\returns file path
*/
virtual char* setFilePath(string s)=0;
/**
returns the default output files root name
*/
virtual char* getFileName()=0;
/**
sets the default output files path
*/
virtual char* setFileName(string s)=0;
/**
returns the default output file index
*/
virtual int getFileIndex()=0;
/**
sets the default output file index
*/
virtual int setFileIndex(int i)=0;
/**
get flat field corrections file directory
\returns flat field correction file directory
*/
virtual char *getFlatFieldCorrectionDir()=0;
/**
set flat field corrections file directory
\param flat field correction file directory
\returns flat field correction file directory
*/
virtual char *setFlatFieldCorrectionDir(string dir)=0;
/**
get flat field corrections file name
\returns flat field correction file name
*/
virtual char *getFlatFieldCorrectionFile()=0;
/**
set flat field corrections
\param fname name of the flat field file (or "" if disable)
\returns 0 if disable (or file could not be read), >0 otherwise
*/
virtual int setFlatFieldCorrection(string fname="")=0;
/**
get flat field corrections
\param corr if !=NULL will be filled with the correction coefficients
\param ecorr if !=NULL will be filled with the correction coefficients errors
\returns 0 if ff correction disabled, >0 otherwise
*/
virtual int getFlatFieldCorrection(float *corr=NULL, float *ecorr=NULL)=0;
/**
set flat field corrections
\param corr if !=NULL the flat field corrections will be filled with corr (NULL usets ff corrections)
\param ecorr if !=NULL the flat field correction errors will be filled with ecorr (1 otherwise)
\returns 0 if ff correction disabled, >0 otherwise
*/
virtual int setFlatFieldCorrection(float *corr=NULL, float *ecorr=NULL)=0;
/**
set rate correction
\param t dead time in ns - if 0 disable correction, if >0 set dead time to t, if <0 set deadtime to default dead time for current settings
\returns 0 if rate correction disabled, >0 otherwise
*/
virtual int setRateCorrection(float t=0)=0;
/**
get rate correction
\param t reference for dead time
\returns 0 if rate correction disabled, >0 otherwise
*/
virtual int getRateCorrection(float &t)=0;
/**
get rate correction tau
\returns 0 if rate correction disabled, otherwise the tau used for the correction
*/
virtual float getRateCorrectionTau()=0;
/**
get rate correction
\returns 0 if rate correction disabled, >0 otherwise
*/
virtual int getRateCorrection()=0;
/**
set bad channels correction
\param fname file with bad channel list ("" disable)
\returns 0 if bad channel disabled, >0 otherwise
*/
virtual int setBadChannelCorrection(string fname="")=0;
/**
set bad channels correction
\param nch number of bad channels
\param chs array of channels
\param ff 0 if normal bad channels, 1 if ff bad channels
\returns 0 if bad channel disabled, >0 otherwise
*/
virtual int setBadChannelCorrection(int nch, int *chs, int ff=0)=0;
/**
get bad channels correction
\param bad pointer to array that if bad!=NULL will be filled with the bad channel list
\returns 0 if bad channel disabled or no bad channels, >0 otherwise
*/
virtual int getBadChannelCorrection(int *bad=NULL)=0;
/**
returns the bad channel list file
*/
virtual string getBadChannelCorrectionFile()=0;
/**
set angular conversion
\param fname file with angular conversion constants ("" disable)
\returns 0 if angular conversion disabled, >0 otherwise
*/
virtual int setAngularConversion(string fname="")=0;
/**
get angular conversion
\param reference to diffractometer direction
\param angconv array that will be filled with the angular conversion constants
\returns 0 if angular conversion disabled, >0 otherwise
*/
virtual int getAngularConversion(int &direction, angleConversionConstant *angconv=NULL)=0;
/**
pure virtual function
returns the angular conversion file
*/
virtual string getAngularConversion()=0;
/**
sets the value of s angular conversion parameter
\param c can be ANGULAR_DIRECTION, GLOBAL_OFFSET, FINE_OFFSET, BIN_SIZE
\param v the value to be set
\returns the actual value
*/
virtual float setAngularConversionParameter(angleConversionParameter c, float v)=0;
/**
returns the value of an angular conversion parameter
\param c can be ANGULAR_DIRECTION, GLOBAL_OFFSET, FINE_OFFSET, BIN_SIZE
\returns the actual value
*/
virtual float getAngularConversionParameter(angleConversionParameter c)=0;
/**
writes a data file
\param name of the file to be written
\param data array of data values
\param err array of arrors on the data. If NULL no errors will be written
\param ang array of angular values. If NULL data will be in the form chan-val(-err) otherwise ang-val(-err)
\param dataformat format of the data: can be 'i' integer or 'f' float (default)
\param nch number of channels to be written to file. if -1 defaults to the number of installed channels of the detector
\returns OK or FAIL if it could not write the file or data=NULL
*/
virtual int writeDataFile(string fname, float *data, float *err=NULL, float *ang=NULL, char dataformat='f', int nch=-1)=0;
/**
writes an angular conversion file
\param fname file to be written
\return OK/FAIL
*/
virtual int writeAngularConversion(string fname)=0;
/**
set/get if the data processing and file writing should be done by a separate thread - do not use except for debugging!
\param b 0 sequencial data acquisition and file writing, 1 separate thread, -1 get
\returns thread flag
*/
virtual int setThreadedProcessing(int i=-1)=0;
/**
set positions for the acquisition
\param nPos number of positions
\param pos array with the encoder positions
\returns number of positions
*/
virtual int setPositions(int nPos, float *pos)=0;
/**
get positions for the acquisition
\param pos array which will contain the encoder positions
\returns number of positions
*/
virtual int getPositions(float *pos=NULL)=0;
/**
set action
\param iaction can be enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript, MAX_ACTIONS}
\param fname for script ("" disable)
\returns 0 if action disabled, >0 otherwise
*/
virtual int setActionScript(int iaction, string fname="")=0;
/**
set action
\param iaction can be enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript, MAX_ACTIONS}
\param par for script ("" disable)
\returns 0 if action disabled, >0 otherwise
*/
virtual int setActionParameter(int iaction, string par="")=0;
/**
returns action script
\param iaction can be enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript}
\returns action script
*/
virtual string getActionScript(int iaction)=0;
/**
returns action parameter
\param iaction can be enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript}
\returns action parameter
*/
virtual string getActionParameter(int iaction)=0;
/**
set scan script
\param index is the scan index (0 or 1)
\param fname for script ("" disable, "none" disables and overwrites current, "threshold" makes threshold scan, "trimbits" make trimbits scan, "energy" makes energy scan)
\returns 0 if scan disabled, >0 otherwise
*/
virtual int setScanScript(int index, string script="")=0;
/**
set scan script parameter
\param index is the scan index (0 or 1)
\param spar parameter to be passed to the scan script with syntax par=spar
\returns 0 if scan disabled, >0 otherwise
*/
virtual int setScanParameter(int index, string spar="")=0;
/**
set scan precision
\param index is the scan index (0 or 1)
\param precision number of decimals to use for the scan variable in the file name
\returns 0 if scan disabled, >0 otherwise
*/
virtual int setScanPrecision(int index, int precision=-1)=0;
/**
set scan steps (passed to the scan script as var=step)
\param index is the scan index (0 or 1)
\param nvalues is the number of steps
\param values array of steps
\returns 0 if scan disabled, >0 otherwise
*/
virtual int setScanSteps(int index, int nvalues=-1, float *values=NULL)=0;
/**
get scan script
\param index is the scan index (0 or 1)
\returns "none" if disables, "threshold" threshold scan, "trimbits" trimbits scan, "energy" energy scan or scan script name
*/
virtual string getScanScript(int index)=0;
/**
get scan script
\param index is the scan index (0 or 1)
\returns scan script parameter
*/
virtual string getScanParameter(int index)=0;
/**
get scan precision
\param index is the scan index (0 or 1)
\returns precision i.e. number of decimals to use for the scan variable in the file name
*/
virtual int getScanPrecision(int index)=0;
/**
get scan steps
\param index is the scan index (0 or 1)
\param values pointer to array of values (must be allocated in advance)
\returns number of steps
*/
virtual int getScanSteps(int index, float *values=NULL)=0;
/**
gets the network parameters (implemented for gotthard)
\param i network parameter type can be CLIENT_IP, CLIENT_MAC, SERVER_MAC
\returns parameter
*/
virtual char *getNetworkParameter(networkParameter i)=0;
/**
sets the network parameters (implemented for gotthard)
\param i network parameter type can be CLIENT_IP, CLIENT_MAC, SERVER_MAC
\param s value to be set
\returns parameter
*/
virtual char *setNetworkParameter(networkParameter i, string s)=0;
/**
changes/gets the port number
\param type port type can be CONTROL_PORT, DATA_PORT, STOP_PORT
\param num new port number (<1024 gets)
\returns actual port number
*/
virtual int setPort(portType t, int i=-1)=0;
/** Locks/Unlocks the connection to the server
/param lock sets (1), usets (0), gets (-1) the lock
/returns lock status of the server
*/
virtual int lockServer(int i=-1)=0;
/**
Returns the IP of the last client connecting to the detector
*/
virtual string getLastClientIP()=0;
/**
configures mac for gotthard readout
\returns OK or FAIL
*/
virtual int configureMAC()=0;
/**
set/get the size of the detector
\param n number of modules
\param d dimension
\returns current number of modules in direction d
*/
virtual int setNumberOfModules(int i=-1, dimension d=X)=0;
/**
get the maximum size of the detector
\param d dimension
\returns maximum number of modules that can be installed in direction d
*/
virtual int getMaxNumberOfModules(dimension d=X)=0;
/**
set/get dynamic range
\param n dynamic range (-1 get)
\returns current dynamic range
updates the size of the data expected from the detector
\sa sharedSlsDetector
*/
virtual int setDynamicRange(int i=-1)=0;
/**
get detector settings
\param imod module number (-1 all)
\returns current settings
*/
virtual detectorSettings getSettings(int imod=-1)=0;
/**
set detector settings
\param isettings settings
\param imod module number (-1 all)
\returns current settings
in this function trimbits/settings and calibration files are searched in the settingsDir and calDir directories and the detector is initialized
*/
virtual detectorSettings setSettings(detectorSettings isettings, int imod=-1)=0;
/**
get threshold energy
\param imod module number (-1 all)
\returns current threshold value for imod in ev (-1 failed)
*/
virtual int getThresholdEnergy(int imod=-1)=0;
/**
set threshold energy
\param e_eV threshold in eV
\param imod module number (-1 all)
\param isettings ev. change settings
\returns current threshold value for imod in ev (-1 failed)
*/
virtual int setThresholdEnergy(int e_eV, int imod=-1, detectorSettings isettings=GET_SETTINGS)=0;
/**
get detector ids/versions for module
\param mode which id/version has to be read
\param imod module number for module serial number
\returns id
*/
virtual int64_t getId(idMode mode, int imod=0)=0;
/**
Digital test of the modules
\param mode test mode
\param imod module number for chip test or module firmware test
\returns OK or error mask
*/
virtual int digitalTest(digitalTestMode mode, int imod=0)=0;
/**
ex cute trimming
\param mode trim mode
\param par1 if noise, beam or fixed setting trimming it is count limit, if improve maximum number of iterations
\param par2 if noise or beam nsigma, if improve par2!=means vthreshold will be optimized, if fixed settings par2<0 trimwith median, par2>=0 trim with level
\param imod module number (-1 all)
\returns OK or FAIl (FAIL also if some channel are 0 or 63
*/
virtual int executeTrimming(trimMode mode, int par1, int par2, int imod=-1)=0;
/**
returns currently the loaded trimfile/settingsfile name
*/
virtual const char *getSettingsFile()=0;
/** loads the modules settings/trimbits reading from a file
\param fname file name . If not specified, extension is automatically generated!
\param imod module number, -1 means all modules
\returns OK or FAIL
*/
virtual int loadSettingsFile(string fname, int imod=-1)=0;
/** saves the modules settings/trimbits writing to a file
\param fname file name . Axtension is automatically generated!
\param imod module number, -1 means all modules
\returns OK or FAIL
*/
virtual int saveSettingsFile(string fname, int imod=-1)=0;
/**
write register
\param addr address
\val value
\returns current register value
DO NOT USE!!! ONLY EXPERT USER!!!
*/
virtual int writeRegister(int addr, int val)=0;
/**
read register
\param addr address
\returns current register value
DO NOT USE!!! ONLY EXPERT USER!!!
*/
virtual int readRegister(int addr)=0;
/**
set dacs value
\param val value (in V)
\param index DAC index
\param imod module number (if -1 alla modules)
\returns current DAC value
*/
virtual float setDAC(float , dacIndex, int imod=-1)=0;
/**
gets ADC value
\param index ADC index
\param imod module number
\returns current ADC value
*/
virtual float getADC(dacIndex, int imod=0)=0;
/**
set/get timer value
\param index timer index
\param t time in ns or number of...(e.g. frames, gates, probes)
\returns timer set value in ns or number of...(e.g. frames, gates, probes)
*/
virtual int64_t setTimer(timerIndex index, int64_t t=-1)=0;
/**
get current timer value
\param index timer index
\returns elapsed time value in ns or number of...(e.g. frames, gates, probes)
*/
virtual int64_t getTimeLeft(timerIndex index)=0;
/** sets/gets the value of important readout speed parameters
\param sp is the parameter to be set/get
\param value is the value to be set, if -1 get value
\returns current value for the specified parameter
\sa speedVariable
*/
virtual int setSpeed(speedVariable sp, int value=-1)=0;
/** sets the number of trim energies and their value \sa sharedSlsDetector
\param nen number of energies
\param en array of energies
\returns number of trim energies
unused!
*/
virtual int setTrimEn(int nen, int *en=NULL)=0;
/** returns the number of trim energies and their value \sa sharedSlsDetector
\param point to the array that will contain the trim energies (in ev)
\returns number of trim energies
unused!
*/
virtual int getTrimEn(int *en=NULL)=0;
/**
set/get the use of an external signal
\param pol meaning of the signal \sa externalSignalFlag
\param signalIndex index of the signal
\returns current meaning of signal signalIndex
*/
virtual externalSignalFlag setExternalSignalFlags(externalSignalFlag pol=GET_EXTERNAL_SIGNAL_FLAG , int signalindex=0)=0;
/**
set/get readout flags
\param flag readout flag to be set
\returns current flag
*/
virtual int setReadOutFlags(readOutFlags flag=GET_READOUT_FLAGS)=0;
/**
set/get the external communication mode
obsolete \sa setExternalSignalFlags
\param pol value to be set \sa externalCommunicationMode
\returns current external communication mode
*/
virtual externalCommunicationMode setExternalCommunicationMode(externalCommunicationMode pol=GET_EXTERNAL_COMMUNICATION_MODE)=0;
/**
Reads the configuration file
\param fname file name
\returns OK or FAIL
*/
virtual int readConfigurationFile(string const fname)=0;
/**
Writes the configuration file
\param fname file name
\returns OK or FAIL
*/
virtual int writeConfigurationFile(string const fname)=0;
/**
Reads the parameters from the detector and writes them to file
\param fname file to write to
\param level if 2 reads also trimbits, flat field, angular correction etc. and writes them to files with automatically added extension
\returns OK or FAIL
*/
virtual int dumpDetectorSetup(string const fname, int level=0)=0;
/**
Loads the detector setup from file
\param fname file to read from
\param level if 2 reads also reads trimbits, angular conversion coefficients etc. from files with default extensions as generated by dumpDetectorSetup
\returns OK or FAIL
*/
virtual int retrieveDetectorSetup(string const fname, int level=0)=0;
/**
Loads dark image or gain image to the detector
\param index can be DARK_IMAGE or GAIN_IMAGE
\fname file name to load data from
\returns OK or FAIL
*/
virtual int loadImageToDetector(imageType index,string const fname)=0;
/**
Test function
\param times number of repetitions
\returns repetition when it fails
*/
virtual int testFunction(int times=0)=0;
};
#endif

View File

@ -1,8 +1,12 @@
#include "slsDetectorCommand.h"
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
slsDetectorCommand::slsDetectorCommand() {
slsDetectorCommand::slsDetectorCommand() : slsDetectorBase() {
int i=0;
@ -105,6 +109,10 @@ slsDetectorCommand::slsDetectorCommand() {
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdAngConv;
i++;
descrToFuncMap[i].m_pFuncName="angdir" ;//
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdAngConv;
i++;
descrToFuncMap[i].m_pFuncName="threaded"; //
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdThreaded;
i++;
@ -150,7 +158,7 @@ slsDetectorCommand::slsDetectorCommand() {
descrToFuncMap[i].m_pFuncName="online"; //
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdUnderDevelopment;
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdOnline;
i++;
/* Acquisition actions */
@ -770,6 +778,8 @@ detectorSettings slsDetectorCommand::getDetectorSettings(string s ){
string slsDetectorCommand::executeLine(int narg, char *args[], int action) {
if (action==READOUT_ACTION)
return cmdAcquire(narg, args, action);
@ -1613,7 +1623,7 @@ string slsDetectorCommand::cmdAngConv(int narg, char *args[], int action){
string sval;
char answer[1000];
float fval;
angleConversionParameter c;
if (string(args[0])==string("angconv")) {
if (action==PUT_ACTION) {
@ -1642,30 +1652,31 @@ string slsDetectorCommand::cmdAngConv(int narg, char *args[], int action){
}
}
} else if (string(args[0])==string("globaloff")) {
if (action==PUT_ACTION) {
if (sscanf(args[1],"%f",&fval))
setGlobalOffset(fval);
}
sprintf(answer,"%f",getGlobalOffset());
return string(answer);
c=GLOBAL_OFFSET;
} else if (string(args[0])==string("fineoff")) {
if (action==PUT_ACTION) {
if (sscanf(args[1],"%f",&fval))
setFineOffset(fval);
}
sprintf(answer,"%f",getFineOffset());
return string(answer);
c=FINE_OFFSET;
} else if (string(args[0])==string("binsize")) {
c=BIN_SIZE;
} else if (string(args[0])==string("angdir")) {
c=ANGULAR_DIRECTION;
} else
return string("could not decode angular conversion parameter ")+cmd;
if (action==PUT_ACTION) {
if (sscanf(args[1],"%f",&fval))
setBinSize(fval);
setAngularConversionParameter(c,fval);
}
sprintf(answer,"%f",getBinSize());
sprintf(answer,"%f",getAngularConversionParameter(c));
return string(answer);
}
}
@ -1752,37 +1763,37 @@ string slsDetectorCommand::helpThreaded(int narg, char *args[], int action){
string slsDetectorCommand::cmdImage(int narg, char *args[], int action){
string sval;
int retval;
if (action==HELP_ACTION)
return helpImage(narg,args,HELP_ACTION);
else if (action==GET_ACTION)
return string("Cannot get");
sval=string(args[1]);
setOnline(ONLINE_FLAG);
if (string(args[0])==string("darkimage"))
retval=loadImageToDetector(DARK_IMAGE,sval);
else if (string(args[0])==string("gainimage"))
retval=loadImageToDetector(GAIN_IMAGE,sval);
if(!retval)
return string("Image loaded succesfully");
else
return string("Image NOT loaded");
string sval;
int retval;
if (action==HELP_ACTION)
return helpImage(narg,args,HELP_ACTION);
else if (action==GET_ACTION)
return string("Cannot get");
sval=string(args[1]);
setOnline(ONLINE_FLAG);
if (string(args[0])==string("darkimage"))
retval=loadImageToDetector(DARK_IMAGE,sval);
else if (string(args[0])==string("gainimage"))
retval=loadImageToDetector(GAIN_IMAGE,sval);
if(!retval)
return string("Image loaded succesfully");
else
return string("Image NOT loaded");
}
string slsDetectorCommand::helpImage(int narg, char *args[], int action){
if (action==PUT_ACTION || action==HELP_ACTION){
if (string(args[0])==string("darkimage"))
return string("darkimage f \t loads the image to detector from file f\n");
else
return string("gainimage f \t loads the image to detector from file f\n");
}
else
return string("Cannot get");
if (action==PUT_ACTION || action==HELP_ACTION){
if (string(args[0])==string("darkimage"))
return string("darkimage f \t loads the image to detector from file f\n");
else
return string("gainimage f \t loads the image to detector from file f\n");
}
else
return string("Cannot get");
}
@ -2083,12 +2094,12 @@ string slsDetectorCommand::cmdPort(int narg, char *args[], int action) {
if (cmd=="port") {
index=CONTROL_PORT;
} if (cmd=="dataport") {
} else if (cmd=="dataport") {
index=DATA_PORT;
} if (cmd=="stopport") {
} else if (cmd=="stopport") {
index=STOP_PORT;
} else
return string("unknown port type")+cmd;
return string("unknown port type ")+cmd;
setOnline(ONLINE_FLAG);
if (action==PUT_ACTION)
@ -2230,18 +2241,18 @@ string slsDetectorCommand::cmdConfigureMac(int narg, char *args[], int action) {
int ival;
int ret;
char ans[1000];
if (action==PUT_ACTION){
if (sscanf(args[1],"%d",&ival))
if(ival==1){
setOnline(ONLINE_FLAG);
ret=configureMAC();
}
else
return string("Not yet implemented with arguments other than 1");
if (sscanf(args[1],"%d",&ival))
if(ival==1){
setOnline(ONLINE_FLAG);
ret=configureMAC();
}
else
return string("Not yet implemented with arguments other than 1");
}
else
return string("Cannot get ")+cmd;
return string("Cannot get ")+cmd;
sprintf(ans,"%d",ret);
return ans;
@ -2253,7 +2264,7 @@ string slsDetectorCommand::helpConfigureMac(int narg, char *args[], int action)
if (action==PUT_ACTION || action==HELP_ACTION)
os << "configuremac i \n configures the MAC of the detector. i=1 for configure; i=0 for unconfigure(not implemented yet)"<< std::endl;
if (action==GET_ACTION || action==HELP_ACTION)
os << "configuremac " << "Cannot get " << std::endl;
os << "configuremac " << "Cannot get " << std::endl;
return os.str();
}
@ -2281,12 +2292,12 @@ string slsDetectorCommand::cmdDetectorSize(int narg, char *args[], int action) {
if (cmd=="nmod") {
ret=setNumberOfModules(val);
} if (cmd=="maxmod") {
} else if (cmd=="maxmod") {
ret=getMaxNumberOfModules();
} if (cmd=="dr") {
} else if (cmd=="dr") {
ret=setDynamicRange(val);
} else
return string("unknown detector size")+cmd;
return string("unknown detector size ")+cmd;
sprintf(ans,"%d",ret);
@ -2338,7 +2349,7 @@ string slsDetectorCommand::cmdSettings(int narg, char *args[], int action) {
if (action==PUT_ACTION)
setSettings(getDetectorSettings(string(args[1])));
return getDetectorSettings(getSettings());
} if (cmd=="threshold") {
} else if (cmd=="threshold") {
if (action==PUT_ACTION) {
if (sscanf(args[1],"%d",&val))
setThresholdEnergy(val);
@ -2347,7 +2358,7 @@ string slsDetectorCommand::cmdSettings(int narg, char *args[], int action) {
}
sprintf(ans,"%d",getThresholdEnergy());
return string(ans);
} if (cmd=="trimbits") {
} else if (cmd=="trimbits") {
if (narg>=2) {
string sval=string(args[1]);
#ifdef VERBOSE
@ -2518,54 +2529,54 @@ string slsDetectorCommand::cmdDigiTest(int narg, char *args[], int action) {
setOnline(ONLINE_FLAG);
if (cmd=="bustest"){
if (action==PUT_ACTION)
return string("cannot set ")+cmd;
sprintf(answer,"%x",digitalTest(DETECTOR_BUS_TEST));
return string(answer);
if (action==PUT_ACTION)
return string("cannot set ")+cmd;
sprintf(answer,"%x",digitalTest(DETECTOR_BUS_TEST));
return string(answer);
}
if (cmd=="digitest") {
if (action==PUT_ACTION)
return string("cannot set ")+cmd;
int ival=-1;
if (sscanf(args[0],"digitest:%d",&ival)) {
sprintf(answer,"%x",digitalTest(CHIP_TEST, ival));
return string(answer);
} else
return string("undefined module number");
if (action==PUT_ACTION)
return string("cannot set ")+cmd;
int ival=-1;
if (sscanf(args[0],"digitest:%d",&ival)) {
sprintf(answer,"%x",digitalTest(CHIP_TEST, ival));
return string(answer);
} else
return string("undefined module number");
}
if (cmd=="digibittest") {
if (action==GET_ACTION)
return string("cannot get ")+cmd;
int ival=-1;
if (sscanf(args[1],"%d",&ival)) {
if((ival==0)||(ival==1)){
sprintf(answer,"%x",digitalTest(DIGITAL_BIT_TEST,ival));
return string(answer);
}
else
return string("Use only 0 or 1 to set/clear digital test bit\n");
} else
return string("undefined number");
if (action==GET_ACTION)
return string("cannot get ")+cmd;
int ival=-1;
if (sscanf(args[1],"%d",&ival)) {
if((ival==0)||(ival==1)){
sprintf(answer,"%x",digitalTest(DIGITAL_BIT_TEST,ival));
return string(answer);
}
else
return string("Use only 0 or 1 to set/clear digital test bit\n");
} else
return string("undefined number");
}
if (cmd=="acqtest") {
if (action==GET_ACTION)
return string("cannot get ")+cmd;
int ival=-1;
if (sscanf(args[1],"%d",&ival)) {
if(ival<1)
return helpDigiTest(narg, args, action);
else {
sprintf(answer,"%x",testFunction(ival));
return string(answer);
}
} else
return string("undefined number");
if (action==GET_ACTION)
return string("cannot get ")+cmd;
int ival=-1;
if (sscanf(args[1],"%d",&ival)) {
if(ival<1)
return helpDigiTest(narg, args, action);
else {
sprintf(answer,"%x",testFunction(ival));
return string(answer);
}
} else
return string("undefined number");
}
return string("unknown digital test mode ")+cmd;
return string("unknown digital test mode ")+cmd;
}
@ -2574,12 +2585,12 @@ string slsDetectorCommand::helpDigiTest(int narg, char *args[], int action) {
ostringstream os;
if (action==GET_ACTION || action==HELP_ACTION) {
os << "digitaltest:i \n performs digital test of the module i. Returns 0 if succeeded, otherwise error mask."<< std::endl;
os << "bustest \n performs test of the bus interface between FPGA and embedded Linux system. Can last up to a few minutes."<< std::endl;
os << "digitaltest:i \t performs digital test of the module i. Returns 0 if succeeded, otherwise error mask."<< std::endl;
os << "bustest \t performs test of the bus interface between FPGA and embedded Linux system. Can last up to a few minutes."<< std::endl;
}
if (action==PUT_ACTION || action==HELP_ACTION) {
os << "digibittest i\n sets a variable in the server to be used in configuremac function. i sets/clears the digital test bit."<< std::endl;
os << "acqtest i\n runs start acquisition i number of times."<< std::endl;
os << "digibittest i\t sets a variable in the server to be used in configuremac function. i sets/clears the digital test bit."<< std::endl;
os << "acqtest i\t runs start acquisition i number of times."<< std::endl;
}
return os.str();
}
@ -2647,73 +2658,73 @@ string slsDetectorCommand::helpRegister(int narg, char *args[], int action) {
string slsDetectorCommand::cmdDAC(int narg, char *args[], int action) {
if (action==HELP_ACTION)
return helpDAC(narg, args, action);
dacIndex dac;
float val=-1;
char answer[1000];
if (cmd=="vthreshold")
dac=THRESHOLD;
else if (cmd=="vcalibration")
dac=CALIBRATION_PULSE;
else if (cmd=="vtrimbit")
dac=TRIMBIT_SIZE;
else if (cmd=="vpreamp")
dac=PREAMP;
else if (cmd=="vshaper1")
dac=SHAPER1;
else if (cmd=="vshaper2")
dac=SHAPER2;
else if (cmd=="vhighvoltage")
dac=HV_POT;
else if (cmd=="vapower")
dac=VA_POT;
else if (cmd=="vddpower")
dac=VDD_POT;
else if (cmd=="vshpower")
dac=VSH_POT;
else if (cmd=="viopower")
dac=VIO_POT;
else if (cmd=="vrefds")
dac=G_VREF_DS;
else if (cmd=="vcascn_pb")
dac=G_VCASCN_PB;
else if (cmd=="vcascp_pb")
dac=G_VCASCP_PB;
else if (cmd=="vout_cm")
dac=G_VOUT_CM;
else if (cmd=="vcasc_out")
dac=G_VCASC_OUT;
else if (cmd=="vin_cm")
dac=G_VIN_CM;
else if (cmd=="vref_comp")
dac=G_VREF_COMP;
else if (cmd=="ib_test_c")
dac=G_IB_TESTC;
else if (cmd=="temp_adc") {
dac=TEMPERATURE_ADC;
if (action==PUT_ACTION)
return string("cannot set ")+cmd;
} else if (cmd=="temp_fpga") {
dac=TEMPERATURE_FPGA;
if (action==PUT_ACTION)
return string("cannot set ")+cmd;
} else
return string("cannot decode dac ")+cmd;
if (action==PUT_ACTION) {
if (sscanf(args[1],"%f", &val))
;
else
return string("cannot scan DAC value ")+string(args[1]);
}
setOnline(ONLINE_FLAG);
sprintf(answer,"%f",setDAC(val,dac));
return string(answer);
if (action==HELP_ACTION)
return helpDAC(narg, args, action);
dacIndex dac;
float val=-1;
char answer[1000];
if (cmd=="vthreshold")
dac=THRESHOLD;
else if (cmd=="vcalibration")
dac=CALIBRATION_PULSE;
else if (cmd=="vtrimbit")
dac=TRIMBIT_SIZE;
else if (cmd=="vpreamp")
dac=PREAMP;
else if (cmd=="vshaper1")
dac=SHAPER1;
else if (cmd=="vshaper2")
dac=SHAPER2;
else if (cmd=="vhighvoltage")
dac=HV_POT;
else if (cmd=="vapower")
dac=VA_POT;
else if (cmd=="vddpower")
dac=VDD_POT;
else if (cmd=="vshpower")
dac=VSH_POT;
else if (cmd=="viopower")
dac=VIO_POT;
else if (cmd=="vrefds")
dac=G_VREF_DS;
else if (cmd=="vcascn_pb")
dac=G_VCASCN_PB;
else if (cmd=="vcascp_pb")
dac=G_VCASCP_PB;
else if (cmd=="vout_cm")
dac=G_VOUT_CM;
else if (cmd=="vcasc_out")
dac=G_VCASC_OUT;
else if (cmd=="vin_cm")
dac=G_VIN_CM;
else if (cmd=="vref_comp")
dac=G_VREF_COMP;
else if (cmd=="ib_test_c")
dac=G_IB_TESTC;
else if (cmd=="temp_adc") {
dac=TEMPERATURE_ADC;
if (action==PUT_ACTION)
return string("cannot set ")+cmd;
} else if (cmd=="temp_fpga") {
dac=TEMPERATURE_FPGA;
if (action==PUT_ACTION)
return string("cannot set ")+cmd;
} else
return string("cannot decode dac ")+cmd;
if (action==PUT_ACTION) {
if (sscanf(args[1],"%f", &val))
;
else
return string("cannot scan DAC value ")+string(args[1]);
}
setOnline(ONLINE_FLAG);
sprintf(answer,"%f",setDAC(val,dac));
return string(answer);
}
@ -2800,24 +2811,24 @@ string slsDetectorCommand::helpDAC(int narg, char *args[], int action) {
string slsDetectorCommand::cmdADC(int narg, char *args[], int action) {
dacIndex adc;
float val=-1;
char answer[1000];
if (action==HELP_ACTION)
return helpADC(narg, args, action);
else if (action==PUT_ACTION)
return string("cannot set ")+cmd;
if (cmd=="temp_adc")
adc=TEMPERATURE_ADC;
else if (cmd=="temp_fpga")
adc=TEMPERATURE_FPGA;
else
return string("cannot decode adc ")+cmd;
setOnline(ONLINE_FLAG);
dacIndex adc;
float val=-1;
char answer[1000];
if (action==HELP_ACTION)
return helpADC(narg, args, action);
else if (action==PUT_ACTION)
return string("cannot set ")+cmd;
if (cmd=="temp_adc")
adc=TEMPERATURE_ADC;
else if (cmd=="temp_fpga")
adc=TEMPERATURE_FPGA;
else
return string("cannot decode adc ")+cmd;
setOnline(ONLINE_FLAG);
sprintf(answer,"%f",getADC(adc));
return string(answer);
@ -2825,16 +2836,16 @@ string slsDetectorCommand::cmdADC(int narg, char *args[], int action) {
string slsDetectorCommand::helpADC(int narg, char *args[], int action) {
ostringstream os;
if (action==PUT_ACTION || action==HELP_ACTION) {
os << "temp_adc " << "Cannot be set" << std::endl;
os << "temp_fpga " << "Cannot be set" << std::endl;
}
if (action==GET_ACTION || action==HELP_ACTION) {
os << "temp_adc " << "\t gets the temperature of the adc" << std::endl;
os << "temp_fpga " << "\t gets the temperature of the fpga" << std::endl;
}
return os.str();
ostringstream os;
if (action==PUT_ACTION || action==HELP_ACTION) {
os << "temp_adc " << "Cannot be set" << std::endl;
os << "temp_fpga " << "Cannot be set" << std::endl;
}
if (action==GET_ACTION || action==HELP_ACTION) {
os << "temp_adc " << "\t gets the temperature of the adc" << std::endl;
os << "temp_fpga " << "\t gets the temperature of the fpga" << std::endl;
}
return os.str();
}

View File

@ -4,22 +4,15 @@
#include "sls_detector_defs.h"
#include <string>
#include <iostream>
#include <sstream>
#include <fstream>
#include "slsDetectorBase.h"
using namespace std;
class slsDetectorCommand;
/* /\** This class handles the command line I/Os, help etc. */
/* It is inherited by both slsDetector and multiSlsDetector */
/* *\/ */
class slsDetectorCommand {
class slsDetectorCommand : public slsDetectorBase{
public:
@ -42,296 +35,52 @@ class slsDetectorCommand;
/* \param action can be PUT_ACTION or GET_ACTION (from text client even READOUT_ACTION for acquisition) */
/* *\/ */
static string helpLine(int narg, char *args[], int action=HELP_ACTION);
string cmdUnderDevelopment(int narg, char *args[], int action);
string cmdUnknown(int narg, char *args[], int action);
string cmdAcquire(int narg, char *args[], int action);
static string helpAcquire(int narg, char *args[], int action);
string cmdData(int narg, char *args[], int action);
static string helpData(int narg, char *args[], int action);
string cmdFrame(int narg, char *args[], int action);
static string helpFrame(int narg, char *args[], int action);
string cmdStatus(int narg, char *args[], int action);
static string helpStatus(int narg, char *args[], int action);
string cmdFree(int narg, char *args[], int action);
static string helpFree(int narg, char *args[], int action);
string cmdAdd(int narg, char *args[], int action);
static string helpAdd(int narg, char *args[], int action);
string cmdRemove(int narg, char *args[], int action);
static string helpRemove(int narg, char *args[], int action);
string cmdHostname(int narg, char *args[], int action);
static string helpHostname(int narg, char *args[], int action);
string cmdId(int narg, char *args[], int action);
static string helpId(int narg, char *args[], int action);
string cmdMaster(int narg, char *args[], int action);
static string helpMaster(int narg, char *args[], int action);
string cmdSync(int narg, char *args[], int action);
static string helpSync(int narg, char *args[], int action);
string cmdHelp(int narg, char *args[], int action);
string cmdExitServer(int narg, char *args[], int action);
static string helpExitServer(int narg, char *args[], int action);
string cmdSettingsDir(int narg, char *args[], int action);
static string helpSettingsDir(int narg, char *args[], int action);
string cmdCalDir(int narg, char *args[], int action);
static string helpCalDir(int narg, char *args[], int action);
string cmdTrimEn(int narg, char *args[], int action);
static string helpTrimEn(int narg, char *args[], int action);
string cmdOutDir(int narg, char *args[], int action);
static string helpOutDir(int narg, char *args[], int action);
string cmdFileName(int narg, char *args[], int action);
static string helpFileName(int narg, char *args[], int action);
string cmdFileIndex(int narg, char *args[], int action);
static string helpFileIndex(int narg, char *args[], int action);
string cmdFlatField(int narg, char *args[], int action);
static string helpFlatField(int narg, char *args[], int action);
string cmdRateCorr(int narg, char *args[], int action);
static string helpRateCorr(int narg, char *args[], int action);
string cmdBadChannels(int narg, char *args[], int action);
static string helpBadChannels(int narg, char *args[], int action);
string cmdAngConv(int narg, char *args[], int action);
static string helpAngConv(int narg, char *args[], int action);
string cmdThreaded(int narg, char *args[], int action);
static string helpThreaded(int narg, char *args[], int action);
string cmdImage(int narg, char *args[], int action);
static string helpImage(int narg, char *args[], int action);
string cmdPositions(int narg, char *args[], int action);
static string helpPositions(int narg, char *args[], int action);
string cmdScripts(int narg, char *args[], int action);
static string helpScripts(int narg, char *args[], int action);
string cmdScans(int narg, char *args[], int action);
static string helpScans(int narg, char *args[], int action);
string cmdNetworkParameter(int narg, char *args[], int action);
static string helpNetworkParameter(int narg, char *args[], int action);
string cmdPort(int narg, char *args[], int action);
static string helpPort(int narg, char *args[], int action);
string cmdLock(int narg, char *args[], int action);
static string helpLock(int narg, char *args[], int action);
string cmdLastClient(int narg, char *args[], int action);
static string helpLastClient(int narg, char *args[], int action);
string cmdOnline(int narg, char *args[], int action);
static string helpOnline(int narg, char *args[], int action);
string cmdConfigureMac(int narg, char *args[], int action);
static string helpConfigureMac(int narg, char *args[], int action);
string cmdDetectorSize(int narg, char *args[], int action);
static string helpDetectorSize(int narg, char *args[], int action);
string cmdSettings(int narg, char *args[], int action);
static string helpSettings(int narg, char *args[], int action);
string cmdSN(int narg, char *args[], int action);
static string helpSN(int narg, char *args[], int action);
string cmdDigiTest(int narg, char *args[], int action);
static string helpDigiTest(int narg, char *args[], int action);
string cmdRegister(int narg, char *args[], int action);
static string helpRegister(int narg, char *args[], int action);
string cmdDAC(int narg, char *args[], int action);
static string helpDAC(int narg, char *args[], int action);
string cmdADC(int narg, char *args[], int action);
static string helpTimer(int narg, char *args[], int action);
static string helpTimeLeft(int narg, char *args[], int action);
static string helpSpeed(int narg, char *args[], int action);
static string helpAdvanced(int narg, char *args[], int action);
static string helpConfiguration(int narg, char *args[], int action);
static string helpImage(int narg, char *args[], int action);
static string helpADC(int narg, char *args[], int action);
string cmdTimer(int narg, char *args[], int action);
static string helpTimer(int narg, char *args[], int action);
string cmdTimeLeft(int narg, char *args[], int action);
static string helpTimeLeft(int narg, char *args[], int action);
string cmdSpeed(int narg, char *args[], int action);
static string helpSpeed(int narg, char *args[], int action);
string cmdAdvanced(int narg, char *args[], int action);
static string helpAdvanced(int narg, char *args[], int action);
string cmdConfiguration(int narg, char *args[], int action);
static string helpConfiguration(int narg, char *args[], int action);
virtual int setOnline(int const online=GET_ONLINE_FLAG)=0;
virtual void acquire(int delflag)=0;
virtual int* readAll()=0;
virtual int* readFrame()=0;
virtual void* processData(int delflag)=0;
virtual int startAcquisition()=0;
virtual int stopAcquisition()=0;
virtual runStatus getRunStatus()=0;
virtual int freeSharedMemory()=0;
virtual int addSlsDetector(int, int pos=-1){return -1;};
virtual int addSlsDetector(char*, int pos=-1){return -1;};
virtual int removeSlsDetector(int pos=-1){return -1;};
virtual int removeSlsDetector(char*){return -1;};
virtual string setHostname(char*, int pos=-1)=0;
virtual string getHostname(int pos=-1)=0;
virtual int getDetectorId(int i=-1) =0;
virtual int setDetectorId(int ival, int i=-1){return -1;};
virtual synchronizationMode setSynchronization(synchronizationMode sync=GET_SYNCHRONIZATION_MODE){return GET_SYNCHRONIZATION_MODE;};
virtual int exitServer()=0;
virtual int setMaster(int i=-1){return -1;};
virtual char* getSettingsDir()=0;
virtual char* setSettingsDir(string s)=0;
virtual char* getCalDir()=0;
virtual char* setCalDir(string s)=0;
virtual char* getFilePath()=0;
virtual char* setFilePath(string s)=0;
virtual char* getFileName()=0;
virtual char* setFileName(string s)=0;
virtual int getFileIndex()=0;
virtual int setFileIndex(int i)=0;
virtual int setFlatFieldCorrection(string fname="")=0;
virtual int getFlatFieldCorrection(float *corr=NULL, float *ecorr=NULL)=0;
virtual int setFlatFieldCorrection(float *corr=NULL, float *ecorr=NULL)=0;
virtual char *getFlatFieldCorrectionDir()=0;
virtual void setFlatFieldCorrectionDir(string dir)=0;
virtual char *getFlatFieldCorrectionFile()=0;
virtual int setRateCorrection(float t=0)=0;
virtual int getRateCorrection(float &t)=0;
virtual float getRateCorrectionTau()=0;
virtual int getRateCorrection()=0;
virtual int setBadChannelCorrection(string fname="")=0;
virtual int setBadChannelCorrection(int nch, int *chs, int ff=0)=0;
virtual int getBadChannelCorrection(int *bad=NULL)=0;
virtual string getBadChannelCorrectionFile()=0;
virtual int setAngularConversion(string fname="")=0;
virtual int getAngularConversion(int &direction, angleConversionConstant *angconv=NULL)=0;
virtual string getAngularConversion()=0;
virtual float setGlobalOffset(float f)=0;
virtual float setFineOffset(float f)=0;
virtual float getFineOffset()=0;
virtual float getGlobalOffset()=0;
virtual float setBinSize(float f)=0;
virtual float getBinSize()=0;
virtual int writeDataFile(string fname, float *data, float *err=NULL, float *ang=NULL, char dataformat='f', int nch=-1)=0;
virtual int writeAngularConversion(string fname)=0;
virtual int setThreadedProcessing(int i=-1)=0;;
virtual int setPositions(int nPos, float *pos)=0;
virtual int getPositions(float *pos=NULL)=0;
virtual int setActionScript(int iaction, string fname="")=0;
virtual int setActionParameter(int iaction, string par="")=0;
virtual string getActionScript(int iaction)=0;
virtual string getActionParameter(int iaction)=0;
virtual int setScanScript(int index, string script="")=0;
virtual int setScanParameter(int index, string par="")=0;
virtual int setScanPrecision(int index, int precision=-1)=0;
virtual int setScanSteps(int index, int nvalues=-1, float *values=NULL)=0;
virtual string getScanScript(int index)=0;
virtual string getScanParameter(int index)=0;
virtual int getScanPrecision(int index)=0;
virtual int getScanSteps(int index, float *values=NULL)=0;
virtual char *getNetworkParameter(networkParameter i)=0;
virtual char *setNetworkParameter(networkParameter i, string s)=0;
virtual int setPort(portType t, int i=-1)=0;
virtual int lockServer(int i=-1)=0;
virtual string getLastClientIP()=0;
virtual int configureMAC()=0;
virtual int setNumberOfModules(int i=-1, dimension d=X)=0;
virtual int getMaxNumberOfModules(dimension d=X)=0;
virtual int setDynamicRange(int i=-1)=0;
virtual detectorSettings getSettings(int imod=-1)=0;
virtual detectorSettings setSettings(detectorSettings isettings, int imod=-1)=0;
virtual int getThresholdEnergy(int imod=-1)=0;
virtual int setThresholdEnergy(int e_eV, int imod=-1, detectorSettings isettings=GET_SETTINGS)=0;
virtual int64_t getId(idMode mode, int imod=0)=0;
virtual int digitalTest(digitalTestMode mode, int imod=0)=0;
virtual int executeTrimming(trimMode mode, int par1, int par2, int imod=-1)=0;
virtual const char *getSettingsFile()=0;
virtual int loadSettingsFile(string fname, int imod=-1)=0;
virtual int saveSettingsFile(string fname, int imod=-1)=0;
virtual int writeRegister(int addr, int val)=0;
virtual int readRegister(int addr)=0;
virtual float setDAC(float , dacIndex, int imod=-1)=0;
virtual float getADC(dacIndex, int imod=0)=0;
virtual int64_t setTimer(timerIndex index, int64_t t=-1)=0;
virtual int64_t getTimeLeft(timerIndex index)=0;
virtual int setSpeed(speedVariable sp, int value=-1)=0;
virtual int setTrimEn(int nen, int *en=NULL)=0;
virtual int getTrimEn(int *en=NULL)=0;
virtual externalSignalFlag setExternalSignalFlags(externalSignalFlag pol=GET_EXTERNAL_SIGNAL_FLAG , int signalindex=0)=0;
virtual int setReadOutFlags(readOutFlags flag=GET_READOUT_FLAGS)=0;
virtual externalCommunicationMode setExternalCommunicationMode(externalCommunicationMode pol=GET_EXTERNAL_COMMUNICATION_MODE)=0;
virtual int readConfigurationFile(string const fname)=0;
virtual int writeConfigurationFile(string const fname)=0;
virtual int dumpDetectorSetup(string const fname, int level=0)=0;
virtual int retrieveDetectorSetup(string const fname, int level=0)=0;
virtual int loadImageToDetector(int index,string const fname)=0;
virtual int testFunction(int times=0)=0;
@ -405,7 +154,132 @@ class slsDetectorCommand;
private:
string cmdUnderDevelopment(int narg, char *args[], int action);
string cmdUnknown(int narg, char *args[], int action);
string cmdAcquire(int narg, char *args[], int action);
string cmdData(int narg, char *args[], int action);
string cmdFrame(int narg, char *args[], int action);
string cmdStatus(int narg, char *args[], int action);
string cmdFree(int narg, char *args[], int action);
string cmdAdd(int narg, char *args[], int action);
string cmdRemove(int narg, char *args[], int action);
string cmdHostname(int narg, char *args[], int action);
string cmdId(int narg, char *args[], int action);
string cmdMaster(int narg, char *args[], int action);
string cmdSync(int narg, char *args[], int action);
string cmdHelp(int narg, char *args[], int action);
string cmdExitServer(int narg, char *args[], int action);
string cmdSettingsDir(int narg, char *args[], int action);
string cmdCalDir(int narg, char *args[], int action);
string cmdTrimEn(int narg, char *args[], int action);
string cmdOutDir(int narg, char *args[], int action);
string cmdFileName(int narg, char *args[], int action);
string cmdFileIndex(int narg, char *args[], int action);
string cmdFlatField(int narg, char *args[], int action);
string cmdRateCorr(int narg, char *args[], int action);
string cmdBadChannels(int narg, char *args[], int action);
string cmdAngConv(int narg, char *args[], int action);
string cmdThreaded(int narg, char *args[], int action);
string cmdPositions(int narg, char *args[], int action);
string cmdScripts(int narg, char *args[], int action);
string cmdScans(int narg, char *args[], int action);
string cmdNetworkParameter(int narg, char *args[], int action);
string cmdPort(int narg, char *args[], int action);
string cmdLock(int narg, char *args[], int action);
string cmdLastClient(int narg, char *args[], int action);
string cmdOnline(int narg, char *args[], int action);
string cmdConfigureMac(int narg, char *args[], int action);
string cmdDetectorSize(int narg, char *args[], int action);
string cmdSettings(int narg, char *args[], int action);
string cmdSN(int narg, char *args[], int action);
string cmdDigiTest(int narg, char *args[], int action);
string cmdRegister(int narg, char *args[], int action);
string cmdDAC(int narg, char *args[], int action);
string cmdTimer(int narg, char *args[], int action);
string cmdTimeLeft(int narg, char *args[], int action);
string cmdSpeed(int narg, char *args[], int action);
string cmdAdvanced(int narg, char *args[], int action);
string cmdConfiguration(int narg, char *args[], int action);
string cmdImage(int narg, char *args[], int action);
string cmdADC(int narg, char *args[], int action);
int numberOfCommands;
string cmd;

View File

@ -402,6 +402,76 @@ int slsDetectorUtils::setBadChannelCorrection(string fname, int &nbad, int *badl
/**
sets the value of s angular conversion parameter
\param c can be ANGULAR_DIRECTION, GLOBAL_OFFSET, FINE_OFFSET, BIN_SIZE
\param v the value to be set
\returns the actual value
*/
float slsDetectorUtils::setAngularConversionParameter(angleConversionParameter c, float v){
switch (c) {
case ANGULAR_DIRECTION:
if (v<0)
*angDirection=-1;
else
*angDirection=1;
return *angDirection;
case GLOBAL_OFFSET:
*globalOffset=v;
return *globalOffset;
case FINE_OFFSET:
*fineOffset=v;
return *fineOffset;
case BIN_SIZE:
*binSize=v;
return *binSize;
default:
return 0;
}
}
/**
returns the value of an angular conversion parameter
\param c can be ANGULAR_DIRECTION, GLOBAL_OFFSET, FINE_OFFSET, BIN_SIZE
\returns the actual value
*/
float slsDetectorUtils::getAngularConversionParameter(angleConversionParameter c) {
switch (c) {
case ANGULAR_DIRECTION:
return *angDirection;
case GLOBAL_OFFSET:
return *globalOffset;
case FINE_OFFSET:
return *fineOffset;
case BIN_SIZE:
return *binSize;
default:
return 0;
}
}
int slsDetectorUtils::readAngularConversion(string fname, int nmod, angleConversionConstant *angOff) {
ifstream infile;
@ -1114,6 +1184,15 @@ void slsDetectorUtils::acquire(int delflag){
#ifdef VERBOSE
cout << "Acquire function "<< delflag << endl;
#endif
#ifdef VERBOSE
cout << "Stopped flag is "<< stoppedFlag << delflag << endl;
#endif
void *status;
int trimbit;
@ -1134,7 +1213,7 @@ void slsDetectorUtils::acquire(int delflag){
setTotalProgress();
progressIndex=0;
*stoppedFlag=0;
@ -1153,7 +1232,9 @@ void slsDetectorUtils::acquire(int delflag){
#ifdef VERBOSE
cout << " starting thread " << endl;
#endif
if (*threadedProcessing) {
startThread(delflag);
@ -1186,7 +1267,7 @@ void slsDetectorUtils::acquire(int delflag){
//cout << "action at start" << endl;
if (stoppedFlag==0) {
if (*stoppedFlag==0) {
if (*actionMask & (1 << startScript)) {
//"Custom start script. The arguments are passed as nrun=n par=p.");
sprintf(cmd,"%s nrun=%d par=%s",getActionScript(startScript).c_str(),*fileIndex,getActionParameter(startScript).c_str());
@ -1267,7 +1348,7 @@ void slsDetectorUtils::acquire(int delflag){
} else
break;
if (stoppedFlag==0) {
if (*stoppedFlag==0) {
if (*actionMask & (1 << scriptBefore)) {
//Custom script before each frame. The arguments are passed as nrun=n fn=filename par=p sv0=scanvar0 sv1=scanvar1 p0=par0 p1=par1"
sprintf(cmd,"%s nrun=%d fn=%s par=%s sv0=%f sv1=%f p0=%s p1=%s",getActionScript(scriptBefore).c_str(),*fileIndex,createFileName().c_str(),getActionParameter(scriptBefore).c_str(),currentScanVariable[0],currentScanVariable[1],getScanParameter(0).c_str(),getScanParameter(1).c_str());
@ -1283,7 +1364,7 @@ void slsDetectorUtils::acquire(int delflag){
for (int ip=0; ip<np; ip++) {
// cout << "positions " << endl;
if (stoppedFlag==0) {
if (*stoppedFlag==0) {
if (*numberOfPositions>0) {
go_to_position (detPositions[ip]);
currentPositionIndex=ip+1;
@ -1367,7 +1448,7 @@ void slsDetectorUtils::acquire(int delflag){
}
pthread_mutex_unlock(&mp);
if (stoppedFlag==0) {
if (*stoppedFlag==0) {
if (*actionMask & (1 << headerAfter)) {
//Custom script after each frame. The arguments are passed as nrun=n fn=filename par=p sv0=scanvar0 sv1=scanvar1 p0=par0 p1=par1"
sprintf(cmd,"%s nrun=%d fn=%s acqtime=%f gainmode=%d threshold=%d badfile=%s angfile=%s bloffset=%f fineoffset=%f fffile=%s/%s tau=%f par=%s", \
@ -1527,13 +1608,13 @@ void* slsDetectorUtils::processData(int delflag) {
while((queuesize=dataQueue.size())>0) {
pthread_mutex_unlock(&mp);
//cout << "thread mutex unlock line 6543" << endl;
//queuesize=dataQueue.size();
//queuesize=dataQueue.size();
/** Pop data queue */
myData=dataQueue.front(); // get the data from the queue
if (myData) {
progressIndex++;
#ifdef VERBOSE
@ -1548,11 +1629,9 @@ void* slsDetectorUtils::processData(int delflag) {
/** write raw data file */
if (*correctionMask==0 && delflag==1) {
//cout << "line 6570----" << endl;
writeDataFile (fname+string(".raw"), getTotalNumberOfChannels(),fdata, NULL, NULL, 'i');
delete [] fdata;
} else {
//cout << "line 6574----" << endl;
writeDataFile (fname+string(".raw"), getTotalNumberOfChannels(),fdata, NULL, NULL, 'i');
/** rate correction */
@ -1586,10 +1665,6 @@ void* slsDetectorUtils::processData(int delflag) {
if (currentPositionIndex<=1) {
if (*binSize>0)
bs=*binSize;
//else // if (angOff[0].r_conversion>0) {
// bs=180./PI*atan(angOff[0].r_conversion);
// *binSize=bs;
// }
else
*binSize=bs;
@ -1608,7 +1683,6 @@ void* slsDetectorUtils::processData(int delflag) {
ang=convertAngles(currentPosition);
if (*correctionMask!=0) {
//cout << "line 6633----" << endl;
if (*numberOfPositions>1)
writeDataFile (fname+string(".dat"), getTotalNumberOfChannels(), ffcdata, ffcerr,ang);
}
@ -1620,7 +1694,6 @@ void* slsDetectorUtils::processData(int delflag) {
currentPositionIndex++;
fname=createFileName();
if (*correctionMask!=0) {
// cout << "line 6643----" << endl;
writeDataFile (fname+string(".dat"),np,mergingCounts, mergingErrors, mergingBins,'f');
}
if (delflag) {
@ -1629,14 +1702,7 @@ void* slsDetectorUtils::processData(int delflag) {
delete [] mergingErrors;
delete [] mergingMultiplicity;
} else {
thisData=new detectorData(mergingCounts,mergingErrors,mergingBins,getCurrentProgress(),(fname+string(ext)).c_str(),np);/*
if (thisDetector->*correctionMask!=0) {
//thisData=new detectorData(mergingCounts,mergingErrors,mergingBins,thisDetector->progressIndex+1,(fname().append(".dat")).c_str(),np);
thisData=new detectorData(mergingCounts,mergingErrors,mergingBins,getCurrentProgress(),(fname().append(".dat")).c_str(),np);
} else {
thisData=new detectorData(mergingCounts,mergingErrors,mergingBins,getCurrentProgress(),(fname().append(".raw")).c_str(),np);
//thisData=new detectorData(mergingCounts,mergingErrors,mergingBins,thisDetector->progressIndex+1,(fname().append(".raw")).c_str(),np);
}*/
thisData=new detectorData(mergingCounts,mergingErrors,mergingBins,getCurrentProgress(),(fname+string(ext)).c_str(),np);
finalDataQueue.push(thisData);
}
}
@ -1649,7 +1715,6 @@ void* slsDetectorUtils::processData(int delflag) {
delete [] ang;
} else {
if (*correctionMask!=0) {
// cout << "line 6672----" << endl;
writeDataFile (fname+string(".dat"), getTotalNumberOfChannels(), ffcdata, ffcerr);
}
if (delflag) {
@ -1661,60 +1726,35 @@ void* slsDetectorUtils::processData(int delflag) {
delete [] ang;
} else {
thisData=new detectorData(ffcdata,ffcerr,NULL,getCurrentProgress(),(fname+string(ext)).c_str(),getTotalNumberOfChannels());
/*
if (thisDetector->*correctionMask!=0) {
thisData=new detectorData(ffcdata,ffcerr,NULL,getCurrentProgress(),(fname().append(".dat")).c_str(),thisDetector->nChans*thisDetector->nChips*thisDetector->nMods);
//thisData=new detectorData(ffcdata,ffcerr,NULL,thisDetector->progressIndex+1,(fname().append(".dat")).c_str(),thisDetector->nChans*thisDetector->nChips*thisDetector->nMods);
} else {
thisData=new detectorData(ffcdata,ffcerr,NULL,getCurrentProgress(),(fname().append(".raw")).c_str(),thisDetector->nChans*thisDetector->nChips*thisDetector->nMods);
//thisData=new detectorData(ffcdata,ffcerr,NULL,thisDetector->progressIndex+1,(fname().append(".raw")).c_str(),thisDetector->nChans*thisDetector->nChips*thisDetector->nMods);
}
*/
finalDataQueue.push(thisData);
}
}
}
*fileIndex++;
/*
thisDetector->progressIndex++;
(*fileIndex)++;
#ifdef VERBOSE
cout << "Progress is " << getCurrentProgress() << " \%" << endl;
cout << "Incrementing file index " << *fileIndex << endl;
#endif
*/
delete [] myData;
myData=NULL;
dataQueue.pop(); //remove the data from the queue
//cout << "thread mutex lock line 6697" << endl;
pthread_mutex_lock(&mp);
queuesize=dataQueue.size();
pthread_mutex_unlock(&mp);
//cout << "thread mutex unlock line 6697" << endl;
usleep(1000);
//pthread_mutex_unlock(&mp);
}
pthread_mutex_unlock(&mp);
//cout << "thread mutex unlock line 6706" << endl;
usleep(1000);
// cout << "PPPPPPPPPPPPPPPPPPPP " << queuesize << " " << thisDetector->fileIndex << endl;
}
pthread_mutex_unlock(&mp);
//cout << "thread mutex unlock line 6711" << endl;
//cout << "thread mutex lock line 6711" << endl;
pthread_mutex_lock(&mp);
if (jointhread) {
pthread_mutex_unlock(&mp);
//cout << "thread mutex unlock line 6715" << endl;
if (dataQueue.size()==0)
break;
} else
pthread_mutex_unlock(&mp);
//cout << "thread mutex unlock line 6720" << endl;
dum=0;
} // ????????????????????????
@ -2335,7 +2375,9 @@ int slsDetectorUtils::setTotalProgress() {
float slsDetectorUtils::getCurrentProgress() {
#ifdef VERBOSE
cout << progressIndex << " / " << totalProgress << endl;
#endif
return 100.*((float)progressIndex)/((float)totalProgress);
}

View File

@ -25,6 +25,7 @@ using namespace std;
#include "sls_detector_defs.h"
#include "slsDetectorCommand.h"
//#include "slsDetectorBase.h"
#define MAX_TIMERS 10
#define MAX_ROIS 100
@ -86,7 +87,7 @@ class slsDetectorUtils : public slsDetectorCommand {
slsDetectorUtils();
virtual ~slsDetectorUtils(){};
virtual ~slsDetectorUtils(){};
@ -286,26 +287,22 @@ class slsDetectorUtils : public slsDetectorCommand {
reads an angular conversion file
\param fname file to be read
\sa angleConversionConstant mythenDetector::readAngularConversion
*/
static int readAngularConversion(string fname, int nmod, angleConversionConstant *angOff);
static int readAngularConversion(string fname, int nmod, angleConversionConstant *angOff);
/**
reads an angular conversion file
\param fname file to be read
\sa angleConversionConstant mythenDetector::readAngularConversion
*/
static int readAngularConversion(ifstream& ifs, int nmod, angleConversionConstant *angOff);
/**
Pure virtual function
writes an angular conversion file
\param fname file to be written
\sa angleConversionConstant mythenDetector::writeAngularConversion
*/
static int writeAngularConversion(string fname, int nmod, angleConversionConstant *angOff);
/**
Pure virtual function
writes an angular conversion file
\param fname file to be written
\sa angleConversionConstant mythenDetector::writeAngularConversion
@ -319,6 +316,8 @@ class slsDetectorUtils : public slsDetectorCommand {
\returns 0 if bad channel disabled, >0 otherwise
*/
static int setBadChannelCorrection(string fname, int &nbad, int *badlist);
/**
flat field correct data
\param datain data
@ -330,6 +329,7 @@ class slsDetectorUtils : public slsDetectorCommand {
\returns 0
*/
static int flatFieldCorrect(float datain, float errin, float &dataout, float &errout, float ffcoefficient, float fferr);
/**
rate correct data
\param datain data
@ -416,19 +416,16 @@ class slsDetectorUtils : public slsDetectorCommand {
/**
sets the default output files path
\sa sharedSlsDetector
*/
char* setFilePath(string s) {sprintf(filePath, s.c_str()); return filePath;};
/**
sets the default output files root name
\sa sharedSlsDetector
*/
char* setFileName(string s) {sprintf(fileName, s.c_str()); return fileName;};
/**
sets the default output file index
\sa sharedSlsDetector
*/
int setFileIndex(int i) {*fileIndex=i; return *fileIndex;};
@ -440,13 +437,11 @@ class slsDetectorUtils : public slsDetectorCommand {
/**
returns the default output files root name
\sa sharedSlsDetector
*/
char* getFileName() {return fileName;};
/**
returns the default output file index
\sa sharedSlsDetector
*/
int getFileIndex() {return *fileIndex;};
@ -454,20 +449,17 @@ class slsDetectorUtils : public slsDetectorCommand {
/**
pure virtual function
set positions for the acquisition
\param nPos number of positions
\param pos array with the encoder positions
\returns number of positions
\sa mythenDetector::setPositions
*/
int setPositions(int nPos, float *pos);
/**
pure virtual function
get positions for the acquisition
\param pos array which will contain the encoder positions
\returns number of positions
\sa mythenDetector::getPositions
*/
int getPositions(float *pos=NULL);
@ -589,32 +581,44 @@ s
/**
/**
pure virtual function
set detector global offset
\sa mythenDetector::setGlobalOffset
*/
float setGlobalOffset(float f){*globalOffset=f; return *globalOffset;};
float setGlobalOffset(float f){return setAngularConversionParameter(GLOBAL_OFFSET,f);};
/**
/**
pure virtual function
set detector fine offset
\sa mythenDetector::setFineOffset
*/
float setFineOffset(float f){*fineOffset=f; return *fineOffset;};
/**
float setFineOffset(float f){return setAngularConversionParameter(FINE_OFFSET,f);};
/**
pure virtual function
get detector fine offset
\sa mythenDetector::getFineOffset
*/
float getFineOffset(){return *fineOffset;};
float getFineOffset(){return getAngularConversionParameter(FINE_OFFSET);};
/**
/**
pure virtual function
get detector global offset
\sa mythenDetector::getGlobalOffset
*/
float getGlobalOffset(){return *globalOffset;};
float getGlobalOffset(){return getAngularConversionParameter(GLOBAL_OFFSET);};
@ -624,13 +628,32 @@ s
\returns current bin size
\sa mythenDetector::setBinSize
*/
float setBinSize(float bs){*binSize=bs; return *binSize;};
float setBinSize(float bs){return setAngularConversionParameter(BIN_SIZE,bs);};
/** pure virtual function
return detector bin size used for merging (approx angular resolution)
\sa mythenDetector::getBinSize
*/
float getBinSize() {return *binSize;};
float getBinSize() {return getAngularConversionParameter(BIN_SIZE);};
/**
sets the value of s angular conversion parameter
\param c can be ANGULAR_DIRECTION, GLOBAL_OFFSET, FINE_OFFSET, BIN_SIZE
\param v the value to be set
\returns the actual value
*/
float setAngularConversionParameter(angleConversionParameter c, float v);
/**
returns the value of an angular conversion parameter
\param c can be ANGULAR_DIRECTION, GLOBAL_OFFSET, FINE_OFFSET, BIN_SIZE
\returns the actual value
*/
float getAngularConversionParameter(angleConversionParameter c);
@ -657,8 +680,9 @@ s
/**
set flat field corrections file directory
\param flat field correction file directory
\returns flat field correction file directory
*/
void setFlatFieldCorrectionDir(string dir){strcpy(flatFieldDir,dir.c_str());};
char *setFlatFieldCorrectionDir(string dir){strcpy(flatFieldDir,dir.c_str()); return flatFieldDir;};
/**
get flat field corrections file name
@ -677,9 +701,24 @@ s
/** performs a complete acquisition including scansand data processing
moves the detector to next position <br>
starts and reads the detector <br>
reads the IC (if required) <br>
reads the encoder (iof required for angualr conversion) <br>
processes the data (flat field, rate, angular conversion and merging ::processData())
\param delflag 0 leaves the data in the final data queue
\returns nothing
*/
void acquire(int delflag);
// must change to total number of channels!
/** processes the data
\param delflag 0 leaves the data in the final data queue
\returns nothing
*/
void *processData(int delflag);
virtual float* convertAngles(float pos)=0;
@ -690,7 +729,9 @@ s
virtual float getRateCorrectionTau()=0;
virtual int* startAndReadAll()=0;
virtual float* decodeData(int *datain)=0;
virtual int rateCorrect(float*, float*, float*, float*)=0;
virtual int flatFieldCorrect(float*, float*, float*, float*)=0;
virtual int getTotalNumberOfChannels()=0;
@ -909,12 +950,12 @@ s
pthread_t dataProcessingThread;
/**
get bad channels correction
\param bad pointer to array that if bad!=NULL will be filled with the bad channel list
\returns 0 if bad channel disabled or no bad channels, >0 otherwise
*/
virtual int getBadChannelCorrection(int *bad=NULL)=0;
/* /\** */
/* get bad channels correction */
/* \param bad pointer to array that if bad!=NULL will be filled with the bad channel list */
/* \returns 0 if bad channel disabled or no bad channels, >0 otherwise */
/* *\/ */
/* virtual int getBadChannelCorrection(int *bad=NULL)=0; */