some more changes - mianly configuration file, and dump and retrieve detector settings added + set speed function

git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@8 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
bergamaschi 2009-12-10 16:25:29 +00:00
parent 2336c330a8
commit 2ceb966c73
8 changed files with 1627 additions and 440 deletions

File diff suppressed because it is too large Load Diff

View File

@ -4,6 +4,7 @@
#ifndef MYTHEN_DETECTOR_H #ifndef MYTHEN_DETECTOR_H
#define MYTHEN_DETECTOR_H #define MYTHEN_DETECTOR_H
#include <ostream>
#include "slsDetector.h" #include "slsDetector.h"
#define defaultTDead {170,90,750} #define defaultTDead {170,90,750}
@ -22,50 +23,62 @@ using namespace std;
class mythenDetector : public slsDetector{ class mythenDetector : public slsDetector{
public: public:
/** /**
(default) constructor (default) constructor
*/ */
mythenDetector(int id=0) : slsDetector(MYTHEN, id){}; mythenDetector(int id=0, detectorType t=MYTHEN) : slsDetector(t, id){};
//slsDetector(string const fname); //slsDetector(string const fname);
// ~slsDetector(){while(dataQueue.size()>0){}}; // ~slsDetector(){while(dataQueue.size()>0){}};
/** destructor */ /** destructor */
~mythenDetector(){}; ~mythenDetector(){};
/**
executes a set of string arguments according to a given format. It is used to read/write configuration file, dump and retrieve detector settings and for the command line interface command parsing
\param narg number of arguments
\param args array of string arguments
\param action can be PUT_ACTION or GET_ACTION (from text client even READOUT_ACTION for acquisition)
\returns answer string
*/
string executeLine(int narg, char *args[], int action=GET_ACTION);
/**
returns the help for the executeLine command
\param os output stream to return the help to
\param action can be PUT_ACTION or GET_ACTION (from text client even READOUT_ACTION for acquisition)
*/
static ostream helpLine(int action=GET_ACTION);
/**
type of action performed
*/
enum {GET_ACTION, PUT_ACTION, READOUT_ACTION};
/**
reads configuration file fname calling executeLine
\param fname file to be read
*/
int readConfigurationFile(string const fname); int readConfigurationFile(string const fname);
/** /**
Every detector should have a basic configuration file containing: writes configuration file calling executeLine
type (mythen, pilatus etc.) \param fname file to write to
hostname
portnumber
communication type (default TCP/IP)
eventually secondary portnumber (e.g. mythen stop function)
number of modules installed if different from the detector size (x,y)
to be changed
*/ */
int writeConfigurationFile(string const fname); 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
*/
/** /**
not yet implemented dumps all the possible detector parameters calling executeLine
\param fname file to write to
should dump to a file all the current detector parameters \param level 0 dumps only main parameters and filenames for flat field correction etc.; 2 dumps really the complete configuration including flat field files, badchannels files, trimbits, angular conversion etc.
*/ */
int dumpDetectorSetup(string const fname); int dumpDetectorSetup(string const fname, int level=0);
/** /**
not yet implemented retrieves alld possible detector parameters from file calling executeLine
\param fname file to be read
should retrieve from a file all the current detector parameters
*/ */
int retrieveDetectorSetup(string const fname); int retrieveDetectorSetup(string const fname, int level=0);
@ -198,7 +211,7 @@ class mythenDetector : public slsDetector{
/** returns the angular conversion file */ /** returns the angular conversion file */
char *getAngularConversion() {return thisDetector->angConvFile;}; string getAngularConversion() {if (thisDetector->correctionMask&(1<< ANGULAR_CONVERSION)) return string(thisDetector->angConvFile); else return string("none");};
/** /**
set detector global offset set detector global offset
@ -289,8 +302,16 @@ class mythenDetector : public slsDetector{
void acquire(int delflag=1); void acquire(int delflag=1);
private:
/**
start data processing thread
*/
void startThread(); //
/** the data processing thread */
pthread_t dataProcessingThread;
}; };
static void* startProcessData(void *n);
#endif #endif

View File

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

View File

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

View File

@ -1600,7 +1600,7 @@ int get_run_status(int fnum) {
printf("Getting status\n"); printf("Getting status\n");
#endif #endif
retval= runState();; retval= runState();
if (ret!=OK) { if (ret!=OK) {
printf("get status failed\n"); printf("get status failed\n");

View File

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

View File

@ -28,6 +28,12 @@ int slsDetector::initSharedMemory(detectorType type, int id) {
nc=10; nc=10;
nd=6; // dacs+adcs nd=6; // dacs+adcs
break; break;
case PICASSO:
nch=128; // complete mythen system
nm=24;
nc=10;
nd=6; // dacs+adcs
break;
default: default:
nch=65535; // one EIGER module nch=65535; // one EIGER module
nm=1; //modules/detector nm=1; //modules/detector
@ -54,7 +60,7 @@ int slsDetector::initSharedMemory(detectorType type, int id) {
thisDetector = (sharedSlsDetector*) shmat(shm_id, NULL, 0); /* attach */ thisDetector = (sharedSlsDetector*) shmat(shm_id, NULL, 0); /* attach */
if ((int) thisDetector == -1) { if (thisDetector == (void*)-1) {
cout <<"*** shmat error (server) ***" << endl; cout <<"*** shmat error (server) ***" << endl;
return shm_id; return shm_id;
} }
@ -93,8 +99,6 @@ slsDetector::slsDetector(detectorType type, int id):
badChannelMask(NULL), badChannelMask(NULL),
detectorModules(NULL) detectorModules(NULL)
{ {
/** sets onlineFlag to OFFLINE_FLAG */
onlineFlag=OFFLINE_FLAG;
while (shmId<0) { while (shmId<0) {
/**Initlializes shared memory \sa initSharedMemory /**Initlializes shared memory \sa initSharedMemory
@ -111,7 +115,6 @@ slsDetector::slsDetector(detectorType type, int id):
/**Initializes the detector stucture \sa initializeDetectorSize /**Initializes the detector stucture \sa initializeDetectorSize
*/ */
initializeDetectorSize(type); initializeDetectorSize(type);
} }
@ -124,6 +127,8 @@ int slsDetector::initializeDetectorSize(detectorType type) {
if (thisDetector->alreadyExisting==0) { if (thisDetector->alreadyExisting==0) {
/** set hostname to default */ /** set hostname to default */
strcpy(thisDetector->hostname,DEFAULT_HOSTNAME); strcpy(thisDetector->hostname,DEFAULT_HOSTNAME);
/** sets onlineFlag to OFFLINE_FLAG */
thisDetector->onlineFlag=OFFLINE_FLAG;
/** set ports to defaults */ /** set ports to defaults */
thisDetector->controlPort=DEFAULT_PORTNO; thisDetector->controlPort=DEFAULT_PORTNO;
thisDetector->stopPort=DEFAULT_PORTNO+1; thisDetector->stopPort=DEFAULT_PORTNO+1;
@ -139,7 +144,7 @@ int slsDetector::initializeDetectorSize(detectorType type) {
thisDetector->nAdcs=0; thisDetector->nAdcs=0;
thisDetector->nModMax[X]=24; thisDetector->nModMax[X]=24;
thisDetector->nModMax[Y]=1; thisDetector->nModMax[Y]=1;
thisDetector->dynamicRange=32; thisDetector->dynamicRange=24;
break; break;
default: default:
thisDetector->nChans=65536; thisDetector->nChans=65536;
@ -164,6 +169,8 @@ int slsDetector::initializeDetectorSize(detectorType type) {
strcpy(thisDetector->trimDir,getenv("HOME")); strcpy(thisDetector->trimDir,getenv("HOME"));
strcpy(thisDetector->calDir,getenv("HOME")); strcpy(thisDetector->calDir,getenv("HOME"));
strcpy(thisDetector->filePath,getenv("HOME")); strcpy(thisDetector->filePath,getenv("HOME"));
/** sets trimbit file */
strcpy(thisDetector->trimFile,"none");
/** set fileName to default to run*/ /** set fileName to default to run*/
strcpy(thisDetector->fileName,"run"); strcpy(thisDetector->fileName,"run");
/** set fileIndex to default to 0*/ /** set fileIndex to default to 0*/
@ -177,6 +184,8 @@ int slsDetector::initializeDetectorSize(detectorType type) {
thisDetector->tDead=0; thisDetector->tDead=0;
/** sets bad channel list file to none */ /** sets bad channel list file to none */
strcpy(thisDetector->badChanFile,"none"); strcpy(thisDetector->badChanFile,"none");
/** sets flat field correction file */
strcpy(thisDetector->flatFieldFile,"none");
/** set number of bad chans to 0*/ /** set number of bad chans to 0*/
thisDetector->nBadChans=0; thisDetector->nBadChans=0;
/** set number of bad flat field chans to 0*/ /** set number of bad flat field chans to 0*/
@ -195,14 +204,15 @@ int slsDetector::initializeDetectorSize(detectorType type) {
thisDetector->currentSettings=UNINITIALIZED; thisDetector->currentSettings=UNINITIALIZED;
/** set threshold to -1*/ /** set threshold to -1*/
thisDetector->currentThresholdEV=-1; thisDetector->currentThresholdEV=-1;
/** set clockdivider to 1*/ // /** set clockdivider to 1*/
thisDetector->clkDiv=1; // thisDetector->clkDiv=1;
/** set number of positions to 0*/ /** set number of positions to 0*/
thisDetector->numberOfPositions=0; thisDetector->numberOfPositions=0;
/** sets angular conversion file to none */ /** sets angular conversion file to none */
strcpy(thisDetector->angConvFile,"none"); strcpy(thisDetector->angConvFile,"none");
/** set binsize*/ /** set binsize*/
thisDetector->binSize=0; thisDetector->binSize=0;
thisDetector->stoppedFlag=0;
@ -223,6 +233,10 @@ int slsDetector::initializeDetectorSize(detectorType type) {
ffcoefficients=(float*)(goff+thisDetector->ffoff); ffcoefficients=(float*)(goff+thisDetector->ffoff);
fferrors=(float*)(goff+thisDetector->fferroff); fferrors=(float*)(goff+thisDetector->fferroff);
detectorModules=(sls_detector_module*)(goff+ thisDetector->modoff); detectorModules=(sls_detector_module*)(goff+ thisDetector->modoff);
#ifdef VERBOSE
for (int imod=0; imod< thisDetector->nModsMax; imod++)
cout << hex << detectorModules+imod << dec <<endl;
#endif
dacs=(float*)(goff+thisDetector->dacoff); dacs=(float*)(goff+thisDetector->dacoff);
adcs=(float*)(goff+thisDetector->adcoff); adcs=(float*)(goff+thisDetector->adcoff);
chipregs=(int*)(goff+thisDetector->chipoff); chipregs=(int*)(goff+thisDetector->chipoff);
@ -252,7 +266,7 @@ int slsDetector::initializeDetectorStructure() {
thisMod->module=imod; thisMod->module=imod;
/** sets the size of the module to nChans, nChips etc. */ /** sets the size of the module to nChans, nChips etc. */
thisMod->nchan=thisDetector->nChans; thisMod->nchan=thisDetector->nChans*thisDetector->nChips;
thisMod->nchip=thisDetector->nChips; thisMod->nchip=thisDetector->nChips;
thisMod->ndac=thisDetector->nDacs; thisMod->ndac=thisDetector->nDacs;
thisMod->nadc=thisDetector->nAdcs; thisMod->nadc=thisDetector->nAdcs;
@ -283,7 +297,7 @@ int slsDetector::initializeDetectorStructure() {
/** initializes the channel registers to 0 */ /** initializes the channel registers to 0 */
for (int ichan=0; ichan<thisDetector->nChans*thisDetector->nChips; ichan++) { for (int ichan=0; ichan<thisDetector->nChans*thisDetector->nChips; ichan++) {
*(chanregs+ichan+thisDetector->nChans*imod)=-1; *(chanregs+ichan+thisDetector->nChips*thisDetector->nChans*imod)=-1;
} }
/** initialize gain and offset to -1 */ /** initialize gain and offset to -1 */
thisMod->gain=-1.; thisMod->gain=-1.;
@ -385,10 +399,28 @@ int slsDetector::receiveModule(sls_detector_module* myMod) {
myMod->chipregs=chipptr; myMod->chipregs=chipptr;
myMod->chanregs=chanptr; myMod->chanregs=chanptr;
#ifdef VERBOSE
cout << "received module " << myMod->module << " of size "<< ts << " register " << myMod->reg << endl;
#endif
ts+=controlSocket->ReceiveDataOnly(myMod->dacs,sizeof(float)*(myMod->ndac)); ts+=controlSocket->ReceiveDataOnly(myMod->dacs,sizeof(float)*(myMod->ndac));
#ifdef VERBOSE
cout << "received dacs " << myMod->module << " of size "<< ts << endl;
#endif
ts+=controlSocket->ReceiveDataOnly(myMod->adcs,sizeof(float)*(myMod->nadc)); ts+=controlSocket->ReceiveDataOnly(myMod->adcs,sizeof(float)*(myMod->nadc));
#ifdef VERBOSE
cout << "received adcs " << myMod->module << " of size "<< ts << endl;
#endif
ts+=controlSocket->ReceiveDataOnly(myMod->chipregs,sizeof(int)*(myMod->nchip)); ts+=controlSocket->ReceiveDataOnly(myMod->chipregs,sizeof(int)*(myMod->nchip));
#ifdef VERBOSE
cout << "received chips " << myMod->module << " of size "<< ts << endl;
#endif
ts+=controlSocket->ReceiveDataOnly(myMod->chanregs,sizeof(int)*(myMod->nchan)); ts+=controlSocket->ReceiveDataOnly(myMod->chanregs,sizeof(int)*(myMod->nchan));
#ifdef VERBOSE
cout << "nchans= " << thisDetector->nChans << " nchips= " << thisDetector->nChips;
cout << "mod - nchans= " << myMod->nchan << " nchips= " <<myMod->nchip;
cout << "received chans " << myMod->module << " of size "<< ts << endl;
#endif
#ifdef VERBOSE #ifdef VERBOSE
cout << "received module " << myMod->module << " of size "<< ts << " register " << myMod->reg << endl; cout << "received module " << myMod->module << " of size "<< ts << " register " << myMod->reg << endl;
#endif #endif
@ -399,8 +431,8 @@ int slsDetector::receiveModule(sls_detector_module* myMod) {
int slsDetector::setOnline(int off) { int slsDetector::setOnline(int off) {
if (off!=GET_ONLINE_FLAG) if (off!=GET_ONLINE_FLAG)
onlineFlag=off; thisDetector->onlineFlag=off;
return onlineFlag; return thisDetector->onlineFlag;
}; };
@ -523,43 +555,20 @@ int slsDetector::setTCPSocket(string const name, int const control_port, int con
cout << "Data socket connected "<< thisName << " " << thisDP << endl; cout << "Data socket connected "<< thisName << " " << thisDP << endl;
#endif #endif
} }
if (retval!=FAIL) if (retval!=FAIL) {
onlineFlag=ONLINE_FLAG;
else
onlineFlag=OFFLINE_FLAG;
/*
test control port
if (retval!=FAIL)
onlineFlag=ONLINE_FLAG;
int i=controlSocket->Connect();
cout << "socket connection " << i<< endl;
if (i>=0) {
cout << "Could connect to socket" << endl;
getMaxNumberOfModules(X);
getMaxNumberOfModules(Y);
controlSocket->Disconnect();
} else {
retval=FAIL;
#ifdef VERBOSE #ifdef VERBOSE
cout << "could not connect to detector" << endl; cout << "online!" << endl;
cout << "setting offline" << endl;
#endif #endif
thisDetector->onlineFlag=ONLINE_FLAG;
} else {
thisDetector->onlineFlag=OFFLINE_FLAG;
#ifdef VERBOSE
cout << "offline!" << endl;
#endif
} }
if (retval==FAIL) {
onlineFlag=OFFLINE_FLAG;
if (controlSocket)
delete controlSocket;
if (stopSocket)
delete stopSocket;
if (dataSocket)
delete dataSocket;
}
*/
return retval; return retval;
}; };
@ -609,7 +618,7 @@ int slsDetector::execCommand(string cmd, string answer){
cout << endl; cout << endl;
cout << "Sending command " << arg << endl; cout << "Sending command " << arg << endl;
#endif #endif
if (onlineFlag==ONLINE_FLAG) { if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (controlSocket) { if (controlSocket) {
if (controlSocket->Connect()>=0) { if (controlSocket->Connect()>=0) {
if (controlSocket->SendDataOnly(&fnum,sizeof(fnum))>=0) { if (controlSocket->SendDataOnly(&fnum,sizeof(fnum))>=0) {
@ -661,7 +670,7 @@ int slsDetector::setDetectorType(detectorType const type){
cout << endl; cout << endl;
cout << "Setting detector type to " << arg << endl; cout << "Setting detector type to " << arg << endl;
#endif #endif
if (onlineFlag==ONLINE_FLAG) { if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (controlSocket) { if (controlSocket) {
if (controlSocket->Connect()>=0) { if (controlSocket->Connect()>=0) {
controlSocket->SendDataOnly(&fnum,sizeof(fnum)); controlSocket->SendDataOnly(&fnum,sizeof(fnum));
@ -764,7 +773,7 @@ int slsDetector::setNumberOfModules(int n, dimension d){
cout << endl; cout << endl;
cout << "Setting number of modules of dimension "<< d << " to " << n << endl; cout << "Setting number of modules of dimension "<< d << " to " << n << endl;
#endif #endif
if (onlineFlag==ONLINE_FLAG) { if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (controlSocket) { if (controlSocket) {
if (controlSocket->Connect()>=0) { if (controlSocket->Connect()>=0) {
controlSocket->SendDataOnly(&fnum,sizeof(fnum)); controlSocket->SendDataOnly(&fnum,sizeof(fnum));
@ -830,7 +839,7 @@ int slsDetector::getMaxNumberOfModules(dimension d){
cout << endl; cout << endl;
cout << "Getting max number of modules in dimension "<< d <<endl; cout << "Getting max number of modules in dimension "<< d <<endl;
#endif #endif
if (onlineFlag==ONLINE_FLAG) { if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (controlSocket) { if (controlSocket) {
if (controlSocket->Connect()>=0) { if (controlSocket->Connect()>=0) {
controlSocket->SendDataOnly(&fnum,sizeof(fnum)); controlSocket->SendDataOnly(&fnum,sizeof(fnum));
@ -897,7 +906,7 @@ enum externalSignalFlag {
cout << endl; cout << endl;
cout << "Setting signal "<< signalindex << " to flag" << pol << endl; cout << "Setting signal "<< signalindex << " to flag" << pol << endl;
#endif #endif
if (onlineFlag==ONLINE_FLAG) { if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (controlSocket) { if (controlSocket) {
if (controlSocket->Connect()>=0) { if (controlSocket->Connect()>=0) {
controlSocket->SendDataOnly(&fnum,sizeof(fnum)); controlSocket->SendDataOnly(&fnum,sizeof(fnum));
@ -918,10 +927,10 @@ enum externalSignalFlag {
} }
#ifdef VERBOSE #ifdef VERBOSE
cout << "Signal "<< signalindex << " flag set to" << retval << endl; cout << "Signal "<< signalindex << " flag set to" << retval << endl;
#endif
if (ret==FAIL) { if (ret==FAIL) {
cout << "Set signal flag failed " << endl; cout << "Set signal flag failed " << endl;
} }
#endif
return retval; return retval;
}; };
@ -960,7 +969,7 @@ enum externalSignalFlag {
cout << endl; cout << endl;
cout << "Setting communication to mode " << pol << endl; cout << "Setting communication to mode " << pol << endl;
#endif #endif
if (onlineFlag==ONLINE_FLAG) { if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (controlSocket) { if (controlSocket) {
if (controlSocket->Connect()>=0) { if (controlSocket->Connect()>=0) {
controlSocket->SendDataOnly(&fnum,sizeof(fnum)); controlSocket->SendDataOnly(&fnum,sizeof(fnum));
@ -1011,7 +1020,7 @@ enum externalSignalFlag {
int64_t slsDetector::getId( idMode mode, int imod){ int64_t slsDetector::getId( idMode mode, int imod){
int64_t retval; int64_t retval=-1;
int fnum=F_GET_ID; int fnum=F_GET_ID;
int ret=FAIL; int ret=FAIL;
@ -1021,7 +1030,7 @@ int64_t slsDetector::getId( idMode mode, int imod){
cout << endl; cout << endl;
cout << "Getting id of "<< mode << endl; cout << "Getting id of "<< mode << endl;
#endif #endif
if (onlineFlag==ONLINE_FLAG) { if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (controlSocket) { if (controlSocket) {
if (controlSocket->Connect()>=0) { if (controlSocket->Connect()>=0) {
controlSocket->SendDataOnly(&fnum,sizeof(fnum)); controlSocket->SendDataOnly(&fnum,sizeof(fnum));
@ -1081,7 +1090,7 @@ int slsDetector::digitalTest( digitalTestMode mode, int imod){
cout << endl; cout << endl;
cout << "Getting id of "<< mode << endl; cout << "Getting id of "<< mode << endl;
#endif #endif
if (onlineFlag==ONLINE_FLAG) { if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (controlSocket) { if (controlSocket) {
@ -1176,7 +1185,7 @@ int slsDetector::writeRegister(int addr, int val){
cout << endl; cout << endl;
cout << "Writing to register "<< addr << " data " << val << endl; cout << "Writing to register "<< addr << " data " << val << endl;
#endif #endif
if (onlineFlag==ONLINE_FLAG) { if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (controlSocket) { if (controlSocket) {
if (controlSocket->Connect()>=0) { if (controlSocket->Connect()>=0) {
controlSocket->SendDataOnly(&fnum,sizeof(fnum)); controlSocket->SendDataOnly(&fnum,sizeof(fnum));
@ -1222,7 +1231,7 @@ int slsDetector::readRegister(int addr){
cout << endl; cout << endl;
cout << "Reding register "<< addr << endl; cout << "Reding register "<< addr << endl;
#endif #endif
if (onlineFlag==ONLINE_FLAG) { if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (controlSocket) { if (controlSocket) {
if (controlSocket->Connect()>=0) { if (controlSocket->Connect()>=0) {
controlSocket->SendDataOnly(&fnum,sizeof(fnum)); controlSocket->SendDataOnly(&fnum,sizeof(fnum));
@ -1281,7 +1290,7 @@ float slsDetector::setDAC(float val, dacIndex index, int imod){
cout << endl; cout << endl;
cout << "Setting DAC "<< index << "of module " << imod << " to " << val << endl; cout << "Setting DAC "<< index << "of module " << imod << " to " << val << endl;
#endif #endif
if (onlineFlag==ONLINE_FLAG) { if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (controlSocket) { if (controlSocket) {
if (controlSocket->Connect()>=0) { if (controlSocket->Connect()>=0) {
controlSocket->SendDataOnly(&fnum,sizeof(fnum)); controlSocket->SendDataOnly(&fnum,sizeof(fnum));
@ -1338,7 +1347,7 @@ float slsDetector::getADC(dacIndex index, int imod){
cout << endl; cout << endl;
cout << "Getting ADC "<< index << "of module " << imod << endl; cout << "Getting ADC "<< index << "of module " << imod << endl;
#endif #endif
if (onlineFlag==ONLINE_FLAG) { if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (controlSocket) { if (controlSocket) {
if (controlSocket->Connect()>=0) { if (controlSocket->Connect()>=0) {
controlSocket->SendDataOnly(&fnum,sizeof(fnum)); controlSocket->SendDataOnly(&fnum,sizeof(fnum));
@ -1430,7 +1439,7 @@ int slsDetector::setChannel(sls_detector_channel chan){
int ichi=chan.chip; int ichi=chan.chip;
int im=chan.module; int im=chan.module;
if (onlineFlag==ONLINE_FLAG) { if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (controlSocket) { if (controlSocket) {
if (controlSocket->Connect()>=0) { if (controlSocket->Connect()>=0) {
controlSocket->SendDataOnly(&fnum,sizeof(fnum)); controlSocket->SendDataOnly(&fnum,sizeof(fnum));
@ -1472,7 +1481,7 @@ int slsDetector::setChannel(sls_detector_channel chan){
arg[0]=ichan; arg[0]=ichan;
arg[1]=ichip; arg[1]=ichip;
arg[2]=imod; arg[2]=imod;
if (onlineFlag==ONLINE_FLAG) { if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (controlSocket) { if (controlSocket) {
if (controlSocket->Connect()>=0) { if (controlSocket->Connect()>=0) {
controlSocket->SendDataOnly(&fnum,sizeof(fnum)); controlSocket->SendDataOnly(&fnum,sizeof(fnum));
@ -1564,7 +1573,7 @@ int slsDetector::setChip(sls_detector_chip chip){
if (onlineFlag==ONLINE_FLAG) { if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (controlSocket) { if (controlSocket) {
if (controlSocket->Connect()>=0) { if (controlSocket->Connect()>=0) {
controlSocket->SendDataOnly(&fnum,sizeof(fnum)); controlSocket->SendDataOnly(&fnum,sizeof(fnum));
@ -1616,7 +1625,7 @@ int slsDetector::setChip(sls_detector_chip chip){
if (onlineFlag==ONLINE_FLAG) { if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (controlSocket) { if (controlSocket) {
if (controlSocket->Connect()>=0) { if (controlSocket->Connect()>=0) {
controlSocket->SendDataOnly(&fnum,sizeof(fnum)); controlSocket->SendDataOnly(&fnum,sizeof(fnum));
@ -1748,7 +1757,7 @@ int slsDetector::setModule(sls_detector_module module){
if (onlineFlag==ONLINE_FLAG) { if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (controlSocket) { if (controlSocket) {
if (controlSocket->Connect()>=0) { if (controlSocket->Connect()>=0) {
controlSocket->SendDataOnly(&fnum,sizeof(fnum)); controlSocket->SendDataOnly(&fnum,sizeof(fnum));
@ -1817,7 +1826,7 @@ sls_detector_module *slsDetector::getModule(int imod){
if (onlineFlag==ONLINE_FLAG) { if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (controlSocket) { if (controlSocket) {
if (controlSocket->Connect()>=0) { if (controlSocket->Connect()>=0) {
controlSocket->SendDataOnly(&fnum,sizeof(fnum)); controlSocket->SendDataOnly(&fnum,sizeof(fnum));
@ -1837,25 +1846,40 @@ sls_detector_module *slsDetector::getModule(int imod){
if (ret==OK) { if (ret==OK) {
if (detectorModules) { if (detectorModules) {
#ifdef VERBOSE
cout << hex << detectorModules+imod <<dec<< endl;
#endif
(detectorModules+imod)->nchan=myMod->nchan; (detectorModules+imod)->nchan=myMod->nchan;
(detectorModules+imod)->nchip=myMod->nchip; (detectorModules+imod)->nchip=myMod->nchip;
(detectorModules+imod)->ndac=myMod->ndac; (detectorModules+imod)->ndac=myMod->ndac;
(detectorModules+imod)->nadc=myMod->nadc; (detectorModules+imod)->nadc=myMod->nadc;
#ifdef VERBOSE
cout << " before " << thisDetector->nChans << " " << thisDetector->nChips << endl << " chan " << myMod->nchan << " chip " << myMod->nchip<< endl;
#endif
thisDetector->nChips=myMod->nchip; thisDetector->nChips=myMod->nchip;
thisDetector->nChans=myMod->nchan/myMod->nchip; thisDetector->nChans=myMod->nchan/myMod->nchip;
#ifdef VERBOSE
cout << " after " << thisDetector->nChans << " " << thisDetector->nChips<< endl;
#endif
thisDetector->nDacs=myMod->ndac; thisDetector->nDacs=myMod->ndac;
thisDetector->nAdcs=myMod->nadc; thisDetector->nAdcs=myMod->nadc;
for (int ichip=0; ichip<thisDetector->nChips; ichip++) { for (int ichip=0; ichip<thisDetector->nChips; ichip++) {
if (chipregs) if (chipregs)
chipregs[ichip+thisDetector->nChips*imod]=myMod->chipregs[ichip]; chipregs[ichip+thisDetector->nChips*imod]=myMod->chipregs[ichip];
if (chanregs) { if (chanregs) {
for (int i=0; i<thisDetector->nChans; i++) { for (int i=0; i<thisDetector->nChans; i++) {
chanregs[i+ichip*thisDetector->nChans+thisDetector->nChips*thisDetector->nChans*imod]=myMod->chanregs[ichip*thisDetector->nChans+i]; chanregs[i+ichip*thisDetector->nChans+thisDetector->nChips*thisDetector->nChans*imod]=myMod->chanregs[ichip*thisDetector->nChans+i];
} }
} }
} }
if (dacs) { if (dacs) {
for (int i=0; i<thisDetector->nDacs; i++) for (int i=0; i<thisDetector->nDacs; i++)
dacs[i+imod*thisDetector->nDacs]=myMod->dacs[i]; dacs[i+imod*thisDetector->nDacs]=myMod->dacs[i];
@ -1864,11 +1888,13 @@ sls_detector_module *slsDetector::getModule(int imod){
for (int i=0; i<thisDetector->nAdcs; i++) for (int i=0; i<thisDetector->nAdcs; i++)
adcs[i+imod*thisDetector->nAdcs]=myMod->adcs[i]; adcs[i+imod*thisDetector->nAdcs]=myMod->adcs[i];
} }
(detectorModules+imod)->gain=myMod->gain; (detectorModules+imod)->gain=myMod->gain;
(detectorModules+imod)->offset=myMod->offset; (detectorModules+imod)->offset=myMod->offset;
(detectorModules+imod)->serialnumber=myMod->serialnumber; (detectorModules+imod)->serialnumber=myMod->serialnumber;
(detectorModules+imod)->reg=myMod->reg; (detectorModules+imod)->reg=myMod->reg;
} }
} else { } else {
deleteModule(myMod); deleteModule(myMod);
myMod=NULL; myMod=NULL;
@ -1920,7 +1946,7 @@ int slsDetector::getThresholdEnergy(int imod){
cout << "Getting threshold energy "<< endl; cout << "Getting threshold energy "<< endl;
#endif #endif
if (onlineFlag==ONLINE_FLAG) { if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (controlSocket) { if (controlSocket) {
if (controlSocket->Connect()>=0) { if (controlSocket->Connect()>=0) {
controlSocket->SendDataOnly(&fnum,sizeof(fnum)); controlSocket->SendDataOnly(&fnum,sizeof(fnum));
@ -1931,13 +1957,14 @@ int slsDetector::getThresholdEnergy(int imod){
controlSocket->ReceiveDataOnly(mess,sizeof(mess)); controlSocket->ReceiveDataOnly(mess,sizeof(mess));
cout << mess << endl; cout << mess << endl;
} else { } else {
controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); controlSocket->ReceiveDataOnly(&retval,sizeof(retval));
thisDetector->currentThresholdEV=retval;
} }
controlSocket->Disconnect(); controlSocket->Disconnect();
} }
} }
} }
return retval; return thisDetector->currentThresholdEV;
}; };
int slsDetector::setThresholdEnergy(int e_eV, int imod, detectorSettings isettings){ int slsDetector::setThresholdEnergy(int e_eV, int imod, detectorSettings isettings){
@ -1949,7 +1976,7 @@ int slsDetector::setThresholdEnergy(int e_eV, int imod, detectorSettings isetti
#ifdef VERBOSE #ifdef VERBOSE
cout << "Getting threshold energy "<< endl; cout << "Getting threshold energy "<< endl;
#endif #endif
if (onlineFlag==ONLINE_FLAG) { if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (controlSocket) { if (controlSocket) {
if (controlSocket->Connect()>=0) { if (controlSocket->Connect()>=0) {
controlSocket->SendDataOnly(&fnum,sizeof(fnum)); controlSocket->SendDataOnly(&fnum,sizeof(fnum));
@ -1965,13 +1992,16 @@ int slsDetector::setThresholdEnergy(int e_eV, int imod, detectorSettings isetti
#ifdef VERBOSE #ifdef VERBOSE
cout << "Detector returned OK "<< endl; cout << "Detector returned OK "<< endl;
#endif #endif
controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); controlSocket->ReceiveDataOnly(&retval,sizeof(retval));
thisDetector->currentThresholdEV=retval;
} }
controlSocket->Disconnect(); controlSocket->Disconnect();
} }
} }
} else {
thisDetector->currentThresholdEV=e_eV;
} }
return retval; return thisDetector->currentThresholdEV;
}; };
/* /*
@ -1990,7 +2020,7 @@ int slsDetector::setThresholdEnergy(int e_eV, int imod, detectorSettings isetti
#ifdef VERBOSE #ifdef VERBOSE
cout << "Getting settings "<< endl; cout << "Getting settings "<< endl;
#endif #endif
if (onlineFlag==ONLINE_FLAG) { if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (controlSocket) { if (controlSocket) {
if (controlSocket->Connect()>=0) { if (controlSocket->Connect()>=0) {
controlSocket->SendDataOnly(&fnum,sizeof(fnum)); controlSocket->SendDataOnly(&fnum,sizeof(fnum));
@ -2024,12 +2054,15 @@ int slsDetector::setThresholdEnergy(int e_eV, int imod, detectorSettings isetti
switch (isettings) { switch (isettings) {
case STANDARD: case STANDARD:
ssettings="/standard"; ssettings="/standard";
thisDetector->currentSettings=STANDARD;
break; break;
case FAST: case FAST:
ssettings="/fast"; ssettings="/fast";
thisDetector->currentSettings=FAST;
break; break;
case HIGHGAIN: case HIGHGAIN:
ssettings="/highgain"; ssettings="/highgain";
thisDetector->currentSettings=HIGHGAIN;
break; break;
default: default:
cout << "Unknown settings!" << endl; cout << "Unknown settings!" << endl;
@ -2040,7 +2073,7 @@ int slsDetector::setThresholdEnergy(int e_eV, int imod, detectorSettings isetti
// modma=thisDetector->nModMax[X]*thisDetector->nModMax[Y]; // modma=thisDetector->nModMax[X]*thisDetector->nModMax[Y];
modma=thisDetector->nMod[X]*thisDetector->nMod[Y]; modma=thisDetector->nMod[X]*thisDetector->nMod[Y];
} }
for (im=modmi; im<modma; im++) { for (im=modmi; im<modma; im++) {
ostringstream ostfn, oscfn; ostringstream ostfn, oscfn;
myMod->module=im; myMod->module=im;
@ -2092,17 +2125,18 @@ int slsDetector::startAcquisition(){
#ifdef VERBOSE #ifdef VERBOSE
cout << "Starting acquisition "<< endl; cout << "Starting acquisition "<< endl;
#endif #endif
if (onlineFlag==ONLINE_FLAG) { thisDetector->stoppedFlag=0;
if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (controlSocket) { if (controlSocket) {
if (controlSocket->Connect()>=0) { if (controlSocket->Connect()>=0) {
controlSocket->SendDataOnly(&fnum,sizeof(fnum)); controlSocket->SendDataOnly(&fnum,sizeof(fnum));
controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
if (ret!=OK) { if (ret!=OK) {
controlSocket->ReceiveDataOnly(mess,sizeof(mess)); controlSocket->ReceiveDataOnly(mess,sizeof(mess));
cout << "Detector returned error: " << mess << endl; cout << "Detector returned error: " << mess << endl;
} }
controlSocket->Disconnect(); controlSocket->Disconnect();
} }
} }
} }
return ret; return ret;
@ -2120,7 +2154,7 @@ int slsDetector::stopAcquisition(){
#ifdef VERBOSE #ifdef VERBOSE
cout << "Stopping acquisition "<< endl; cout << "Stopping acquisition "<< endl;
#endif #endif
if (onlineFlag==ONLINE_FLAG) { if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (stopSocket) { if (stopSocket) {
if (stopSocket->Connect()>=0) { if (stopSocket->Connect()>=0) {
stopSocket->SendDataOnly(&fnum,sizeof(fnum)); stopSocket->SendDataOnly(&fnum,sizeof(fnum));
@ -2133,6 +2167,7 @@ int slsDetector::stopAcquisition(){
} }
} }
} }
thisDetector->stoppedFlag=1;
return ret; return ret;
@ -2147,7 +2182,7 @@ int slsDetector::startReadOut(){
#ifdef VERBOSE #ifdef VERBOSE
cout << "Starting readout "<< endl; cout << "Starting readout "<< endl;
#endif #endif
if (onlineFlag==ONLINE_FLAG) { if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (controlSocket) { if (controlSocket) {
if (controlSocket->Connect()>=0) { if (controlSocket->Connect()>=0) {
controlSocket->SendDataOnly(&fnum,sizeof(fnum)); controlSocket->SendDataOnly(&fnum,sizeof(fnum));
@ -2173,7 +2208,7 @@ int slsDetector::getRunStatus(){
#ifdef VERBOSE #ifdef VERBOSE
cout << "Getting status "<< endl; cout << "Getting status "<< endl;
#endif #endif
if (onlineFlag==ONLINE_FLAG) { if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (controlSocket) { if (controlSocket) {
if (controlSocket->Connect()>=0) { if (controlSocket->Connect()>=0) {
controlSocket->SendDataOnly(&fnum,sizeof(fnum)); controlSocket->SendDataOnly(&fnum,sizeof(fnum));
@ -2195,18 +2230,21 @@ int slsDetector::getRunStatus(){
int* slsDetector::readFrame(){ int* slsDetector::readFrame(){
int fnum=F_READ_FRAME, n; int fnum=F_READ_FRAME, n;
int* retval; int* retval=NULL;
#ifdef VERBOSE #ifdef VERBOSE
cout << "slsDetector: Reading frame "<< endl; cout << "slsDetector: Reading frame "<< endl;
#endif #endif
if (onlineFlag==ONLINE_FLAG) { if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (controlSocket) { if (controlSocket) {
if (controlSocket->Connect()>=0) { if (controlSocket->Connect()>=0) {
controlSocket->SendDataOnly(&fnum,sizeof(fnum)); controlSocket->SendDataOnly(&fnum,sizeof(fnum));
retval=getDataFromDetector(); retval=getDataFromDetector();
controlSocket->Disconnect(); if (retval) {
} dataQueue.push(retval);
controlSocket->Disconnect();
}
}
} }
} }
return retval; return retval;
@ -2218,7 +2256,7 @@ int* slsDetector::getDataFromDetector(){
int n; int n;
int* retval=new int[nel]; int* retval=new int[nel];
int ret=FAIL; int ret=FAIL;
char mess[100]; char mess[100]="Nothing";
#ifdef VERY_VERBOSE #ifdef VERY_VERBOSE
int i; int i;
#endif #endif
@ -2229,10 +2267,15 @@ int* slsDetector::getDataFromDetector(){
controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
if (ret!=OK) { if (ret!=OK) {
n= controlSocket->ReceiveDataOnly(mess,sizeof(mess)); n= controlSocket->ReceiveDataOnly(mess,sizeof(mess));
#ifndef VERBOSE if (ret==FAIL) {
if (ret==FAIL) thisDetector->stoppedFlag=1;
#endif
cout << "Detector returned: " << mess << " " << n << endl; cout << "Detector returned: " << mess << " " << n << endl;
} else {
;
#ifdef VERBOSE
cout << "Detector successfully returned: " << mess << " " << n << endl;
#endif
}
delete [] retval; delete [] retval;
retval=NULL; retval=NULL;
} else { } else {
@ -2243,6 +2286,7 @@ int* slsDetector::getDataFromDetector(){
#endif #endif
if (n!=thisDetector->dataBytes) { if (n!=thisDetector->dataBytes) {
cout << "wrong data size received: received " << n << " but expected " << thisDetector->dataBytes << endl; cout << "wrong data size received: received " << n << " but expected " << thisDetector->dataBytes << endl;
thisDetector->stoppedFlag=1;
ret=FAIL; ret=FAIL;
delete [] retval; delete [] retval;
retval=NULL; retval=NULL;
@ -2265,7 +2309,7 @@ int* slsDetector::readAll(){
#ifdef VERBOSE #ifdef VERBOSE
cout << "Reading all frames "<< endl; cout << "Reading all frames "<< endl;
#endif #endif
if (onlineFlag==ONLINE_FLAG) { if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (controlSocket) { if (controlSocket) {
if (controlSocket->Connect()>=0) { if (controlSocket->Connect()>=0) {
controlSocket->SendDataOnly(&fnum,sizeof(fnum)); controlSocket->SendDataOnly(&fnum,sizeof(fnum));
@ -2329,7 +2373,8 @@ int slsDetector::startAndReadAllNoWait(){
#ifdef VERBOSE #ifdef VERBOSE
cout << "Starting and reading all frames "<< endl; cout << "Starting and reading all frames "<< endl;
#endif #endif
if (onlineFlag==ONLINE_FLAG) { thisDetector->stoppedFlag=0;
if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (controlSocket) { if (controlSocket) {
if (controlSocket->Connect()>=0) { if (controlSocket->Connect()>=0) {
controlSocket->SendDataOnly(&fnum,sizeof(fnum)); controlSocket->SendDataOnly(&fnum,sizeof(fnum));
@ -2342,7 +2387,7 @@ int slsDetector::startAndReadAllNoWait(){
int* slsDetector::getDataFromDetectorNoWait() { int* slsDetector::getDataFromDetectorNoWait() {
int *retval=getDataFromDetector(); int *retval=getDataFromDetector();
if (onlineFlag==ONLINE_FLAG) { if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (controlSocket) { if (controlSocket) {
if (retval==NULL){ if (retval==NULL){
controlSocket->Disconnect(); controlSocket->Disconnect();
@ -2408,32 +2453,32 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t){
cout << "Setting timer "<< index << " to " << t << "ns" << endl; cout << "Setting timer "<< index << " to " << t << "ns" << endl;
#endif #endif
ut=t; ut=t;
if (onlineFlag==ONLINE_FLAG) { if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (controlSocket) { if (controlSocket) {
if (controlSocket->Connect()>=0) { if (controlSocket->Connect()>=0) {
controlSocket->SendDataOnly(&fnum,sizeof(fnum)); controlSocket->SendDataOnly(&fnum,sizeof(fnum));
controlSocket->SendDataOnly(&index,sizeof(index)); controlSocket->SendDataOnly(&index,sizeof(index));
n=controlSocket->SendDataOnly(&t,sizeof(t)); n=controlSocket->SendDataOnly(&t,sizeof(t));
#ifdef VERBOSE controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
cout << "Sent "<< n << " bytes " << endl; if (ret!=OK) {
#endif controlSocket->ReceiveDataOnly(mess,sizeof(mess));
controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); cout << "Detector returned error: " << mess << endl;
if (ret!=OK) { } else {
controlSocket->ReceiveDataOnly(mess,sizeof(mess)); controlSocket->ReceiveDataOnly(&retval,sizeof(retval));
cout << "Detector returned error: " << mess << endl; thisDetector->timerValue[index]=retval;
} else { }
controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); controlSocket->Disconnect();
} }
controlSocket->Disconnect();
}
} }
} else {
//cout << "offline " << endl;
if (t>=0)
thisDetector->timerValue[index]=t;
} }
#ifdef VERBOSE #ifdef VERBOSE
cout << "Timer set to "<< retval << "ns" << endl; cout << "Timer set to "<< thisDetector->timerValue[index] << "ns" << endl;
#endif #endif
if (t>0) return thisDetector->timerValue[index];
thisDetector->timerValue[index]=retval;
return retval;
}; };
@ -2451,14 +2496,14 @@ int slsDetector::setSpeed(speedVariable sp, int value) {
int fnum=F_SET_SPEED; int fnum=F_SET_SPEED;
int retval; int retval=-1;
char mess[100]; char mess[100];
int ret=OK; int ret=OK;
int n=0; int n=0;
#ifdef VERBOSE #ifdef VERBOSE
cout << "Setting speed variable"<< sp << " to " << value << endl; cout << "Setting speed variable"<< sp << " to " << value << endl;
#endif #endif
if (onlineFlag==ONLINE_FLAG) { if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (controlSocket) { if (controlSocket) {
if (controlSocket->Connect()>=0) { if (controlSocket->Connect()>=0) {
controlSocket->SendDataOnly(&fnum,sizeof(fnum)); controlSocket->SendDataOnly(&fnum,sizeof(fnum));
@ -2511,7 +2556,7 @@ int64_t slsDetector::getTimeLeft(timerIndex index){
#ifdef VERBOSE #ifdef VERBOSE
cout << "Getting timer "<< index << endl; cout << "Getting timer "<< index << endl;
#endif #endif
if (onlineFlag==ONLINE_FLAG) { if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (controlSocket) { if (controlSocket) {
if (controlSocket->Connect()>=0) { if (controlSocket->Connect()>=0) {
controlSocket->SendDataOnly(&fnum,sizeof(fnum)); controlSocket->SendDataOnly(&fnum,sizeof(fnum));
@ -2549,35 +2594,40 @@ int slsDetector::setDynamicRange(int n){
#endif #endif
if (n==24) if (n==24)
n=32; n=32;
if (onlineFlag==ONLINE_FLAG) { if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (controlSocket) { if (controlSocket) {
if (controlSocket->Connect()>=0) { if (controlSocket->Connect()>=0) {
controlSocket->SendDataOnly(&fnum,sizeof(fnum)); controlSocket->SendDataOnly(&fnum,sizeof(fnum));
controlSocket->SendDataOnly(&n,sizeof(n)); controlSocket->SendDataOnly(&n,sizeof(n));
controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
if (ret!=OK) { if (ret!=OK) {
controlSocket->ReceiveDataOnly(mess,sizeof(mess)); controlSocket->ReceiveDataOnly(mess,sizeof(mess));
cout << "Detector returned error: " << mess << endl; cout << "Detector returned error: " << mess << endl;
} else { } else {
controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); controlSocket->ReceiveDataOnly(&retval,sizeof(retval));
}
controlSocket->Disconnect();
}
} }
controlSocket->Disconnect(); } else {
if (n>0)
thisDetector->dynamicRange=n;
retval=thisDetector->dynamicRange;
} }
}
}
if (ret==OK) {
thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*retval/8;
if (retval==32)
thisDetector->dynamicRange=24;
else
thisDetector->dynamicRange=retval;
if (ret==OK && retval>0) {
thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*retval/8;
if (retval==32)
thisDetector->dynamicRange=24;
else
thisDetector->dynamicRange=retval;
#ifdef VERBOSE #ifdef VERBOSE
cout << "Dynamic range set to "<< thisDetector->dynamicRange << endl; cout << "Dynamic range set to "<< thisDetector->dynamicRange << endl;
cout << "Data bytes "<< thisDetector->dataBytes << endl; cout << "Data bytes "<< thisDetector->dataBytes << endl;
#endif #endif
} }
return thisDetector->dynamicRange; return thisDetector->dynamicRange;
}; };
@ -2614,7 +2664,7 @@ int slsDetector::setReadOutFlags(readOutFlags flag){
cout << "Setting readout flags to "<< flag << endl; cout << "Setting readout flags to "<< flag << endl;
#endif #endif
if (onlineFlag==ONLINE_FLAG) { if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (controlSocket) { if (controlSocket) {
if (controlSocket->Connect()>=0) { if (controlSocket->Connect()>=0) {
controlSocket->SendDataOnly(&fnum,sizeof(fnum)); controlSocket->SendDataOnly(&fnum,sizeof(fnum));
@ -2630,11 +2680,15 @@ int slsDetector::setReadOutFlags(readOutFlags flag){
controlSocket->Disconnect(); controlSocket->Disconnect();
} }
} }
} else {
if (flag!=GET_READOUT_FLAGS)
thisDetector->roFlags=flag;
} }
#ifdef VERBOSE #ifdef VERBOSE
cout << "Readout flag set to "<< retval << endl; cout << "Readout flag set to "<< retval << endl;
#endif #endif
return retval; return thisDetector->roFlags;
}; };
//Trimming //Trimming
@ -2663,7 +2717,7 @@ int slsDetector::executeTrimming(trimMode mode, int par1, int par2, int imod){
cout << "Trimming module " << imod << " with mode "<< mode << " parameters " << par1 << " " << par2 << endl; cout << "Trimming module " << imod << " with mode "<< mode << " parameters " << par1 << " " << par2 << endl;
#endif #endif
if (onlineFlag==ONLINE_FLAG) { if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (controlSocket) { if (controlSocket) {
if (controlSocket->Connect()>=0) { if (controlSocket->Connect()>=0) {
controlSocket->SendDataOnly(&fnum,sizeof(fnum)); controlSocket->SendDataOnly(&fnum,sizeof(fnum));
@ -2809,12 +2863,14 @@ int slsDetector::setFlatFieldCorrection(string fname){
cout << "disabling flat field correction" << endl; cout << "disabling flat field correction" << endl;
#endif #endif
thisDetector->correctionMask&=~(1<<FLAT_FIELD_CORRECTION); thisDetector->correctionMask&=~(1<<FLAT_FIELD_CORRECTION);
strcpy(thisDetector->flatFieldFile,"none");
} else { } else {
#ifdef VERBOSE #ifdef VERBOSE
cout << "Setting flat field correction from file " << fname << endl; cout << "Setting flat field correction from file " << fname << endl;
#endif #endif
nch=readDataFile(fname,data); nch=readDataFile(fname,data);
if (nch>0) { if (nch>0) {
strcpy(thisDetector->flatFieldFile,fname.c_str());
for (int ichan=0; ichan<nch; ichan++) { for (int ichan=0; ichan<nch; ichan++) {
if (data[ichan]>0) { if (data[ichan]>0) {
/* add to median */ /* add to median */
@ -2827,11 +2883,14 @@ int slsDetector::setFlatFieldCorrection(string fname){
nmed++; nmed++;
} else { } else {
//add the channel to the ff bad channel list //add the channel to the ff bad channel list
thisDetector->badFFList[thisDetector->nBadFF]=ichan; if (thisDetector->nBadFF<MAX_BADCHANS) {
(thisDetector->nBadFF)++; thisDetector->badFFList[thisDetector->nBadFF]=ichan;
(thisDetector->nBadFF)++;
#ifdef VERBOSE #ifdef VERBOSE
cout << "Channel " << ichan << " added to the bad channel list" << endl; cout << "Channel " << ichan << " added to the bad channel list" << endl;
#endif #endif
} else
cout << "Too many bad channels " << endl;
} }
} }
@ -2877,9 +2936,10 @@ int slsDetector::getFlatFieldCorrection(float *corr, float *ecorr) {
#endif #endif
if (corr) { if (corr) {
for (int ichan=0; ichan<thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChans*thisDetector->nChips; ichan++) { for (int ichan=0; ichan<thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChans*thisDetector->nChips; ichan++) {
corr[ichan]=ffcoefficients[ichan]; corr[ichan]=(ffcoefficients[ichan]*ffcoefficients[ichan])/(fferrors[ichan]*fferrors[ichan]);
if (ecorr) if (ecorr) {
ecorr[ichan]=fferrors[ichan]; ecorr[ichan]=ffcoefficients[ichan]/fferrors[ichan];
}
} }
} }
return 1; return 1;
@ -3042,7 +3102,8 @@ int slsDetector::setBadChannelCorrection(string fname){
thisDetector->correctionMask&=~(1<< DISCARD_BAD_CHANNELS); thisDetector->correctionMask&=~(1<< DISCARD_BAD_CHANNELS);
thisDetector->nBadChans=0; thisDetector->nBadChans=0;
} else { } else {
thisDetector->correctionMask|=(1<< DISCARD_BAD_CHANNELS); if (fname=="default")
fname=string(thisDetector->badChanFile);
infile.open(fname.c_str(), ios_base::in); infile.open(fname.c_str(), ios_base::in);
thisDetector->nBadChans=0; thisDetector->nBadChans=0;
while (infile.good() and interrupt==0) { while (infile.good() and interrupt==0) {
@ -3063,11 +3124,14 @@ int slsDetector::setBadChannelCorrection(string fname){
} else { } else {
ssstr.str(str); ssstr.str(str);
ssstr >> ich; ssstr >> ich;
thisDetector->badChansList[thisDetector->nBadChans]=ich; if (thisDetector->nBadChans<MAX_BADCHANS) {
thisDetector->nBadChans++; thisDetector->badChansList[thisDetector->nBadChans]=ich;
thisDetector->nBadChans++;
#ifdef VERBOSE #ifdef VERBOSE
cout << thisDetector->nBadChans << " Found bad channel "<< ich << endl; cout << thisDetector->nBadChans << " Found bad channel "<< ich << endl;
#endif #endif
} else
interrupt=1;
} }
@ -3077,7 +3141,10 @@ 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());
}
} }
fillBadChannelMask(); fillBadChannelMask();
return thisDetector->nBadChans; return thisDetector->nBadChans;
@ -3092,7 +3159,7 @@ int slsDetector::getBadChannelCorrection(int *bad) {
for (int ich=0; ich<thisDetector->nBadFF; ich++) for (int ich=0; ich<thisDetector->nBadFF; ich++)
bad[ichan+ich]=thisDetector->badFFList[ich]; bad[ichan+ich]=thisDetector->badFFList[ich];
} }
return thisDetector->nBadChans+ thisDetector->nBadFF; return thisDetector->nBadChans+thisDetector->nBadFF;
} else } else
return 0; return 0;
} }
@ -3129,7 +3196,7 @@ int slsDetector::exitServer(){
int fnum=F_EXIT_SERVER; int fnum=F_EXIT_SERVER;
if (onlineFlag==ONLINE_FLAG) { if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (controlSocket) { if (controlSocket) {
controlSocket->Connect(); controlSocket->Connect();
controlSocket->SendDataOnly(&fnum,sizeof(fnum)); controlSocket->SendDataOnly(&fnum,sizeof(fnum));

View File

@ -56,7 +56,7 @@ class detectorData {
\param fname file name to which the data are saved \param fname file name to which the data are saved
\param np number of points defaults to the number of detector channels \param np number of points defaults to the number of detector channels
*/ */
detectorData(float *val=NULL, float *err=NULL, float *ang=NULL, int f_ind=-1, char *fname="", int np=-1) : values(val), errors(err), angles(ang), fileIndex(f_ind), npoints(np){strcpy(fileName,fname);}; detectorData(float *val=NULL, float *err=NULL, float *ang=NULL, int f_ind=-1, const char *fname="", int np=-1) : values(val), errors(err), angles(ang), fileIndex(f_ind), npoints(np){strcpy(fileName,fname);};
/** /**
the destructor the destructor
deletes also the arrays pointing to data/errors/angles if not NULL deletes also the arrays pointing to data/errors/angles if not NULL
@ -73,13 +73,6 @@ class detectorData {
using namespace std; using namespace std;
/** /**
\mainpage Common C++ library for SLS detectors data acquisition \mainpage Common C++ library for SLS detectors data acquisition
@ -128,9 +121,9 @@ class slsDetector {
/** online flags enum \sa setOnline*/ /** online flags enum \sa setOnline*/
enum {GET_ONLINE_FLAG, /**< returns wether the detector is in online or offline state */ enum {GET_ONLINE_FLAG=-1, /**< 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!) */ OFFLINE_FLAG=0, /**< 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) */ ONLINE_FLAG =1/**< detector in online state (i.e. communication to the detector updating the local structure) */
}; };
@ -142,7 +135,14 @@ class slsDetector {
typedef struct sharedSlsDetector { typedef struct sharedSlsDetector {
/** already existing flag. If the detector does not yet exist (alreadyExisting=0) the sharedMemory will be created, otherwise it will simly be linked */ /** already existing flag. If the detector does not yet exist (alreadyExisting=0) the sharedMemory will be created, otherwise it will simly be linked */
int alreadyExisting; int alreadyExisting;
/*
/** online flag - is set if the detector is connected, unset if socket connection is not possible */
int onlineFlag;
/** stopped flag - is set if an acquisition error occurs or the detector is stopped manually. Is reset to 0 at the start of the acquisition */
int stoppedFlag;
/** is the hostname (or IP address) of the detector. needs to be set before startin the communication */ /** is the hostname (or IP address) of the detector. needs to be set before startin the communication */
char hostname[MAX_STR_LENGTH]; char hostname[MAX_STR_LENGTH];
/** is the port used for control functions normally it should not be changed*/ /** is the port used for control functions normally it should not be changed*/
@ -198,8 +198,12 @@ typedef struct sharedSlsDetector {
/** corrections to be applied to the data \see ::correctionFlags */ /** corrections to be applied to the data \see ::correctionFlags */
int correctionMask; int correctionMask;
/** threaded processing flag (i.e. if data are processed and written to file in a separate thread) */
int threadedProcessing;
/** dead time (in ns) for rate corrections */ /** dead time (in ns) for rate corrections */
float tDead; float tDead;
/** file used for flat field corrections */
char flatFieldFile[MAX_STR_LENGTH];
/** number of bad channels from bad channel list */ /** number of bad channels from bad channel list */
int nBadChans; int nBadChans;
/** file with the bad channels */ /** file with the bad channels */
@ -237,14 +241,16 @@ typedef struct sharedSlsDetector {
readOutFlags roFlags; readOutFlags roFlags;
/* detector setup - not needed */ /* detector setup - not needed */
/** detector settings (standard, fast, etc.) */ /** name root of the output files */
detectorSettings currentSettings; char trimFile[MAX_STR_LENGTH];
/** detector threshold (eV) */ /** detector settings (standard, fast, etc.) */
int currentThresholdEV; detectorSettings currentSettings;
/** timer values */ /** detector threshold (eV) */
int64_t timerValue[MAX_TIMERS]; int currentThresholdEV;
/** clock divider */ /** timer values */
int clkDiv; int64_t timerValue[MAX_TIMERS];
/** clock divider */
//int clkDiv;
/*offsets*/ /*offsets*/
/** memory offsets for the flat filed coefficients */ /** memory offsets for the flat filed coefficients */
@ -281,7 +287,7 @@ typedef struct sharedSlsDetector {
/** sets the onlineFlag /** 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) */ \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); int setOnline(int const online=GET_ONLINE_FLAG);
/** sets the onlineFlag /** sets the onlineFlag
\returns 1 if the detector structure has already be initlialized, 0 otherwise */ \returns 1 if the detector structure has already be initlialized, 0 otherwise */
int exists() {return thisDetector->alreadyExisting;}; int exists() {return thisDetector->alreadyExisting;};
@ -311,13 +317,13 @@ typedef struct sharedSlsDetector {
Should be implemented in the specific detector class Should be implemented in the specific detector class
/sa mythenDetector::dumpDetectorSetup /sa mythenDetector::dumpDetectorSetup
*/ */
virtual int dumpDetectorSetup(string const fname)=0; virtual int dumpDetectorSetup(string const fname, int level)=0;
/** /**
Purely virtual function Purely virtual function
Should be implemented in the specific detector class Should be implemented in the specific detector class
/sa mythenDetector::retrieveDetectorSetup /sa mythenDetector::retrieveDetectorSetup
*/ */
virtual int retrieveDetectorSetup(string const fname)=0; virtual int retrieveDetectorSetup(string const fname, int level)=0;
/** /**
configure the socket communication and initializes the socket instances configure the socket communication and initializes the socket instances
@ -350,9 +356,21 @@ typedef struct sharedSlsDetector {
\param point to the array that will contain the trim energies (in ev) \param point to the array that will contain the trim energies (in ev)
\returns number of trim energies \returns number of trim energies
unused!
\sa 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);}; 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
\returns number of trim energies
unused!
\sa sharedSlsDetector
*/
int setTrimEn(int nen, int *en=NULL) {if (en) {for (int ien=0; ien<nen; ien++) thisDetector->trimEnergies[ien]=en[ien]; thisDetector->nTrimEn=nen;} return (thisDetector->nTrimEn);};
/** /**
Pure virtual function Pure virtual function
@ -376,6 +394,19 @@ typedef struct sharedSlsDetector {
*/ */
virtual int writeTrimFile(string fname, sls_detector_module mod)=0; virtual int writeTrimFile(string fname, sls_detector_module mod)=0;
/**
returns currently the loaded trimfile name
*/
const char *getTrimFile(){\
string s(thisDetector->trimFile); \
if (s.length()>6) {\
if (s.substr(s.length()-6,3)==string(".sn") && s.substr(s.length()-3)!=string("xxx") ) \
return s.substr(0,s.length()-6).c_str(); \
} \
return thisDetector->trimFile;\
};
/** /**
Pure virtual function Pure virtual function
writes a trim file for module number imod - the values will be read from the current detector structure writes a trim file for module number imod - the values will be read from the current detector structure
@ -491,7 +522,7 @@ typedef struct sharedSlsDetector {
returns the location of the calibration files returns the location of the calibration files
\sa sharedSlsDetector \sa sharedSlsDetector
*/ */
char* getCalDir() {cout << "cal dir is " << thisDetector->calDir; return thisDetector->calDir;}; char* getCalDir() {return thisDetector->calDir;};
/** /**
@ -867,7 +898,7 @@ typedef struct sharedSlsDetector {
/** /**
start detector acquisition and read all data putting them a data queue start detector acquisition and read all data putting them a data queue
\returns pointer to the fron tof the data queue \returns pointer to the front of the data queue
\sa startAndReadAllNoWait getDataFromDetector dataQueue \sa startAndReadAllNoWait getDataFromDetector dataQueue
*/ */
int* startAndReadAll(); int* startAndReadAll();
@ -886,8 +917,8 @@ typedef struct sharedSlsDetector {
int* getDataFromDetectorNoWait(); int* getDataFromDetectorNoWait();
/** /**
asks and receives a data frame from the detector asks and receives a data frame from the detector and puts it in the data queue
\returns pointer to the data or NULL. If NULL disconnects the socket \returns pointer to the data or NULL.
\sa getDataFromDetector \sa getDataFromDetector
*/ */
int* readFrame(); int* readFrame();
@ -975,7 +1006,16 @@ typedef struct sharedSlsDetector {
int executeTrimming(trimMode mode, int par1, int par2, int imod=-1); int executeTrimming(trimMode mode, int par1, int par2, int imod=-1);
//Corrections //Corrections
/**
set/get if the data processing and file writing should be done by a separate thread
s
\param b 0 sequencial data acquisition and file writing, 1 separate thread, -1 get
\returns thread flag
*/
int setThreadedProcessing(int b=-1) {if (b>=0) thisDetector->threadedProcessing=b; return thisDetector->threadedProcessing;}
/** /**
set flat field corrections set flat field corrections
@ -992,6 +1032,12 @@ typedef struct sharedSlsDetector {
*/ */
int getFlatFieldCorrection(float *corr=NULL, float *ecorr=NULL); int getFlatFieldCorrection(float *corr=NULL, float *ecorr=NULL);
/**
get flat field corrections file name
\returns flat field correction file name
*/
char *getFlatFieldCorrectionFile(){return thisDetector->flatFieldFile;};
/** /**
set rate correction 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 \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
@ -1028,7 +1074,7 @@ typedef struct sharedSlsDetector {
int getBadChannelCorrection(int *bad=NULL); int getBadChannelCorrection(int *bad=NULL);
/** returns the bad channel list file */ /** returns the bad channel list file */
char *getBadChannelCorrectionFile() {return thisDetector->badChanFile;}; string getBadChannelCorrectionFile() {if (thisDetector->correctionMask&(1<< DISCARD_BAD_CHANNELS)) return string(thisDetector->badChanFile); else return string("none");};
/** /**
@ -1055,7 +1101,7 @@ typedef struct sharedSlsDetector {
pure virtual function pure virtual function
returns the angular conversion file returns the angular conversion file
\sa mythenDetector::getAngularConversion */ \sa mythenDetector::getAngularConversion */
virtual char *getAngularConversion()=0; virtual string getAngularConversion()=0;
/** /**
pure virtual function pure virtual function
@ -1259,10 +1305,10 @@ typedef struct sharedSlsDetector {
*/ */
sharedSlsDetector *thisDetector; sharedSlsDetector *thisDetector;
/** // /**
\sa setOnline // \sa setOnline
*/ // */
int onlineFlag; //int onlineFlag;
/** /**
detector ID detector ID
@ -1405,9 +1451,9 @@ typedef struct sharedSlsDetector {
int receiveModule(sls_detector_module*); int receiveModule(sls_detector_module*);
/** /**
start data processing threas start data processing thread
*/ */
void startThread(); //void startThread();
/** /**
fill bad channel mask (0 if channel is good, 1 if bad) fill bad channel mask (0 if channel is good, 1 if bad)