server locking flag (not real lock), last client vs this client, change port implemented, most funcs of the multidetector implemented again

git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@64 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
bergamaschi
2011-11-25 15:33:25 +00:00
parent f1654363e0
commit 4cbd9b2265
14 changed files with 1958 additions and 1388 deletions

View File

@ -1,12 +1,12 @@
CFLAGS= -DC_ONLY
FLAGS=
#-DVERBOSE
INCLUDES= -I commonFiles -I slsDetector -I MySocketTCP -I eigerDetector -ImythenDetector -IgotthardDetector -I usersFunctions
INCLUDES= -I commonFiles -I slsDetector -I MySocketTCP -I eigerDetector -ImythenDetector -IgotthardDetector -I usersFunctions -I multiSlsDetector
#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 mythenDetector/mythenDetector.cpp eigerDetector/eigerDetector.cpp gotthardDetector/gotthardDetector.cpp
SRC_CLNT= slsDetector/slsDetector.cpp MySocketTCP/MySocketTCP.cxx usersFunctions/usersFunctions.c mythenDetector/mythenDetector.cpp eigerDetector/eigerDetector.cpp gotthardDetector/gotthardDetector.cpp multiSlsDetector/multiSlsDetector.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
@ -19,7 +19,7 @@ doc: $(SRC_H) $(SRC_CLNT)
mythenServer: $(SRC_MYTHEN_SVC)
$(CC) $(SRC_MYTHEN_SVC) $(CFLAGS) $(FLAGS) $(INCLUDES) -ImythenDetectorServer -DVIRTUAL -lm -D MCB_FUNCS -DC_ONLY
$(CC) $(SRC_MYTHEN_SVC) $(CFLAGS) $(FLAGS) $(INCLUDES) -ImythenDetectorServer -DVIRTUAL -lm -D MCB_FUNCS -DC_ONLY -DVERBOSE
mv a.out mythenServer
@ -37,7 +37,8 @@ package: $(SRC_CLNT)
$(CXX) -fPIC -g -o objs/gotthardDetector.o -c -Wall gotthardDetector/gotthardDetector.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) -shared -Wl,-soname,libSlsDetector.so.1 -o libSlsDetector.so.1.0.1 objs/slsDetector.o objs/mythenDetector.o objs/gotthardDetector.o objs/usersFunctions.o objs/MySocketTCP.o -lc $(INCLUDES) $(FLAGS) $(EPICSFLAGS)
$(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/mythenDetector.o objs/gotthardDetector.o objs/usersFunctions.o objs/MySocketTCP.o objs/multiSDetector.o -lc $(INCLUDES) $(FLAGS) $(EPICSFLAGS)
ln -sf libSlsDetector.so.1.0.1 libSlsDetector.so
ln -sf libSlsDetector.so.1 libSlsDetector.so
ar rcs libSlsDetector.a objs/slsDetector.o objs/mythenDetector.o objs/gotthardDetector.o objs/usersFunctions.o objs/MySocketTCP.o

View File

@ -10,11 +10,13 @@
//int socketDescriptor, file_des;
int socketDescriptor, file_des;
const int send_rec_max_size=SEND_REC_MAX_SIZE;
extern int errno;
//struct sockaddr_in address;
//#define VERBOSE
@ -23,7 +25,8 @@ int bindSocket(unsigned short int port_number) {
int i;
struct sockaddr_in addressS;
int socketDescriptor;
int file_des;
file_des= -1;
socketDescriptor = socket(AF_INET, SOCK_STREAM,0); //tcp
@ -68,7 +71,7 @@ int bindSocket(unsigned short int port_number) {
printf(" %s %s\n",lastClientIP, thisClientIP);
return socketDescriptor;
@ -76,54 +79,20 @@ int bindSocket(unsigned short int port_number) {
}
/*
only client funcs
*/
/*
#ifndef C_ONLY
MySocketTCP::MySocketTCP(const char* const host_ip_or_name, unsigned short int const port_number):
last_keep_connection_open_action_was_a_send(0), file_des(-1), send_rec_max_size(SEND_REC_MAX_SIZE), is_a_server(0), portno(DEFAULT_PORTNO), socketDescriptor(-1)
{ // sender (client): where to? ip
//is_a_server = 0;
// SetupParameters();
strcpy(hostname,host_ip_or_name);
portno=port_number;
struct hostent *hostInfo = gethostbyname(host_ip_or_name);
if (hostInfo == NULL){
cerr << "Exiting: Problem interpreting host: " << host_ip_or_name << "\n";
} else {
// Set some fields in the serverAddress structure.
serverAddress.sin_family = hostInfo->h_addrtype;
memcpy((char *) &serverAddress.sin_addr.s_addr,
hostInfo->h_addr_list[0], hostInfo->h_length);
serverAddress.sin_port = htons(port_number);
socketDescriptor=0; //You can use send and recv, //would it work?????
}
}
int MySocketTCP::getHostname(char *name) {
if (is_a_server==0) {
strcpy(name,hostname);
}
return is_a_server;
};
#endif
*/
int getServerError()
int getServerError(int socketDescriptor)
{
if (socketDescriptor<0) return 1;
else return 0;
};
int acceptConnection() {
int acceptConnection(int socketDescriptor) {
struct sockaddr_in addressC;
int file_des;
//socklen_t address_length;
size_t address_length=sizeof(struct sockaddr_in);
@ -193,9 +162,24 @@ int acceptConnection() {
socketDescriptor=-1;
}
inet_ntop(AF_INET, &(addressC.sin_addr), thisClientIP, INET_ADDRSTRLEN);
#ifdef VERBOSE
printf("client connected %d\n", file_des);
printf("client connected %d\n", file_des);
printf("addressC %s\n", thisClientIP);
printf("addressC %s\n", lastClientIP);
#endif
// 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 */
//};
}
@ -208,7 +192,7 @@ int acceptConnection() {
void closeConnection() {
void closeConnection(int file_des) {
//fflush(stdout);
//printf("Closing file_des %d\n", file_des);
//sleep(1);
@ -216,10 +200,13 @@ void closeConnection() {
#endif
if(file_des>=0)
close(file_des);
if (lockStatus==0) {
strcpy(lastClientIP,thisClientIP);
}
file_des=-1;
}
void exitServer() {
void exitServer(int socketDescriptor) {
if (socketDescriptor>=0)
close(socketDescriptor);
#ifdef VERY_VERBOSE
@ -252,7 +239,7 @@ void MySocketTCP::Disconnect(){
*/
int sendDataOnly(void* buf,int length) {
int sendDataOnly(int file_des, void* buf,int length) {
/*
int total_sent=0;
int nsending;
@ -279,7 +266,7 @@ int sendDataOnly(void* buf,int length) {
}
int receiveDataOnly(void* buf,int length) {
int receiveDataOnly(int file_des, void* buf,int length) {
int total_received=0;
int nreceiving;
@ -327,44 +314,44 @@ int sendDataOnly(void* buf,int length) {
int sendChannel(sls_detector_channel *myChan) {
return sendDataOnly(myChan, sizeof(sls_detector_channel));
int sendChannel(int file_des, sls_detector_channel *myChan) {
return sendDataOnly(file_des,myChan, sizeof(sls_detector_channel));
}
int sendChip(sls_detector_chip *myChip) {
int sendChip(int file_des, sls_detector_chip *myChip) {
int ts=0;
int nChans=myChip->nchan;
ts+=sendDataOnly(myChip,sizeof(sls_detector_chip));
ts+=sendDataOnly(myChip->chanregs,nChans*sizeof(int));
ts+=sendDataOnly(file_des,myChip,sizeof(sls_detector_chip));
ts+=sendDataOnly(file_des,myChip->chanregs,nChans*sizeof(int));
return ts;
}
int sendModule(sls_detector_module *myMod) {
int sendModule(int file_des, sls_detector_module *myMod) {
int ts=0;
int idac;
int nChips=myMod->nchip;
int nChans=myMod->nchan;
int nAdcs=myMod->nadc;
int nDacs=myMod->ndac;
ts+= sendDataOnly(myMod,sizeof(sls_detector_module));
ts+= sendDataOnly(file_des,myMod,sizeof(sls_detector_module));
#ifdef VERBOSE
printf("module %d of size %d sent\n",myMod->module, ts);
#endif
ts+= sendDataOnly(myMod->dacs,sizeof(float)*nDacs);
ts+= sendDataOnly(file_des,myMod->dacs,sizeof(float)*nDacs);
#ifdef VERBOSE
printf("dacs %d of size %d sent\n",myMod->module, ts);
for (idac=0; idac< nDacs; idac++)
printf("dac %d is %d\n",idac,myMod->dacs[idac]);
#endif
ts+= sendDataOnly(myMod->adcs,sizeof(float)*nAdcs);
ts+= sendDataOnly(file_des,myMod->adcs,sizeof(float)*nAdcs);
#ifdef VERBOSE
printf("adcs %d of size %d sent\n",myMod->module, ts);
#endif
ts+=sendDataOnly(myMod->chipregs,sizeof(int)*nChips);
ts+=sendDataOnly(file_des,myMod->chipregs,sizeof(int)*nChips);
#ifdef VERBOSE
printf("chips %d of size %d sent\n",myMod->module, ts);
#endif
ts+=sendDataOnly(myMod->chanregs,sizeof(int)*nChans);
ts+=sendDataOnly(file_des,myMod->chanregs,sizeof(int)*nChans);
#ifdef VERBOSE
printf("chans %d of size %d sent - %d\n",myMod->module, ts, myMod->nchan);
#endif
@ -374,17 +361,17 @@ int sendModule(sls_detector_module *myMod) {
return ts;
}
int receiveChannel(sls_detector_channel *myChan) {
return receiveDataOnly(myChan,sizeof(sls_detector_channel));
int receiveChannel(int file_des, sls_detector_channel *myChan) {
return receiveDataOnly(file_des,myChan,sizeof(sls_detector_channel));
}
int receiveChip(sls_detector_chip* myChip) {
int receiveChip(int file_des, sls_detector_chip* myChip) {
int *ptr=myChip->chanregs;
int ts=0;
int nChans, nchanold=myChip->nchan, chdiff;
ts+= receiveDataOnly(myChip,sizeof(sls_detector_chip));
ts+= receiveDataOnly(file_des,myChip,sizeof(sls_detector_chip));
myChip->chanregs=ptr;
@ -401,12 +388,12 @@ int receiveChip(sls_detector_chip* myChip) {
#endif
if (chdiff<=0)
ts+=receiveDataOnly(myChip->chanregs, sizeof(int)*nChans);
ts+=receiveDataOnly(file_des,myChip->chanregs, sizeof(int)*nChans);
else {
ptr=malloc(chdiff*sizeof(int));
myChip->nchan=nchanold;
ts+=receiveDataOnly(myChip->chanregs, sizeof(int)*nchanold);
ts+=receiveDataOnly(ptr, sizeof(int)*chdiff);
ts+=receiveDataOnly(file_des,myChip->chanregs, sizeof(int)*nchanold);
ts+=receiveDataOnly(file_des,ptr, sizeof(int)*chdiff);
free(ptr);
return FAIL;
}
@ -417,7 +404,7 @@ int receiveChip(sls_detector_chip* myChip) {
return ts;
}
int receiveModule(sls_detector_module* myMod) {
int receiveModule(int file_des, sls_detector_module* myMod) {
float *dacptr=myMod->dacs;
@ -430,7 +417,7 @@ int receiveModule(sls_detector_module* myMod) {
int nAdcs, naold=myMod->nadc, nadcdiff;
ts+= receiveDataOnly(myMod,sizeof(sls_detector_module));
ts+= receiveDataOnly(file_des,myMod,sizeof(sls_detector_module));
myMod->dacs=dacptr;
myMod->adcs=adcptr;
@ -478,57 +465,57 @@ int receiveModule(sls_detector_module* myMod) {
printf("received %d adcs\n",nAdcs);
#endif
if (ndacdiff<=0) {
ts+=receiveDataOnly(myMod->dacs, sizeof(float)*nDacs);
ts+=receiveDataOnly(file_des,myMod->dacs, sizeof(float)*nDacs);
#ifdef VERBOSE
printf("dacs received\n");
#endif
} else {
dacptr=malloc(ndacdiff*sizeof(float));
myMod->ndac=ndold;
ts+=receiveDataOnly(myMod->dacs, sizeof(float)*ndold);
ts+=receiveDataOnly(dacptr, sizeof(float)*ndacdiff);
ts+=receiveDataOnly(file_des,myMod->dacs, sizeof(float)*ndold);
ts+=receiveDataOnly(file_des,dacptr, sizeof(float)*ndacdiff);
free(dacptr);
return FAIL;
}
if (nadcdiff<=0) {
ts+=receiveDataOnly(myMod->adcs, sizeof(float)*nAdcs);
ts+=receiveDataOnly(file_des,myMod->adcs, sizeof(float)*nAdcs);
#ifdef VERBOSE
printf("adcs received\n");
#endif
} else {
adcptr=malloc(nadcdiff*sizeof(float));
myMod->nadc=naold;
ts+=receiveDataOnly(myMod->adcs, sizeof(float)*naold);
ts+=receiveDataOnly(adcptr, sizeof(float)*nadcdiff);
ts+=receiveDataOnly(file_des,myMod->adcs, sizeof(float)*naold);
ts+=receiveDataOnly(file_des,adcptr, sizeof(float)*nadcdiff);
free(adcptr);
return FAIL;
}
if (nchipdiff<=0) {
ts+=receiveDataOnly(myMod->chipregs, sizeof(int)*nChips);
ts+=receiveDataOnly(file_des,myMod->chipregs, sizeof(int)*nChips);
#ifdef VERBOSE
printf("chips received\n");
#endif
} else {
chipptr=malloc(nchipdiff*sizeof(int));
myMod->nchip=nchipold;
ts+=receiveDataOnly(myMod->chipregs, sizeof(int)*nchipold);
ts+=receiveDataOnly(chipptr, sizeof(int)*nchipdiff);
ts+=receiveDataOnly(file_des,myMod->chipregs, sizeof(int)*nchipold);
ts+=receiveDataOnly(file_des,chipptr, sizeof(int)*nchipdiff);
free(chipptr);
return FAIL;
}
if (nchandiff<=0) {
ts+=receiveDataOnly(myMod->chanregs, sizeof(int)*nChans);
ts+=receiveDataOnly(file_des,myMod->chanregs, sizeof(int)*nChans);
#ifdef VERBOSE
printf("chans received\n");
#endif
} else {
chanptr=malloc(nchandiff*sizeof(int));
myMod->nchan=nchanold;
ts+=receiveDataOnly(myMod->chanregs, sizeof(int)*nchanold);
ts+=receiveDataOnly(chanptr, sizeof(int)*nchandiff);
ts+=receiveDataOnly(file_des,myMod->chanregs, sizeof(int)*nchanold);
ts+=receiveDataOnly(file_des,chanptr, sizeof(int)*nchandiff);
free(chanptr);
return FAIL;
}

View File

@ -14,19 +14,23 @@
#include "sls_detector_defs.h"
int bindSocket(unsigned short int port_number);
int acceptConnection();
void closeConnection();
void exitServer();
int sendDataOnly(void* buf,int length);
int receiveDataOnly(void* buf,int length);
char lastClientIP[INET_ADDRSTRLEN];
char thisClientIP[INET_ADDRSTRLEN];
int lockStatus;
int getServerError();
int sendChannel(sls_detector_channel *myChan);
int sendChip(sls_detector_chip *myChip);
int sendModule(sls_detector_module *myMod);
int receiveChannel(sls_detector_channel *myChan);
int receiveChip(sls_detector_chip* myChip);
int receiveModule(sls_detector_module* myMod);
int bindSocket(unsigned short int port_number);
int acceptConnection(int socketDescriptor);
void closeConnection(int file_Des);
void exitServer(int socketDescriptor);
int sendDataOnly(int file_des, void* buf,int length);
int receiveDataOnly(int file_des, void* buf,int length);
int getServerError(int socketDescriptor);
int sendChannel(int file_des, sls_detector_channel *myChan);
int sendChip(int file_des, sls_detector_chip *myChip);
int sendModule(int file_des, sls_detector_module *myMod);
int receiveChannel(int file_des, sls_detector_channel *myChan);
int receiveChip(int file_des, sls_detector_chip* myChip);
int receiveModule(int file_des, sls_detector_module* myMod);
#endif

View File

@ -383,6 +383,12 @@ enum correctionFlags {
I0_NORMALIZATION
};
enum portType {
CONTROL_PORT, /**< control port */
STOP_PORT, /**<stop port */
DATA_PORT /**< data port */
};
/**
function indexes to call on the server
@ -466,9 +472,11 @@ enum {
F_EXIT_SERVER, /**< turn off detector server */
F_GET_TEMPERATURE,
F_SET_GOTTHARD,
F_GET_GOTTHARD
F_LOCK_SERVER, /**< Locks/Unlocks server communication to the given client */
F_GET_LAST_CLIENT_IP, /**< returns the IP of the client last connected to the detector */
F_SET_PORT /**< Changes communication port of the server */
/* Always append functions hereafter!!! */

File diff suppressed because it is too large Load Diff

View File

@ -15,11 +15,24 @@ ID: $Id$
#include "slsDetector.h"
#include "sls_detector_defs.h"
#define MAXDET 100
//using namespace std;
/** 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 */
};
/**
@ -38,8 +51,18 @@ class multiSlsDetector {
typedef struct sharedMultiSlsDetector {
/** already existing flag. If the detector does not yet exist (alreadyExisting=0) the sharedMemory will be created, otherwise it will simly be linked */
int alreadyExisting;
/** last process id accessing the shared memory */
pid_t lastPID;
/** online flag - is set if the detector is connected, unset if socket connection is not possible */
int onlineFlag;
@ -54,7 +77,13 @@ class multiSlsDetector {
/** Ids of the detectors to be operated at once */
int detectorIds[MAXDET];
/** id of the master detector */
/** Detectors offset in the X direction (in number of channels)*/
int offsetX[MAXDET];
/** Detectors offsets in the Y direction (in number of channels) */
int offsetY[MAXDET];
/** position of the master detector */
int masterPosition;
/** type of synchronization between detectors */
@ -63,15 +92,27 @@ class multiSlsDetector {
/** size of the data that are transfered from all detectors */
int dataBytes;
/** total number of channels for all detectors */
int numberOfChannels;
/** timer values */
int64_t timerValue[MAX_TIMERS];
/** detector settings (standard, fast, etc.) */
detectorSettings currentSettings;
/** detector threshold (eV) */
int currentThresholdEV;
/** indicator for the acquisition progress - set to 0 at the beginning of the acquisition and incremented every time that the data are written to file */
int progressIndex;
/** total number of frames to be acquired */
int totalProgress;
/** current index of the output file */
/** current index of the output file */
int fileIndex;
/** path of the output files */
char filePath[MAX_STR_LENGTH];
@ -85,21 +126,33 @@ class multiSlsDetector {
int threadedProcessing;
/** dead time (in ns) for rate corrections */
float tDead;
/** directory where the flat field files are stored */
char flatFieldDir[MAX_STR_LENGTH];
/** file used for flat field corrections */
char flatFieldFile[MAX_STR_LENGTH];
/** number of bad channels from bad channel list */
int nBadChans;
/** file with the bad channels */
char badChanFile[MAX_STR_LENGTH];
/** list of bad channels */
int badChansList[MAX_BADCHANS];
/** number of bad channels from flat field i.e. channels which read 0 in the flat field file */
int nBadFF;
/** list of bad channels from flat field i.e. channels which read 0 in the flat field file */
int badFFList[MAX_BADCHANS];
/** array of angular conversion constants for each module \see ::angleConversionConstant */
angleConversionConstant angOff[MAXMODS];
/** angular direction (1 if it corresponds to the encoder direction i.e. channel 0 is 0, maxchan is positive high angle, 0 otherwise */
int angDirection;
/** beamline fine offset (of the order of mdeg, might be adjusted for each measurements) */
float fineOffset;
/** beamline offset (might be a few degrees beacuse of encoder offset - normally it is kept fixed for a long period of time) */
float globalOffset;
/** number of positions at which the detector should acquire */
int numberOfPositions;
/** list of encoder positions at which the detector should acquire */
float detPositions[MAXPOS];
/** bin size for data merging */
float binSize;
/** Scans and scripts */
@ -119,7 +172,7 @@ class multiSlsDetector {
}
};
@ -137,8 +190,8 @@ class multiSlsDetector {
public:
/**
@short Structure allocated in shared memory to store detector settings and be accessed in parallel by several applications (take care of possible conflicts!)
@ -160,13 +213,13 @@ class multiSlsDetector {
int freeSharedMemory() ;
/** allocates the shared memory occpied for the sharedMultiSlsDetector structure */
int initSharedMemory() ;
int initSharedMemory(int) ;
/** 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)
\return the actual number of detectors*/
int addSlsDetector(int id, int pos=-1);
int addSlsDetector(int id, int pos=-1, int oX=-1, int oY=-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)
@ -184,6 +237,25 @@ class multiSlsDetector {
\returns number of detectors */
int getNumberOfDetectors() {return thisMultiDetector->numberOfDetectors;};
/** returns the detector offset (in number of channels)
\param pos position of the detector
\param ox reference to the offset in x
\param oy reference to the offset in y
\returns OK/FAIL if the detector does not exist
*/
int getDetectorOffset(int pos, int &ox, int &oy);
/** sets the detector offset (in number of channels)
\param pos position of the detector
\param ox offset in x (-1 does not change)
\param oy offset in y (-1 does not change)
\returns OK/FAIL if the detector does not exist
*/
int setDetectorOffset(int pos, int ox=-1, int oy=-1);
/** sets the detector in position i as master of the structure (e.g. it gates the other detectors and therefore must be started as last. <BR> Assumes that signal 0 is gate in, signal 1 is trigger in, signal 2 is gate out
\param i position of master (-1 gets)
\return master's position (-1 none)
@ -195,17 +267,7 @@ class multiSlsDetector {
\param sync syncronization mode
\returns current syncronization mode
*/
synchronizationMode setSyncronization(synchronizationMode sync=GET_SYNHRONIZATION_MODE);
/** synchronization of the various detectors (should be set for each detector individually?!?!?) */
enum synchronyzationMode {
GET_SYNHRONIZATION_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 */
}
synchronizationMode setSynchronization(synchronizationMode sync=GET_SYNCHRONIZATION_MODE);
@ -214,7 +276,7 @@ class multiSlsDetector {
\param off can be: GET_ONLINE_FLAG, returns wether the detector is in online or offline state; OFFLINE_FLAG, detector in offline state (i.e. no communication to the detector - using only local structure - no data acquisition possible!); ONLINE_FLAG detector in online state (i.e. communication to the detector updating the local structure)
\returns online/offline status
*/
int setOnline(int const online=GET_ONLINE_FLAG);
int setOnline(int const online=slsDetector::GET_ONLINE_FLAG);
/** sets the onlineFlag
\returns 1 if the detector structure has already be initlialized with the given idand belongs to this multiDetector instance, 0 otherwise */
int exists() ;
@ -274,7 +336,7 @@ class multiSlsDetector {
\sa slsDetector::getFileIndexFromFileName
*/
int multiSlsDetector::getFileIndexFromFileName(string fname) ;
int getFileIndexFromFileName(string fname) ;
/**
@ -288,7 +350,7 @@ class multiSlsDetector {
\sa slsDetector::getVariablesFromFileName
*/
int multiSlsDetector::getVariablesFromFileName(string fname, int &index, int &p_index, float &sv0, float &sv1) ;
int getVariablesFromFileName(string fname, int &index, int &p_index, float &sv0, float &sv1) ;
@ -443,14 +505,7 @@ class multiSlsDetector {
// calibration functions
// int setCalibration(int imod, detectorSettings isettings, float gain, float offset);
//int getCalibration(int imod, detectorSettings isettings, float &gain, float &offset);
/*
calibrated setup of the threshold
*/
/**
get threshold energy
\param imod module number (-1 all)
@ -482,7 +537,7 @@ class multiSlsDetector {
in this function trimbits and calibration files are searched in the trimDir and calDir directories and the detector is initialized
*/
virtual detectorSettings setSettings(detectorSettings isettings, int imod=-1);
detectorSettings setSettings(detectorSettings isettings, int imod=-1);
@ -557,7 +612,13 @@ class multiSlsDetector {
\returns pointer to the data or NULL. If NULL disconnects the socket
\sa getDataFromDetector
*/
int* getDataFromDetectorNoWait();
//int* getDataFromDetectorNoWait();
/**
receives a data frame from the detector socket
\returns pointer to the data or NULL. If NULL disconnects the socket
\sa getDataFromDetector
*/
int* getDataFromDetector();
/**
asks and receives a data frame from the detector and puts it in the data queue
@ -619,24 +680,27 @@ class multiSlsDetector {
*/
int64_t setTimer(timerIndex index, int64_t t=-1);
/**
get current timer value
\param index timer index
\returns elapsed time value in ns or number of...(e.g. frames, gates, probes)
*/
int64_t getTimeLeft(timerIndex index);
/* /\** */
/* get current timer value */
/* \param index timer index */
/* \returns elapsed time value in ns or number of...(e.g. frames, gates, probes) */
/* *\/ */
/* int64_t getTimeLeft(timerIndex index); */
// Flags
/**
set/get dynamic range
set/get dynamic range and updates the number of dataBytes
\param n dynamic range (-1 get)
\param pos detector position (-1 all detectors)
\returns current dynamic range
updates the size of the data expected from the detector
\sa sharedSlsDetector
*/
int setDynamicRange(int n=-1);
int setDynamicRange(int n=-1, int pos=-1);
/**
set roi
@ -646,22 +710,6 @@ class multiSlsDetector {
int setROI(int nroi=-1, int *xmin=NULL, int *xmax=NULL, int *ymin=NULL, int *ymax=NULL);
/**
set/get readout flags
\param flag readout flag to be set
\returns current flag
*/
int setReadOutFlags(readOutFlags flag);
/**
execute 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
*/
int executeTrimming(trimMode mode, int par1, int par2, int imod=-1);
//Corrections
@ -673,7 +721,7 @@ s
\returns thread flag
*/
int setThreadedProcessing(int b=-1) {if (b>=0) thisDetector->threadedProcessing=b; return thisDetector->threadedProcessing;}
int setThreadedProcessing(int b=-1) {if (b>=0) thisMultiDetector->threadedProcessing=b; return thisMultiDetector->threadedProcessing;}
/**
set flat field corrections
@ -694,18 +742,18 @@ s
get flat field corrections file directory
\returns flat field correction file directory
*/
char *getFlatFieldCorrectionDir(){return thisDetector->flatFieldDir;};
char *getFlatFieldCorrectionDir(){return thisMultiDetector->flatFieldDir;};
/**
set flat field corrections file directory
\param flat field correction file directory
*/
void setFlatFieldCorrectionDir(string dir){strcpy(thisDetector->flatFieldDir,dir.c_str());};
void setFlatFieldCorrectionDir(string dir){strcpy(thisMultiDetector->flatFieldDir,dir.c_str());};
/**
get flat field corrections file name
\returns flat field correction file name
*/
char *getFlatFieldCorrectionFile(){ if (thisDetector->correctionMask&(1<<FLAT_FIELD_CORRECTION)) return thisDetector->flatFieldFile; else return "none";};
char *getFlatFieldCorrectionFile(){ if (thisMultiDetector->correctionMask&(1<<FLAT_FIELD_CORRECTION)) return thisMultiDetector->flatFieldFile; else return "none";};
/**
set rate correction
@ -749,7 +797,7 @@ s
int getBadChannelCorrection(int *bad=NULL);
/** returns the bad channel list file */
string getBadChannelCorrectionFile() {if (thisDetector->correctionMask&(1<< DISCARD_BAD_CHANNELS)) return string(thisDetector->badChanFile); else return string("none");};
string getBadChannelCorrectionFile() {if (thisMultiDetector->correctionMask&(1<< DISCARD_BAD_CHANNELS)) return string(thisMultiDetector->badChanFile); else return string("none");};
/**
@ -1063,14 +1111,36 @@ s
protected:
/** Shared memory ID */
int shmId;
/** pointers to the slsDetector structures */
slsDetector *detectors[MAXDET];
/** Shared memory structure */
sharedMultiSlsDetector *thisMultiDetector;
/**
data queue
*/
queue<int*> dataQueue;
/**
queue containing the postprocessed data
*/
queue<detectorData*> finalDataQueue;
/**
current position of the detector
*/

View File

@ -679,7 +679,7 @@ int mythenDetector::readDataFile(string fname, float *data, float *err, float *a
if (ang==NULL) {
ssstr >> ichan >> fdata;
ich=ichan;
if (!ssstr.good()) {
if (ssstr.fail() || ssstr.bad()) {
interrupt=1;
break;
}
@ -689,13 +689,13 @@ int mythenDetector::readDataFile(string fname, float *data, float *err, float *a
ssstr >> fang >> fdata;
ich=iline;
}
if (!ssstr.good()) {
if (ssstr.fail() || ssstr.bad()) {
interrupt=1;
break;
}
if (err)
ssstr >> ferr;
if (!ssstr.good()) {
if (ssstr.fail() || ssstr.bad()) {
interrupt=1;
break;
}
@ -707,7 +707,7 @@ int mythenDetector::readDataFile(string fname, float *data, float *err, float *a
if (err)
err[ich]=ferr;
iline++;
} else {
} else {
std::cout<< " too many lines in file: "<< iline << " instead of " << maxchans << std::endl;
interrupt=1;
break;
@ -744,7 +744,7 @@ int mythenDetector::readDataFile(string fname, int *data){
#endif
istringstream ssstr(str);
ssstr >> ichan >> idata;
if (!ssstr.good()) {
if (ssstr.fail() || ssstr.bad()) {
interrupt=1;
break;
}

View File

@ -975,14 +975,13 @@ u_int32_t* fifo_read_event()
#ifdef VERYVERBOSE
printf("Copying to ptr %x %d\n",now_ptr, dataBytes);
#endif
#ifdef VERYVERBOSE
printf("after readout %08x %08x\n", runState(), bus_r(LOOK_AT_ME_REG));
for (ichip=0; ichip<nModBoard*NCHIP; ichip++) {
if ((fifoReadCounter(ichip)&FIFO_COUNTER_MASK)%128)
printf("FIFO %d contains %d words\n",ichip,(fifoReadCounter(ichip)&FIFO_COUNTER_MASK));
}
#endif
if (storeInRAM>0) {
now_ptr+=dataBytes;
}

View File

@ -5,7 +5,7 @@
#include <stdlib.h>
int sockfd;
extern int sockfd;
void error(char *msg)
@ -18,6 +18,8 @@ int main(int argc, char *argv[])
int portno, b;
char cmd[100];
int retval=OK;
int sd, fd;
if (argc==1) {
portno = DEFAULT_PORTNO;
@ -37,8 +39,12 @@ int main(int argc, char *argv[])
init_detector(b);
bindSocket(portno);
if (getServerError()) {
sd=bindSocket(portno);
sockfd=sd;
if (getServerError(sd)) {
printf("server error!\n");
return -1;
}
@ -58,21 +64,21 @@ int main(int argc, char *argv[])
#ifdef VERY_VERBOSE
printf("Waiting for client call\n");
#endif
acceptConnection();
fd=acceptConnection(sockfd);
#ifdef VERY_VERBOSE
printf("Conenction accepted\n");
#endif
retval=decode_function();
#ifdef VERY_VERBOSE
retval=decode_function(fd);
//#ifdef VERY_VERBOSE
printf("function executed\n");
#endif
closeConnection();
//#endif
closeConnection(fd);
#ifdef VERY_VERBOSE
printf("connection closed\n");
#endif
}
exitServer();
exitServer(sockfd);
printf("Goodbye!\n");
return 0;

View File

@ -38,5 +38,5 @@
#define CLK_FREQ 100E+6
#define THIS_SOFTWARE_VERSION 0x20100429
#define THIS_SOFTWARE_VERSION 0x20111125
#endif

File diff suppressed because it is too large Load Diff

View File

@ -12,9 +12,12 @@
#define GOODBYE -200
int sockfd;
int function_table();
int decode_function();
int decode_function(int);
int init_detector(int);
@ -64,7 +67,9 @@ int get_roi(int);
int set_speed(int);
int set_readout_flags(int);
int execute_trimming(int);
int lock_server(int);
int set_port(int);
int get_last_client_ip(int);

View File

@ -37,11 +37,17 @@ int slsDetector::initSharedMemory(detectorType type, int id) {
nc=10;
nd=13; // dacs+adcs
break;
default:
case EIGER:
nch=65535; // one EIGER module
nm=1; //modules/detector
nc=8; //chips
nd=16; //dacs+adcs
default:
nch=0; // one EIGER module
nm=0; //modules/detector
nc=0; //chips
nd=0; //dacs+adcs
}
/**
The size of the shared memory is:
@ -159,7 +165,6 @@ slsDetector::slsDetector(detectorType type, int id):
pthread_mutex_t mp1 = PTHREAD_MUTEX_INITIALIZER;
mp=mp1;
@ -258,6 +263,33 @@ detectorType slsDetector::getDetectorType(char *name, int cport) {
}
// detectorType slsDetector::getDetectorType(int id) {
// detectorType t=GENERIC;
// initSharedMemory(GENERIC, id);
// sharedSlsDetector* det = (sharedSlsDetector*) shmat(shm_id, NULL, 0);
// if (det == (void*)-1) {
// std::cout<<"*** shmat error - detector id not found ***" << std::endl;
// return t;
// }
// return t;
// }
detectorType slsDetector::getDetectorType(int id) {
detectorType t=GENERIC;
@ -351,7 +383,7 @@ int slsDetector::initializeDetectorSize(detectorType type) {
thisDetector->nChips=12;
thisDetector->nDacs=6;
thisDetector->nAdcs=0;
thisDetector->nModMax[X]=24;
thisDetector->nModMax[X]=6;
thisDetector->nModMax[Y]=1;
thisDetector->dynamicRange=24;
break;
@ -497,6 +529,11 @@ int slsDetector::initializeDetectorSize(detectorType type) {
}
/** fill the BadChannelMask \sa fillBadChannelMask */
fillBadChannelMask();
/** modifies the last PID accessing the detector */
thisDetector->lastPID=getpid();
return OK;
}
@ -834,6 +871,46 @@ int slsDetector::setTCPSocket(string const name, int const control_port, int con
};
/** connect to the control port */
int slsDetector::connectControl() {
if (controlSocket)
return controlSocket->Connect();
}
/** disconnect from the control port */
int slsDetector::disconnectControl() {
if (controlSocket)
controlSocket->Disconnect();
return OK;
}
/** connect to the data port */
int slsDetector::connectData() {
if (dataSocket)
return dataSocket->Connect();
};
/** disconnect from the data port */
int slsDetector::disconnectData(){
if (dataSocket)
dataSocket->Disconnect();
return OK;
}
;
/** connect to the stop port */
int slsDetector::connectStop() {
if (stopSocket)
return stopSocket->Connect();
};
/** disconnect from the stop port */
int slsDetector::disconnectStop(){
if (stopSocket)
stopSocket->Disconnect();
return OK;
}
;
@ -2917,6 +2994,36 @@ int* slsDetector::readAll(){
};
int slsDetector::readAllNoWait(){
int fnum= F_READ_ALL;
#ifdef VERBOSE
std::cout<< "Reading all frames "<< std::endl;
#endif
if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (controlSocket) {
if (controlSocket->Connect()>=0) {
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
return OK;
}
}
}
return FAIL;
};
int* slsDetector::startAndReadAll(){
@ -2971,25 +3078,25 @@ int slsDetector::startAndReadAllNoWait(){
return FAIL;
};
int* slsDetector::getDataFromDetectorNoWait() {
int *retval=getDataFromDetector();
if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (controlSocket) {
if (retval==NULL){
controlSocket->Disconnect();
// int* slsDetector::getDataFromDetectorNoWait() {
// int *retval=getDataFromDetector();
// if (thisDetector->onlineFlag==ONLINE_FLAG) {
// if (controlSocket) {
// if (retval==NULL){
// controlSocket->Disconnect();
#ifdef VERBOSE
std::cout<< "Run finished "<< std::endl;
#endif
} else {
#ifdef VERBOSE
std::cout<< "Frame received "<< std::endl;
#endif
}
}
}
return retval; // check what we return!
};
// #ifdef VERBOSE
// std::cout<< "Run finished "<< std::endl;
// #endif
// } else {
// #ifdef VERBOSE
// std::cout<< "Frame received "<< std::endl;
// #endif
// }
// }
// }
// return retval; // check what we return!
// };
@ -3105,6 +3212,195 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t){
};
int slsDetector::lockServer(int lock) {
int fnum=F_LOCK_SERVER;
int retval=-1;
int ret=OK;
char mess[100];
if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (controlSocket) {
if (controlSocket->Connect()>=0) {
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
controlSocket->SendDataOnly(&lock,sizeof(lock));
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
if (ret!=OK) {
controlSocket->ReceiveDataOnly(mess,sizeof(mess));
std::cout<< "Detector returned error: " << mess << std::endl;
} else {
controlSocket->ReceiveDataOnly(&retval,sizeof(retval));
}
controlSocket->Disconnect();
}
}
}
return retval;
}
string slsDetector::getLastClientIP() {
int fnum=F_GET_LAST_CLIENT_IP;
char clientName[INET_ADDRSTRLEN];
char mess[100];
int ret=OK;
if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (controlSocket) {
if (controlSocket->Connect()>=0) {
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
if (ret!=OK) {
controlSocket->ReceiveDataOnly(mess,sizeof(mess));
std::cout<< "Detector returned error: " << mess << std::endl;
} else {
controlSocket->ReceiveDataOnly(clientName,sizeof(clientName));
}
controlSocket->Disconnect();
}
}
}
return string(clientName);
}
int slsDetector::setPort(portType index, int num){
int fnum=F_SET_PORT;
int retval;
uint64_t ut;
char mess[100];
int ret=OK;
int n=0;
MySocketTCP *s;
switch(index) {
case CONTROL_PORT:
s=controlSocket;
retval=thisDetector->controlPort;
break;
case DATA_PORT:
s=dataSocket;
retval=thisDetector->dataPort;
break;
case STOP_PORT:
s=stopSocket;
retval=thisDetector->stopPort;
break;
default:
s=NULL;
}
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));
if (ret!=OK) {
s->ReceiveDataOnly(mess,sizeof(mess));
std::cout<< "Detector returned error: " << mess << std::endl;
} else {
s->ReceiveDataOnly(&retval,sizeof(retval));
}
s->Disconnect();
}
} 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;
}
} 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==OK) {
switch(index) {
case CONTROL_PORT:
thisDetector->controlPort=retval;
break;
case DATA_PORT:
thisDetector->dataPort=retval;
break;
case STOP_PORT:
thisDetector->stopPort=retval;
break;
default:
;
}
}
// setTCPSocket();
return retval;
};
@ -3634,6 +3930,35 @@ int slsDetector::setFlatFieldCorrection(string fname){
}
return thisDetector->correctionMask&(1<<FLAT_FIELD_CORRECTION);
}
int slsDetector::setFlatFieldCorrection(float *corr, float *ecorr) {
if (corr!=NULL) {
for (int ichan=0; ichan<thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChans*thisDetector->nChips; ichan++) {
ffcoefficients[ichan]=corr[ichan];
if (ecorr!=NULL)
fferrors[ichan]=ecorr[ichan];
else
fferrors[ichan]=1;
}
thisDetector->correctionMask|=(1<<FLAT_FIELD_CORRECTION);
} else
thisDetector->correctionMask&=~(1<<FLAT_FIELD_CORRECTION);
return thisDetector->correctionMask&(1<<FLAT_FIELD_CORRECTION);
}
int slsDetector::getFlatFieldCorrection(float *corr, float *ecorr) {
if (thisDetector->correctionMask&(1<<FLAT_FIELD_CORRECTION)) {
@ -3821,9 +4146,24 @@ int slsDetector::rateCorrect(float* datain, float *errin, float* dataout, float
return 0;
};
int slsDetector::setBadChannelCorrection(string fname){
if (fname=="default")
fname=string(thisDetector->badChanFile);
int ret=setBadChannelCorrection(fname, thisDetector->nBadChans, thisDetector->badChansList);
if (ret) {
thisDetector->correctionMask|=(1<<DISCARD_BAD_CHANNELS);
strcpy(thisDetector->badChanFile,fname.c_str());
} else
thisDetector->correctionMask&=~(1<<DISCARD_BAD_CHANNELS);
fillBadChannelMask();
return thisDetector->correctionMask&(1<<DISCARD_BAD_CHANNELS);
}
int slsDetector::setBadChannelCorrection(string fname, int &nbad, int *badlist){
ifstream infile;
string str;
int interrupt=0;
@ -3834,17 +4174,15 @@ int slsDetector::setBadChannelCorrection(string fname){
#endif
if (fname=="") {
thisDetector->correctionMask&=~(1<<DISCARD_BAD_CHANNELS);
thisDetector->nBadChans=0;
nbad=0;
return 0;
} else {
if (fname=="default")
fname=string(thisDetector->badChanFile);
infile.open(fname.c_str(), ios_base::in);
if (infile.is_open()==0) {
std::cout << "could not open file " << fname <<std::endl;
return -1;
}
thisDetector->nBadChans=0;
nbad=0;
while (infile.good() and interrupt==0) {
getline(infile,str);
#ifdef VERBOSE
@ -3852,7 +4190,7 @@ int slsDetector::setBadChannelCorrection(string fname){
#endif
istringstream ssstr;
ssstr.str(str);
if (!ssstr.good() || infile.eof()) {
if (ssstr.bad() || ssstr.fail() || infile.eof()) {
interrupt=1;
break;
}
@ -3864,11 +4202,11 @@ int slsDetector::setBadChannelCorrection(string fname){
std::cout << "channels between"<< chmin << " and " << chmax << std::endl;
#endif
for (ich=chmin; ich<=chmax; ich++) {
if (thisDetector->nBadChans<MAX_BADCHANS) {
thisDetector->badChansList[thisDetector->nBadChans]=ich;
thisDetector->nBadChans++;
if (nbad<MAX_BADCHANS) {
badlist[nbad]=ich;
nbad++;
#ifdef VERBOSE
std::cout<< thisDetector->nBadChans << " Found bad channel "<< ich << std::endl;
std::cout<< nbad << " Found bad channel "<< ich << std::endl;
#endif
} else
interrupt=1;
@ -3878,11 +4216,11 @@ int slsDetector::setBadChannelCorrection(string fname){
#ifdef VERBOSE
std::cout << "channel "<< ich << std::endl;
#endif
if (thisDetector->nBadChans<MAX_BADCHANS) {
thisDetector->badChansList[thisDetector->nBadChans]=ich;
thisDetector->nBadChans++;
if (nbad<MAX_BADCHANS) {
badlist[nbad]=ich;
nbad++;
#ifdef VERBOSE
std::cout << thisDetector->nBadChans << " Found bad channel "<< ich << std::endl;
std::cout << nbad << " Found bad channel "<< ich << std::endl;
#endif
} else
interrupt=1;
@ -3890,20 +4228,39 @@ int slsDetector::setBadChannelCorrection(string fname){
}
if (thisDetector->nBadChans>0 && thisDetector->nBadChans<MAX_BADCHANS) {
thisDetector->correctionMask|=(1<< DISCARD_BAD_CHANNELS);
strcpy(thisDetector->badChanFile,fname.c_str());
}
}
infile.close();
#ifdef VERBOSE
std::cout << "found " << thisDetector->nBadChans << " badchannels "<< std::endl;
#endif
if (nbad>0 && nbad<MAX_BADCHANS) {
return 1;
} else
return 0;
}
int slsDetector::setBadChannelCorrection(int nch, int *chs, int ff) {
if (ff==0) {
if (nch<MAX_BADCHANS) {
thisDetector->nBadChans=nch;
for (int ich=0 ;ich<nch; ich++) {
thisDetector->badChansList[ich]=chs[ich];
}
}
} else {
if (nch<MAX_BADCHANS) {
thisDetector->nBadFF=nch;
for (int ich=0 ;ich<nch; ich++) {
thisDetector->badFFList[ich]=chs[ich];
}
}
}
fillBadChannelMask();
#ifdef VERBOSE
std::cout << " badchannels mask filled"<< std::endl;
#endif
return thisDetector->nBadChans;
if (thisDetector->correctionMask&(1<< DISCARD_BAD_CHANNELS)) {
return thisDetector->nBadChans+thisDetector->nBadFF;
} else
return 0;
}
int slsDetector::getBadChannelCorrection(int *bad) {
@ -4509,25 +4866,6 @@ string slsDetector::executeLine(int narg, char *args[], int action) {
}
strcpy(answer, getHostname());
return string(answer);
} else if (var=="port") {
if (action==PUT_ACTION) {
if (sscanf(args[1],"%d",&ival)) {
sval="";
setTCPSocket(sval,ival);
}
}
sprintf(answer,"%d",getControlPort());
return string(answer);
} else if (var=="stopport") {
if (action==PUT_ACTION) {
if (sscanf(args[1],"%d",&ival)) {
sval="";
setTCPSocket(sval,-1,ival);
}
}
sprintf(answer,"%d",getStopPort());
return string(answer);
} else if (var=="flatfield") {
if (action==PUT_ACTION) {
sval=string(args[1]);
@ -4981,6 +5319,55 @@ string slsDetector::executeLine(int narg, char *args[], int action) {
if (setOnline())
setTCPSocket();
if (var=="port") {
if (action==PUT_ACTION) {
sscanf(args[1],"%d",&ival);
setPort(CONTROL_PORT, ival);
} else
ival=-1;
sprintf(answer,"%d",getControlPort());
return string(answer);
} else if (var=="stopport") {
if (action==PUT_ACTION) {
sscanf(args[1],"%d",&ival);
setPort(STOP_PORT, ival);
} else
ival=-1;
sprintf(answer,"%d",getStopPort());
return string(answer);
} else if (var=="dataport") {
if (action==PUT_ACTION) {
sscanf(args[1],"%d",&ival);
setPort(DATA_PORT, ival);
} else
ival=-1;
sprintf(answer,"%d",getDataPort());
return string(answer);
} else if (var=="lock") {
if (action==PUT_ACTION) {
sscanf(args[1],"%d",&ival);
} else
ival=-1;
sprintf(answer,"%d",lockServer(ival));
return string(answer);
} else if (var=="lastclient") {
if (action==PUT_ACTION) {
return string("cannot set");
} else
return getLastClientIP();
}
if (var=="nmod") {
if (action==PUT_ACTION) {
sscanf(args[1],"%d",&ival);

View File

@ -21,7 +21,6 @@ extern "C" {
#include <sys/types.h>
#include <sys/uio.h>
#include "sls_detector_defs.h"
#define MAX_TIMERS 10
@ -140,6 +139,17 @@ class slsDetector {
typedef struct sharedSlsDetector {
/** already existing flag. If the detector does not yet exist (alreadyExisting=0) the sharedMemory will be created, otherwise it will simly be linked */
int alreadyExisting;
/** last process id accessing the shared memory */
pid_t lastPID;
/** online flag - is set if the detector is connected, unset if socket connection is not possible */
int onlineFlag;
@ -321,6 +331,14 @@ typedef struct sharedSlsDetector {
*/
slsDetector(detectorType type=GENERIC, int id=0);
/** constructor
\param id is the detector index which is needed to define the shared memory id. Different physical detectors should have different IDs in order to work independently
*/
slsDetector(int id){slsDetector(getDetectorType(id),id);};
slsDetector(char *name, int id=0, int cport=DEFAULT_PORTNO);
//slsDetector(string const fname);
@ -382,6 +400,26 @@ typedef struct sharedSlsDetector {
\sa sharedSlsDetector
*/
int setTCPSocket(string const name="", int const control_port=-1, int const stop_port=-1, int const data_port=-1);
/**
changes/gets the port number
\param type port type
\param num new port number (-1 gets)
\returns actual port number
*/
int setPort(portType type, int num=-1);
/** Locks/Unlocks the connection to the server
/param lock sets (1), usets (0), gets (-1) the lock
/returns lock status of the server
*/
int lockServer(int lock=-1);
/**
Returns the IP of the last client connecting to the detector
*/
string getLastClientIP();
/** returns the detector hostname \sa sharedSlsDetector */
char* getHostname() {return thisDetector->hostname;};
/** returns the detector control port \sa sharedSlsDetector */
@ -391,6 +429,21 @@ typedef struct sharedSlsDetector {
/** returns the detector data port \sa sharedSlsDetector */
int getDataPort() {return thisDetector->dataPort;};
/** connect to the control port */
int connectControl();
/** disconnect from the control port */
int disconnectControl();
/** connect to the data port */
int connectData();
/** disconnect from the data port */
int disconnectData();
/** connect to the stop port */
int connectStop();
/** disconnect from the stop port */
int disconnectStop();
/* I/O */
/** returns the detector trimbit/settings directory \sa sharedSlsDetector */
@ -649,12 +702,15 @@ typedef struct sharedSlsDetector {
*/
int writeAngularConversion(string fname="");
/** Returns the number of channels per chip */
/** Returns the number of channels per chip (without connecting to the detector) */
int getNChans(){return thisDetector->nChans;}; //
/** Returns the number of chips per module */
/** Returns the number of chips per module (without connecting to the detector) */
int getNChips(){return thisDetector->nChips;}; //
/** Returns the number of modules (without connecting to the detector) */
int getNMods(){return thisDetector->nMods;}; //
/* Communication to server */
@ -994,17 +1050,18 @@ typedef struct sharedSlsDetector {
int* startAndReadAll();
/**
start detector acquisition and read out, but does not read data from socket
start detector acquisition and read out, but does not read data from socket leaving socket opened
\returns OK or FAIL
*/
int startAndReadAllNoWait();
/**
receives a data frame from the detector socket
\returns pointer to the data or NULL. If NULL disconnects the socket
\sa getDataFromDetector
*/
int* getDataFromDetectorNoWait();
/* /\** */
/* receives a data frame from the detector socket */
/* \returns pointer to the data or NULL. If NULL disconnects the socket */
/* \sa getDataFromDetector */
/* *\/ */
/* int* getDataFromDetectorNoWait(); */
/**
asks and receives a data frame from the detector and puts it in the data queue
@ -1020,6 +1077,12 @@ typedef struct sharedSlsDetector {
*/
int* readAll();
/**
asks and receives all data from the detector and leaves the socket opened
\returns OK or FAIL
*/
int readAllNoWait();
/**
pops the data from the data queue
@ -1157,6 +1220,14 @@ s
*/
int getFlatFieldCorrection(float *corr=NULL, float *ecorr=NULL);
/**
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
*/
int setFlatFieldCorrection(float *corr=NULL, float *ecorr=NULL);
/**
get flat field corrections file directory
\returns flat field correction file directory
@ -1200,6 +1271,15 @@ s
\returns 0 if rate correction disabled, >0 otherwise
*/
int getRateCorrection();
/**
set bad channels correction
\param fname file with bad channel list ("" disable)
\param nbad reference to number of bad channels
\param badlist array of badchannels
\returns 0 if bad channel disabled, >0 otherwise
*/
static int setBadChannelCorrection(string fname, int &nbad, int *badlist);
/**
set bad channels correction
@ -1208,6 +1288,18 @@ s
*/
int setBadChannelCorrection(string fname="");
/**
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
*/
int setBadChannelCorrection(int nch, int *chs, int ff=0);
/**
get bad channels correction
\param bad pointer to array that if bad!=NULL will be filled with the bad channel list
@ -1430,7 +1522,7 @@ s
\param fferr erro on ffcoefficient
\returns 0
*/
int flatFieldCorrect(float datain, float errin, float &dataout, float &errout, float ffcoefficient, float fferr);
static int flatFieldCorrect(float datain, float errin, float &dataout, float &errout, float ffcoefficient, float fferr);
/**
flat field correct data
@ -1454,7 +1546,7 @@ s
\param t acquisition time (in ns)
\returns 0
*/
int rateCorrect(float datain, float errin, float &dataout, float &errout, float tau, float t);
static int rateCorrect(float datain, float errin, float &dataout, float &errout, float tau, float t);
/**
rate correct data
@ -1581,23 +1673,34 @@ enum {GET_ACTION, PUT_ACTION, READOUT_ACTION};
\param action can be PUT_ACTION or GET_ACTION (from text client even READOUT_ACTION for acquisition)
*/
static detectorType getDetectorType(char *name, int cport=DEFAULT_PORTNO);
/**
returns the detector type from hostname and controlport
\param
\param action can be PUT_ACTION or GET_ACTION (from text client even READOUT_ACTION for acquisition)
*/
static detectorType getDetectorType(int id);
/**
Returns detector id
\return pointer to the data (or NULL if failed)
*/
int getDetectorId() { return detId;};
/**
Receives a data frame from the detector socket
\return pointer to the data (or NULL if failed)
*/
int* getDataFromDetector();
protected:
static const int64_t thisSoftwareVersion=0x20110113;
static const int64_t thisSoftwareVersion=0x20111124;
/**
address of the detector structure in shared memory
@ -1707,12 +1810,6 @@ enum {GET_ACTION, PUT_ACTION, READOUT_ACTION};
/** pointer to bad channel mask 0 is channel is good 1 if it is bad \sa fillBadChannelMask() */
int *badChannelMask;
/**
Receives a data frame from the detector socket
\return pointer to the data (or NULL if failed)
*/
int* getDataFromDetector();
/** Initializes the shared memory
\param type is needed to define the size of the shared memory