diff --git a/slsDetectorSoftware/Makefile b/slsDetectorSoftware/Makefile index 7d14790f7..ce7457b41 100644 --- a/slsDetectorSoftware/Makefile +++ b/slsDetectorSoftware/Makefile @@ -1,11 +1,11 @@ CFLAGS= -DC_ONLY FLAGS=-DVERBOSE -INCLUDES= -I commonFiles -I slsDetector -I MySocketTCP -I usersFunctions #-I multiSlsDetector +INCLUDES= -IcommonFiles -IslsDetector -IMySocketTCP -IusersFunctions -ImultiSlsDetector -IslsDetectorUtils -IslsDetectorCommand #-I eigerDetector -ImythenDetector -IgotthardDetector #EPICSFLAGS=-D EPICS -I/usr/local/epics/base/include/ -I /usr/local/epics/base/include/os/Linux/ -L /usr/local/epics/base/lib/SL5-x86/ -Wl,-R/usr/local/epics/base/lib/SL5-x86 -lca -lCom -SRC_CLNT= slsDetector/slsDetector.cpp MySocketTCP/MySocketTCP.cxx usersFunctions/usersFunctions.c #multiSlsDetector/multiSlsDetector.cpp +SRC_CLNT= slsDetector/slsDetector.cpp MySocketTCP/MySocketTCP.cxx usersFunctions/usersFunctions.c multiSlsDetector/multiSlsDetector.cpp slsDetector/slsDetectorUtils.cpp slsDetector/slsDetectorCommand.cpp #mythenDetector/mythenDetector.cpp eigerDetector/eigerDetector.cpp gotthardDetector/gotthardDetector.cpp SRC_MYTHEN_SVC = mythenDetectorServer/server.c mythenDetectorServer/server_funcs.c mythenDetectorServer/communication_funcs.c mythenDetectorServer/firmware_funcs.c mythenDetectorServer/mcb_funcs.c mythenDetectorServer/trimming_funcs.c #mythenDetectorServer/sharedmemory.c @@ -28,22 +28,20 @@ picassoServer: $(SRC_MYTHEN_SVC) -package: $(SRC_CLNT) -# $(CXX) -fPIC -g -o objs/multiSlsDetector.o -c -Wall multiSlsDetector/multiSlsDetector.cpp $(INCLUDES) $(FLAGS) - $(CXX) -fPIC -g -o objs/slsDetector.o -c -Wall slsDetector/slsDetector.cpp $(INCLUDES) $(FLAGS) -# $(CXX) -fPIC -g -o objs/eigerDetector.o -c -Wall eigerDetector/eigerDetector.cpp $(INCLUDES) $(FLAGS) -# $(CXX) -fPIC -g -o objs/mythenDetector.o -c -Wall mythenDetector/mythenDetector.cpp $(INCLUDES) $(FLAGS) -# $(CXX) -fPIC -g -o objs/gotthardDetector.o -c -Wall gotthardDetector/gotthardDetector.cpp $(INCLUDES) $(FLAGS) +package: $(SRC_CLNT) + $(CXX) -fPIC -g -o objs/slsDetectorCommand.o -c -Wall slsDetector/slsDetectorCommand.cpp $(INCLUDES) $(FLAGS) + $(CXX) -fPIC -g -o objs/slsDetectorUtils.o -c -Wall slsDetector/slsDetectorUtils.cpp $(INCLUDES) $(FLAGS) + $(CXX) -fPIC -g -o objs/slsDetector.o -c -Wall slsDetector/slsDetector.cpp $(INCLUDES) $(FLAGS) + $(CXX) -fPIC -g -o objs/multiSlsDetector.o -c -Wall multiSlsDetector/multiSlsDetector.cpp $(INCLUDES) $(FLAGS) $(CXX) -fPIC -g -o objs/usersFunctions.o -c -Wall usersFunctions/usersFunctions.c $(INCLUDES) $(FLAGS) $(EPICSFLAGS) $(CXX) -fPIC -g -o objs/MySocketTCP.o -c -Wall MySocketTCP/MySocketTCP.cpp $(INCLUDES) $(FLAGS) # $(CXX) -fPIC -g -o objs/multiSDetector.o -c -Wall multiSlsDetector/multiSlsDetector.cpp $(INCLUDES) $(FLAGS) # $(CXX) -shared -Wl,-soname,libSlsDetector.so.1 -o libSlsDetector.so.1.0.1 objs/slsDetector.o objs/usersFunctions.o objs/MySocketTCP.o objs/multiSDetector.o -lc $(INCLUDES) $(FLAGS) $(EPICSFLAGS) - $(CXX) -shared -Wl,-soname,libSlsDetector.so.1 -o libSlsDetector.so.1.0.1 objs/slsDetector.o objs/usersFunctions.o objs/MySocketTCP.o -lc $(INCLUDES) $(FLAGS) $(EPICSFLAGS) + $(CXX) -shared -Wl,-soname,libSlsDetector.so.1 -o libSlsDetector.so.1.0.1 objs/slsDetector.o objs/slsDetectorUtils.o objs/slsDetectorCommand.o objs/multiSlsDetector.o objs/usersFunctions.o objs/MySocketTCP.o -lc $(INCLUDES) $(FLAGS) $(EPICSFLAGS) #objs/mythenDetector.o objs/gotthardDetector.o - ln -sf libSlsDetector.so.1.0.1 libSlsDetector.so + ln -sf libSlsDetector.so libSlsDetector.so.1.0.1 ln -sf libSlsDetector.so.1 libSlsDetector.so - ar rcs libSlsDetector.a objs/slsDetector.o objs/usersFunctions.o objs/MySocketTCP.o #objs/multiSlsDetector.o -#objs/mythenDetector.o objs/gotthardDetector.o + ar rcs libSlsDetector.a objs/slsDetector.o objs/usersFunctions.o objs/MySocketTCP.o objs/multiSlsDetector.o objs/slsDetectorUtils.o objs/slsDetectorCommand.o clean: rm -rf libSlsDetector.so.1.0.1 libSlsDetector.so core objs/* docs/* @@ -64,6 +62,9 @@ install_inc: # cp -P ../slsDetectorSoftware/mythenDetector/mythenDetector.h $(DESTDIR) # cp -P ../slsDetectorSoftware/gotthardDetector/gotthardDetector.h $(DESTDIR) cp -P ../slsDetectorSoftware/slsDetector/slsDetector.h $(DESTDIR) + cp -P ../slsDetectorSoftware/slsDetector/slsDetectorUtils.h $(DESTDIR) + cp -P ../slsDetectorSoftware/slsDetector/slsDetectorCommand.h $(DESTDIR) + cp -P ../slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h $(DESTDIR) cp -P ../slsDetectorSoftware/commonFiles/sls_detector_defs.h $(DESTDIR) cp -P ../slsDetectorSoftware/usersFunctions/usersFunctions.h $(DESTDIR) diff --git a/slsDetectorSoftware/commonFiles/sls_detector_defs.h b/slsDetectorSoftware/commonFiles/sls_detector_defs.h index 9ce6d4fd6..c4d911cc6 100755 --- a/slsDetectorSoftware/commonFiles/sls_detector_defs.h +++ b/slsDetectorSoftware/commonFiles/sls_detector_defs.h @@ -3,8 +3,16 @@ #include +/** default maximum string length */ +#define MAX_STR_LENGTH 1000 +/** default maximum string length */ +#define MAX_SCAN_STEPS 2000 + + typedef float float32_t; -typedef int int32_t; +typedef int int32_t; +typedef char mystring[MAX_STR_LENGTH]; +typedef float mysteps[MAX_SCAN_STEPS]; /** \file sls_detector_defs.h @@ -17,11 +25,14 @@ and to the server programs running on the detector * @see slsDetector */ -/** default maximum string length */ -#define MAX_STR_LENGTH 1000 /** get flag form most functions */ #define GET_FLAG -1 + +enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript, MAX_ACTIONS}; + + + /** structure for a detector channel should not be used by unexperienced users @@ -100,7 +111,6 @@ typedef struct { */ typedef struct { - int len; /**< is the number of elements of the array */ int *iptr; /**< is the pointer to the array */ } iarray ; @@ -128,6 +138,37 @@ enum communicationProtocol{ UDP /**< UDP */ }; +/** + Communication protocol (normally TCP) +*/ +enum networkParameter { + CLIENT_IP, /**< client IP */ + CLIENT_MAC, /**< client mac */ + SERVER_MAC /**< server MAC */ +}; + + /** + type of action performed (for text client) + */ +enum {GET_ACTION, PUT_ACTION, READOUT_ACTION, HELP_ACTION}; + +/** online flags enum \sa setOnline*/ +enum {GET_ONLINE_FLAG=-1, /**< returns wether the detector is in online or offline state */ + OFFLINE_FLAG=0, /**< detector in offline state (i.e. no communication to the detector - using only local structure - no data acquisition possible!) */ + ONLINE_FLAG =1/**< detector in online state (i.e. communication to the detector updating the local structure) */ +}; + + /** synchronization of the various detectors (should be set for each detector individually?!?!?) */ + + enum synchronizationMode { + GET_SYNCHRONIZATION_MODE=-1, /**< the multidetector will return its synchronization mode */ + NONE, /**< all detectors are independent (no cabling) */ + MASTER_GATES, /**< the master gates the other detectors */ + MASTER_TRIGGERS, /**< the master triggers the other detectors */ + SLAVE_STARTS_WHEN_MASTER_STOPS /**< the slave acquires when the master finishes, to avoid deadtime */ + }; + + /** flags to get (or set) the size of the detector diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index 55bc7fe73..fc1640f70 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -11,6 +11,7 @@ ID: $Id$ #include "multiSlsDetector.h" +#include "slsDetector.h" #include "usersFunctions.h" #include #include @@ -82,7 +83,7 @@ int multiSlsDetector::initSharedMemory(int id=0) { -multiSlsDetector::multiSlsDetector(int id) : shmId(-1) +multiSlsDetector::multiSlsDetector(int id) : slsDetectorUtils(), shmId(-1) { while (shmId<0) { shmId=initSharedMemory(id); @@ -92,7 +93,7 @@ multiSlsDetector::multiSlsDetector(int id) : shmId(-1) if (thisMultiDetector->alreadyExisting==0) { - thisMultiDetector->onlineFlag = slsDetector::ONLINE_FLAG; + thisMultiDetector->onlineFlag = ONLINE_FLAG; thisMultiDetector->numberOfDetectors=0; for (int id=0; iddetectorIds[id]=-1; @@ -103,12 +104,85 @@ multiSlsDetector::multiSlsDetector(int id) : shmId(-1) thisMultiDetector->dataBytes=0; thisMultiDetector->numberOfChannels=0; + + + + /** set trimDsdir, calDir and filePath to default to home directory*/ + strcpy(thisMultiDetector->filePath,getenv("HOME")); + /** set fileName to default to run*/ + strcpy(thisMultiDetector->fileName,"run"); + /** set fileIndex to default to 0*/ + thisMultiDetector->fileIndex=0; + /** set progress Index to default to 0*/ + thisMultiDetector->progressIndex=0; + /** set total number of frames to be acquired to default to 1*/ + thisMultiDetector->totalProgress=1; + + + + + /** set correction mask to 0*/ + thisMultiDetector->correctionMask=0; + /** set deat time*/ + thisMultiDetector->tDead=0; + /** sets bad channel list file to none */ + strcpy(thisMultiDetector->badChanFile,"none"); + /** sets flat field correction directory */ + strcpy(thisMultiDetector->flatFieldDir,getenv("HOME")); + /** sets flat field correction file */ + strcpy(thisMultiDetector->flatFieldFile,"none"); + /** set angular direction to 1*/ + thisMultiDetector->angDirection=1; + /** set fine offset to 0*/ + thisMultiDetector->fineOffset=0; + /** set global offset to 0*/ + thisMultiDetector->globalOffset=0; + + + + /** set threshold to -1*/ + thisMultiDetector->currentThresholdEV=-1; + // /** set clockdivider to 1*/ + // thisMultiDetector->clkDiv=1; + /** set number of positions to 0*/ + thisMultiDetector->numberOfPositions=0; + /** sets angular conversion file to none */ + strcpy(thisMultiDetector->angConvFile,"none"); + /** set binsize*/ + thisMultiDetector->binSize=0; + thisMultiDetector->stoppedFlag=0; + + thisMultiDetector->actionMask=0; + + + for (int ia=0; iaactionMode[ia]=0; + strcpy(thisMultiDetector->actionScript[ia],"none"); + strcpy(thisMultiDetector->actionParameter[ia],"none"); + } + + + for (int iscan=0; iscanscanMode[iscan]=0; + strcpy(thisMultiDetector->scanScript[iscan],"none"); + strcpy(thisMultiDetector->scanParameter[iscan],"none"); + thisMultiDetector->nScanSteps[iscan]=0; + thisMultiDetector->scanPrecision[iscan]=0; + } + + + + + thisMultiDetector->alreadyExisting=1; } for (int i=0; inumberOfDetectors; i++) { +#ifdef VERBOSE cout << thisMultiDetector->detectorIds[i] << endl; +#endif detectors[i]=new slsDetector(thisMultiDetector->detectorIds[i]); } for (int i=thisMultiDetector->numberOfDetectors; ilastPID=getpid(); + getPointers(&thisMultiDetector->stoppedFlag, \ + &thisMultiDetector->threadedProcessing, \ + &thisMultiDetector->actionMask, \ + thisMultiDetector->actionScript, \ + thisMultiDetector->actionParameter, \ + thisMultiDetector->nScanSteps, \ + thisMultiDetector->scanMode, \ + thisMultiDetector->scanScript, \ + thisMultiDetector->scanParameter, \ + thisMultiDetector->scanSteps, \ + thisMultiDetector->scanPrecision, \ + &thisMultiDetector->numberOfPositions, \ + thisMultiDetector->detPositions, \ + thisMultiDetector->angConvFile, \ + &thisMultiDetector->correctionMask, \ + &thisMultiDetector->binSize, \ + &thisMultiDetector->fineOffset, \ + &thisMultiDetector->globalOffset, \ + &thisMultiDetector->angDirection, \ + thisMultiDetector->flatFieldDir, \ + thisMultiDetector->flatFieldFile, \ + thisMultiDetector->badChanFile, \ + thisMultiDetector->timerValue, \ + &thisMultiDetector->currentSettings, \ + &thisMultiDetector->currentThresholdEV, \ + thisMultiDetector->filePath, \ + thisMultiDetector->fileName, \ + &thisMultiDetector->fileIndex); + + +#ifdef VERBOSE + cout << "filling bad channel mask" << endl; +#endif + /** fill the BadChannelMask \sa fillBadChannelMask */ + fillBadChannelMask(); + +#ifdef VERBOSE + cout << "done" << endl; +#endif } @@ -126,9 +239,14 @@ multiSlsDetector::~multiSlsDetector() { } -int multiSlsDetector::addSlsDetector(int id, int pos, int ox, int oy) { +int multiSlsDetector::addSlsDetector(int id, int pos) { int j=thisMultiDetector->numberOfDetectors; + + if (slsDetector::exists(id)==0) { + cout << "Detector " << id << " does not exist - You should first create it to determine type etc." << endl; + } + #ifdef VERBOSE cout << "Adding detector " << id << " in position " << pos << endl; #endif @@ -140,6 +258,21 @@ int multiSlsDetector::addSlsDetector(int id, int pos, int ox, int oy) { pos=thisMultiDetector->numberOfDetectors; + + //check that it is not already in the list + + for (int i=0; inumberOfDetectors; i++) { + //check that it is not already in the list, in that case move to new position + if (detectors[i]) { + if (detectors[i]->getDetectorId()==id) { + cout << "Detector " << id << "already part of the multiDetector in position " << i << "!" << endl << "Remove it before adding it back in a new position!"<< endl; + return -1; + } + } + } + + + if (pos!=thisMultiDetector->numberOfDetectors) { for (int ip=thisMultiDetector->numberOfDetectors-1; ip>=pos; ip--) { #ifdef VERBOSE @@ -153,8 +286,6 @@ int multiSlsDetector::addSlsDetector(int id, int pos, int ox, int oy) { cout << "Creating new detector " << pos << endl; #endif - - // detectorType t=slsDetector::getDetectorType(id); detectors[pos]=new slsDetector(id); thisMultiDetector->detectorIds[pos]=detectors[pos]->getDetectorId(); thisMultiDetector->numberOfDetectors++; @@ -177,6 +308,158 @@ int multiSlsDetector::addSlsDetector(int id, int pos, int ox, int oy) { } + +string multiSlsDetector::setHostname(char* name, int pos){ + + int id=0; + string s; + if (pos>=0) { + addSlsDetector(name, pos); + if (detectors[pos]) + return detectors[pos]->getHostname(); + } else { + size_t p1=0; + s=string(name); + size_t p2=s.find('+',p1); + char hn[1000]; + while (p2!=string::npos) { + + strcpy(hn,s.substr(p1,p2-p1).c_str()); + addSlsDetector(hn, pos); + s=s.substr(p2+1); + p2=s.find('+'); + } + } + return getHostname(pos); +} + + +string multiSlsDetector::getHostname(int pos) { + +#ifdef VERBOSE + cout << "returning hostname" << pos << endl; +#endif + if (pos>=0) { + if (detectors[pos]) + return detectors[pos]->getHostname(); + } else { + string s=string(""); + for (int ip=0; ipnumberOfDetectors; ip++) { +#ifdef VERBOSE + cout << "detector " << ip << endl; +#endif + if (detectors[ip]) { + s+=detectors[ip]->getHostname(); + s+=string("+"); + } +#ifdef VERBOSE + cout << "hostname " << s << endl; +#endif + } + return s; + } +} + +int multiSlsDetector::getDetectorId(int pos) { + +#ifdef VERBOSE + cout << "Getting detector ID " << pos << endl; +#endif + + if (pos>=0) { + if (detectors[pos]) + return detectors[pos]->getDetectorId(); + } + return -1; +} + + + +int multiSlsDetector::setDetectorId(int ival, int pos){ + + if (pos>=0) { + addSlsDetector(ival, pos); + if (detectors[pos]) + return detectors[pos]->getDetectorId(); + } else { + return -1; + } + + +} + + +int multiSlsDetector::addSlsDetector(char *name, int pos) { + + + detectorType t=GENERIC; + slsDetector *s=NULL; + int id; +#ifdef VERBOSE + cout << "Adding detector "<numberOfDetectors; i++) { + if (detectors[i]) { + if (detectors[i]->getHostname()==string(name)) { + cout << "Detector " << name << "already part of the multiDetector in position " << i << "!" << endl<< "Remove it before adding it back in a new position!"<< endl; + return -1; + } + } + } + + //checking that the detector doesn't already exists + + for (id=0; id0) { + s=new slsDetector(id); + if (s->getHostname()==string(name)) + break; + delete s; + s=NULL; + id++; + } + } + + if (s==NULL) { + t=slsDetector::getDetectorType(name, DEFAULT_PORTNO); + if (t==GENERIC) { + cout << "Detector " << name << "does not exist in shared memory and could not connect to it to determine the type!" << endl; + return -1; + } + //#ifdef VERBOSE + else + cout << "Detector type is " << t << endl; + //#endif + + for (id=0; idsetTCPSocket(name); + delete s; + } + + return addSlsDetector(id, pos); + + + } + + + + + + + + + + + int multiSlsDetector::getDetectorOffset(int pos, int &ox, int &oy) { ox=-1; oy=-1; @@ -210,6 +493,17 @@ int multiSlsDetector::setDetectorOffset(int pos, int ox, int oy) { +int multiSlsDetector::removeSlsDetector(char *name){ + for (int id=0; idnumberOfDetectors; id++) { + if (detectors[id]) { + if (detectors[id]->getHostname()==string(name)) { + removeSlsDetector(id); + } + } + } + return thisMultiDetector->numberOfDetectors; +}; + @@ -325,9 +619,6 @@ int multiSlsDetector::setMaster(int i) { // MASTER_TRIGGERS, /**< the master triggers the other detectors */ // SLAVE_STARTS_WHEN_MASTER_STOPS /**< the slave acquires when the master finishes, to avoid deadtime */ // } - - - /** Sets/gets the synchronization mode of the various detectors @@ -433,7 +724,7 @@ synchronizationMode multiSlsDetector::setSynchronization(synchronizationMode syn int multiSlsDetector::setOnline(int off) { - if (off!=slsDetector::GET_ONLINE_FLAG) { + if (off!=GET_ONLINE_FLAG) { thisMultiDetector->onlineFlag=off; for (int i=0; inumberOfDetectors+1; i++) { if (detectors[i]) @@ -451,28 +742,6 @@ int multiSlsDetector::exists() { - /* I/O */ - -/* generates file name without extension*/ - -string multiSlsDetector::createFileName() { - return slsDetector::createFileName(thisMultiDetector->filePath, thisMultiDetector->fileName, thisMultiDetector->actionMask, currentScanVariable[0], thisMultiDetector->scanPrecision[0], currentScanVariable[1], thisMultiDetector->scanPrecision[1], currentPositionIndex, thisMultiDetector->numberOfPositions, thisMultiDetector->fileIndex); - -} - -/* I/O */ - - - -int multiSlsDetector::getFileIndexFromFileName(string fname) { - return slsDetector::getFileIndexFromFileName(fname); -} - -int multiSlsDetector::getVariablesFromFileName(string fname, int &index, int &p_index, float &sv0, float &sv1) { - return slsDetector::getVariablesFromFileName(fname, index, p_index, sv0, sv1); -} - - @@ -778,7 +1047,7 @@ int* multiSlsDetector::readAll(){ #ifdef VERBOSE std::cout<< "Reading all frames "<< std::endl; #endif - if (thisMultiDetector->onlineFlag==slsDetector::ONLINE_FLAG) { + if (thisMultiDetector->onlineFlag==ONLINE_FLAG) { for (int id=0; idnumberOfDetectors; id++) { if (detectors[id]) { @@ -813,7 +1082,7 @@ int* multiSlsDetector::startAndReadAll(){ int* retval; int i=0; - if (thisMultiDetector->onlineFlag==slsDetector::ONLINE_FLAG) { + if (thisMultiDetector->onlineFlag==ONLINE_FLAG) { startAndReadAllNoWait(); @@ -869,6 +1138,32 @@ int multiSlsDetector::startAndReadAllNoWait(){ } +/** + get run status + \returns status mask +*/ +runStatus multiSlsDetector::getRunStatus() { + + runStatus s,s1; + + if (thisMultiDetector->masterPosition>=0) + if (detectors[thisMultiDetector->masterPosition]) + return detectors[thisMultiDetector->masterPosition]->getRunStatus(); + + + if (detectors[0]) s=detectors[0]->getRunStatus(); + + for (int i=0; inumberOfDetectors; i++) { + s1=detectors[i]->getRunStatus(); + if (s1==ERROR) + s=ERROR; + if (s1==IDLE && s!=IDLE) + s=ERROR; + + } + return s; +} + int* multiSlsDetector::popDataQueue() { int *retval=NULL; @@ -978,76 +1273,68 @@ int64_t multiSlsDetector::setTimer(timerIndex index, int64_t t){ return ret1; }; - - - - - - - - - - - - - - - - - - - - - -// int64_t multiSlsDetector::getTimeLeft(timerIndex index){ + +int64_t multiSlsDetector::getTimeLeft(timerIndex index){ + int i; + int64_t ret1=-100, ret; -// int fnum=F_GET_TIME_LEFT; -// int64_t retval; -// char mess[100]; -// int ret=OK; - -// #ifdef VERBOSE -// std::cout<< "Getting timer "<< index << std::endl; -// #endif -// if (thisDetector->onlineFlag==ONLINE_FLAG) { -// // if (controlSocket) { -// // if (controlSocket->Connect()>=0) { -// // controlSocket->SendDataOnly(&fnum,sizeof(fnum)); -// // controlSocket->SendDataOnly(&index,sizeof(index)); -// // controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); -// // if (ret!=OK) { -// // controlSocket->ReceiveDataOnly(mess,sizeof(mess)); -// // std::cout<< "Detector returned error: " << mess << std::endl; -// // } else { -// // controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); -// // // thisDetector->timerValue[index]=retval; -// // } -// // controlSocket->Disconnect(); -// // } -// // } -// if (stopSocket) { -// if (stopSocket->Connect()>=0) { -// stopSocket->SendDataOnly(&fnum,sizeof(fnum)); -// stopSocket->SendDataOnly(&index,sizeof(index)); -// stopSocket->ReceiveDataOnly(&ret,sizeof(ret)); -// if (ret!=OK) { -// stopSocket->ReceiveDataOnly(mess,sizeof(mess)); -// std::cout<< "Detector returned error: " << mess << std::endl; -// } else { -// stopSocket->ReceiveDataOnly(&retval,sizeof(retval)); -// // thisDetector->timerValue[index]=retval; -// } -// stopSocket->Disconnect(); -// } -// } -// } -// #ifdef VERBOSE -// std::cout<< "Time left is "<< retval << std::endl; -// #endif -// return retval; + if (thisMultiDetector->masterPosition>=0) + if (detectors[thisMultiDetector->masterPosition]) + return detectors[thisMultiDetector->masterPosition]->getTimeLeft(index); -// }; + + for (i=0; inumberOfDetectors; i++) { + if (detectors[i]) { + ret=detectors[i]->getTimeLeft(index); + if (ret1==-100) + ret1=ret; + else if (ret!=ret1) + ret1=-1; + } + } + + return ret1; + +} + + + +int multiSlsDetector::setSpeed(speedVariable index, int value){ + int i; + int64_t ret1=-100, ret; + + + + for (i=0; inumberOfDetectors; i++) { + if (detectors[i]) { + ret=detectors[i]->setSpeed(index,value); + if (ret1==-100) + ret1=ret; + else if (ret!=ret1) + ret1=FAIL; + } + } + + return ret1; + +} + + + + + + + + + + + + + + + + // Flags @@ -1063,7 +1350,7 @@ int multiSlsDetector::setDynamicRange(int n, int pos){ imi=pos; ima=pos+1; } - + for (i=imi; idataBytes-=detectors[i]->getDataBytes(); @@ -1259,6 +1546,26 @@ int multiSlsDetector::setFlatFieldCorrection(string fname){ +int multiSlsDetector::setFlatFieldCorrection(float *corr, float *ecorr) { + int ichdet=0; + float *p, *ep; + for (int idet=0; idetnumberOfDetectors; idet++) { + if (detectors[idet]) { + if (corr!=NULL) + p=corr+ichdet; + else + p=NULL; + if (ecorr!=NULL) + ep=ecorr+ichdet; + else + ep=NULL; + detectors[idet]->setFlatFieldCorrection(p, ep); + ichdet+=detectors[idet]->getNChans()*detectors[idet]->getNChips()*detectors[idet]->getNMods(); + } + } + return 0; +} + @@ -1285,13 +1592,32 @@ int multiSlsDetector::getFlatFieldCorrection(float *corr, float *ecorr) { } } return 0; - } + + + + + + + + + + + + + + + + + + + + int multiSlsDetector::flatFieldCorrect(float datain, float errin, float &dataout, float &errout, float ffcoefficient, float fferr){ - return slsDetector::flatFieldCorrect(datain, errin, dataout, errout, ffcoefficient, fferr); + return flatFieldCorrect(datain, errin, dataout, errout, ffcoefficient, fferr); }; @@ -1358,6 +1684,10 @@ float multiSlsDetector::getRateCorrectionTau(){ std::cout<< "Rate correction is enabled with dead time "<< thisMultiDetector->tDead << std::endl; #endif //which t should we return if they are all different? + + + + return 1; } else #ifdef VERBOSE @@ -1368,10 +1698,6 @@ float multiSlsDetector::getRateCorrectionTau(){ - - - - int multiSlsDetector::getRateCorrection(){ if (thisMultiDetector->correctionMask&(1<badChanFile); - int ret=slsDetector::setBadChannelCorrection(fname, nbad, badlist); - if (ret) { + int ret=setBadChannelCorrection(fname, nbad, badlist); + + if (ret==0) + nbad=0; + + return setBadChannelCorrection(nbad,badlist,0); + +} + + + +int multiSlsDetector::setBadChannelCorrection(int nbad, int *badlist, int ff) { + + + int badlistdet[MAX_BADCHANS]; + int nbaddet=0, choff=0, idet=0; + + if (nbad>0) { thisMultiDetector->correctionMask|=(1<numberOfDetectors; i++) { if (detectors[i]) { @@ -1436,17 +1778,184 @@ int multiSlsDetector::setBadChannelCorrection(string fname){ } } - } else { + } else { nbaddet=0; - for (int i=0; i<numberOfDetectors; i++) { + for (int i=0; inumberOfDetectors; i++) { if (detectors[idet]) { detectors[idet]->setBadChannelCorrection(nbaddet,badlist,0); } } thisMultiDetector->correctionMask&=~(1<correctionMask&(1<correctionMask&=~(1<< ANGULAR_CONVERSION); + //strcpy(thisDetector->angConvFile,"none"); + //#ifdef VERBOSE + std::cout << "Unsetting angular conversion" << std::endl; + //#endif + } else { + if (fname=="default") { + fname=string(thisMultiDetector->angConvFile); + } + + //#ifdef VERBOSE + std::cout << "Setting angular conversion to" << fname << std:: endl; + //#endif + if (readAngularConversion(fname)>=0) { + thisMultiDetector->correctionMask|=(1<< ANGULAR_CONVERSION); + strcpy(thisMultiDetector->angConvFile,fname.c_str()); + } + } + return thisMultiDetector->correctionMask&(1<< ANGULAR_CONVERSION); +} + +int multiSlsDetector::readAngularConversion(string fname) { + + + ifstream infile; + int nm=0; + infile.open(fname.c_str(), ios_base::in); + if (infile.is_open()) { + + for (int idet=0; idetnumberOfDetectors; idet++) { + if (detectors[idet]) { + detectors[idet]->readAngularConversion(infile); + } + } + infile.close(); + } else { + std::cout<< "Could not open calibration file "<< fname << std::endl; + return -1; + } + return 0; + +} + + +int multiSlsDetector::writeAngularConversion(string fname) { + + + ofstream outfile; + int nm=0; + outfile.open(fname.c_str(), ios_base::out); + if (outfile.is_open()) { + + for (int idet=0; idetnumberOfDetectors; idet++) { + if (detectors[idet]) { + detectors[idet]->writeAngularConversion(outfile); + } + } + outfile.close(); + } else { + std::cout<< "Could not open calibration file "<< fname << std::endl; + return -1; + } + return 0; + +} + +int multiSlsDetector::getAngularConversion(int &direction, angleConversionConstant *angconv) { + + int dir=-100, dir1; + angleConversionConstant *a1=angconv; + + for (int idet=0; idetnumberOfDetectors; idet++) { + if (detectors[idet]) { + detectors[idet]->getAngularConversion(dir1,a1); + if (dir==-100) + dir = dir1; + if (dir!=dir1) + dir=0; + if (angconv) { + a1+=detectors[idet]->getNMods(); + } + } + } + direction=dir; + + if (thisMultiDetector->correctionMask&(1<< ANGULAR_CONVERSION)) { + return 1; + } + return 0; + + +} + + + +float multiSlsDetector::setDAC(float val, dacIndex idac, int imod) { + float ret, ret1=-100; + + int id=-1, im=-1; + int dmi=0, dma=thisMultiDetector->numberOfDetectors; + + if (decodeNMod(imod, id, im)>=0) { + dmi=id; + dma=dma+1; + } + + for (int idet=dmi; idetsetDAC(val, idac, im); + if (ret1==-100) + ret1=ret; + else if (ret!=ret1) + ret1=-1; + } + } + return ret1; +} + +float multiSlsDetector::getADC(dacIndex idac, int imod) { + float ret, ret1=-100; + + int id=-1, im=-1; + int dmi=0, dma=thisMultiDetector->numberOfDetectors; + + if (decodeNMod(imod, id, im)>=0) { + dmi=id; + dma=dma+1; + } + + for (int idet=dmi; idetgetADC(idac, im); + if (ret1==-100) + ret1=ret; + else if (ret!=ret1) + ret1=-1; + } + } + return ret1; +} + +int multiSlsDetector::setChannel(long long reg, int ichan, int ichip, int imod) { + int ret, ret1=-100; + int id=-1, im=-1; + int dmi=0, dma=thisMultiDetector->numberOfDetectors; + + if (decodeNMod(imod, id, im)>=0) { + dmi=id; + dma=dma+1; + } + for (int idet=dmi; idetsetChannel(reg, ichan, ichip, im); + if (ret1==-100) + ret1=ret; + else if (ret!=ret1) + ret1=-1; + } + } + return ret1; + } @@ -1454,496 +1963,163 @@ int multiSlsDetector::setBadChannelCorrection(string fname){ +float* multiSlsDetector::convertAngles(float pos) { + float *ang=new float[thisMultiDetector->numberOfChannels]; + + float *p=ang; + int choff=0; + + for (int idet=0; idetnumberOfDetectors; idet++) { + + if (detectors[idet]) { + p=detectors[idet]->convertAngles(pos); + for (int ich=0; ichgetNChans()*detectors[idet]->getNChips()*detectors[idet]->getNMods(); ich++) { + ang[choff+ich]=p[ich]; + } + choff+=detectors[idet]->getNChans()*detectors[idet]->getNChips()*detectors[idet]->getNMods(); + delete [] p; + } + } + return ang; +} int multiSlsDetector::getBadChannelCorrection(int *bad) { - int nbad=0, nbaddet=0, choff=0; - int detbad[MAX_BADCHANS]; + int ichan; + int *bd, nd, ntot=0, choff=0;; + + for (int idet=0; idetnumberOfDetectors; idet++) { - - if (detectors[idet]) { - nbaddet=detectors[idet]->getBadChannelCorrection(detbad); - for (int ich=0; ichgetBadChannelCorrection(); + bd = new int[nd]; + nd=detectors[idet]->getBadChannelCorrection(bd); + for (int id=0; idgetNChans()*detectors[idet]->getNChips()*detectors[idet]->getNMods()) { + if (bad) bad[ntot]=choff+bd[id]; + ntot++; } - choff+=detectors[idet]->getNChans()*detectors[idet]->getNChips()*detectors[idet]->getNMods(); } + choff+=detectors[idet]->getNChans()*detectors[idet]->getNChips()*detectors[idet]->getNMods(); + delete [] bd; + } } - return nbad; + return ntot; + } +int multiSlsDetector::exitServer() { - - - - - - - - /** - set action - \param iaction can be enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript, MAX_ACTIONS} - \param fname for script ("" disable but leaves script unchanged, "none" disables and overwrites) - \returns 0 if action disabled, >0 otherwise - */ -int multiSlsDetector::setAction(int iaction, string fname, string par) { - - if (iaction>=0 && iactionactionMode[iaction]=0; - } else if (fname=="none") { - thisMultiDetector->actionMode[iaction]=0; - strcpy(thisMultiDetector->actionScript[iaction],fname.c_str()); - } else { - strcpy(thisMultiDetector->actionScript[iaction],fname.c_str()); - thisMultiDetector->actionMode[iaction]=1; + int ival=FAIL, iv; + for (int idet=0; idetnumberOfDetectors; idet++) { + if (detectors[idet]) { + iv=detectors[idet]->exitServer(); + if (iv==OK) + ival=iv; } - - if (par!="") { - strcpy(thisMultiDetector->actionParameter[iaction],par.c_str()); - } - - if (thisMultiDetector->actionMode[iaction]) { - -#ifdef VERBOSE - cout << iaction << " " << hex << (1 << iaction) << " " << thisMultiDetector->actionMask << dec; -#endif - - thisMultiDetector->actionMask |= (1 << iaction); - -#ifdef VERBOSE - cout << " set " << hex << thisMultiDetector->actionMask << dec << endl; -#endif - - } else { -#ifdef VERBOSE - cout << iaction << " " << hex << thisMultiDetector->actionMask << dec; -#endif - - thisMultiDetector->actionMask &= ~(1 << iaction); - -#ifdef VERBOSE - cout << " unset " << hex << thisMultiDetector->actionMask << dec << endl; -#endif - } -#ifdef VERBOSE - cout << iaction << " Action mask set to " << hex << thisMultiDetector->actionMask << dec << endl; -#endif - - return thisMultiDetector->actionMode[iaction]; - } else - return -1; -} - - -int multiSlsDetector::setActionScript(int iaction, string fname) { -#ifdef VERBOSE - -#endif - return setAction(iaction,fname,""); -} - - - -int multiSlsDetector::setActionParameter(int iaction, string par) { - if (iaction>=0 && iactionactionParameter[iaction],par.c_str()); - } - - if (thisMultiDetector->actionMode[iaction]) { - thisMultiDetector->actionMask |= (1 << iaction); - } else { - thisMultiDetector->actionMask &= ~(1 << iaction); - } - - return thisMultiDetector->actionMode[iaction]; - } else - return -1; -} - - /** - returns action script - \param iaction can be enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript} - \returns action script - */ -string multiSlsDetector::getActionScript(int iaction){ - if (iaction>=0 && iactionactionScript[iaction]); - else - return string("wrong index"); -}; - - /** - returns action parameter - \param iaction can be enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript} - \returns action parameter - */ -string multiSlsDetector::getActionParameter(int iaction){ - if (iaction>=0 && iactionactionParameter[iaction]); - else - return string("wrong index"); -} - - /** - returns action mode - \param iaction can be enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript} - \returns action mode - */ -int multiSlsDetector::getActionMode(int iaction){ - if (iaction>=0 && iactionactionMode[iaction] << endl; -#endif - return thisMultiDetector->actionMode[iaction]; - } else { -#ifdef VERBOSE - cout << "slsDetetctor : wrong action index " << iaction << endl; -#endif - return -1; } + return ival; } - /** - set scan - \param index of the scan (0,1) - \param fname for script ("" disable) - \returns 0 if scan disabled, >0 otherwise - */ -int multiSlsDetector::setScan(int iscan, string script, int nvalues, float *values, string par, int precision) { - if (iscan>=0 && iscanscanMode[iscan]=0; - } else { - strcpy(thisMultiDetector->scanScript[iscan],script.c_str()); - if (script=="none") { - thisMultiDetector->scanMode[iscan]=0; - } else if (script=="energy") { - thisMultiDetector->scanMode[iscan]=1; - } else if (script=="threshold") { - thisMultiDetector->scanMode[iscan]=2; - } else if (script=="trimbits") { - thisMultiDetector->scanMode[iscan]=3; - } else { - thisMultiDetector->scanMode[iscan]=4; - } - } - + /** returns the detector trimbit/settings directory \sa sharedSlsDetector */ +char* multiSlsDetector::getSettingsDir() { + string s0="", s1="", s; - + char ans[1000]; + for (int idet=0; idetnumberOfDetectors; idet++) { + if (detectors[idet]) { + s=detectors[idet]->getSettingsDir(); - - if (par!="") - strcpy(thisMultiDetector->scanParameter[iscan],par.c_str()); - - if (nvalues>=0) { - if (nvalues==0) - thisMultiDetector->scanMode[iscan]=0; - else { - thisMultiDetector->nScanSteps[iscan]=nvalues; - if (nvalues>MAX_SCAN_STEPS) - thisMultiDetector->nScanSteps[iscan]=MAX_SCAN_STEPS; - } - } - - if (values && thisMultiDetector->scanMode[iscan]>0 ) { - for (int iv=0; ivnScanSteps[iscan]; iv++) { - thisMultiDetector->scanSteps[iscan][iv]=values[iv]; - } - } - - if (precision>=0) - thisMultiDetector->scanPrecision[iscan]=precision; - - if (thisMultiDetector->scanMode[iscan]>0){ - thisMultiDetector->actionMask |= 1<< (iscan+MAX_ACTIONS); - } else { - thisMultiDetector->actionMask &= ~(1 << (iscan+MAX_ACTIONS)); - } - - - - setTotalProgress(); - - - - - - - - - - - return thisMultiDetector->scanMode[iscan]; - } else - return -1; - -} - -int multiSlsDetector::setScanScript(int iscan, string script) { - if (iscan>=0 && iscanscanMode[iscan]=0; - } else { - strcpy(thisMultiDetector->scanScript[iscan],script.c_str()); - if (script=="none") { - thisMultiDetector->scanMode[iscan]=0; - } else if (script=="energy") { - thisMultiDetector->scanMode[iscan]=1; - } else if (script=="threshold") { - thisMultiDetector->scanMode[iscan]=2; - } else if (script=="trimbits") { - thisMultiDetector->scanMode[iscan]=3; - } else { - thisMultiDetector->scanMode[iscan]=4; - } - } - - if (thisMultiDetector->scanMode[iscan]>0){ - thisMultiDetector->actionMask |= (1 << (iscan+MAX_ACTIONS)); - } else { - thisMultiDetector->actionMask &= ~(1 << (iscan+MAX_ACTIONS)); - } - - setTotalProgress(); - - - - - - - - - - - - - - - - - - -#ifdef VERBOSE - cout << "Action mask is " << hex << thisMultiDetector->actionMask << dec << endl; -#endif - return thisMultiDetector->scanMode[iscan]; - - - } else - return -1; - -} - - - -int multiSlsDetector::setScanParameter(int iscan, string par) { - - - if (iscan>=0 && iscanscanParameter[iscan],par.c_str()); - return thisMultiDetector->scanMode[iscan]; - } else - return -1; - -} - - -int multiSlsDetector::setScanPrecision(int iscan, int precision) { - if (iscan>=0 && iscan=0) - thisMultiDetector->scanPrecision[iscan]=precision; - return thisMultiDetector->scanMode[iscan]; - } else - return -1; - -} - -int multiSlsDetector::setScanSteps(int iscan, int nvalues, float *values) { - - if (iscan>=0 && iscan=0) { - if (nvalues==0) - thisMultiDetector->scanMode[iscan]=0; - else { - thisMultiDetector->nScanSteps[iscan]=nvalues; - if (nvalues>MAX_SCAN_STEPS) - thisMultiDetector->nScanSteps[iscan]=MAX_SCAN_STEPS; - } - } - - if (values) { - for (int iv=0; ivnScanSteps[iscan]; iv++) { - thisMultiDetector->scanSteps[iscan][iv]=values[iv]; - } - } - - if (thisMultiDetector->scanMode[iscan]>0){ - thisMultiDetector->actionMask |= (1 << (iscan+MAX_ACTIONS)); - } else { - thisMultiDetector->actionMask &= ~(1 << (iscan+MAX_ACTIONS)); - } - -#ifdef VERBOSE - cout << "Action mask is " << hex << thisMultiDetector->actionMask << dec << endl; -#endif - setTotalProgress(); - - - - - return thisMultiDetector->scanMode[iscan]; - - - } else - return -1; - - - - -} - - - - /** - returns scan script - \param iscan can be (0,1) - \returns scan script - */ -string multiSlsDetector::getScanScript(int iscan){ - if (iscan>=0 && iscanscanMode[iscan]) - return string(thisMultiDetector->scanScript[iscan]); + if (s0=="") + s0=s; else - return string("none"); - } else - return string("wrong index"); - -}; - - /** - returns scan parameter - \param iscan can be (0,1) - \returns scan parameter - */ -string multiSlsDetector::getScanParameter(int iscan){ - if (iscan>=0 && iscanscanMode[iscan]) - return string(thisMultiDetector->scanParameter[iscan]); - else - return string("none"); - } else - return string("wrong index"); -} - - - /** - returns scan mode - \param iscan can be (0,1) - \returns scan mode - */ -int multiSlsDetector::getScanMode(int iscan){ - if (iscan>=0 && iscanscanMode[iscan]; + s0+=string("+")+s; + if (s1=="") + s1=s; + else if (s1!=s) + s1="bad"; + } + } + if (s1=="bad") + strcpy(ans,s0.c_str()); else - return -1; + strcpy(ans,s1.c_str()); + return ans; } - /** - returns scan steps - \param iscan can be (0,1) - \param v is the pointer to the scan steps - \returns scan steps - */ -int multiSlsDetector::getScanSteps(int iscan, float *v) { - if (iscan>=0 && iscannScanSteps[iscan]; iv++) { - v[iv]=thisMultiDetector->scanSteps[iscan][iv]; + /** sets the detector trimbit/settings directory \sa sharedSlsDetector */ +char* multiSlsDetector::setSettingsDir(string s){ + + if (s.find('+')==string::npos) { + for (int idet=0; idetnumberOfDetectors; idet++) { + if (detectors[idet]) { + detectors[idet]->setSettingsDir(s); } } + } else { + size_t p1=0; + size_t p2=s.find('+',p1); + int id=0; + while (p2!=string::npos) { + + if (detectors[id]) { + detectors[id]->setSettingsDir(s.substr(p1,p2-p1)); + } + id++; + s=s.substr(p2+1); + p2=s.find('+'); + if (id>=thisMultiDetector->numberOfDetectors) + break; + } + + } + return getSettingsDir(); - setTotalProgress(); - - if (thisMultiDetector->scanMode[iscan]) - return thisMultiDetector->nScanSteps[iscan]; - else - return 0; - } else - return -1; -} - - -int multiSlsDetector::getScanPrecision(int iscan){ - if (iscan>=0 && iscanscanPrecision[iscan]; - } else - return -1; } -int multiSlsDetector::setTotalProgress() { - int nf=1, npos=1, nscan[MAX_SCAN_LEVELS]={1,1}, nc=1; +int multiSlsDetector::setTrimEn(int ne, int *ene) { + int ret=-100, ret1; - + for (int idet=0; idetnumberOfDetectors; idet++) { + if (detectors[idet]) { + ret1=detectors[idet]->setTrimEn(ne,ene); + if (ret==-100) + ret=ret1; + else if (ret!=ret1) + ret=-1; + } + } + return ret; - - if (thisMultiDetector->timerValue[FRAME_NUMBER]) - nf=thisMultiDetector->timerValue[FRAME_NUMBER]; - - if (thisMultiDetector->timerValue[CYCLES_NUMBER]>0) - nc=thisMultiDetector->timerValue[CYCLES_NUMBER]; - - - - - - - - - if (thisMultiDetector->numberOfPositions>0) - npos=thisMultiDetector->numberOfPositions; - - if ((thisMultiDetector->nScanSteps[0]>0) && (thisMultiDetector->actionMask & (1 << MAX_ACTIONS))) - nscan[0]=thisMultiDetector->nScanSteps[0]; - - if ((thisMultiDetector->nScanSteps[1]>0) && (thisMultiDetector->actionMask & (1 << (MAX_ACTIONS+1)))) - nscan[1]=thisMultiDetector->nScanSteps[1]; - - thisMultiDetector->totalProgress=nf*nc*npos*nscan[0]*nscan[1]; - -#ifdef VERBOSE - cout << "nc " << nc << endl; - cout << "nf " << nf << endl; - cout << "npos " << npos << endl; - cout << "nscan[0] " << nscan[0] << endl; - cout << "nscan[1] " << nscan[1] << endl; - - cout << "Set total progress " << thisMultiDetector->totalProgress << endl; -#endif - return thisMultiDetector->totalProgress; } -float multiSlsDetector::getCurrentProgress() { - return 100.*((float)thisMultiDetector->progressIndex)/((float)thisMultiDetector->totalProgress); +int multiSlsDetector::getTrimEn(int *ene) { + + int ret=-100, ret1; + + for (int idet=0; idetnumberOfDetectors; idet++) { + if (detectors[idet]) { + ret1=detectors[idet]->getTrimEn(ene); + if (ret==-100) + ret=ret1; + else if (ret!=ret1) + ret=-1; + } + } + return ret; + } @@ -1951,206 +2127,552 @@ float multiSlsDetector::getCurrentProgress() { -string multiSlsDetector::executeLine(int narg, char *args[], int action) { - ostringstream os; - string var=string(args[0]), sval; - int ival, ivar; - int id; - int myId=-1; - os << "Executing " ; - for (int ia=0; ianumberOfDetectors; idet++) { + if (detectors[idet]) { + s=detectors[idet]->getCalDir(); + + if (s0=="") + s0=s; + else + s0+=string("+")+s; + if (s1=="") + s1=s; + else if (s1!=s) + s1="bad"; + } + } + if (s1=="bad") + strcpy(ans,s0.c_str()); + else + strcpy(ans,s1.c_str()); + return ans; +} + + + /** + sets the location of the calibration files + \sa sharedSlsDetector + */ +char* multiSlsDetector::setCalDir(string s){ + + if (s.find('+')==string::npos) { + for (int idet=0; idetnumberOfDetectors; idet++) { + if (detectors[idet]) { + detectors[idet]->setCalDir(s); + } + } + } else { + size_t p1=0; + size_t p2=s.find('+',p1); + int id=0; + while (p2!=string::npos) { + + if (detectors[id]) { + detectors[id]->setCalDir(s.substr(p1,p2-p1)); + } + id++; + s=s.substr(p2+1); + p2=s.find('+'); + if (id>=thisMultiDetector->numberOfDetectors) + break; + } + + } + return getCalDir(); + +} + + /** + returns the location of the calibration files + \sa sharedSlsDetector + */ +char* multiSlsDetector::getNetworkParameter(networkParameter p) { + string s0="", s1="",s ; + + char ans[1000]; + for (int idet=0; idetnumberOfDetectors; idet++) { + if (detectors[idet]) { + s=detectors[idet]->getNetworkParameter(p); + + if (s0=="") + s0=s; + else + s0+=string("+")+s; + if (s1=="") + s1=s; + else if (s1!=s) + s1="bad"; + } + } + if (s1=="bad") + strcpy(ans,s0.c_str()); + else + strcpy(ans,s1.c_str()); + return ans; +} + + + /** + sets the location of the calibration files + \sa sharedSlsDetector + */ +char* multiSlsDetector::setNetworkParameter(networkParameter p, string s){ + + if (s.find('+')==string::npos) { + for (int idet=0; idetnumberOfDetectors; idet++) { + if (detectors[idet]) { + detectors[idet]->setNetworkParameter(p,s); + } + } + } else { + size_t p1=0; + size_t p2=s.find('+',p1); + int id=0; + while (p2!=string::npos) { + + if (detectors[id]) { + detectors[id]->setCalDir(s.substr(p1,p2-p1)); + } + id++; + s=s.substr(p2+1); + p2=s.find('+'); + if (id>=thisMultiDetector->numberOfDetectors) + break; + } + + } + return getNetworkParameter(p); + +} + +int multiSlsDetector::setPort(portType t, int p) { + + int ret=-100, ret1; + + for (int idet=0; idetnumberOfDetectors; idet++) { + if (detectors[idet]) { + ret1=detectors[idet]->setPort(t,p); + if (ret==-100) + ret=ret1; + else if (ret!=ret1) + ret=-1; + } + } + return ret; + +} + +int multiSlsDetector::lockServer(int p) { + + int ret=-100, ret1; + + for (int idet=0; idetnumberOfDetectors; idet++) { + if (detectors[idet]) { + ret1=detectors[idet]->lockServer(p); + if (ret==-100) + ret=ret1; + else if (ret!=ret1) + ret=-1; + } + } + + return ret; + +} + +string multiSlsDetector::getLastClientIP() { + string s0="", s1="",s ; + + for (int idet=0; idetnumberOfDetectors; idet++) { + if (detectors[idet]) { + s=detectors[idet]->getLastClientIP(); + + if (s0=="") + s0=s; + else + s0+=string("+")+s; + if (s1=="") + s1=s; + else if (s1!=s) + s1="bad"; + } + } + if (s1=="bad") + return s0; + else + return s1; +} +int multiSlsDetector::setReadOutFlags(readOutFlags flag) { + + int ret=-100, ret1; + + for (int idet=0; idetnumberOfDetectors; idet++) { + if (detectors[idet]) { + ret1=detectors[idet]->setReadOutFlags(flag); + if (ret==-100) + ret=ret1; + else if (ret!=ret1) + ret=-1; + } + } + + return ret; + + +} + + +externalCommunicationMode multiSlsDetector::setExternalCommunicationMode(externalCommunicationMode pol) { + + externalCommunicationMode ret, ret1; + + if (detectors[0]) + ret=detectors[0]->setExternalCommunicationMode(pol); + - - - - - - - - - if (action==slsDetector::READOUT_ACTION) { - os << "Executing readout" << endl; - return string("ok"); + for (int idet=1; idetnumberOfDetectors; idet++) { + if (detectors[idet]) { + ret1=detectors[idet]->setExternalCommunicationMode(pol); + if (ret!=ret1) + ret=GET_EXTERNAL_COMMUNICATION_MODE; + } } + setMaster(); + setSynchronization(); + return ret; + +} - if (var.find("add")==0) { - if (var.size()<=4) - ivar=-1; - else { - //return string("syntax is add:i where i is the detector position"); - istringstream vvstr(var.substr(9)); - vvstr >> ivar; - if (vvstr.fail()) - ivar=-1; //append at the end - //return string("syntax is add:i where i is the detector position"); - } - if (action==slsDetector::PUT_ACTION) { - // if (ivar>thisMultiDetector->numberOfDetectors || ivar<0) { - // ivar=thisMultiDetector->numberOfDetectors; - // cout << "Appending detector " << endl; - //} - if (sscanf(args[1],"%d",&ival)) { - // add by detector id -#ifdef VERBOSE - cout << "Add detector by id " << thisMultiDetector->numberOfDetectors << endl; -#endif - - for (id=0; idnumberOfDetectors; id++) { - //check that it is not already in the list, in that case move to new position - if (detectors[id]) { - if (detectors[id]->getDetectorId()==ival) { - cout << "Detector " << id << "exists!" << endl; - if (id==ivar) - break; - if (id==(thisMultiDetector->numberOfDetectors-1) && ivar==-1) - break; - removeSlsDetector(id); - addSlsDetector(ival, ivar); - break; - } - } - } - if (id==thisMultiDetector->numberOfDetectors) { - if (slsDetector::exists(ivar)==0) { - return string("Detector does not exist - You should first create it to determine type etc."); - } - addSlsDetector(ival, ivar); - } - // if it does not already exist create it - } else { - //add by hostname -#ifdef VERBOSE - cout << "Adding " << args[1] << " in position " << ivar << endl; -#endif +externalSignalFlag multiSlsDetector::setExternalSignalFlags(externalSignalFlag pol, int signalindex) { - for (id=0; idnumberOfDetectors; id++) { - //check that it is not already in the list, in that case move to new position - if (detectors[id]) { -#ifdef VERBOSE - cout << "Detector " << id << " is " << detectors[id]->getHostname() << endl; -#endif - if (detectors[id]->getHostname()==string(args[1])) { -#ifdef VERBOSE - cout << "Detector " << id << " exists!" << endl; -#endif - if (id==ivar) - break; - if (id==(thisMultiDetector->numberOfDetectors-1) && ivar==-1) - break; - myId=detectors[id]->getDetectorId(); - removeSlsDetector(id); - addSlsDetector(myId, ivar); - break; - } - } + externalSignalFlag ret, ret1; + + if (detectors[0]) + ret=detectors[0]->setExternalSignalFlags(pol,signalindex); + + for (int idet=1; idetnumberOfDetectors; idet++) { + if (detectors[idet]) { + ret1=detectors[idet]->setExternalSignalFlags(pol,signalindex); + if (ret!=ret1) + ret=GET_EXTERNAL_SIGNAL_FLAG; + } + } + + setMaster(); + setSynchronization(); + return ret; + + +} + + + + + + + + + + + + +const char * multiSlsDetector::getSettingsFile() { + + string s0="", s1="",s ; + + for (int idet=0; idetnumberOfDetectors; idet++) { + if (detectors[idet]) { + s=detectors[idet]->getSettingsFile(); + + if (s0=="") + s0=s; + else + s0+=string("+")+s; + if (s1=="") + s1=s; + else if (s1!=s) + s1="bad"; + } + } + if (s1=="bad") + return s0.c_str(); + else + return s1.c_str(); + +} + + +int multiSlsDetector::configureMAC(int p) { + + int ret=-100, ret1; + + for (int idet=0; idetnumberOfDetectors; idet++) { + if (detectors[idet]) { + ret1=detectors[idet]->configureMAC(p); + if (ret==-100) + ret=ret1; + else if (ret!=ret1) + ret=-1; + } + } + + return ret; + +} + + +int multiSlsDetector::setDynamicRange(int p) { + + int ret=-100, ret1; + thisMultiDetector->dataBytes=0; + thisMultiDetector->numberOfChannels=0; + + for (int idet=0; idetnumberOfDetectors; idet++) { + if (detectors[idet]) { + ret1=detectors[idet]->setDynamicRange(p); + thisMultiDetector->dataBytes+=detectors[idet]->getDataBytes(); + thisMultiDetector->numberOfChannels+=detectors[idet]->getNChans()*detectors[idet]->getNChips()*detectors[idet]->getNMods(); + if (ret==-100) + ret=ret1; + else if (ret!=ret1) + ret=-1; + } + } + + return ret; + +} + + +int multiSlsDetector::getMaxNumberOfModules(dimension d) { + + int ret=0, ret1; + + for (int idet=0; idetnumberOfDetectors; idet++) { + if (detectors[idet]) { + ret1=detectors[idet]->getMaxNumberOfModules(); + ret+=ret1; + } + } + return ret; + +} + +int multiSlsDetector::setNumberOfModules(int p, dimension d) { + + int ret=0, ret1; + int nm, mm, nt=p; + + thisMultiDetector->dataBytes=0; + thisMultiDetector->numberOfChannels=0; + + for (int idet=0; idetnumberOfDetectors; idet++) { + if (detectors[idet]) { + if (p<0) + nm=p; + else { + mm=detectors[idet]->getMaxNumberOfModules(); + if (nt>mm) { + nm=mm; + nt-=nm; + } else { + nm=nt; + nt-=nm; } - if (id==thisMultiDetector->numberOfDetectors) { - detectorType t=slsDetector::getDetectorType(args[1], DEFAULT_PORTNO); - if (t==GENERIC) - return string("could not connect to detector to determine type"); -#ifdef VERBOSE - else - cout << "Detector type is " << t << endl; -#endif - myId=10; - slsDetector *s=NULL; - while (slsDetector::exists(myId)>0) { - cout << myId << endl; - s=new slsDetector(myId); - if (s->getHostname()==string(args[1])) - break; - delete s; - s=NULL; - myId++; - } - // if it does not already exist create it - if (s==NULL) { -#ifdef VERBOSE - cout << "Creating new detector with id " << myId << endl; -#endif - s=new slsDetector(t, myId); - s->setTCPSocket(args[1]); - delete s; - } - addSlsDetector(myId, ivar); - } - } - + ret+=detectors[idet]->setDynamicRange(nm); + thisMultiDetector->dataBytes+=detectors[idet]->getDataBytes(); + thisMultiDetector->numberOfChannels+=detectors[idet]->getNChans()*detectors[idet]->getNChips()*detectors[idet]->getNMods(); } - - - - - } else if (var.find("hostname")==0) { - - if (var.size()<=9) - return string("syntax is hostname:i where i is the detector id"); - istringstream vvstr(var.substr(9)); - vvstr >> ival; - if (vvstr.fail()) - return string("syntax is hostname:i where i is the detector id"); - if (action==slsDetector::PUT_ACTION) { - sval=string(args[1]); - os << "setting hostname of detector " << ival << " to " << sval << endl; - //cout << slsDetector::getDetectorType(args[1], DEFAULT_PORTNO) << endl; - - //controlla che non esista gia' - // se esiste modifica l'hostname, altrimenti aggiungilo in coda + } + return ret; +} +int multiSlsDetector::decodeNMod(int i, int &id, int &im) { + if (i<0 || i>=setNumberOfModules()) { + id=-1; + im=-1; + return -1; + } + int nm; + for (int idet=0; idetnumberOfDetectors; idet++) { + if (detectors[idet]) { + nm=detectors[idet]->setNumberOfModules(); + if (nm>i) { + id=idet; + im=i; + return im; + } else { + i-=nm; + } + } + } + + id=-1; + im=-1; + return -1; + + +} + + + +int64_t multiSlsDetector::getId(idMode mode, int imod) { + + int id, im; + + if (decodeNMod(imod, id, im)>=0) { + if (detectors[id]) { + return detectors[id]->getId(mode, im); } - os << "getting hostname of detector " << ival << endl; } + return -1; - - - - - - - - return os.str(); } +int multiSlsDetector::digitalTest(digitalTestMode mode, int imod) { + int id, im; -string multiSlsDetector::helpLine(int action) { - ostringstream os; + if (decodeNMod(imod, id, im)>=0) { + if (detectors[id]) { + return detectors[id]->digitalTest(mode, im); + } + } - os << "This is the help line of action " << action << endl; + return -1; - return os.str(); } +int multiSlsDetector::executeTrimming(trimMode mode, int par1, int par2, int imod) { + int id, im, ret; + + + if (decodeNMod(imod, id, im)>=0) { + if (detectors[id]) { + return detectors[id]->executeTrimming(mode, par1, par2, im); + } + } else if (imod<0) { + for (int idet=0; idetnumberOfDetectors; idet++) { + if (detectors[idet]) { + ret=detectors[idet]->executeTrimming(mode, par1, par2, imod); + } + } + return ret; + } + return -1; +} +int multiSlsDetector::loadSettingsFile(string fname, int imod) { + int id, im, ret; + + if (decodeNMod(imod, id, im)>=0) { + if (detectors[id]) { + return detectors[id]->loadSettingsFile(fname, im); + } + } else if (imod<0) { + for (int idet=0; idetnumberOfDetectors; idet++) { + if (detectors[idet]) { + ret=detectors[idet]->loadSettingsFile(fname, imod); + } + } + return ret; + } + return -1; + +} +int multiSlsDetector::saveSettingsFile(string fname, int imod) { + int id, im, ret; + + if (decodeNMod(imod, id, im)>=0) { + if (detectors[id]) { + return detectors[id]->saveSettingsFile(fname, im); + } + } else if (imod<0) { + for (int idet=0; idetnumberOfDetectors; idet++) { + if (detectors[idet]) { + ret=detectors[idet]->saveSettingsFile(fname, imod); + } + } + return ret; + } + return -1; + +} + +int multiSlsDetector::writeRegister(int addr, int val){ + + int imi, ima, i; + int ret, ret1=-100; + + for (i=0; inumberOfDetectors; i++) { + if (detectors[i]) { + ret=detectors[i]->writeRegister(addr,val); + if (ret1==-100) + ret1=ret; + else if (ret!=ret1) + ret1=-1; + } + } + + return ret1; +}; +int multiSlsDetector::readRegister(int addr){ + + int imi, ima, i; + int ret, ret1=-100; + + for (i=0; inumberOfDetectors; i++) { + if (detectors[i]) { + ret=detectors[i]->readRegister(addr); + if (ret1==-100) + ret1=ret; + else if (ret!=ret1) + ret1=-1; + } + } + + return ret1; +}; + + +int multiSlsDetector::readConfigurationFile(string const fname){}; +int multiSlsDetector::writeConfigurationFile(string const fname){}; +int multiSlsDetector::dumpDetectorSetup(string const fname, int level){}; +int multiSlsDetector::retrieveDetectorSetup(string const fname, int level){}; diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h index d8124ee6d..45b743e2e 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h @@ -13,26 +13,17 @@ ID: $Id$ #ifndef MULTI_SLS_DETECTOR_H #define MULTI_SLS_DETECTOR_H -#include "slsDetector.h" +#include "slsDetectorUtils.h" -#include "sls_detector_defs.h" +class slsDetector; + +//#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 */ - }; - - /** @@ -46,7 +37,7 @@ ID: $Id$ */ -class multiSlsDetector { +class multiSlsDetector : public slsDetectorUtils { @@ -98,11 +89,12 @@ class multiSlsDetector { /** timer values */ - int64_t timerValue[MAX_TIMERS]; + int64_t timerValue[MAX_TIMERS]; // needed?!?!?!? + /** detector settings (standard, fast, etc.) */ - detectorSettings currentSettings; + detectorSettings currentSettings; // needed?!?!?!? /** detector threshold (eV) */ - int currentThresholdEV; + int currentThresholdEV; // needed?!?!?!? /** 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 */ @@ -138,8 +130,12 @@ class multiSlsDetector { /** file with the bad channels */ char badChanFile[MAX_STR_LENGTH]; + + /** angular conversion file */ + char angConvFile[MAX_STR_LENGTH]; + /** array of angular conversion constants for each module \see ::angleConversionConstant */ - angleConversionConstant angOff[MAXMODS]; + //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) */ @@ -158,16 +154,16 @@ class multiSlsDetector { int actionMask; - int actionMode[MAX_ACTIONS]; - char actionScript[MAX_ACTIONS][MAX_STR_LENGTH]; - char actionParameter[MAX_ACTIONS][MAX_STR_LENGTH]; + //int actionMode[MAX_ACTIONS]; + mystring actionScript[MAX_ACTIONS]; + mystring actionParameter[MAX_ACTIONS]; int scanMode[MAX_SCAN_LEVELS]; - char scanScript[MAX_SCAN_LEVELS][MAX_STR_LENGTH]; - char scanParameter[MAX_SCAN_LEVELS][MAX_STR_LENGTH]; + mystring scanScript[MAX_SCAN_LEVELS]; + mystring scanParameter[MAX_SCAN_LEVELS]; int nScanSteps[MAX_SCAN_LEVELS]; - float scanSteps[MAX_SCAN_LEVELS][MAX_SCAN_STEPS]; + mysteps scanSteps[MAX_SCAN_LEVELS]; int scanPrecision[MAX_SCAN_LEVELS]; @@ -192,6 +188,19 @@ class multiSlsDetector { public: + + using slsDetectorUtils::flatFieldCorrect; + using slsDetectorUtils::rateCorrect; + using slsDetectorUtils::setBadChannelCorrection; + using slsDetectorUtils::readAngularConversion; + using slsDetectorUtils::writeAngularConversion; + using slsDetectorUtils::resetMerging; + using slsDetectorUtils::finalizeMerging; + using slsDetectorUtils::addToMerging; + using slsDetectorUtils::readDataFile; + using slsDetectorUtils::writeDataFile; + using slsDetectorUtils::createFileName; + /** @short Structure allocated in shared memory to store detector settings and be accessed in parallel by several applications (take care of possible conflicts!) @@ -218,8 +227,14 @@ class multiSlsDetector { /** 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 oX=-1, int oY=-1); + \return the actual number of detectors or -1 if it failed*/ + int addSlsDetector(int id, int pos=-1); + + /** adds the detector with ID id in postion pos + \param name of the detector to be added (should already exist in shared memory or at least be online) + \param pos position where it should be added (normally at the end of the list (default to -1) + \return the actual number of detectors or -1 if it failed*/ + int addSlsDetector(char *name, int pos=-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) @@ -227,17 +242,44 @@ class multiSlsDetector { */ int removeSlsDetector(int pos=-1); + /**removes the detector in position pos from the multidetector + \param name is the name of the detector + \returns the actual number of detectors + */ + int removeSlsDetector(char *name); + + + + + string setHostname(char*, int pos=-1); + + + string getHostname(int pos=-1); + + + + /** adds a detector by id in position pos + \param ival detector id to be added + \param pos position to add it (-1 fails) + \returns detector ID or -1 if detector in position i is empty + */ + int setDetectorId(int ival, int pos=-1); + + + /** returns the id of the detector in position i \param i position of the detector \returns detector ID or -1 if detector in position i is empty*/ - int getDetectorId(int i) {if (i>=0) if (detectors[i]) return detectors[i]->getDetectorId(); else return -1;}; + int getDetectorId(int i); /** returns the number of detectors in the multidetector structure \returns number of detectors */ int getNumberOfDetectors() {return thisMultiDetector->numberOfDetectors;}; + int getTotalNumberOfChannels(){return thisMultiDetector->numberOfChannels;}; + float getScanStep(int index, int istep){return thisMultiDetector->scanSteps[index][istep];}; /** returns the detector offset (in number of channels) \param pos position of the detector \param ox reference to the offset in x @@ -265,21 +307,29 @@ class multiSlsDetector { /** Sets/gets the synchronization mode of the various detectors \param sync syncronization mode - \returns current syncronization mode - */ + \returns current syncronization mode + */ +/* 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 *\/ */ +/* }; */ + synchronizationMode setSynchronization(synchronizationMode sync=GET_SYNCHRONIZATION_MODE); - - /** sets the onlineFlag \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=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() ; + int setOnline(int const online=GET_ONLINE_FLAG); + /** + \returns 1 if the detector structure has already be initlialized with the given id and belongs to this multiDetector instance, 0 otherwise */ + int exists(); + + /** Purely virtual function @@ -306,204 +356,21 @@ class multiSlsDetector { Should be implemented in the specific detector class /sa mythenDetector::dumpDetectorSetup */ - int dumpMultiDetectorSetup(string const fname, int level); + int dumpMultiDetectorSetup(string const fname, int level=0); /** Purely virtual function Should be implemented in the specific detector class /sa mythenDetector::retrieveDetectorSetup */ - int retrieveMultiDetectorSetup(string const fname, int level); - - - /** generates file name without extension - - always appends to file path and file name the run index. - - in case also appends the position index - - Filenames will be of the form: filepath/filename(_px)_i - where x is the position index and i is the run index - \returns file name without extension - \sa slsDetector::createFileName - - */ - string createFileName(); - - /** - function that returns the file index from the file name - \param fname file name - \returns file index - \sa slsDetector::getFileIndexFromFileName - - */ - int getFileIndexFromFileName(string fname) ; - - /** - - function that returns the variables from the file name - \param fname file name - \param index reference to index - \param p_index reference to position index - \param sv0 reference to scan variable 0 - \param sv1 reference to scan variable 1 - \returns file index - \sa slsDetector::getVariablesFromFileName - - */ - int getVariablesFromFileName(string fname, int &index, int &p_index, float &sv0, float &sv1) ; - - - - - - - - - - - - + int retrieveMultiDetectorSetup(string const fname, int level=0); /* I/O */ - - /** - sets the default output files path - \sa sharedMultiSlsDetector - */ - char* setFilePath(string s, int i=-1) {sprintf(thisMultiDetector->filePath, s.c_str()); return thisMultiDetector->filePath;};; - - /** - sets the default output files root name - \sa sharedMultiSlsDetector - */ - char* setFileName(string s, int i=-1){sprintf(thisMultiDetector->fileName, s.c_str()); return thisMultiDetector->fileName;}; - - /** - sets the default output file index - \sa sharedMultiSlsDetector - */ - int setFileIndex(int i, int id=-1){thisMultiDetector->fileIndex=i; return thisMultiDetector->fileIndex;}; - /** - returns the default output files path - \sa sharedMultiSlsDetector - */ - char* getFilePath(int id=-1) {return thisMultiDetector->filePath;}; - - /** - returns the default output files root name - \sa sharedMultiSlsDetector - */ - char* getFileName(int id=-1) {return thisMultiDetector->fileName;}; - - /** - returns the default output file index - \sa sharedMultiSlsDetector - */ - int getFileIndex(int id=-1) {return thisMultiDetector->fileIndex;}; - - - - /** - - writes a data file - \param name of the file to be written - \param data array of data values - \param err array of arrors on the data. If NULL no errors will be written - - \param ang array of angular values. If NULL data will be in the form chan-val(-err) otherwise ang-val(-err) - \param dataformat format of the data: can be 'i' integer or 'f' float (default) - \param nch number of channels to be written to file. if -1 defaults to the number of installed channels of the detector - \returns OK or FAIL if it could not write the file or data=NULL - \sa mythenDetector::writeDataFile - - */ - int writeDataFile(string fname, float *data, float *err=NULL, float *ang=NULL, char dataformat='f', int nch=-1); - - /** - - writes a data file - \param name of the file to be written - \param data array of data values - \returns OK or FAIL if it could not write the file or data=NULL - \sa mythenDetector::writeDataFile - */ - int writeDataFile(string fname, int *data); - - /** - reads a data file - \param name of the file to be read - \param data array of data values to be filled - \param err array of arrors on the data. If NULL no errors are expected on the file - - \param ang array of angular values. If NULL data are expected in the form chan-val(-err) otherwise ang-val(-err) - \param dataformat format of the data: can be 'i' integer or 'f' float (default) - \param nch number of channels to be written to file. if <=0 defaults to the number of installed channels of the detector - \returns OK or FAIL if it could not read the file or data=NULL - - \sa mythenDetector::readDataFile - */ - int readDataFile(string fname, float *data, float *err=NULL, float *ang=NULL, char dataformat='f', int nch=0) {return slsDetector::readDataFile(nch, fname, data, err, ang, dataformat);} - - /** - - reads a data file - \param name of the file to be read - \param data array of data values - \returns OK or FAIL if it could not read the file or data=NULL - \sa mythenDetector::readDataFile - */ - int readDataFile(string fname, int *data){slsDetector::readDataFile(fname,data,thisMultiDetector->numberOfChannels);}; - - - /** - - reads an angular conversion file for all detectors - \param fname file to be read - \sa angleConversionConstant mythenDetector::readAngularConversion - */ - /////////////////////////////// virtual int readAngularConversion(string fname="", int id=-1); - - - - /** - - writes an angular conversion file for all detectors - \param fname file to be written - \sa angleConversionConstant mythenDetector::writeAngularConversion - */ - /////////////////////////////////////////virtual int writeAngularConversion(string fname="", int id=-1); - - - - - - - - - /* Communication to server */ - - - - - - - - - - - - - - // Expert Initialization functions - - - /** get threshold energy @@ -543,6 +410,21 @@ class multiSlsDetector { + + int64_t getId(idMode mode, int imod=0); + int digitalTest(digitalTestMode mode, int imod=0); + int executeTrimming(trimMode mode, int par1, int par2, int imod=-1); + const char *getSettingsFile(); + + + int decodeNMod(int i, int &idet, int &imod); + + + /** loads the modules settings/trimbits reading from a file - file name extension is automatically generated! */ + int loadSettingsFile(string fname, int nmod=0); + + /** gets the modules settings/trimbits and writes them to file - file name extension is automatically generated! */ + int saveSettingsFile(string fname, int nmod=0); @@ -550,9 +432,8 @@ class multiSlsDetector { - - - + int dumpDetectorSetup(string const fname, int level=0); + int retrieveDetectorSetup(string const fname, int level=0); @@ -587,11 +468,7 @@ class multiSlsDetector { */ int startReadOut(); - /** - get run status
Does it make sense to ask the status for all detectors?!?!?! - \returns status mask - */ - runStatus getRunStatus(); + /** start detector acquisition and read all data putting them a data queue @@ -669,6 +546,7 @@ class multiSlsDetector { + int setSpeed(speedVariable sp, int value=-1); /** @@ -678,6 +556,13 @@ class multiSlsDetector { \returns timer set value in ns or number of...(e.g. frames, gates, probes) */ int64_t setTimer(timerIndex index, int64_t t=-1); + /** + set/get timer value + \param index timer index + \param t time in ns or number of...(e.g. frames, gates, probes) + \returns timer set value in ns or number of...(e.g. frames, gates, probes) + */ + int64_t getTimeLeft(timerIndex index); /* /\** */ /* get current timer value */ @@ -713,14 +598,6 @@ class multiSlsDetector { //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) thisMultiDetector->threadedProcessing=b; return thisMultiDetector->threadedProcessing;} /** set flat field corrections @@ -729,6 +606,14 @@ s */ int setFlatFieldCorrection(string fname=""); + /** + 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 \param corr if !=NULL will be filled with the correction coefficients @@ -737,22 +622,12 @@ s */ int getFlatFieldCorrection(float *corr=NULL, float *ecorr=NULL); - /** - get flat field corrections file directory - \returns flat field correction file directory - */ - char *getFlatFieldCorrectionDir(){return thisMultiDetector->flatFieldDir;}; - /** - set flat field corrections file directory - \param flat field correction file directory - */ - 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 (thisMultiDetector->correctionMask&(1<flatFieldFile; else return "none";}; + + + + + + /** set rate correction @@ -788,6 +663,11 @@ s */ int setBadChannelCorrection(string fname=""); + + int setBadChannelCorrection(int nch, int *chs, int ff); + + + /** get bad channels correction \param bad pointer to array that if bad!=NULL will be filled with the bad channel list @@ -795,19 +675,8 @@ s */ int getBadChannelCorrection(int *bad=NULL); - /** returns the bad channel list file */ - string getBadChannelCorrectionFile() {if (thisMultiDetector->correctionMask&(1<< DISCARD_BAD_CHANNELS)) return string(thisMultiDetector->badChanFile); else return string("none");}; - - - /** - pure virtual function - set angular conversion - \param fname file with angular conversion constants ("" disable) - \returns 0 if angular conversion disabled, >0 otherwise - \sa mythenDetector::setAngularConversion - */ - /////////////////////////////////////////////////// virtual int setAngularConversion(string fname=""); + /** pure virtual function get angular conversion @@ -819,173 +688,13 @@ s /////////////////////////////////////////////////// virtual int getAngularConversion(int &direction, angleConversionConstant *angconv=NULL); - /** - pure virtual function - returns the angular conversion file - \sa mythenDetector::getAngularConversion */ - /////////////////////////////////////////////////// virtual string getAngularConversion(); - - /** - pure virtual function - set detector global offset - \sa mythenDetector::setGlobalOffset - */ - /////////////////////////////////////////////////// virtual float setGlobalOffset(float f); + int setAngularConversion(string fname); - /** - pure virtual function - set detector fine offset - \sa mythenDetector::setFineOffset - */ - /////////////////////////////////////////////////// virtual float setFineOffset(float f); - /** - pure virtual function - get detector fine offset - \sa mythenDetector::getFineOffset - */ - /////////////////////////////////////////////////// virtual float getFineOffset(); - - /** - pure virtual function - get detector global offset - \sa mythenDetector::getGlobalOffset - */ - /////////////////////////////////////////////////// virtual float getGlobalOffset(); + int readAngularConversion(string fname); - /** - pure virtual function - set positions for the acquisition - \param nPos number of positions - \param pos array with the encoder positions - \returns number of positions - \sa mythenDetector::setPositions - */ - /////////////////////////////////////////////////// virtual int setPositions(int nPos, float *pos); - /** - pure virtual function - get positions for the acquisition - \param pos array which will contain the encoder positions - \returns number of positions - \sa mythenDetector::getPositions - */ - /////////////////////////////////////////////////// virtual int getPositions(float *pos=NULL); - - - /** pure virtual function - set detector bin size used for merging (approx angular resolution) - \param bs bin size in degrees - \returns current bin size - \sa mythenDetector::setBinSize -*/ - /////////////////////////////////////////////////// virtual float setBinSize(float bs); + int writeAngularConversion(string fname); - /** pure virtual function - return detector bin size used for merging (approx angular resolution) - \sa mythenDetector::getBinSize - */ - /////////////////////////////////////////////////// virtual float getBinSize(); - - - - - - /** - set action - \param iaction can be enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript, MAX_ACTIONS} - \param fname for script ("" disable) - \param par for script - \returns 0 if action disabled, >0 otherwise - */ - int setAction(int iaction, string fname="", string par=""); - - /** - set action - \param iaction can be enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript, MAX_ACTIONS} - \param fname for script ("" disable) - \returns 0 if action disabled, >0 otherwise - */ - int setActionScript(int iaction, string fname=""); - /** - set action - \param iaction can be enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript, MAX_ACTIONS} - \param par for script ("" disable) - \returns 0 if action disabled, >0 otherwise - */ - int setActionParameter(int iaction, string par=""); - - /** - returns action script - \param iaction can be enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript} - \returns action script - */ - string getActionScript(int iaction); - - /** - returns action parameter - \param iaction can be enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript} - \returns action parameter - */ - string getActionParameter(int iaction); - - /** - returns action mode - \param iaction can be enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript} - \returns action mode - */ - int getActionMode(int iaction); - - - /** - set scan - \param index of the scan (0,1) - \param fname for script ("" disables, "none" disables and overwrites current) - \param nvalues number of steps (0 disables, -1 leaves current value) - \param values pointer to steps (if NULL leaves current values) - \param par parameter for the scan script ("" leaves unchanged) - \returns 0 is scan disabled, >0 otherwise - */ - int setScan(int index, string script="", int nvalues=-1, float *values=NULL, string par="", int precision=-1); - - int setScanScript(int index, string script=""); - int setScanParameter(int index, string par=""); - int setScanPrecision(int index, int precision=-1); - int setScanSteps(int index, int nvalues=-1, float *values=NULL); - /** - returns scan script - \param iscan can be (0,1) - \returns scan script - */ - string getScanScript(int iscan); - - /** - returns scan parameter - \param iscan can be (0,1) - \returns scan parameter - */ - string getScanParameter(int iscan); - - /** - returns scan mode - \param iscan can be (0,1) - \returns scan mode - */ - int getScanMode(int iscan); - - /** - returns scan steps - \param iscan can be (0,1) - \param v is the pointer to the scan steps - \returns scan steps - */ - int getScanSteps(int iscan, float *v=NULL); - - - /** - returns scan precision - \param iscan can be (0,1) - \returns scan precision - */ - int getScanPrecision(int iscan); + float* convertAngles(float pos); @@ -1047,41 +756,41 @@ s int rateCorrect(float* datain, float *errin, float* dataout, float *errout); - /** - pure virtual function - sets the arrays of the merged data to 0. NB The array should be created with size >= 360./getBinSize(); - \param mp already merged postions - \param mv already merged data - \param me already merged errors (squared sum) - \param mm multiplicity of merged arrays - \returns OK or FAIL - \sa mythenDetector::resetMerging - */ - /////////////////////////////////////////////////// virtual int resetMerging(float *mp, float *mv,float *me, int *mm); - /** - pure virtual function - merge dataset - \param p1 angular positions of dataset - \param v1 data - \param e1 errors - \param mp already merged postions - \param mv already merged data - \param me already merged errors (squared sum) - \param mm multiplicity of merged arrays - \sa mythenDetector::addToMerging - */ - /////////////////////////////////////////////////// virtual int addToMerging(float *p1, float *v1, float *e1, float *mp, float *mv,float *me, int *mm); +/* /\** */ +/* pure virtual function */ +/* sets the arrays of the merged data to 0. NB The array should be created with size >= 360./getBinSize(); */ +/* \param mp already merged postions */ +/* \param mv already merged data */ +/* \param me already merged errors (squared sum) */ +/* \param mm multiplicity of merged arrays */ +/* \returns OK or FAIL */ +/* \sa mythenDetector::resetMerging */ +/* *\/ */ +/* int resetMerging(float *mp, float *mv,float *me, int *mm) ; */ +/* /\** */ +/* pure virtual function */ +/* merge dataset */ +/* \param p1 angular positions of dataset */ +/* \param v1 data */ +/* \param e1 errors */ +/* \param mp already merged postions */ +/* \param mv already merged data */ +/* \param me already merged errors (squared sum) */ +/* \param mm multiplicity of merged arrays */ +/* \sa mythenDetector::addToMerging */ +/* *\/ */ +/* int addToMerging(float *p1, float *v1, float *e1, float *mp, float *mv,float *me, int *mm); */ - /** pure virtual function - calculates the "final" positions, data value and errors for the emrged data - \param mp already merged postions - \param mv already merged data - \param me already merged errors (squared sum) - \param mm multiplicity of merged arrays - \returns FAIL or the number of non empty bins (i.e. points belonging to the pattern) - \sa mythenDetector::finalizeMerging - */ - int finalizeMerging(float *mp, float *mv,float *me, int *mm); +/* /\** pure virtual function */ +/* calculates the "final" positions, data value and errors for the emrged data */ +/* \param mp already merged postions */ +/* \param mv already merged data */ +/* \param me already merged errors (squared sum) */ +/* \param mm multiplicity of merged arrays */ +/* \returns FAIL or the number of non empty bins (i.e. points belonging to the pattern) */ +/* \sa mythenDetector::finalizeMerging */ +/* *\/ */ +/* int finalizeMerging(float *mp, float *mv,float *me, int *mm); */ /** turns off server @@ -1107,27 +816,108 @@ s float getCurrentProgress(); + /** + get run status + \returns status mask + */ + //virtual runStatus getRunStatus()=0; + runStatus getRunStatus(); + + + /** + set dacs value + \param val value (in V) + \param index DAC index + \param imod module number (if -1 alla modules) + \returns current DAC value + */ + float setDAC(float val, dacIndex index, int imod=-1); + /** + set dacs value + \param val value (in V) + \param index DAC index + \param imod module number (if -1 alla modules) + \returns current DAC value + */ + float getADC(dacIndex index, int imod=0); + /** + configure channel + \param reg channel register + \param ichan channel number (-1 all) + \param ichip chip number (-1 all) + \param imod module number (-1 all) + \returns current register value + \sa ::sls_detector_channel + */ + int setChannel(int64_t reg, int ichan=-1, int ichip=-1, int imod=-1); + /** + pure virtual function + get angular conversion + \param reference to diffractometer direction + \param angconv array that will be filled with the angular conversion constants + \returns 0 if angular conversion disabled, >0 otherwise + \sa mythenDetector::getAngularConversion + */ + int getAngularConversion(int &direction, angleConversionConstant *angconv=NULL) ; + + + /** returns the detector trimbit/settings directory \sa sharedSlsDetector */ + char* getSettingsDir(); + /** sets the detector trimbit/settings directory \sa sharedSlsDetector */ + char* setSettingsDir(string s); + /** + returns the location of the calibration files + \sa sharedSlsDetector + */ + char* getCalDir(); + /** + sets the location of the calibration files + \sa sharedSlsDetector + */ + char* setCalDir(string s); + + + char *getNetworkParameter(networkParameter); + char *setNetworkParameter(networkParameter, std::string); + int setPort(portType, int); + int lockServer(int); + + string getLastClientIP(); + + + int configureMAC(int); - string executeLine(int narg, char *args[], int action=slsDetector::GET_ACTION); - - - - static string helpLine(int action=slsDetector::GET_ACTION); + int setNumberOfModules(int i=-1, dimension d=X); + int getMaxNumberOfModules(dimension d=X); + int setDynamicRange(int i=-1); + int writeRegister(int addr, int val); + + int readRegister(int addr); + + + + int setTrimEn(int nen, int *en=NULL); + int getTrimEn(int *en=NULL); + + + externalSignalFlag setExternalSignalFlags(externalSignalFlag pol=GET_EXTERNAL_SIGNAL_FLAG , int signalindex=0); + int setReadOutFlags(readOutFlags flag=GET_READOUT_FLAGS); + externalCommunicationMode setExternalCommunicationMode(externalCommunicationMode pol=GET_EXTERNAL_COMMUNICATION_MODE); protected: @@ -1205,8 +995,9 @@ s /** merging multiplicity */ int *mergingMultiplicity; - + }; + #endif diff --git a/slsDetectorSoftware/mythenDetectorServer/server_funcs.c b/slsDetectorSoftware/mythenDetectorServer/server_funcs.c index 37452438e..53f4cb7b0 100755 --- a/slsDetectorSoftware/mythenDetectorServer/server_funcs.c +++ b/slsDetectorSoftware/mythenDetectorServer/server_funcs.c @@ -2159,7 +2159,7 @@ int get_time_left(int file_des) { #endif n = sendDataOnly(file_des,&ret,sizeof(ret)); - if (ret!=OK) { + if (ret==FAIL) { n += sendDataOnly(file_des,mess,sizeof(mess)); } else { n = sendDataOnly(file_des,&retval,sizeof(retval)); diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index 58f918ce3..94598af4b 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -78,6 +78,11 @@ int slsDetector::initSharedMemory(detectorType type, int id) { std::cout<<"*** shmat error (server) ***" << std::endl; return shm_id; } + + + + + /** shm_id returns -1 is shared memory initialization fails */ @@ -119,28 +124,20 @@ int slsDetector::freeSharedMemory() { -slsDetector::slsDetector(int id) : +slsDetector::slsDetector(int id) :slsDetectorUtils(), thisDetector(NULL), detId(id), shmId(-1), controlSocket(NULL), stopSocket(NULL), dataSocket(NULL), - currentPosition(0), - currentPositionIndex(0), - currentI0(0), - mergingBins(NULL), - mergingCounts(NULL), - mergingErrors(NULL), - mergingMultiplicity(NULL), ffcoefficients(NULL), fferrors(NULL), detectorModules(NULL), dacs(NULL), adcs(NULL), chipregs(NULL), - chanregs(NULL), - badChannelMask(NULL) + chanregs(NULL) { @@ -168,43 +165,26 @@ slsDetector::slsDetector(int id) : - - pthread_mutex_t mp1 = PTHREAD_MUTEX_INITIALIZER; - - mp=mp1; - - pthread_mutex_init(&mp, NULL); - - - }; -slsDetector::slsDetector(detectorType type, int id): +slsDetector::slsDetector(detectorType type, int id): slsDetectorUtils(), thisDetector(NULL), detId(id), shmId(-1), controlSocket(NULL), stopSocket(NULL), dataSocket(NULL), - currentPosition(0), - currentPositionIndex(0), - currentI0(0), - mergingBins(NULL), - mergingCounts(NULL), - mergingErrors(NULL), - mergingMultiplicity(NULL), ffcoefficients(NULL), fferrors(NULL), detectorModules(NULL), dacs(NULL), adcs(NULL), chipregs(NULL), - chanregs(NULL), - badChannelMask(NULL) + chanregs(NULL) { while (shmId<0) { /**Initlializes shared memory \sa initSharedMemory @@ -227,12 +207,6 @@ slsDetector::slsDetector(detectorType type, int id): - pthread_mutex_t mp1 = PTHREAD_MUTEX_INITIALIZER; - - mp=mp1; - - pthread_mutex_init(&mp, NULL); - } @@ -248,28 +222,20 @@ slsDetector::~slsDetector(){ }; -slsDetector::slsDetector(char *name, int id, int cport) : +slsDetector::slsDetector(char *name, int id, int cport) : slsDetectorUtils(), thisDetector(NULL), detId(id), shmId(-1), controlSocket(NULL), stopSocket(NULL), dataSocket(NULL), - currentPosition(0), - currentPositionIndex(0), - currentI0(0), - mergingBins(NULL), - mergingCounts(NULL), - mergingErrors(NULL), - mergingMultiplicity(NULL), ffcoefficients(NULL), fferrors(NULL), detectorModules(NULL), dacs(NULL), adcs(NULL), chipregs(NULL), - chanregs(NULL), - badChannelMask(NULL) + chanregs(NULL) { detectorType type=(detectorType)getDetectorType(name, cport); @@ -297,11 +263,6 @@ slsDetector::slsDetector(char *name, int id, int cport) : - pthread_mutex_t mp1 = PTHREAD_MUTEX_INITIALIZER; - - mp=mp1; - - pthread_mutex_init(&mp, NULL); setTCPSocket(name, cport); updateDetector(); @@ -315,14 +276,21 @@ detectorType slsDetector::getDetectorType(char *name, int cport) { int fnum=F_GET_DETECTOR_TYPE; MySocketTCP *s= new MySocketTCP(name, cport); char m[100]; - +#ifdef VERBOSE + cout << "Getting detector type " << endl; +#endif if (s->Connect()>=0) { s->SendDataOnly(&fnum,sizeof(fnum)); s->ReceiveDataOnly(&retval,sizeof(retval)); - if (retval==OK) + if (retval!=FAIL) { s->ReceiveDataOnly(&t,sizeof(t)); - else { + +#ifdef VERBOSE + cout << "Detector type is "<< t << endl; +#endif + + } else { s->ReceiveDataOnly(m,sizeof(m)); std::cout<< "Detector returned error: " << m << std::endl; } @@ -336,21 +304,6 @@ 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; - -// } - @@ -629,7 +582,6 @@ int slsDetector::initializeDetectorSize(detectorType type) { for (int ia=0; iaactionMode[ia]=0; strcpy(thisDetector->actionScript[ia],"none"); strcpy(thisDetector->actionParameter[ia],"none"); } @@ -677,9 +629,54 @@ int slsDetector::initializeDetectorSize(detectorType type) { /** set thisDetector->alreadyExisting=1 */ thisDetector->alreadyExisting=1; } + +#ifdef VERBOSE + cout << "passing pointers" << endl; +#endif + + getPointers(&thisDetector->stoppedFlag, \ + &thisDetector->threadedProcessing, \ + &thisDetector->actionMask, \ + thisDetector->actionScript, \ + thisDetector->actionParameter, \ + thisDetector->nScanSteps, \ + thisDetector->scanMode, \ + thisDetector->scanScript, \ + thisDetector->scanParameter, \ + thisDetector->scanSteps, \ + thisDetector->scanPrecision, \ + &thisDetector->numberOfPositions, \ + thisDetector->detPositions, \ + thisDetector->angConvFile, \ + &thisDetector->correctionMask, \ + &thisDetector->binSize, \ + &thisDetector->fineOffset, \ + &thisDetector->globalOffset, \ + &thisDetector->angDirection, \ + thisDetector->flatFieldDir, \ + thisDetector->flatFieldFile, \ + thisDetector->badChanFile, \ + thisDetector->timerValue, \ + &thisDetector->currentSettings, \ + &thisDetector->currentThresholdEV, \ + thisDetector->filePath, \ + thisDetector->fileName, \ + &thisDetector->fileIndex); + + + +#ifdef VERBOSE + cout << "done" << endl; +#endif +#ifdef VERBOSE + cout << "filling bad channel mask" << endl; +#endif /** fill the BadChannelMask \sa fillBadChannelMask */ fillBadChannelMask(); +#ifdef VERBOSE + cout << "done" << endl; +#endif /** modifies the last PID accessing the detector */ thisDetector->lastPID=getpid(); @@ -869,10 +866,13 @@ int slsDetector::receiveModule(sls_detector_module* myMod) { int slsDetector::setOnline(int off) { - if (off!=GET_ONLINE_FLAG) + if (off!=GET_ONLINE_FLAG) { thisDetector->onlineFlag=off; + if (thisDetector->onlineFlag==ONLINE_FLAG) + setTCPSocket(); + } return thisDetector->onlineFlag; -}; +} @@ -1066,207 +1066,6 @@ int slsDetector::disconnectControl() { - /* I/O */ - -/* generates file name without extension*/ - -string slsDetector::createFileName() { - return createFileName(thisDetector->filePath, thisDetector->fileName, thisDetector->actionMask, currentScanVariable[0], thisDetector->scanPrecision[0], currentScanVariable[1], thisDetector->scanPrecision[1], currentPositionIndex, thisDetector->numberOfPositions, thisDetector->fileIndex); - -} - -string slsDetector::createFileName(char *filepath, char *filename, int aMask, float sv0, int prec0, float sv1, int prec1, int pindex, int npos, int findex) { - ostringstream osfn; - // string fn; - /*directory name +root file name */ - osfn << filepath << "/" << filename; - - // cout << osfn.str() << endl; - - // scan level 0 - if ( aMask& (1 << (MAX_ACTIONS))) - osfn << "_S" << fixed << setprecision(prec0) << sv0; - - //cout << osfn.str() << endl; - - //scan level 1 - if (aMask & (1 << (MAX_ACTIONS+1))) - osfn << "_s" << fixed << setprecision(prec1) << sv1; - - //cout << osfn.str() << endl; - - - //position - if (pindex>0 && pindex<=npos) - osfn << "_p" << pindex; - - //cout << osfn.str() << endl; - - // file index - osfn << "_" << findex; - - //cout << osfn.str() << endl; - - -#ifdef VERBOSE - cout << "created file name " << osfn.str() << endl; -#endif - - //cout << osfn.str() << endl; - //fn=oosfn.str()sfn.str(); - return osfn.str(); - -} - - - - - - - - - - - - -int slsDetector::getFileIndexFromFileName(string fname) { - int i; - size_t dot=fname.rfind("."); - if (dot==string::npos) - return -1; - size_t uscore=fname.rfind("_"); - if (uscore==string::npos) - return -1; - - if (sscanf( fname.substr(uscore+1,dot-uscore-1).c_str(),"%d",&i)) { - - return i; - } - //#ifdef VERBOSE - cout << "******************************** cannot parse file index" << endl; - //#endif - return 0; -} - -int slsDetector::getVariablesFromFileName(string fname, int &index, int &p_index, float &sv0, float &sv1) { - - int i; - float f; - string s; - - - index=-1; - p_index=-1; - sv0=-1; - sv1=-1; - - - // size_t dot=fname.rfind("."); - //if (dot==string::npos) - // return -1; - size_t uscore=fname.rfind("_"); - if (uscore==string::npos) - return -1; - s=fname; - - //if (sscanf(s.substr(uscore+1,dot-uscore-1).c_str(),"%d",&i)) { - if (sscanf(s.substr(uscore+1,s.size()-uscore-1).c_str(),"%d",&i)) { - index=i; -#ifdef VERBOSE - cout << "******************************** file index is " << index << endl; -#endif - //return i; - s=fname.substr(0,uscore); - } -#ifdef VERBOSE - else - cout << "******************************** cannot parse file index" << endl; - - cout << s << endl; -#endif - - - uscore=s.rfind("_"); - - - - - if (sscanf( s.substr(uscore+1,s.size()-uscore-1).c_str(),"p%d",&i)) { - p_index=i; -#ifdef VERBOSE - cout << "******************************** position index is " << p_index << endl; -#endif - s=fname.substr(0,uscore); - } -#ifdef VERBOSE - else - cout << "******************************** cannot parse position index" << endl; - - cout << s << endl; - - -#endif - - - - - uscore=s.rfind("_"); - - - - - if (sscanf( s.substr(uscore+1,s.size()-uscore-1).c_str(),"s%f",&f)) { - sv1=f; -#ifdef VERBOSE - cout << "******************************** scan variable 1 is " << sv1 << endl; -#endif - s=fname.substr(0,uscore); - } -#ifdef VERBOSE - else - cout << "******************************** cannot parse scan varable 1" << endl; - - cout << s << endl; - - -#endif - - uscore=s.rfind("_"); - - - - - if (sscanf( s.substr(uscore+1,s.size()-uscore-1).c_str(),"S%f",&f)) { - sv0=f; -#ifdef VERBOSE - cout << "******************************** scan variable 0 is " << sv0 << endl; -#endif - } -#ifdef VERBOSE - else - cout << "******************************** cannot parse scan varable 0" << endl; - -#endif - - - - return index; -} - - - - - - - - - - - - - - - @@ -1391,44 +1190,15 @@ int slsDetector::setDetectorType(detectorType const type){ return retType; }; -int slsDetector::setDetectorType(string const type){ - detectorType dtype=GENERIC; - if (type=="Mythen") - dtype=MYTHEN; - else if (type=="Pilatus") - dtype=PILATUS; - else if (type=="Eiger") - dtype=EIGER; - else if (type=="Gotthard") - dtype=GOTTHARD; - else if (type=="Agipd") - dtype=AGIPD; - return setDetectorType(dtype); +int slsDetector::setDetectorType(string const stype){ + return setDetectorType(getDetectorType(stype)); }; string slsDetector::getDetectorType(){ - switch (thisDetector->myDetectorType) { - case MYTHEN: - return string("Mythen"); - break; - case PILATUS: - return string("Pilatus"); - break; - case EIGER: - return string("Eiger"); - break; - case GOTTHARD: - return string("Gotthard"); - break; - case AGIPD: - return string("Agipd"); - break; - default: - return string("Unknown"); - break; - } -}; + return getDetectorType(thisDetector->myDetectorType); + +} @@ -2181,8 +1951,8 @@ int slsDetector::setChannel(sls_detector_channel chan){ std::cout<< "Detector returned error: " << mess << std::endl; } controlSocket->Disconnect(); - if (ret==FORCE_UPDATE) - updateDetector(); + if (ret==FORCE_UPDATE) + updateDetector(); } } } @@ -2191,48 +1961,65 @@ int slsDetector::setChannel(sls_detector_channel chan){ if (ret!=FAIL) { if (chanregs) { -int mmin=imod, mmax=imod+1, chimin=ichip, chimax=ichip+1, chamin=ichan, chamax=ichan+1; + int mmin=imod, mmax=imod+1, chimin=ichip, chimax=ichip+1, chamin=ichan, chamax=ichan+1; - if (imod==-1) { - mmin=0; - mmax=thisDetector->nModsMax; - } + if (imod==-1) { + mmin=0; + mmax=thisDetector->nModsMax; + } - if (ichip==-1) { - chimin=0; - chimax=thisDetector->nChips; - } - - if (ichan==-1) { - chamin=0; - chamax=thisDetector->nChans; - } + if (ichip==-1) { + chimin=0; + chimax=thisDetector->nChips; + } + + if (ichan==-1) { + chamin=0; + chamax=thisDetector->nChans; + } + - - for (int im=mmin; imnChans*thisDetector->nChips+ichi*thisDetector->nChips+icha)=retval; - - } - } -} - + for (int im=mmin; imnChans*thisDetector->nChips+ichi*thisDetector->nChips+icha)=retval; + + } + } + } + } } #ifdef VERBOSE std::cout<< "Channel register returned "<< retval << std::endl; #endif return retval; - + } - sls_detector_channel slsDetector::getChannel(int ichan, int ichip, int imod){ + + + + + + + + + + + + + + + + + +sls_detector_channel slsDetector::getChannel(int ichan, int ichip, int imod){ int fnum=F_GET_CHANNEL; @@ -3403,45 +3190,6 @@ int slsDetector::startAndReadAllNoWait(){ - -int* slsDetector::popDataQueue() { - int *retval=NULL; - if( !dataQueue.empty() ) { - retval=dataQueue.front(); - dataQueue.pop(); - } - return retval; -} - -detectorData* slsDetector::popFinalDataQueue() { - detectorData *retval=NULL; - if( !finalDataQueue.empty() ) { - retval=finalDataQueue.front(); - finalDataQueue.pop(); - } - return retval; -} - -void slsDetector::resetDataQueue() { - int *retval=NULL; - while( !dataQueue.empty() ) { - retval=dataQueue.front(); - dataQueue.pop(); - delete [] retval; - } - -} - -void slsDetector::resetFinalDataQueue() { - detectorData *retval=NULL; - while( !finalDataQueue.empty() ) { - retval=finalDataQueue.front(); - finalDataQueue.pop(); - delete retval; - } - -} - /* set or read the acquisition timers enum timerIndex { @@ -3864,7 +3612,7 @@ int64_t slsDetector::getTimeLeft(timerIndex index){ stopSocket->SendDataOnly(&fnum,sizeof(fnum)); stopSocket->SendDataOnly(&index,sizeof(index)); stopSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=OK) { + if (ret==FAIL) { stopSocket->ReceiveDataOnly(mess,sizeof(mess)); std::cout<< "Detector returned error: " << mess << std::endl; } else { @@ -4306,24 +4054,6 @@ int slsDetector::getFlatFieldCorrection(float *corr, float *ecorr) { } -int slsDetector::flatFieldCorrect(float datain, float errin, float &dataout, float &errout, float ffcoefficient, float fferr){ - float e; - - dataout=datain*ffcoefficient; - - if (errin==0 && datain>=0) - e=sqrt(datain); - else - e=errin; - - if (dataout>0) - errout=sqrt(e*ffcoefficient*e*ffcoefficient+datain*fferr*datain*fferr); - else - errout=1.; - - return 0; -}; - int slsDetector::flatFieldCorrect(float* datain, float *errin, float* dataout, float *errout){ #ifdef VERBOSE std::cout<< "Flat field correcting data" << std::endl; @@ -4419,27 +4149,6 @@ int slsDetector::getRateCorrection(){ - int slsDetector::rateCorrect(float datain, float errin, float &dataout, float &errout, float tau, float t){ - - // float data; - float e; - - dataout=(datain*exp(tau*datain/t)); - - if (errin==0 && datain>=0) - e=sqrt(datain); - else - e=errin; - - if (dataout>0) - errout=e*dataout*sqrt((1/(datain*datain)+tau*tau/(t*t))); - else - errout=1.; - return 0; - -}; - - int slsDetector::rateCorrect(float* datain, float *errin, float* dataout, float *errout){ float tau=thisDetector->tDead; float t=thisDetector->timerValue[ACQUISITION_TIME]; @@ -4479,81 +4188,6 @@ int slsDetector::setBadChannelCorrection(string fname){ } -int slsDetector::setBadChannelCorrection(string fname, int &nbad, int *badlist){ - ifstream infile; - string str; - int interrupt=0; - int ich; - int chmin,chmax; -#ifdef VERBOSE - std::cout << "Setting bad channel correction to " << fname << std::endl; -#endif - - if (fname=="") { - nbad=0; - return 0; - } else { - infile.open(fname.c_str(), ios_base::in); - if (infile.is_open()==0) { - std::cout << "could not open file " << fname <> chmin ; - ssstr.str(str.substr(str.find('-')+1,str.size())); - ssstr >> chmax; -#ifdef VERBOSE - std::cout << "channels between"<< chmin << " and " << chmax << std::endl; -#endif - for (ich=chmin; ich<=chmax; ich++) { - if (nbad> ich; -#ifdef VERBOSE - std::cout << "channel "<< ich << std::endl; -#endif - if (nbad0 && nbadcorrectionMask&(1<< DISCARD_BAD_CHANNELS)) { @@ -4594,40 +4235,13 @@ int slsDetector::getBadChannelCorrection(int *bad) { } -int slsDetector::fillBadChannelMask() { - if (thisDetector->correctionMask&(1<< DISCARD_BAD_CHANNELS)) { - if (badChannelMask) - delete [] badChannelMask; - badChannelMask=new int[thisDetector->nChans*thisDetector->nChips*thisDetector->nMods]; - for (int ichan=0; ichannChans*thisDetector->nChips*thisDetector->nMods; ichan++) - badChannelMask[ichan]=0; - for (int ichan=0; ichannBadChans; ichan++) { - if (thisDetector->badChansList[ichan]nChans*thisDetector->nChips*thisDetector->nMods) { - badChannelMask[thisDetector->badChansList[ichan]]=1; -#ifdef VERBOSE - std::cout << ichan << " badchannel "<< ichan << std::endl; -#endif - } - } - for (int ichan=0; ichannBadFF; ichan++) { - if (thisDetector->badFFList[ichan]nChans*thisDetector->nChips*thisDetector->nMods) { - badChannelMask[thisDetector->badFFList[ichan]]=1; -#ifdef VERBOSE - std::cout << ichan << "ff badchannel "<< thisDetector->badFFList[ichan] << std::endl; -#endif - } - } - - } else { - if (badChannelMask) { - delete [] badChannelMask; - badChannelMask=NULL; - } - } - return thisDetector->nBadFF; -} + + + + + int slsDetector::exitServer(){ @@ -4652,427 +4266,46 @@ int slsDetector::exitServer(){ }; - - - - - - - - - /** - set action - \param iaction can be enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript, MAX_ACTIONS} - \param fname for script ("" disable but leaves script unchanged, "none" disables and overwrites) - \returns 0 if action disabled, >0 otherwise - */ -int slsDetector::setAction(int iaction, string fname, string par) { - - if (iaction>=0 && iactionactionMode[iaction]=0; - } else if (fname=="none") { - thisDetector->actionMode[iaction]=0; - strcpy(thisDetector->actionScript[iaction],fname.c_str()); - } else { - strcpy(thisDetector->actionScript[iaction],fname.c_str()); - thisDetector->actionMode[iaction]=1; - } - - if (par!="") { - strcpy(thisDetector->actionParameter[iaction],par.c_str()); - } - - if (thisDetector->actionMode[iaction]) { - -#ifdef VERBOSE - cout << iaction << " " << hex << (1 << iaction) << " " << thisDetector->actionMask << dec; -#endif - - thisDetector->actionMask |= (1 << iaction); - -#ifdef VERBOSE - cout << " set " << hex << thisDetector->actionMask << dec << endl; -#endif - - } else { -#ifdef VERBOSE - cout << iaction << " " << hex << thisDetector->actionMask << dec; -#endif - - thisDetector->actionMask &= ~(1 << iaction); - -#ifdef VERBOSE - cout << " unset " << hex << thisDetector->actionMask << dec << endl; -#endif - } -#ifdef VERBOSE - cout << iaction << " Action mask set to " << hex << thisDetector->actionMask << dec << endl; -#endif - - return thisDetector->actionMode[iaction]; - } else - return -1; -} - - -int slsDetector::setActionScript(int iaction, string fname) { -#ifdef VERBOSE +char* slsDetector::setNetworkParameter(networkParameter index, string value) { -#endif - return setAction(iaction,fname,""); -} - - - -int slsDetector::setActionParameter(int iaction, string par) { - if (iaction>=0 && iactionactionParameter[iaction],par.c_str()); - } - - if (thisDetector->actionMode[iaction]) { - thisDetector->actionMask |= (1 << iaction); - } else { - thisDetector->actionMask &= ~(1 << iaction); - } - - return thisDetector->actionMode[iaction]; - } else - return -1; -} - - /** - returns action script - \param iaction can be enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript} - \returns action script - */ -string slsDetector::getActionScript(int iaction){ - if (iaction>=0 && iactionactionScript[iaction]); - else - return string("wrong index"); -}; - - /** - returns action parameter - \param iaction can be enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript} - \returns action parameter - */ -string slsDetector::getActionParameter(int iaction){ - if (iaction>=0 && iactionactionParameter[iaction]); - else - return string("wrong index"); -} - - /** - returns action mode - \param iaction can be enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript} - \returns action mode - */ -int slsDetector::getActionMode(int iaction){ - if (iaction>=0 && iactionactionMode[iaction] << endl; -#endif - return thisDetector->actionMode[iaction]; - } else { -#ifdef VERBOSE - cout << "slsDetetctor : wrong action index " << iaction << endl; -#endif - return -1; + switch (index) { + case CLIENT_IP: + return setClientIP(value); + break; + case CLIENT_MAC: + return setClientMAC(value); + break; + case SERVER_MAC: + return setServerMAC(value); + break; + default: + return ("unknown network parameter"); } + } - - /** - set scan - \param index of the scan (0,1) - \param fname for script ("" disable) - \returns 0 if scan disabled, >0 otherwise - */ -int slsDetector::setScan(int iscan, string script, int nvalues, float *values, string par, int precision) { - if (iscan>=0 && iscanscanMode[iscan]=0; - } else { - strcpy(thisDetector->scanScript[iscan],script.c_str()); - if (script=="none") { - thisDetector->scanMode[iscan]=0; - } else if (script=="energy") { - thisDetector->scanMode[iscan]=1; - } else if (script=="threshold") { - thisDetector->scanMode[iscan]=2; - } else if (script=="trimbits") { - thisDetector->scanMode[iscan]=3; - } else { - thisDetector->scanMode[iscan]=4; - } - } - +char* slsDetector::getNetworkParameter(networkParameter index) { + switch (index) { + case CLIENT_IP: + return getClientIP(); + break; + case CLIENT_MAC: + return getClientMAC(); + break; + case SERVER_MAC: + return getServerMAC(); + break; + default: + return ("unknown network parameter"); + } - - - - if (par!="") - strcpy(thisDetector->scanParameter[iscan],par.c_str()); - - if (nvalues>=0) { - if (nvalues==0) - thisDetector->scanMode[iscan]=0; - else { - thisDetector->nScanSteps[iscan]=nvalues; - if (nvalues>MAX_SCAN_STEPS) - thisDetector->nScanSteps[iscan]=MAX_SCAN_STEPS; - } - } - - if (values && thisDetector->scanMode[iscan]>0 ) { - for (int iv=0; ivnScanSteps[iscan]; iv++) { - thisDetector->scanSteps[iscan][iv]=values[iv]; - } - } - - if (precision>=0) - thisDetector->scanPrecision[iscan]=precision; - - if (thisDetector->scanMode[iscan]>0){ - thisDetector->actionMask |= 1<< (iscan+MAX_ACTIONS); - } else { - thisDetector->actionMask &= ~(1 << (iscan+MAX_ACTIONS)); - } - - - - setTotalProgress(); - - - - - - - - - - - return thisDetector->scanMode[iscan]; - } else - return -1; - -} - -int slsDetector::setScanScript(int iscan, string script) { - if (iscan>=0 && iscanscanMode[iscan]=0; - } else { - strcpy(thisDetector->scanScript[iscan],script.c_str()); - if (script=="none") { - thisDetector->scanMode[iscan]=0; - } else if (script=="energy") { - thisDetector->scanMode[iscan]=1; - } else if (script=="threshold") { - thisDetector->scanMode[iscan]=2; - } else if (script=="trimbits") { - thisDetector->scanMode[iscan]=3; - } else { - thisDetector->scanMode[iscan]=4; - } - } - - if (thisDetector->scanMode[iscan]>0){ - thisDetector->actionMask |= (1 << (iscan+MAX_ACTIONS)); - } else { - thisDetector->actionMask &= ~(1 << (iscan+MAX_ACTIONS)); - } - - setTotalProgress(); - - - - - - - - - - - - - - - - - - -#ifdef VERBOSE - cout << "Action mask is " << hex << thisDetector->actionMask << dec << endl; -#endif - return thisDetector->scanMode[iscan]; - - - } else - return -1; - } -int slsDetector::setScanParameter(int iscan, string par) { - if (iscan>=0 && iscanscanParameter[iscan],par.c_str()); - return thisDetector->scanMode[iscan]; - } else - return -1; - -} - - -int slsDetector::setScanPrecision(int iscan, int precision) { - if (iscan>=0 && iscan=0) - thisDetector->scanPrecision[iscan]=precision; - return thisDetector->scanMode[iscan]; - } else - return -1; - -} - -int slsDetector::setScanSteps(int iscan, int nvalues, float *values) { - - if (iscan>=0 && iscan=0) { - if (nvalues==0) - thisDetector->scanMode[iscan]=0; - else { - thisDetector->nScanSteps[iscan]=nvalues; - if (nvalues>MAX_SCAN_STEPS) - thisDetector->nScanSteps[iscan]=MAX_SCAN_STEPS; - } - } - - if (values) { - for (int iv=0; ivnScanSteps[iscan]; iv++) { - thisDetector->scanSteps[iscan][iv]=values[iv]; - } - } - - if (thisDetector->scanMode[iscan]>0){ - thisDetector->actionMask |= (1 << (iscan+MAX_ACTIONS)); - } else { - thisDetector->actionMask &= ~(1 << (iscan+MAX_ACTIONS)); - } - -#ifdef VERBOSE - cout << "Action mask is " << hex << thisDetector->actionMask << dec << endl; -#endif - setTotalProgress(); - - - - - return thisDetector->scanMode[iscan]; - - - } else - return -1; - - - - -} - - - - /** - returns scan script - \param iscan can be (0,1) - \returns scan script - */ -string slsDetector::getScanScript(int iscan){ - if (iscan>=0 && iscanscanMode[iscan]) - return string(thisDetector->scanScript[iscan]); - else - return string("none"); - } else - return string("wrong index"); - -}; - - /** - returns scan parameter - \param iscan can be (0,1) - \returns scan parameter - */ -string slsDetector::getScanParameter(int iscan){ - if (iscan>=0 && iscanscanMode[iscan]) - return string(thisDetector->scanParameter[iscan]); - else - return string("none"); - } else - return string("wrong index"); -} - - - /** - returns scan mode - \param iscan can be (0,1) - \returns scan mode - */ -int slsDetector::getScanMode(int iscan){ - if (iscan>=0 && iscanscanMode[iscan]; - else - return -1; -} - - - /** - returns scan steps - \param iscan can be (0,1) - \param v is the pointer to the scan steps - \returns scan steps - */ -int slsDetector::getScanSteps(int iscan, float *v) { - - if (iscan>=0 && iscannScanSteps[iscan]; iv++) { - v[iv]=thisDetector->scanSteps[iscan][iv]; - } - } - - - setTotalProgress(); - - - if (thisDetector->scanMode[iscan]) - return thisDetector->nScanSteps[iscan]; - else - return 0; - } else - return -1; -} - - -int slsDetector::getScanPrecision(int iscan){ - if (iscan>=0 && iscanscanPrecision[iscan]; - } else - return -1; -} - char* slsDetector::setClientIP(string clientIP){ int wrongFormat=1; @@ -5207,1825 +4440,8 @@ int slsDetector::configureMAC(int ival){ -string slsDetector::executeLine(int narg, char *args[], int action) { - - -#ifdef VERBOSE - for (int ia=0; ia1) - sval=string(args[1]); - else - sval="none"; - float corr[24*1280], ecorr[24*1280]; - if (getFlatFieldCorrection(corr,ecorr)) { - if (sval!="none") { - writeDataFile(sval,corr,ecorr,NULL,'i'); - return sval; - } - return string(getFlatFieldCorrectionFile()); - } else { - return string("none"); - } - } - } else if (var=="ffdir") { - if (action==PUT_ACTION) { - sval=string(args[1]); - if (sval=="none") - sval=""; - setFlatFieldCorrectionDir(sval); - } - return string(getFlatFieldCorrectionDir()); - } else if (var=="ratecorr") { - if (action==PUT_ACTION) { - sscanf(args[1],"%f",&fval); - setRateCorrection(fval); - } - float t; - if (getRateCorrection(t)) { - sprintf(answer,"%f",t); - } else { - sprintf(answer,"%f",0.); - } - return string(answer); - } else if (var=="badchannels") { - if (action==PUT_ACTION) { - sval=string(args[1]); - if (sval=="none") - sval=""; - setBadChannelCorrection(sval); - } else if (action==GET_ACTION) { - if (narg>1) - sval=string(args[1]); - else - sval="none"; - int bch[24*1280], nbch; - if ((nbch=getBadChannelCorrection(bch))) { - if (sval!="none") { - ofstream outfile; - outfile.open (sval.c_str(),ios_base::out); - if (outfile.is_open()) { - for (int ich=0; ich1) - sval=string(args[1]); - else - sval="none"; - int dir; - if (getAngularConversion(dir)) { - if (sval!="none") { - writeAngularConversion(sval.c_str()); - return sval; - } - return string(getAngularConversion()); - } else { - return string("none"); - } - } - } else if (var=="globaloff") { - if (action==PUT_ACTION) { - sscanf(args[1],"%f",&fval); - setGlobalOffset(fval); - } - sprintf(answer,"%f",getGlobalOffset()); - return string(answer); - } else if (var=="fineoff") { - if (action==PUT_ACTION) { - sscanf(args[1],"%f",&fval); - setFineOffset(fval); - } - sprintf(answer,"%f",getFineOffset()); - return string(answer); - } else if (var=="binsize") { - if (action==PUT_ACTION) { - sscanf(args[1],"%f",&fval); - setBinSize(fval); - } - sprintf(answer,"%f",getBinSize()); - return string(answer); - } else if (var=="positions") { - if (action==PUT_ACTION) { - sscanf(args[1],"%d",&ival); - float pos[ival]; - for (int ip=0; ipnarg-2) - ival=narg-2; - int ene[ival]; - for (int ie=0; ienarg-2) - ival=narg-2; - float ene[ival]; - for (int ie=0; ienarg-2) - ival=narg-2; - float ene[ival]; - for (int ie=0; ie> ival; - if (vvstr.fail()) - return string("syntax is extsig:i where signal is signal number"); - externalSignalFlag flag=GET_EXTERNAL_SIGNAL_FLAG, ret; - if (action==PUT_ACTION) { - sval=string(args[1]); -#ifdef VERBOSE - std::cout<< "sig " << ival << " flag " << sval; -#endif - if (sval=="off") flag=SIGNAL_OFF; - else if (sval=="gate_in_active_high") flag=GATE_IN_ACTIVE_HIGH; - else if (sval=="gate_in_active_low") flag=GATE_IN_ACTIVE_LOW; - else if (sval=="trigger_in_rising_edge") flag=TRIGGER_IN_RISING_EDGE; - else if (sval=="trigger_in_falling_edge") flag=TRIGGER_IN_FALLING_EDGE; - else if (sval=="ro_trigger_in_rising_edge") flag=RO_TRIGGER_IN_RISING_EDGE; - else if (sval=="ro_trigger_in_falling_edge") flag=RO_TRIGGER_IN_FALLING_EDGE; - else if (sval=="gate_out_active_high") flag=GATE_OUT_ACTIVE_HIGH; - else if (sval=="gate_out_active_low") flag=GATE_OUT_ACTIVE_LOW; - else if (sval=="trigger_out_rising_edge") flag=TRIGGER_OUT_RISING_EDGE; - else if (sval=="trigger_out_falling_edge") flag=TRIGGER_OUT_FALLING_EDGE; - else if (sval=="ro_trigger_out_rising_edge") flag=RO_TRIGGER_OUT_RISING_EDGE; - else if (sval=="ro_trigger_out_falling_edge") flag=RO_TRIGGER_OUT_FALLING_EDGE; - - - } - ret= setExternalSignalFlags(flag,ival); - switch (ret) { - case SIGNAL_OFF: - return string( "off"); - case GATE_IN_ACTIVE_HIGH: - return string( "gate_in_active_high"); - case GATE_IN_ACTIVE_LOW: - return string( "gate_in_active_low"); - case TRIGGER_IN_RISING_EDGE: - return string( "trigger_in_rising_edge"); - case TRIGGER_IN_FALLING_EDGE: - return string( "trigger_in_falling_edge"); - case RO_TRIGGER_IN_RISING_EDGE: - return string( "ro_trigger_in_rising_edge"); - case RO_TRIGGER_IN_FALLING_EDGE: - return string( "ro_trigger_in_falling_edge"); - case GATE_OUT_ACTIVE_HIGH: - return string( "gate_out_active_high"); - case GATE_OUT_ACTIVE_LOW: - return string( "gate_out_active_low"); - case TRIGGER_OUT_RISING_EDGE: - return string( "trigger_out_rising_edge"); - case TRIGGER_OUT_FALLING_EDGE: - return string( "trigger_out_falling_edge"); - case RO_TRIGGER_OUT_RISING_EDGE: - return string( "ro_trigger_out_rising_edge"); - case RO_TRIGGER_OUT_FALLING_EDGE: - return string( "ro_trigger_out_falling_edge"); - default: - return string( "unknown"); - } - } else if (var.find("modulenumber")==0) {//else if (var=="modulenumber") { - cout << "modulenumber" << endl; - if (action==PUT_ACTION) { - return string("cannot set"); - } - if (var.size()<=13) - return string("syntax is modulenumber:i where i is module number"); - istringstream vvstr(var.substr(13)); - vvstr >> ival; - if (vvstr.fail()) - return string("syntax is modulenumber:i where i is module number"); - //cout << var.substr(13) << endl; - sprintf(answer,"%llx",getId(MODULE_SERIAL_NUMBER,ival)); - return string(answer); - } else if (var=="moduleversion") { - if (action==PUT_ACTION) { - return string("cannot set" ); - } - sprintf(answer,"%llx",getId(MODULE_FIRMWARE_VERSION)); - return string(answer); - } else if (var=="detectornumber") { - if (action==PUT_ACTION) { - return string("cannot set "); - } - sprintf(answer,"%llx",getId(DETECTOR_SERIAL_NUMBER)); - return string(answer); - } else if (var=="detectorversion") { - if (action==PUT_ACTION) { - return string("cannot set "); - } - sprintf(answer,"%llx",getId(DETECTOR_FIRMWARE_VERSION)); - return string(answer); - } else if (var=="softwareversion") { - if (action==PUT_ACTION) { - return string("cannot set "); - } - sprintf(answer,"%llx",getId(DETECTOR_SOFTWARE_VERSION)); - return string(answer); - } else if (var=="thisversion") { - if (action==PUT_ACTION) { - return string("cannot set "); - } - sprintf(answer,"%llx",getId(THIS_SOFTWARE_VERSION)); - return string(answer); - } - - else if (var.find("digitest")==0) {//else if (var=="digitest") { - cout << "digitest" << endl; - if (action==PUT_ACTION) { - return string("cannot set "); - } - if (var.size()<=9) - return string("syntax is digitest:i where i is the module number"); - - - istringstream vvstr(var.substr(9)); - vvstr >> ival; - if (vvstr.fail()) - return string("syntax is digitest:i where i is the module number"); - sprintf(answer,"%x",digitalTest(CHIP_TEST, ival)); - return string(answer); - } else if (var=="bustest") { - if (action==PUT_ACTION) { - return string("cannot set "); - } - sprintf(answer,"%x",digitalTest(DETECTOR_BUS_TEST)); - return string(answer); - } else if (var=="settings") { - detectorSettings sett=GET_SETTINGS; - if (action==PUT_ACTION) { - sval=string(args[1]); - switch(thisDetector->myDetectorType) { - - case MYTHEN: - case PICASSO: - case EIGER: - if (sval=="standard") - sett=STANDARD; - else if (sval=="fast") - sett=FAST; - else if (sval=="highgain") - sett=HIGHGAIN; - else { - sprintf(answer,"%s not defined for this detector",sval.c_str()); - return string(answer); - } - break; - - case GOTTHARD: - case AGIPD: - if (sval=="highgain") - sett=HIGHGAIN; - else if (sval=="dynamicgain") - sett=DYNAMICGAIN; - else if (sval=="lowgain") - sett=LOWGAIN; - else if (sval=="mediumgain") - sett=MEDIUMGAIN; - else if (sval=="veryhighgain") - sett=VERYHIGHGAIN; - else { - sprintf(answer,"%s not defined for this detector",sval.c_str()); - return string(answer); - } - break; - - default: - sprintf(answer,"%s not defined for this detector",sval.c_str()); - return string(answer); - } - } - switch (setSettings(sett)) { - case STANDARD: - return string("standard"); - case FAST: - return string("fast"); - case HIGHGAIN: - return string("highgain"); - case DYNAMICGAIN: - return string("dynamicgain"); - case LOWGAIN: - return string("lowgain"); - case MEDIUMGAIN: - return string("mediumgain"); - case VERYHIGHGAIN: - return string("veryhighgain"); - default: - return string("undefined"); - } - } else if (var=="threshold") { - if (action==PUT_ACTION) { - sscanf(args[1],"%d",&ival); - setThresholdEnergy(ival); - } - sprintf(answer,"%d",getThresholdEnergy()); - return string(answer); - } - - /* MYTHEN POTS */ - else if (var=="vthreshold") { - if (action==PUT_ACTION) { - sscanf(args[1],"%f",&fval); - setDAC(fval, THRESHOLD); - } - sprintf(answer,"%f",setDAC(-1,THRESHOLD)); - return string(answer); - } else if (var=="vcalibration") { - if (action==PUT_ACTION) { - sscanf(args[1],"%f",&fval); - setDAC(fval, CALIBRATION_PULSE); - } - sprintf(answer,"%f",setDAC(-1,CALIBRATION_PULSE)); - return string(answer); - } else if (var=="vtrimbit") { - if (action==PUT_ACTION) { - sscanf(args[1],"%f",&fval); - setDAC(fval, TRIMBIT_SIZE); - } - sprintf(answer,"%f",setDAC(-1,TRIMBIT_SIZE)); - return string(answer); - } else if (var=="vpreamp") { - if (action==PUT_ACTION) { - sscanf(args[1],"%f",&fval); - setDAC(fval, PREAMP); - } - sprintf(answer,"%f",setDAC(-1,PREAMP)); - return string(answer); - } else if (var=="vshaper1") { - if (action==PUT_ACTION) { - sscanf(args[1],"%f",&fval); - setDAC(fval, SHAPER1); - } - sprintf(answer,"%f",setDAC(-1,SHAPER1)); - return string(answer); - } else if (var=="vshaper2") { - if (action==PUT_ACTION) { - sscanf(args[1],"%f",&fval); - setDAC(fval, SHAPER2); - } - sprintf(answer,"%f",setDAC(-1,SHAPER2)); - return string(answer); - } else if (var=="vhighvoltage") { - if (action==PUT_ACTION) { - sscanf(args[1],"%f",&fval); - setDAC(fval, HV_POT); - } - sprintf(answer,"%f",setDAC(-1,HV_POT)); - return string(answer); - } else if (var=="vapower") { - if (action==PUT_ACTION) { - sscanf(args[1],"%f",&fval); - setDAC(fval, VA_POT); - } - sprintf(answer,"%f",setDAC(-1,VA_POT)); - return string(answer); - } else if (var=="vddpower") { - if (action==PUT_ACTION) { - sscanf(args[1],"%f",&fval); - setDAC(fval, VDD_POT); - } - sprintf(answer,"%f",setDAC(-1,VDD_POT)); - return string(answer); - } else if (var=="vshpower") { - if (action==PUT_ACTION) { - sscanf(args[1],"%f",&fval); - setDAC(fval, VSH_POT); - } - sprintf(answer,"%f",setDAC(-1,VSH_POT)); - return string(answer); - } else if (var=="viopower") { - if (action==PUT_ACTION) { - sscanf(args[1],"%f",&fval); - setDAC(fval, VIO_POT); - } - sprintf(answer,"%f",setDAC(-1,VIO_POT)); - return string(answer); - } - /* GOTTHARD POTS */ - else if (var=="vref_ds") { - if (action==PUT_ACTION) { - sscanf(args[1],"%f",&fval); - setDAC(fval,G_VREF_DS ); - } - sprintf(answer,"%f",setDAC(-1,G_VREF_DS)); - return string(answer); - } else if (var=="vcascn_pb") { - if (action==PUT_ACTION) { - sscanf(args[1],"%f",&fval); - setDAC(fval,G_VCASCN_PB ); - } - sprintf(answer,"%f",setDAC(-1,G_VCASCN_PB)); - return string(answer); - } else if (var=="vcascp_pb") { - if (action==PUT_ACTION) { - sscanf(args[1],"%f",&fval); - setDAC(fval, G_VCASCP_PB); - } - sprintf(answer,"%f",setDAC(-1,G_VCASCP_PB)); - return string(answer); - } else if (var=="vout_cm") { - if (action==PUT_ACTION) { - sscanf(args[1],"%f",&fval); - setDAC(fval,G_VOUT_CM ); - } - sprintf(answer,"%f",setDAC(-1,G_VOUT_CM)); - return string(answer); - } else if (var=="vcasc_out") { - if (action==PUT_ACTION) { - sscanf(args[1],"%f",&fval); - setDAC(fval,G_VCASC_OUT ); - } - sprintf(answer,"%f",setDAC(-1,G_VCASC_OUT)); - return string(answer); - } else if (var=="vin_cm") { - if (action==PUT_ACTION) { - sscanf(args[1],"%f",&fval); - setDAC(fval,G_VIN_CM ); - } - sprintf(answer,"%f",setDAC(-1,G_VIN_CM)); - return string(answer); - } else if (var=="vref_comp") { - if (action==PUT_ACTION) { - sscanf(args[1],"%f",&fval); - setDAC(fval,G_VREF_COMP); - } - sprintf(answer,"%f",setDAC(-1,G_VREF_COMP)); - return string(answer); - } else if (var=="ib_test_c") { - if (action==PUT_ACTION) { - sscanf(args[1],"%f",&fval); - setDAC(fval,G_IB_TESTC ); - } - sprintf(answer,"%f",setDAC(-1,G_IB_TESTC)); - return string(answer); - } - /* GOTTHARD TEMPERATURE */ - else if (var=="temp_adc") { - sprintf(answer,"%f",getADC(TEMPERATURE_ADC)); - return string(answer); - } else if (var=="temp_fpga") { - sprintf(answer,"%f",getADC(TEMPERATURE_FPGA)); - return string(answer); - } - /* DEBUGGING FUNCTIONS */ - else if (var=="reg_rw") { - if(narg<2) - return string("\nError:Use gotthard_put i:reg_rw (address) (value in hex)OR gotthard_get i:reg_rw (address)"); - sscanf(args[1],"%x",&ival); - if (action==PUT_ACTION) { - if(narg<3) - return string("\nError:Use gotthard_put i:reg_rw (address) (value in hex)OR gotthard_get i:reg_rw (address)"); - sscanf(args[2],"%x",&ival2); - sprintf(answer,"%x",writeRegister(ival,ival2)); - } - sprintf(answer,"%x",readRegister(ival)); - return string(answer); - } - else if (var=="reg_frame") { - int i=0; - int val; - ofstream outfile; - outfile.open ("/home/l_maliakal_d/wORKSPACE/scratch/frame.txt",ios_base::out); - if (outfile.is_open()) - { - for (i=0;i<2560;i++){ - val=readRegister(0x80); - outfile <myDetectorType) { - case GOTTHARD: - sprintf(answer,"Number of gates is always 1 for this detector",sval.c_str()); - return string(answer); - break; - default: - if (action==PUT_ACTION) { - sscanf(args[1],"%d",&ival); - setTimer( GATES_NUMBER,ival); - } - sprintf(answer,"%lld",setTimer(GATES_NUMBER)); - return string(answer); - } - } else if (var=="frames") { - if (action==PUT_ACTION) { - sscanf(args[1],"%d",&ival); - setTimer(FRAME_NUMBER,ival); - } - sprintf(answer,"%lld",setTimer(FRAME_NUMBER)); - return string(answer); - } else if (var=="cycles") { - if (action==PUT_ACTION) { - sscanf(args[1],"%d",&ival); - setTimer(CYCLES_NUMBER,ival); - } - sprintf(answer,"%lld",setTimer(CYCLES_NUMBER)); - return string(answer); - } else if (var=="probes") { - if (action==PUT_ACTION) { - sscanf(args[1],"%d",&ival); - setTimer(PROBES_NUMBER,ival); - } - sprintf(answer,"%lld",setTimer(PROBES_NUMBER)); - return string(answer); - } - - else if (var=="exptimel") { - if (action==PUT_ACTION) { - sprintf(answer,"Cannot set\n"); - } else - sprintf(answer,"%f",(float)getTimeLeft(ACQUISITION_TIME)*1E-9); - return string(answer); - } else if (var=="periodl") { - if (action==PUT_ACTION) { - sprintf(answer,"Cannot set\n"); - } else - sprintf(answer,"%f",(float)getTimeLeft(FRAME_PERIOD)*1E-9); - return string(answer); - } else if (var=="delayl") { - if (action==PUT_ACTION) { - sprintf(answer,"Cannot set\n"); - } else - sprintf(answer,"%f",(float)getTimeLeft(DELAY_AFTER_TRIGGER)*1E-9); - return string(answer); - } else if (var=="gatesl") { - if (action==PUT_ACTION) { - sprintf(answer,"Cannot set\n"); - } else - sprintf(answer,"%f",(float)getTimeLeft(GATES_NUMBER)); - return string(answer); - } else if (var=="framesl") { - if (action==PUT_ACTION) { - sprintf(answer,"Cannot set\n"); - } else - sprintf(answer,"%f",(float)getTimeLeft(FRAME_NUMBER)+2); - return string(answer); - } else if (var=="cyclesl") { - if (action==PUT_ACTION) { - sprintf(answer,"Cannot set\n"); - } else - sprintf(answer,"%f",(float)getTimeLeft(CYCLES_NUMBER)+2); - return string(answer); - } else if (var=="progress") { - if (action==PUT_ACTION) { - setTotalProgress(); - sprintf(answer,"Cannot set\n"); - } else - sprintf(answer,"%f",getCurrentProgress()); - return string(answer); - } else if (var=="now") { - if (action==PUT_ACTION) { - sprintf(answer,"Cannot set\n"); - } else - sprintf(answer,"%0.9f",(float)getTimeLeft(ACTUAL_TIME)*1E-9); - //sprintf(answer,"%x",getTimeLeft(ACTUAL_TIME)); - return string(answer); - } else if (var=="timestamp") { - if (action==PUT_ACTION) { - sprintf(answer,"Cannot set\n"); - } else - sprintf(answer,"%0.9f",(float)getTimeLeft(MEASUREMENT_TIME)*1E-9); - //sprintf(answer,"%x",getTimeLeft(MEASUREMENT_TIME)); - return string(answer); - } - - - else if (var=="dr") { - if (action==PUT_ACTION) { - sscanf(args[1],"%d",&ival); - setDynamicRange(ival); - } - sprintf(answer,"%d",setDynamicRange()); - return string(answer); - } else if (var=="flags") { - if (action==PUT_ACTION) { - sval=string(args[1]); - readOutFlags flag=GET_READOUT_FLAGS; - if (sval=="none") - flag=NORMAL_READOUT; - //else if (sval=="pumpprobe") - // flag=PUMP_PROBE_MODE; - else if (sval=="storeinram") - flag=STORE_IN_RAM; - else if (sval=="tot") - flag=TOT_MODE; - else if (sval=="continous") - flag=CONTINOUS_RO; - setReadOutFlags(flag); - - } - - switch (setReadOutFlags(GET_READOUT_FLAGS)) { - case NORMAL_READOUT: - return string("none"); - case STORE_IN_RAM: - return string("storeinram"); - case TOT_MODE: - return string("tot"); - case CONTINOUS_RO: - return string("continous"); - default: - return string("unknown"); - } - } else if (var=="trimbits") { - if (narg>=2) { - int nm=setNumberOfModules(GET_FLAG,X)*setNumberOfModules(GET_FLAG,Y); - sls_detector_module *myMod=NULL; - sval=string(args[1]); - std::cout<< " trimfile " << sval << std::endl; - - for (int im=0; immodule=im; - setModule(*myMod); - deleteModule(myMod); - } //else cout << "myMod NULL" << endl; - } - } - } - std::cout<< "Returning trimfile " << std::endl; - return string(getSettingsFile()); - } else if (var.find("trim")==0) { - if (action==GET_ACTION) { - trimMode mode=NOISE_TRIMMING; - int par1=0, par2=0; - if (var.size()<=5) - return string("trim:mode fname"); - - if (var.substr(5)=="noise") { - // par1 is countlim; par2 is nsigma - mode=NOISE_TRIMMING; - par1=500; - par2=4; - } else if (var.substr(5)=="beam") { - // par1 is countlim; par2 is nsigma - mode=BEAM_TRIMMING; - par1=1000; - par2=4; - } else if (var.substr(5)=="improve") { - // par1 is maxit; if par2!=0 vthresh will be optimized - mode=IMPROVE_TRIMMING; - par1=5; - par2=0; - } else if (var.substr(5)=="fix") { - // par1 is countlim; if par2<0 then trimwithlevel else trim with median - mode=FIXEDSETTINGS_TRIMMING; - par1=1000; - par2=1; - } else if (var.substr(5)=="offline") { - mode=OFFLINE_TRIMMING; - } else { - return string("Unknown trim mode ")+var.substr(5); - } - executeTrimming(mode, par1, par2); - sval=string(args[1]); - sls_detector_module *myMod=NULL; - int nm=setNumberOfModules(GET_FLAG,X)*setNumberOfModules(GET_FLAG,Y); - for (int im=0; im1)) - return string("use only 0/1 to reset/set digital_test_bit"); - if(configureMAC(ival)==-1) - return string("client ip address/client mac address not valid"); - return string("mac configuration completed"); - } - } - return ("Unknown command"); - -} - - - - - - - - -string slsDetector::helpLine( int action) { - - - ostringstream os; - - if (action==READOUT_ACTION) { - os << "Usage is "<< std::endl << "mythen_acquire id " << std::endl; - os << "where id is the id of the detector " << std::endl; - os << "the detector will be started, the data acquired, processed and written to file according to the preferences configured " << std::endl; - } else if (action==PUT_ACTION) { - os << "help \t This help " << std::endl; - os << std::endl; - os << "config fname\t reads the configuration file specified and sets the values " << std::endl; - os << std::endl; - os << "parameters fname\t sets the detector parameters specified in the file " << std::endl; - os << std::endl; - os << "setup rootname\t reads the files specfied (and that could be created by get setup) and resets the complete detector configuration including flatfield corrections, badchannels, trimbits etc. " << std::endl; - os << std::endl; - os << "status s \t either start or stop " << std::endl; - os << std::endl; - os << "hostname name \t Sets the detector hostname (or IP address) " << std::endl; - os << std::endl; - os << "caldir path \t Sets path of the calibration files " << std::endl; - os << std::endl; - os << "trimdir path \t Sets path of the trim files " << std::endl; - os << std::endl; - os << "trimen nen [e0 e1...en] \t sets the number of energies for which trimbit files exist and their value"<< std::endl; - os << std::endl; - - - - - - - - - os << "startscript script \t sets script to execute at the beginning of the measurements - \"none\" to unset - will be launched as a system call with arguments nrun=fileindex par=startscriptpar"<< std::endl; - os << std::endl; - os << "startscriptpar par \t sets start script parameter (see startscript)"<< std::endl; - os << std::endl; - - os << "scan0script script \t sets script to launch at level 0 scan. If \"energy\" energy scan, if \"threshold\" threshold scan, if \"trimbits\" trimbits scan, \"none\" unsets otherwise will be launched as a system call with arguments nrun=fileindex fn=filename var=scan0var par=scan0par"<< std::endl; - os << std::endl; - os << "scan0par par\t sets the level 0 scan parameter. See scan0script"<< std::endl; - os << std::endl; - os << "scan0prec n \t sets the level 0 scan precision for the output file name. See scan0script"<< std::endl; - os << std::endl; - os << "scan0steps nsteps [s0 s1...] \t sets the level 0 scan steps. See scan0script - nsteps=0 unsets the scan level"<< std::endl; - os << std::endl; - - - os << "scan1script script \t sets script to launch at level 1 scan. If \"energy\" energy scan, if \"threshold\" threshold scan, if \"trimbits\" trimbits scan, \"none\" unsets otherwise will be launched as a system call with arguments nrun=fileindex fn=filename var=scan1var par=scan1par"<< std::endl; - os << std::endl; - - os << "scan1par par\t sets the level 1 scan parameter. See scan1script"<< std::endl; - os << std::endl; - os << "scan1prec n \t sets the level 1 scan precision for the output file name. See scan1script"<< std::endl; - os << std::endl; - os << "scan1steps nsteps [s0 s1...] \t sets the level 1 scan steps. See scan1script - nsteps=0 unsets the scan level"<< std::endl; - os << std::endl; - - - os << "scriptbefore script \t sets script to execute at the beginning of the realtime acquisition - \"none\" to unset - will be launched as a system call with arguments nrun=fileindex fn=filename par=scriptbeforepar sv0=scan0var sv1=scan1var p0=scan0par p1=scan1par"<< std::endl; - os << std::endl; - os << "scriptbeforepar \t sets script before parameter (see scriptbefore)"<< std::endl; - os << std::endl; - - os << "headerbefore script \n script to launch to acquire the headerfile just before the acquisition - \"none\" to unset - will be launched as a system call with arguments nrun=fileindex fn=filename acqtime=t gainmode=sett threshold=thr badfile=badf angfile=angf bloffset=bloffset fineoffset=fineoffset fffile=ffile tau=taucorr par=headerbeforepar"<< std::endl; - os << std::endl; - os << "headerbeforepar \t sets header before parameter (see headerbefore)"<< std::endl; - os << std::endl; - - - os << "headerafter script \n script to launch to acquire the headerfile just after the acquisition - \"none\" to unset - will be launched as a system call with arguments nrun=fileindex fn=filename acqtime=t gainmode=sett threshold=thr badfile=badf angfile=angf bloffset=bloffset fineoffset=fineoffset fffile=ffile tau=taucorr par=headerafterpar"<< std::endl; - os << std::endl; - os << "headerafterpar par \t sets header after parameter (see headerafter)"<< std::endl; - os << std::endl; - - os << "scriptafter script \t sets script to execute at the end of the realtime acquisition - \"none\" to unset - will be launched as a system call with arguments nrun=fileindex fn=filename par=scriptafterpar sv0=scan0var sv1=scan1var p0=scan0par p1=scan1par"<< std::endl; - os << std::endl; - os << "scriptafterpar par \t sets script after parameter (see scriptafter)"<< std::endl; - os << std::endl; - - - os << "stopscript script \t sets script to execute at the end of the measurements - \"none\" to unset - will be launched as a system call with arguments nrun=fileindex par=stopscriptpar"<< std::endl; - os << std::endl; - os << "stopscriptpar par\t sets stop script parameter (see stopscript)"<< std::endl; - os << std::endl; - - - - - - os << "outdir \t directory to which the files will be written by default" << std::endl; - os << std::endl; - os << "fname \t filename to which the files will be written by default (to which file and position indexes will eventually be attached)" << std::endl; - os << std::endl; - os << "index \t start index of the files (automatically incremented by the acquisition functions)" << std::endl; - os << std::endl; - os << "nmod n \t Sets number of detector modules " << std::endl; - os << std::endl; - os << "extsig:i mode \t Sets usage of the external digital signal i. mode can be: " << std::endl; - os << "\t off"; - os << std::endl; - os << "\t gate_in_active_high"; - os << std::endl; - os << "\t gate_in_active_low"; - os << std::endl; - os << "\t trigger_in_rising_edge"; - os << std::endl; - os << "\t trigger_in_falling_edge"; - os << std::endl; - os << "\t ro_trigger_in_rising_edge"; - os << std::endl; - os << "\t ro_trigger_in_falling_edge"; - os << std::endl; - os << "\t gate_out_active_high"; - os << std::endl; - os << "\t gate_out_active_low"; - os << std::endl; - os << "\t trigger_out_rising_edge"; - os << std::endl; - os << "\t trigger_out_falling_edge"; - os << std::endl; - os << "\t ro_trigger_out_rising_edge"; - os << std::endl; - os << "\t ro_trigger_out_falling_edge" << std::endl; - os << std::endl; - os << "settings sett \t Sets detector settings. Can be: " << std::endl; - os << "\t standard \t fast \t highgain" << std::endl; - os << "\t depending on trheshold energy and maximum count rate: please refere to manual for limit values!"<< std::endl; - os << std::endl; - os << "threshold ev \t Sets detector threshold in eV. Should be half of the beam energy. It is precise only if the detector is calibrated"<< std::endl; - os << std::endl; - os << "vthreshold dacu\t sets the detector threshold in dac units (0-1024). The energy is approx 800-15*keV" << std::endl; - os << std::endl; - - os << "vcalibration " << "dacu\t sets the calibration pulse amplitude in dac units (0-1024)." << std::endl; - os << std::endl; - os << "vtrimbit " << "dacu\t sets the trimbit amplitude in dac units (0-1024)." << std::endl; - os << std::endl; - os << "vpreamp " << "dacu\t sets the preamp feedback voltage in dac units (0-1024)." << std::endl; - os << std::endl; - os << "vshaper1 " << "dacu\t sets the shaper1 feedback voltage in dac units (0-1024)." << std::endl; - os << std::endl; - os << "vshaper2 " << "dacu\t sets the shaper2 feedback voltage in dac units (0-1024)." << std::endl; - os << std::endl; - os << "vhighvoltage " << "dacu\t CHIPTEST BOARD ONLY - sets the detector HV in dac units (0-1024)." << std::endl; - os << std::endl; - os << "vapower " << "dacu\t CHIPTEST BOARD ONLY - sets the analog power supply in dac units (0-1024)." << std::endl; - os << std::endl; - os << "vddpower " << "dacu\t CHIPTEST BOARD ONLY - sets the digital power supply in dac units (0-1024)." << std::endl; - os << std::endl; - os << "vshpower " << "dacu\t CHIPTEST BOARD ONLY - sets the comparator power supply in dac units (0-1024)." << std::endl; - os << std::endl; - os << "viopower " << "dacu\t CHIPTEST BOARD ONLY - sets the FPGA I/O power supply in dac units (0-1024)." << std::endl; - - os << std::endl; - os << "exptime t \t Sets the exposure time per frame (in s)"<< std::endl; - os << std::endl; - os << "period t \t Sets the frames period (in s)"<< std::endl; - os << std::endl; - os << "delay t \t Sets the delay after trigger (in s)"<< std::endl; - os << std::endl; - os << "gates n \t Sets the number of gates per frame"<< std::endl; - os << std::endl; - os << "frames n \t Sets the number of frames per cycle (e.g. after each trigger)"<< std::endl; - os << std::endl; - os << "cycles n \t Sets the number of cycles (e.g. number of triggers)"<< std::endl; - os << std::endl; - os << "probes n \t Sets the number of probes to accumulate (max 3)"<< std::endl; - os << std::endl; - os << "dr n \t Sets the dynamic range - can be 1, 4, 8,16 or 24 bits"<< std::endl; - os << std::endl; - os << "flags mode \t Sets the readout flags - can be none or storeinram"<< std::endl; - os << std::endl; - os << "ffdir dir \t Sets the default directory where the flat field are located"<< std::endl; - os << std::endl; - os << "flatfield fname \t Sets the flatfield file name - none disable flat field corrections"<< std::endl; - os << std::endl; - os << "ratecorr t \t Sets the rate corrections with dead time t ns (0 unsets, -1 uses default dead time for chosen settings"<< std::endl; - os << std::endl; - os << "badchannels fname \t Sets the badchannels file name - none disable bad channels corrections"<< std::endl; - os << std::endl; - os << "angconv fname \t Sets the angular conversion file name"<< std::endl; - os << std::endl; - os << "globaloff o \t sets the fixed angular offset of your encoder - should be almost constant!"<< std::endl; - os << std::endl; - os << "fineoff o \t sets a possible angular offset of your setup - should be small but can be senseful to modify"<< std::endl; - os << std::endl; - os << "binsize s\t sets the binning size of the angular conversion (otherwise defaults from the angualr conversion constants)"<< std::endl; - os << std::endl; - os << "positions np [pos0 pos1...posnp] \t sets the number of positions at which the detector is moved during the acquisition and their values"<< std::endl; - os << std::endl; - os << "threaded b \t sets whether the postprocessing and file writing of the data is done in a separate thread (0 sequencial, 1 threaded). Please remeber to set the threaded mode if you acquire long real time measurements and/or use the storeinram option otherwise you risk to lose your data"<< std::endl; - os << std::endl; - os << "online b\t sets the detector in online (1) or offline (0) state " << std::endl; - os << std::endl; - } else if (action==GET_ACTION) { - os << "help \t This help " << std::endl; - - - os << "status \t gets the detector status - can be: running, error, transmitting, finished, waiting or idle" << std::endl; - os << "data \t gets all data from the detector (if any) processes them and writes them to file according to the preferences already setup" << std::endl; - os << "frame \t gets a single frame from the detector (if any) processes it and writes it to file according to the preferences already setup" << std::endl; - os << "config fname\t writes the configuration file" << std::endl; - os << std::endl; - os << "parameters fname\t writes the main detector parameters for the measuremen tin the file " << std::endl; - os << std::endl; - os << "setup rootname\t writes the complete detector setup (including configuration, trimbits, flat field coefficients, badchannels etc.) in a set of files for which the extension is automatically generated " << std::endl; - os << std::endl; - os << "hostname \t Gets the detector hostname (or IP address) " << std::endl; - os << std::endl; - os << "caldir \t Gets path of the calibration files " << std::endl; - os << std::endl; - os << "trimdir \t Gets path of the trim files " << std::endl; - os << std::endl; - os << "trimen \t returns the number of energies for which trimbit files exist and their values"<< std::endl; - - - - - - - os << "startscript \t gets script to execute at the beginning of the measurements - \"none\" to unset - will be launched as a system call with arguments nrun=fileindex par=startscriptpar"<< std::endl; - os << std::endl; - os << "startscriptpar \t gets start script parameter (see startscript)"<< std::endl; - os << std::endl; - - os << "scan0script \t gets script to launch at level 0 scan. If \"energy\" energy scan, if \"threshold\" threshold scan, if \"trimbits\" trimbits scan, \"none\" unsets otherwise will be launched as a system call with arguments nrun=fileindex fn=filename var=scan0var par=scan0par"<< std::endl; - os << std::endl; - os << "scan0par \t gets the level 0 scan parameter. See scan0script"<< std::endl; - os << std::endl; - os << "scan0prec \t gets the level 0 scan precision for the output file name. See scan0script"<< std::endl; - os << std::endl; - os << "scan0steps \t gets the level 0 scan steps. See scan0script - nsteps=0 unsets the scan level"<< std::endl; - os << std::endl; - - - os << "scan1script \t gets script to launch at level 1 scan. If \"energy\" energy scan, if \"threshold\" threshold scan, if \"trimbits\" trimbits scan, \"none\" unsets otherwise will be launched as a system call with arguments nrun=fileindex fn=filename var=scan1var par=scan1par"<< std::endl; - os << std::endl; - - os << "scan1par \t gets the level 1 scan parameter. See scan1script"<< std::endl; - os << std::endl; - os << "scan1prec \t gets the level 1 scan precision for the output file name. See scan1script"<< std::endl; - os << std::endl; - os << "scan1steps \t gets the level 1 scan steps. See scan1script - nsteps=0 unsets the scan level"<< std::endl; - os << std::endl; - - - os << "scriptbefore \t gets script to execute at the beginning of the realtime acquisition - \"none\" to unset - will be launched as a system call with arguments nrun=fileindex fn=filename par=scriptbeforepar sv0=scan0var sv1=scan1var p0=scan0par p1=scan1par"<< std::endl; - os << std::endl; - os << "scriptbeforepar \t gets script before parameter (see scriptbefore)"<< std::endl; - os << std::endl; - - os << "headerbefore \n gets the script to launch to acquire the headerfile just before the acquisition - \"none\" to unset - will be launched as a system call with arguments nrun=fileindex fn=filename acqtime=t gainmode=sett threshold=thr badfile=badf angfile=angf bloffset=bloffset fineoffset=fineoffset fffile=ffile tau=taucorr par=headerbeforepar"<< std::endl; - os << std::endl; - os << "headerbeforepar \t gets header before parameter (see headerbefore)"<< std::endl; - os << std::endl; - - - os << "headerafter \n gets the script to launch to acquire the headerfile just after the acquisition - \"none\" to unset - will be launched as a system call with arguments nrun=fileindex fn=filename acqtime=t gainmode=sett threshold=thr badfile=badf angfile=angf bloffset=bloffset fineoffset=fineoffset fffile=ffile tau=taucorr par=headerafterpar"<< std::endl; - os << std::endl; - os << "headerafterpar \t gets header after parameter (see headerafter)"<< std::endl; - os << std::endl; - - os << "scriptafter \t gets script to execute at the end of the realtime acquisition - \"none\" to unset - will be launched as a system call with arguments nrun=fileindex fn=filename par=scriptafterpar sv0=scan0var sv1=scan1var p0=scan0par p1=scan1par"<< std::endl; - os << std::endl; - os << "scriptafterpar \t gets script after parameter (see scriptafter)"<< std::endl; - os << std::endl; - - - os << "stopscript \t gets script to execute at the end of the measurements - \"none\" to unset - will be launched as a system call with arguments nrun=fileindex par=stopscriptpar"<< std::endl; - os << std::endl; - os << "stopscriptpar\t gets stop script parameter (see stopscript)"<< std::endl; - os << std::endl; - - - - - - - - - - - - - - - - - - - - - - os << "outdir \t directory to which the files will be written by default" << std::endl; - os << std::endl; - os << "fname \t filename to which the files will be written by default (to which file and position indexes will eventually be attached)" << std::endl; - os << std::endl; - os << "index \t start index of the files (automatically incremented by the acquisition functions)" << std::endl; - os << std::endl; - os << "nmod \t Gets number of detector modules " << std::endl; - os << std::endl; - os << "maxmod \t Gets maximum number of detector modules " << std::endl; - os << std::endl; - os << "extsig:i\t Gets usage of the external digital signal i. The return value can be: " << std::endl; - os << "\t 0 off"; - os << std::endl; - os << "\t 1 gate_in_active_high"; - os << std::endl; - os << "\t 2 gate_in_active_low"; - os << std::endl; - os << "\t 3 trigger_in_rising_edge"; - os << std::endl; - os << "\t 4 trigger_in_falling_edge"; - os << std::endl; - os << "\t 5 ro_trigger_in_rising_edge"; - os << std::endl; - os << "\t 6 ro_trigger_in_falling_edge"; - os << std::endl; - os << "\t 7 gate_out_active_high"; - os << std::endl; - os << "\t 8 gate_out_active_low"; - os << std::endl; - os << "\t 9 trigger_out_rising_edge"; - os << std::endl; - os << "\t 10 trigger_out_falling_edge"; - os << std::endl; - os << "\t 11 ro_trigger_out_rising_edge"; - os << std::endl; - os << "\t 12 ro_trigger_out_falling_edge" << std::endl; - os << std::endl; - os << "modulenumber:i \t Gets the serial number of module i" << std::endl; - os << std::endl; - os << "moduleversion\t Gets the module version " << std::endl; - os << std::endl; - os << "detectornumber\t Gets the detector number (MAC address) " << std::endl; - os << std::endl; - os << "detectorversion\t Gets the detector firmware version " << std::endl; - os << std::endl; - os << "softwareversion\t Gets the detector software version " << std::endl; - os << std::endl; - os << "thisversion\t Gets the version of this software" << std::endl; - os << std::endl; - os << "digitest:i\t Makes a digital test of the detector module i. Returns 0 if it succeeds " << std::endl; - os << std::endl; - os << "bustest\t Makes a test of the detector bus. Returns 0 if it succeeds " << std::endl; - os << std::endl; - os << "settings\t Gets detector settings. Can be: " << std::endl; - os << "\t 0 standard \t 1 fast \t 2 highgain \t else undefined" << std::endl; - os << std::endl; - os << "threshold\t Gets detector threshold in eV. It is precise only if the detector is calibrated"<< std::endl; - os << std::endl; - os << "vthreshold \t Gets the detector threshold in dac units (0-1024). The energy is approx 800-15*keV" << std::endl; - os << std::endl; - - os << "vcalibration " << "dacu\t gets the calibration pulse amplitude in dac units (0-1024)." << std::endl; - os << std::endl; - os << "vtrimbit " << "dacu\t gets the trimbit amplitude in dac units (0-1024)." << std::endl; - os << std::endl; - os << "vpreamp " << "dacu\t gets the preamp feedback voltage in dac units (0-1024)." << std::endl; - os << std::endl; - os << "vshaper1 " << "dacu\t gets the shaper1 feedback voltage in dac units (0-1024)." << std::endl; - os << std::endl; - os << "vshaper2 " << "dacu\t gets the shaper2 feedback voltage in dac units (0-1024)." << std::endl; - os << std::endl; - os << "vhighvoltage " << "dacu\t CHIPTEST BOARD ONLY - gets the detector HV in dac units (0-1024)." << std::endl; - os << std::endl; - os << "vapower " << "dacu\t CHIPTEST BOARD ONLY - gets the analog power supply in dac units (0-1024)." << std::endl; - os << std::endl; - os << "vddpower " << "dacu\t CHIPTEST BOARD ONLY - gets the digital power supply in dac units (0-1024)." << std::endl; - os << std::endl; - os << "vshpower " << "dacu\t CHIPTEST BOARD ONLY - gets the comparator power supply in dac units (0-1024)." << std::endl; - os << std::endl; - os << "viopower " << "dacu\t CHIPTEST BOARD ONLY - gets the FPGA I/O power supply in dac units (0-1024)." << std::endl; - os << std::endl; - - - os << "exptime\t Gets the exposure time per frame (in s)"<< std::endl; - os << std::endl; - os << "period \t Gets the frames period (in s)"<< std::endl; - os << std::endl; - os << "delay \t Gets the delay after trigger (in s)"<< std::endl; - os << std::endl; - os << "gates \t Gets the number of gates per frame"<< std::endl; - os << std::endl; - os << "frames \t Gets the number of frames per cycle (e.g. after each trigger)"<< std::endl; - os << std::endl; - os << "cycles \t Gets the number of cycles (e.g. number of triggers)"<< std::endl; - os << std::endl; - os << "probes \t Gets the number of probes to accumulate (max 3)"<< std::endl; - - - - - os << "exptimel\t Gets the exposure time left in the current frame (in s)"<< std::endl; - os << std::endl; - os << "periodl \t Gets the period left in the current frame (in s)"<< std::endl; - os << std::endl; - os << "delayl \t Gets the delay after current trigger left (in s)"<< std::endl; - os << std::endl; - os << "gatesl \t Gets the number of gates left in the current frame"<< std::endl; - os << std::endl; - os << "framesl \t Gets the number of frames left (after the current trigger)"<< std::endl; - os << std::endl; - os << "cyclesl \t Gets the number of cycles left (e.g. number of triggers)"<< std::endl; - //os << std::endl; - //os << "progress \t Gets acquisition progress - to be implemented"<< std::endl; - - os << std::endl; - os << "now \t Gets the actual time of the detector (in s)"<< std::endl; - - - os << std::endl; - os << "timestamp \t Gets the time of the measurements of the detector (in s, -1 if no measurement left)"<< std::endl; - - - - - - os << std::endl; - os << "dr \t Gets the dynamic range"<< std::endl; - os << std::endl; - os << "trim:mode fname \t trims the detector and writes the trimfile fname.snxx "<< std::endl; - os << "\t mode can be:\t noise\t beam\t improve\t fix\t offline "<< std::endl; - os << "Check that the start conditions are OK!!!"<< std::endl; - os << std::endl; - os << "ffdir \t Returns the default directory where the flat field are located"<< std::endl; - os << std::endl; - os << "flatfield fname \t returns wether the flat field corrections are enabled and if so writes the coefficients to the specified filename. If fname is none it is not written"<< std::endl; - os << std::endl; - os << "ratecorr \t returns wether teh rate corrections are enabled and what is the dead time used in ns"<< std::endl; - os << std::endl; - os << "badchannels fname \t returns wether the bad channels corrections are enabled and if so writes the bad channels to the specified filename. If fname is none it is not written"<< std::endl; - os << std::endl; - os << "angconv fname \t returns wether the angular conversion is enabled and if so writes the angular conversion coefficients to the specified filename. If fname is none, it is not written"<< std::endl; - os << std::endl; - os << "globaloff \t returns the fixed angular offset of your encoder - should be almost constant!"<< std::endl; - os << std::endl; - os << "fineoff \t returns a possible angualr offset of your setup - should be small but can be senseful to modify"<< std::endl; - os << std::endl; - os << "binsize \t returns the binning size of the anular conversion"<< std::endl; - os << std::endl; - os << "positions \t returns the number of positions at which the detector is moved during the acquisition and their values"<< std::endl; - os << std::endl; - os << "threaded \t gets whether the postprocessing and file writing of the data is done in a separate thread (0 sequencial, 1 threaded). Check that it is set to 1 if you acquire long real time measurements and/or use the storeinram option otherwise you risk to lose your data"<< std::endl; - os << std::endl; - os << "online \t gets the detector online (1) or offline (0) state " << std::endl; - os << std::endl; - - - } - - - return os.str(); -} - - - - - //Corrections - - int slsDetector::setAngularConversion(string fname) { if (fname=="") { thisDetector->correctionMask&=~(1<< ANGULAR_CONVERSION); @@ -7077,865 +4493,92 @@ int slsDetector::getAngularConversion(int &direction, angleConversionConstant * -int slsDetector::readAngularConversion(string fname) { - string str; - ifstream infile; - int mod; - float center, ecenter; - float r_conv, er_conv; - float off, eoff; - string ss; - int interrupt=0; + int slsDetector::readAngularConversion(string fname) { - //" module %i center %E +- %E conversion %E +- %E offset %f +- %f \n" -#ifdef VERBOSE - std::cout<< "Opening file "<< fname << std::endl; -#endif - infile.open(fname.c_str(), ios_base::in); - if (infile.is_open()) { - while (infile.good() and interrupt==0) { - getline(infile,str); -#ifdef VERBOSE - std::cout<< str << std::endl; -#endif - istringstream ssstr(str); - ssstr >> ss >> mod; - ssstr >> ss >> center; - ssstr >> ss >> ecenter; - ssstr >> ss >> r_conv; - ssstr >> ss >> er_conv; - ssstr >> ss >> off; - ssstr >> ss >> eoff; - if (modnModsMax && mod>=0) { - thisDetector->angOff[mod].center=center; - thisDetector->angOff[mod].r_conversion=r_conv; - thisDetector->angOff[mod].offset=off; - thisDetector->angOff[mod].ecenter=ecenter; - thisDetector->angOff[mod].er_conversion=er_conv; - thisDetector->angOff[mod].eoffset=eoff; - } - } - } else { - std::cout<< "Could not open calibration file "<< fname << std::endl; - return -1; + return readAngularConversion(fname,thisDetector->nModsMax, thisDetector->angOff); + + } + + int slsDetector::readAngularConversion(ifstream& ifs) { + + return readAngularConversion(ifs,thisDetector->nModsMax, thisDetector->angOff); + + } + + + + + + + + + + + + +float* slsDetector::convertAngles(float pos) { + int imod; + float *ang=new float[thisDetector->nChans*thisDetector->nChips*thisDetector->nMods]; + for (int ip=0; ipnChans*thisDetector->nChips*thisDetector->nMods; ip++) { + imod=ip/(thisDetector->nChans*thisDetector->nChips); + ang[ip]=angle(ip%(thisDetector->nChans*thisDetector->nChips),pos,thisDetector->fineOffset+thisDetector->globalOffset,thisDetector->angOff[imod].r_conversion,thisDetector->angOff[imod].center, thisDetector->angOff[imod].offset,thisDetector->angOff[imod].tilt,thisDetector->angDirection); } - return 0; + return ang; } + + + int slsDetector:: writeAngularConversion(string fname) { - ofstream outfile; - outfile.open (fname.c_str(),ios_base::out); - if (outfile.is_open()) - { - for (int imod=0; imodnMods; imod++) { - outfile << " module " << imod << " center "<< thisDetector->angOff[imod].center<<" +- "<< thisDetector->angOff[imod].ecenter<<" conversion "<< thisDetector->angOff[imod].r_conversion << " +- "<< thisDetector->angOff[imod].er_conversion << " offset "<< thisDetector->angOff[imod].offset << " +- "<< thisDetector->angOff[imod].eoffset << std::endl; - } - outfile.close(); - } else { - std::cout<< "Could not open file " << fname << "for writing"<< std::endl; - return -1; - } - //" module %i center %E +- %E conversion %E +- %E offset %f +- %f \n" - return 0; -} -int slsDetector::resetMerging(float *mp, float *mv, float *me, int *mm) { - - float binsize; - if (thisDetector->binSize>0) - binsize=thisDetector->binSize; - else - return FAIL; - - for (int ibin=0; ibin<(360./binsize); ibin++) { - mp[ibin]=0; - mv[ibin]=0; - me[ibin]=0; - mm[ibin]=0; - } - return OK; + return writeAngularConversion(fname, thisDetector->nMods, thisDetector->angOff); + } -int slsDetector::finalizeMerging(float *mp, float *mv, float *me, int *mm) { - float binsize; - int np=0; +int slsDetector:: writeAngularConversion(ofstream &ofs) { - if (thisDetector->binSize>0) - binsize=thisDetector->binSize; - else - return FAIL; - - for (int ibin=0; ibin<(360./binsize); ibin++) { - if (mm[ibin]>0) { - mp[np]=mp[ibin]/mm[ibin]; - mv[np]=mv[ibin]/mm[ibin]; - me[np]=me[ibin]/mm[ibin]; - me[np]=sqrt(me[ibin]); - mm[np]=mm[ibin]; - np++; - } - } - return np; -} + return writeAngularConversion(ofs, thisDetector->nMods, thisDetector->angOff); -int slsDetector::addToMerging(float *p1, float *v1, float *e1, float *mp, float *mv,float *me, int *mm) { - - float binsize; - float binmi=-180., binma; - int ibin=0; - int imod; - float ang=0; - if (thisDetector->binSize>0) - binsize=thisDetector->binSize; - else - return FAIL; - binmi=-180.; - binma=binmi+binsize; - - - if (thisDetector->angDirection>0) { - for (int ip=0; ipnChans*thisDetector->nChips*thisDetector->nMods; ip++) { - if ((thisDetector->correctionMask)&(1<< DISCARD_BAD_CHANNELS)) { - if (badChannelMask[ip]) { - continue; - } - } - imod=ip/(thisDetector->nChans*thisDetector->nChips); - if (p1) - ang=p1[ip]; - else - ang=angle(ip,currentPosition,thisDetector->fineOffset+thisDetector->globalOffset,thisDetector->angOff[imod].r_conversion,thisDetector->angOff[imod].center, thisDetector->angOff[imod].offset,thisDetector->angOff[imod].tilt,thisDetector->angDirection); - - - - while (binmanChans*thisDetector->nChips*thisDetector->nMods-1; ip>=0; ip--) { - if ((thisDetector->correctionMask)&(1<< DISCARD_BAD_CHANNELS)) { - if (badChannelMask[ip]) - continue; - - } - - while (binmafileIndex; - int lastindex=thisDetector->fileIndex; - char cmd[MAX_STR_LENGTH]; - int nowindex=thisDetector->fileIndex; - string fn; - - - //string sett; - if ((thisDetector->correctionMask&(1<< ANGULAR_CONVERSION)) || (thisDetector->correctionMask&(1<< I0_NORMALIZATION))) - connect_channels(); - - - - - thisDetector->progressIndex=0; - thisDetector->stoppedFlag=0; - - - - resetFinalDataQueue(); - resetDataQueue(); - - - //cout << "main mutex lock line 6188" << endl; - pthread_mutex_lock(&mp); - jointhread=0; - queuesize=0; - pthread_mutex_unlock(&mp); - //cout << "main mutex unlock line 6188" << endl; - - - - - - if (thisDetector->threadedProcessing) { - startThread(delflag); - } - //cout << "data thread started " << endl; - int np=1; - if (thisDetector->numberOfPositions>0) - np=thisDetector->numberOfPositions; - - int ns0=1; - if (thisDetector->actionMask & (1 << MAX_ACTIONS)) { - ns0=thisDetector->nScanSteps[0]; - } - if (ns0<1) - ns0=1; - - - int ns1=1; - if (thisDetector->actionMask & (1 << (MAX_ACTIONS+1))) { - ns1=thisDetector->nScanSteps[1]; - } - if (ns1<1) - ns1=1; - - - - - //cout << "action at start" << endl; - if (thisDetector->stoppedFlag==0) { - if (thisDetector->actionMask & (1 << startScript)) { - //"Custom start script. The arguments are passed as nrun=n par=p."); - sprintf(cmd,"%s nrun=%d par=%s",thisDetector->actionScript[startScript],thisDetector->fileIndex,thisDetector->actionParameter[startScript]); -#ifdef VERBOSE - cout << "Executing start script " << cmd << endl; -#endif - system(cmd); - } - } - - for (int is0=0; is0stoppedFlag==0) { - - currentScanVariable[0]=thisDetector->scanSteps[0][is0]; - currentScanIndex[0]=is0; - - switch(thisDetector->scanMode[0]) { - case 1: - setThresholdEnergy((int)currentScanVariable[0]); //energy scan - break; - case 2: - setDAC(currentScanVariable[0],THRESHOLD); // threshold scan - break; - case 3: - trimbit=(int)currentScanVariable[0]; - setChannel((trimbit<<((int)TRIMBIT_OFF))|((int)COMPARATOR_ENABLE)); // trimbit scan - break; - case 0: - currentScanVariable[0]=0; - break; - default: - //Custom scan script level 0. The arguments are passed as nrun=n fn=filename var=v par=p" - sprintf(cmd,"%s nrun=%d fn=%s var=%f par=%s",thisDetector->scanScript[0],thisDetector->fileIndex,createFileName().c_str(),currentScanVariable[0],thisDetector->scanParameter[0]); -#ifdef VERBOSE - cout << "Executing scan script 0 " << cmd << endl; -#endif - system(cmd); - - - } - } else - break; - - - for (int is1=0; is1stoppedFlag==0) { - - currentScanVariable[1]=thisDetector->scanSteps[1][is1]; - currentScanIndex[1]=is1; - - switch(thisDetector->scanMode[1]) { - case 1: - setThresholdEnergy((int)currentScanVariable[1]); //energy scan - break; - case 2: - setDAC(currentScanVariable[1],THRESHOLD); // threshold scan - break; - case 3: - trimbit=(int)currentScanVariable[1]; - setChannel((trimbit<<((int)TRIMBIT_OFF))|((int)COMPARATOR_ENABLE)); // trimbit scan - break; - case 0: - currentScanVariable[1]=0; - break; - default: - //Custom scan script level 1. The arguments are passed as nrun=n fn=filename var=v par=p" - sprintf(cmd,"%s nrun=%d fn=%s var=%f par=%s",thisDetector->scanScript[1],thisDetector->fileIndex,createFileName().c_str(),currentScanVariable[1],thisDetector->scanParameter[1]); -#ifdef VERBOSE - cout << "Executing scan script 1 " << cmd << endl; -#endif - system(cmd); - } - - } else - break; - - if (thisDetector->stoppedFlag==0) { - if (thisDetector->actionMask & (1 << scriptBefore)) { - //Custom script before each frame. The arguments are passed as nrun=n fn=filename par=p sv0=scanvar0 sv1=scanvar1 p0=par0 p1=par1" - sprintf(cmd,"%s nrun=%d fn=%s par=%s sv0=%f sv1=%f p0=%s p1=%s",thisDetector->actionScript[scriptBefore],thisDetector->fileIndex,createFileName().c_str(),thisDetector->actionParameter[scriptBefore],currentScanVariable[0],currentScanVariable[1],thisDetector->scanParameter[0],thisDetector->scanParameter[1]); -#ifdef VERBOSE - cout << "Executing script before " << cmd << endl; -#endif - system(cmd); - } - } else - break; - - currentPositionIndex=0; - - for (int ip=0; ipstoppedFlag==0) { - if (thisDetector->numberOfPositions>0) { - go_to_position (thisDetector->detPositions[ip]); - currentPositionIndex=ip+1; -#ifdef VERBOSE - std::cout<< "moving to position" << std::endl; -#endif - } - } else - break; - - //write header before? - //cmd=headerBeforeScript; - //Custom script to write the header. \n The arguments will be passed as nrun=n fn=filenam acqtime=t gainmode=g threshold=thr badfile=badf angfile=angf bloffset=blo fineoffset=fo fffile=fffn tau=deadtau par=p") - - // cout << "aaaaa" << endl; - //cout << createFileName() << endl; - //cout << "bbbbb" << endl; - fn=createFileName(); - //cout << fn << endl; - nowindex=thisDetector->fileIndex; - - if (thisDetector->stoppedFlag==0) { - - - if (thisDetector->correctionMask&(1<< I0_NORMALIZATION)) - currentI0=get_i0(); - - // cout << "header " << endl; - if (thisDetector->actionMask & (1 << headerBefore)) { - //Custom script after each frame. The arguments are passed as nrun=n fn=filename par=p sv0=scanvar0 sv1=scanvar1 p0=par0 p1=par1" - sprintf(cmd,"%s nrun=%d fn=%s acqtime=%f gainmode=%d threshold=%d badfile=%s angfile=%s bloffset=%f fineoffset=%f fffile=%s/%s tau=%f par=%s",thisDetector->actionScript[headerBefore],nowindex,fn.c_str(),((float)thisDetector->timerValue[ACQUISITION_TIME])*1E-9, thisDetector->currentSettings, thisDetector->currentThresholdEV, getBadChannelCorrectionFile().c_str(), getAngularConversion().c_str(), thisDetector->globalOffset, thisDetector->fineOffset,getFlatFieldCorrectionDir(),getFlatFieldCorrectionFile(), getRateCorrectionTau(), thisDetector->actionParameter[headerBefore]); -#ifdef VERBOSE - cout << "Executing header before " << cmd << endl; -#endif - system(cmd); - } - } else - break; - - - - if (thisDetector->stoppedFlag==0) { - - // cout << "starting???? " << endl; - startAndReadAll(); - - if (thisDetector->correctionMask&(1<< ANGULAR_CONVERSION)) - currentPosition=get_position(); - - if (thisDetector->correctionMask&(1<< I0_NORMALIZATION)) - currentI0=get_i0()-currentI0; - - - if (thisDetector->threadedProcessing==0) - processData(delflag); - - - } else - break; - - //while (!dataQueue.empty()){ - //cout << "main mutex lock line 6372" << endl; - pthread_mutex_lock(&mp); - while (queuesize){ - pthread_mutex_unlock(&mp); - //cout << "main mutex unlock line 6375" << endl; - usleep(10000); - //cout << "main mutex lock line 6378" << endl; - pthread_mutex_lock(&mp); - } - pthread_mutex_unlock(&mp); - //cout << "main mutex unlock line 6381" << endl; - - if (thisDetector->stoppedFlag==0) { - if (thisDetector->actionMask & (1 << headerAfter)) { - //Custom script after each frame. The arguments are passed as nrun=n fn=filename par=p sv0=scanvar0 sv1=scanvar1 p0=par0 p1=par1" - sprintf(cmd,"%s nrun=%d fn=%s acqtime=%f gainmode=%d threshold=%d badfile=%s angfile=%s bloffset=%f fineoffset=%f fffile=%s/%s tau=%f par=%s", \ - thisDetector->actionScript[headerAfter], \ - nowindex, \ - fn.c_str(), \ - ((float)thisDetector->timerValue[ACQUISITION_TIME])*1E-9, \ - thisDetector->currentSettings, \ - thisDetector->currentThresholdEV, \ - getBadChannelCorrectionFile().c_str(), \ - getAngularConversion().c_str(), \ - thisDetector->globalOffset, \ - thisDetector->fineOffset, \ - getFlatFieldCorrectionDir(), \ - getFlatFieldCorrectionFile(), \ - getRateCorrectionTau(), \ - thisDetector->actionParameter[headerAfter]); -#ifdef VERBOSE - cout << "Executing header after " << cmd << endl; -#endif - system(cmd); - - } - if (thisDetector->fileIndex>lastindex) - lastindex=thisDetector->fileIndex; - } else { - - - if (thisDetector->fileIndex>lastindex) - lastindex=thisDetector->fileIndex; - - break; - } - - - - if (thisDetector->stoppedFlag) { -#ifdef VERBOSE - std::cout<< "exiting since the detector has been stopped" << std::endl; -#endif - break; - } else if (ip<(np-1)) { - thisDetector->fileIndex=startindex; - } - } // loop on position finished - - //script after - if (thisDetector->stoppedFlag==0) { - if (thisDetector->actionMask & (1 << scriptAfter)) { - //Custom script after each frame. The arguments are passed as nrun=n fn=filename par=p sv0=scanvar0 sv1=scanvar1 p0=par0 p1=par1" - sprintf(cmd,"%s nrun=%d fn=%s par=%s sv0=%f sv1=%f p0=%s p1=%s",thisDetector->actionScript[scriptAfter],thisDetector->fileIndex,createFileName().c_str(),thisDetector->actionParameter[scriptAfter],currentScanVariable[0],currentScanVariable[1],thisDetector->scanParameter[0],thisDetector->scanParameter[1]); -#ifdef VERBOSE - cout << "Executing script after " << cmd << endl; -#endif - system(cmd); - } - } else - break; - - - if (thisDetector->stoppedFlag) { -#ifdef VERBOSE - std::cout<< "exiting since the detector has been stopped" << std::endl; -#endif - break; - } else if (is1<(ns1-1)) { - thisDetector->fileIndex=startindex; - } - - - } - - //end scan1 loop is1 - //currentScanVariable[MAX_SCAN_LEVELS]; - - - if (thisDetector->stoppedFlag) { -#ifdef VERBOSE - std::cout<< "exiting since the detector has been stopped" << std::endl; -#endif - break; - } else if (is0<(ns0-1)) { - thisDetector->fileIndex=startindex; - } - } //end scan0 loop is0 - - thisDetector->fileIndex=lastindex; - if (thisDetector->stoppedFlag==0) { - if (thisDetector->actionMask & (1 << stopScript)) { - //Custom stop script. The arguments are passed as nrun=n par=p. - sprintf(cmd,"%s nrun=%d par=%s",thisDetector->actionScript[stopScript],thisDetector->fileIndex,thisDetector->actionParameter[stopScript]); -#ifdef VERBOSE - cout << "Executing stop script " << cmd << endl; -#endif - system(cmd); - } - } - - - if (thisDetector->threadedProcessing) { - //#ifdef VERBOSE - // std::cout<< " ***********************waiting for data processing thread to finish " << queuesize <<" " << thisDetector->fileIndex << std::endl ; - //#endif - //cout << "main mutex lock line 6488" << endl; - pthread_mutex_lock(&mp); - jointhread=1; - pthread_mutex_unlock(&mp); - //cout << "main mutex unlock line 6488" << endl; - pthread_join(dataProcessingThread, &status); - // std::cout<< " ***********************data processing finished " << queuesize <<" " << thisDetector->fileIndex << std::endl ; - } - - if ((thisDetector->correctionMask&(1<< ANGULAR_CONVERSION)) || (thisDetector->correctionMask&(1<< I0_NORMALIZATION))) - disconnect_channels(); -} - - -void* slsDetector::processData(int delflag) { - - - //cout << "thread mutex lock line 6505" << endl; - pthread_mutex_lock(&mp); - queuesize=dataQueue.size(); - pthread_mutex_unlock(&mp); - //cout << "thread mutex unlock line 6505" << endl; - - int *myData; - float *fdata; - float *rcdata=NULL, *rcerr=NULL; - float *ffcdata=NULL, *ffcerr=NULL; - float *ang=NULL; - float bs=0.004; - int imod; - int nb; - int np; - detectorData *thisData; - int dum=1; - string ext; - string fname; - - -#ifdef ACQVERBOSE - std::cout<< " processing data - threaded mode " << thisDetector->threadedProcessing; -#endif - - if (thisDetector->correctionMask!=0) { - ext=".dat"; - } else { - ext=".raw"; - } - while(dum | thisDetector->threadedProcessing) { // ???????????????????????? - - - // while( !dataQueue.empty() ) { - //cout << "thread mutex lock line 6539" << endl; - pthread_mutex_lock(&mp); - while((queuesize=dataQueue.size())>0) { - pthread_mutex_unlock(&mp); - //cout << "thread mutex unlock line 6543" << endl; - //queuesize=dataQueue.size(); - - /** Pop data queue */ - myData=dataQueue.front(); // get the data from the queue - if (myData) { - - - - thisDetector->progressIndex++; -#ifdef VERBOSE - cout << "Progress is " << getCurrentProgress() << " \%" << endl; -#endif - - //process data - /** decode data */ - fdata=decodeData(myData); - - fname=createFileName(); - - /** write raw data file */ - if (thisDetector->correctionMask==0 && delflag==1) { - //cout << "line 6570----" << endl; - writeDataFile (fname+string(".raw"), fdata, NULL, NULL, 'i'); - delete [] fdata; - } else { - //cout << "line 6574----" << endl; - writeDataFile (fname+string(".raw"), fdata, NULL, NULL, 'i'); - - /** rate correction */ - if (thisDetector->correctionMask&(1<nChans*thisDetector->nChips*thisDetector->nMods]; - rcerr=new float[thisDetector->nChans*thisDetector->nChips*thisDetector->nMods]; - rateCorrect(fdata,NULL,rcdata,rcerr); - delete [] fdata; - } else { - rcdata=fdata; - fdata=NULL; - } - - /** flat field correction */ - if (thisDetector->correctionMask&(1<nChans*thisDetector->nChips*thisDetector->nMods]; - ffcerr=new float[thisDetector->nChans*thisDetector->nChips*thisDetector->nMods]; - flatFieldCorrect(rcdata,rcerr,ffcdata,ffcerr); - delete [] rcdata; - delete [] rcerr; - } else { - ffcdata=rcdata; - ffcerr=rcerr; - rcdata=NULL; - rcerr=NULL; - } - - if (thisDetector->correctionMask&(1<< ANGULAR_CONVERSION)) { - - if (currentPositionIndex<=1) { - if (thisDetector->binSize>0) - bs=thisDetector->binSize; - else if (thisDetector->angOff[0].r_conversion>0) { - bs=180./PI*atan(thisDetector->angOff[0].r_conversion); - thisDetector->binSize=bs; - } else - thisDetector->binSize=bs; - - - nb=(int)(360./bs); - - mergingBins=new float[nb]; - mergingCounts=new float[nb]; - mergingErrors=new float[nb]; - mergingMultiplicity=new int[nb]; - - resetMerging(mergingBins, mergingCounts,mergingErrors, mergingMultiplicity); - } - /* it would be better to create an ang0 with 0 encoder position and add to merging/write to file simply specifying that offset so that when it cycles writing the data or adding to merging it also calculates the angular position */ - - ang=new float[thisDetector->nChans*thisDetector->nChips*thisDetector->nMods]; - for (int ip=0; ipnChans*thisDetector->nChips*thisDetector->nMods; ip++) { - imod=ip/(thisDetector->nChans*thisDetector->nChips); - ang[ip]=angle(ip%(thisDetector->nChans*thisDetector->nChips),currentPosition,thisDetector->fineOffset+thisDetector->globalOffset,thisDetector->angOff[imod].r_conversion,thisDetector->angOff[imod].center, thisDetector->angOff[imod].offset,thisDetector->angOff[imod].tilt,thisDetector->angDirection); - } - - if (thisDetector->correctionMask!=0) { - //cout << "line 6633----" << endl; - if (thisDetector->numberOfPositions>1) - writeDataFile (fname+string(".dat"), ffcdata, ffcerr,ang); - } - addToMerging(ang, ffcdata, ffcerr, mergingBins, mergingCounts,mergingErrors, mergingMultiplicity); - - if ((currentPositionIndex==thisDetector->numberOfPositions) || (currentPositionIndex==0)) { - np=finalizeMerging(mergingBins, mergingCounts,mergingErrors, mergingMultiplicity); - /** file writing */ - currentPositionIndex++; - fname=createFileName(); - if (thisDetector->correctionMask!=0) { - // cout << "line 6643----" << endl; - writeDataFile (fname+string(".dat"),mergingCounts, mergingErrors, mergingBins,'f',np); - } - if (delflag) { - delete [] mergingBins; - delete [] mergingCounts; - delete [] mergingErrors; - delete [] mergingMultiplicity; - } else { - thisData=new detectorData(mergingCounts,mergingErrors,mergingBins,getCurrentProgress(),(fname+string(ext)).c_str(),np);/* - if (thisDetector->correctionMask!=0) { - //thisData=new detectorData(mergingCounts,mergingErrors,mergingBins,thisDetector->progressIndex+1,(fname().append(".dat")).c_str(),np); - thisData=new detectorData(mergingCounts,mergingErrors,mergingBins,getCurrentProgress(),(fname().append(".dat")).c_str(),np); - } else { - thisData=new detectorData(mergingCounts,mergingErrors,mergingBins,getCurrentProgress(),(fname().append(".raw")).c_str(),np); - //thisData=new detectorData(mergingCounts,mergingErrors,mergingBins,thisDetector->progressIndex+1,(fname().append(".raw")).c_str(),np); - }*/ - finalDataQueue.push(thisData); - } - } - - if (ffcdata) - delete [] ffcdata; - if (ffcerr) - delete [] ffcerr; - if (ang) - delete [] ang; - } else { - if (thisDetector->correctionMask!=0) { - // cout << "line 6672----" << endl; - writeDataFile (fname+string(".dat"), ffcdata, ffcerr); - } - if (delflag) { - if (ffcdata) - delete [] ffcdata; - if (ffcerr) - delete [] ffcerr; - if (ang) - delete [] ang; - } else { - thisData=new detectorData(ffcdata,ffcerr,NULL,getCurrentProgress(),(fname+string(ext)).c_str(),thisDetector->nChans*thisDetector->nChips*thisDetector->nMods);/* - if (thisDetector->correctionMask!=0) { - thisData=new detectorData(ffcdata,ffcerr,NULL,getCurrentProgress(),(fname().append(".dat")).c_str(),thisDetector->nChans*thisDetector->nChips*thisDetector->nMods); - //thisData=new detectorData(ffcdata,ffcerr,NULL,thisDetector->progressIndex+1,(fname().append(".dat")).c_str(),thisDetector->nChans*thisDetector->nChips*thisDetector->nMods); - } else { - thisData=new detectorData(ffcdata,ffcerr,NULL,getCurrentProgress(),(fname().append(".raw")).c_str(),thisDetector->nChans*thisDetector->nChips*thisDetector->nMods); - //thisData=new detectorData(ffcdata,ffcerr,NULL,thisDetector->progressIndex+1,(fname().append(".raw")).c_str(),thisDetector->nChans*thisDetector->nChips*thisDetector->nMods); - }*/ - finalDataQueue.push(thisData); - } - } - } - thisDetector->fileIndex++; - - /* - thisDetector->progressIndex++; -#ifdef VERBOSE - cout << "Progress is " << getCurrentProgress() << " \%" << endl; -#endif - */ - - delete [] myData; - myData=NULL; - dataQueue.pop(); //remove the data from the queue - //cout << "thread mutex lock line 6697" << endl; - pthread_mutex_lock(&mp); - queuesize=dataQueue.size(); - pthread_mutex_unlock(&mp); - //cout << "thread mutex unlock line 6697" << endl; - usleep(1000); - //pthread_mutex_unlock(&mp); - } - pthread_mutex_unlock(&mp); - //cout << "thread mutex unlock line 6706" << endl; - usleep(1000); - // cout << "PPPPPPPPPPPPPPPPPPPP " << queuesize << " " << thisDetector->fileIndex << endl; - } - pthread_mutex_unlock(&mp); - //cout << "thread mutex unlock line 6711" << endl; - //cout << "thread mutex lock line 6711" << endl; - pthread_mutex_lock(&mp); - if (jointhread) { - pthread_mutex_unlock(&mp); - //cout << "thread mutex unlock line 6715" << endl; - if (dataQueue.size()==0) - break; - } else - pthread_mutex_unlock(&mp); - //cout << "thread mutex unlock line 6720" << endl; - - dum=0; - } // ???????????????????????? - return 0; } -void slsDetector::startThread(int delflag) { - pthread_attr_t tattr; - int ret; - sched_param param, mparam; - int policy= SCHED_OTHER; - - - // set the priority; others are unchanged - //newprio = 30; - mparam.sched_priority =1; - param.sched_priority =1; - - - /* Initialize and set thread detached attribute */ - pthread_attr_init(&tattr); - pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_JOINABLE); - - - - // param.sched_priority = 5; - // scheduling parameters of main thread - ret = pthread_setschedparam(pthread_self(), policy, &mparam); - //#ifdef VERBOSE - // printf("current priority is %d\n",param.sched_priority); - //#endif - if (delflag) - ret = pthread_create(&dataProcessingThread, &tattr,startProcessData, (void*)this); - else - ret = pthread_create(&dataProcessingThread, &tattr,startProcessDataNoDelete, (void*)this); - - pthread_attr_destroy(&tattr); - // scheduling parameters of target thread - ret = pthread_setschedparam(dataProcessingThread, policy, ¶m); - -} - - -void* startProcessData(void *n) { - //void* processData(void *n) { - slsDetector *myDet=(slsDetector*)n; - myDet->processData(1); - pthread_exit(NULL); - -} - -void* startProcessDataNoDelete(void *n) { - //void* processData(void *n) { - slsDetector *myDet=(slsDetector*)n; - myDet->processData(0); - pthread_exit(NULL); - -} - - /* - set positions for the acquisition - \param nPos number of positions - \param pos array with the encoder positions - \returns number of positions - */ -int slsDetector::setPositions(int nPos, float *pos){ - if (nPos>=0) - thisDetector->numberOfPositions=nPos; - for (int ip=0; ipdetPositions[ip]=pos[ip]; - setTotalProgress(); - - return thisDetector->numberOfPositions; -} -/* - get positions for the acquisition - \param pos array which will contain the encoder positions - \returns number of positions -*/ -int slsDetector::getPositions(float *pos){ - if (pos ) { - for (int ip=0; ipnumberOfPositions; ip++) - pos[ip]=thisDetector->detPositions[ip]; - } - setTotalProgress(); - - return thisDetector->numberOfPositions; -} - + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -8559,274 +5202,57 @@ int slsDetector::writeSettingsFile(string fname, int imod){ }; -int slsDetector::writeDataFile(string fname, float *data, float *err, float *ang, char dataformat, int nch){ +int slsDetector::loadSettingsFile(string fname, int imod) { - - if (nch==-1) - nch=thisDetector->nChans*thisDetector->nChips*thisDetector->nMods; - - - ofstream outfile; - int idata; - if (data==NULL) - return FAIL; - - // args|=0x10; // one line per channel! - - outfile.open (fname.c_str(),ios_base::out); - if (outfile.is_open()) - { -#ifdef VERBOSE - std::cout<< "writeDataFile Writing to file " << fname << std::endl; -#endif - for (int ichan=0; ichan=0) { + mmin=imod; + mmax=imod+1; + } + for (int im=mmin; immodule=im; + setModule(*myMod); + deleteModule(myMod); + } else + return FAIL; } -}; - - - - - - - -/*writes raw data file */ -int slsDetector::writeDataFile(string fname, int *data){ - ofstream outfile; - if (data==NULL) - return FAIL; - - outfile.open (fname.c_str(),ios_base::out); - if (outfile.is_open()) - { -#ifdef VERBOSE - std::cout<< "Writing to file " << fname << std::endl; -#endif - for (int ichan=0; ichannChans*thisDetector->nChips*thisDetector->nMods; ichan++) - outfile << ichan << " " << *(data+ichan) << std::endl; - outfile.close(); - return OK; - } else { - std::cout<< "Could not open file " << fname << "for writing"<< std::endl; - return FAIL; - } -}; - - - -int slsDetector::readDataFile(string fname, float *data, float *err, float *ang, char dataformat) { - return readDataFile(thisDetector->nChans*thisDetector->nChips*thisDetector->nMods, fname, data, err, ang, dataformat); - + return OK; } - int slsDetector::readDataFile(int nch, string fname, float *data, float *err, float *ang, char dataformat){ + +int slsDetector::saveSettingsFile(string fname, int imod) { - ifstream infile; - int ichan, iline=0; - int interrupt=0; - float fdata, ferr, fang; - int maxchans; - int ich; - string str; + sls_detector_module *myMod=NULL; + int ret=FAIL; - - maxchans=nch; - -#ifdef VERBOSE - std::cout<< "Opening file "<< fname << std::endl; -#endif - infile.open(fname.c_str(), ios_base::in); - if (infile.is_open()) { - while (infile.good() and interrupt==0) { - getline(infile,str); -#ifdef VERBOSE - std::cout<< str << std::endl; -#endif - istringstream ssstr(str); - if (ang==NULL) { - ssstr >> ichan >> fdata; - ich=ichan; - if (ssstr.fail() || ssstr.bad()) { - interrupt=1; - break; - } - if (ich!=iline) - std::cout<< "Channel number " << ichan << " does not match with line number " << iline << " " << dataformat << std::endl; - } else { - ssstr >> fang >> fdata; - ich=iline; - } - if (ssstr.fail() || ssstr.bad()) { - interrupt=1; - break; - } - if (err) - ssstr >> ferr; - if (ssstr.fail() || ssstr.bad()) { - interrupt=1; - break; - } - if (ich=0) { + mmin=imod; + mmax=imod+1; + } + for (int im=mmin; imnChans*thisDetector->nChips*thisDetector->nMods); -}; - -int slsDetector::readDataFile(string fname, int *data, int nch){ - - ifstream infile; - int ichan, idata, iline=0; - int interrupt=0; - string str; - -#ifdef VERBOSE - std::cout<< "Opening file "<< fname << std::endl; -#endif - infile.open(fname.c_str(), ios_base::in); - if (infile.is_open()) { - while (infile.good() and interrupt==0) { - getline(infile,str); -#ifdef VERBOSE - std::cout<< str << std::endl; -#endif - istringstream ssstr(str); - ssstr >> ichan >> idata; - if (ssstr.fail() || ssstr.bad()) { - interrupt=1; - break; - } - if (ichan!=iline) { - std::cout<< " Expected channel "<< iline <<" but read channel "<< ichan << std::endl; - interrupt=1; - break; - } else { - if (iline> offset >> gain; - infile.close(); - } else { - std::cout<< "Could not open calibration file "<< fname << std::endl; - gain=0.; - offset=0.; - return -1; - } - return 0; -}; - -int slsDetector::writeCalibrationFile(string fname, float gain, float offset){ - //std::cout<< "Function not yet implemented " << std::endl; - ofstream outfile; - - outfile.open (fname.c_str()); - - // >> i/o operations here << - if (outfile.is_open()) { - outfile << offset << " " << gain << std::endl; - } else { - std::cout<< "Could not open calibration file "<< fname << " for writing" << std::endl; - return -1; - } - - outfile.close(); - - return 0; -}; - - - - - + return ret; +} diff --git a/slsDetectorSoftware/slsDetector/slsDetector.h b/slsDetectorSoftware/slsDetector/slsDetector.h index 77b518446..d35b04444 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.h +++ b/slsDetectorSoftware/slsDetector/slsDetector.h @@ -5,75 +5,30 @@ #define SLS_DETECTOR_H #include "MySocketTCP.h" -#include -#include -#include -#include -#include -#include - #include -extern "C" { - #include -} - #include - #include - #include - #include - #include +/* #include */ +/* #include */ +/* #include */ +/* #include */ +/* #include */ +/* #include */ +/* #include */ +/* extern "C" { */ +/* #include */ +/* } */ +/* #include */ +/* #include */ +/* #include */ +/* #include */ +/* #include */ -#include "sls_detector_defs.h" - -#define MAX_TIMERS 10 -#define MAX_ROIS 100 -#define MAX_BADCHANS 2000 -#define MAXPOS 50 -#define MAX_SCAN_LEVELS 2 -#define MAX_SCAN_STEPS 2000 - -#define NMODMAXX 24 -#define NMODMAXY 24 -#define MAXMODS 36 -#define NCHIPSMAX 10 -#define NCHANSMAX 65536 -#define NDACSMAX 16 - -#define DEFAULT_HOSTNAME "localhost" -#define DEFAULT_SHM_KEY 5678 - -#define defaultTDead {170,90,750} /**< should be changed in order to have it separate for the different detector types */ +//#include "sls_detector_defs.h" +#include "slsDetectorUtils.h" -enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript, MAX_ACTIONS}; +//enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript, MAX_ACTIONS}; -/** - data structure to hold the detector data after postprocessing (e.g. to plot, store in a root tree etc.) - */ -class detectorData { - public: - /** The constructor - \param val pointer to the data - \param err pointer to errors - \param ang pointer to the angles - \param f_ind file index - \param fname file name to which the data are saved - \param np number of points defaults to the number of detector channels - */ - detectorData(float *val=NULL, float *err=NULL, float *ang=NULL, int p_ind=-1, const char *fname="", int np=-1) : values(val), errors(err), angles(ang), progressIndex(p_ind), npoints(np){strcpy(fileName,fname);}; - /** - the destructor - deletes also the arrays pointing to data/errors/angles if not NULL - */ - ~detectorData() {if (values) delete [] values; if (errors) delete [] errors; if (angles) delete [] angles;}; - //private: - float *values; /**< pointer to the data */ - float *errors; /**< pointer to the errors */ - float *angles;/**< pointer to the angles */ - int progressIndex;/**< file index */ - char fileName[1000];/**< file name */ - int npoints;/**< number of points */ -}; @@ -117,18 +72,18 @@ Then in your software you should use the class related to the detector you want */ -class slsDetector { +class slsDetector : public slsDetectorUtils { public: - /** online flags enum \sa setOnline*/ - enum {GET_ONLINE_FLAG=-1, /**< returns wether the detector is in online or offline state */ - OFFLINE_FLAG=0, /**< detector in offline state (i.e. no communication to the detector - using only local structure - no data acquisition possible!) */ - ONLINE_FLAG =1/**< detector in online state (i.e. communication to the detector updating the local structure) */ - }; +/* /\** online flags enum \sa setOnline*\/ */ +/* enum {GET_ONLINE_FLAG=-1, /\**< returns wether the detector is in online or offline state *\/ */ +/* OFFLINE_FLAG=0, /\**< detector in offline state (i.e. no communication to the detector - using only local structure - no data acquisition possible!) *\/ */ +/* ONLINE_FLAG =1/\**< detector in online state (i.e. communication to the detector updating the local structure) *\/ */ +/* }; */ @@ -234,7 +189,7 @@ typedef struct sharedSlsDetector { /** 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]; + int badFFList[MAX_BADCHANS]; /** file with the angular conversion factors */ char angConvFile[MAX_STR_LENGTH]; @@ -276,21 +231,22 @@ typedef struct sharedSlsDetector { /** Scans and scripts */ - + ////////////////////////// only in the multi detector class?!?!?!? additional shared memory class?!?!?!? int actionMask; - int actionMode[MAX_ACTIONS]; - char actionScript[MAX_ACTIONS][MAX_STR_LENGTH]; - char actionParameter[MAX_ACTIONS][MAX_STR_LENGTH]; + mystring actionScript[MAX_ACTIONS]; + + mystring actionParameter[MAX_ACTIONS]; int scanMode[MAX_SCAN_LEVELS]; - char scanScript[MAX_SCAN_LEVELS][MAX_STR_LENGTH]; - char scanParameter[MAX_SCAN_LEVELS][MAX_STR_LENGTH]; + mystring scanScript[MAX_SCAN_LEVELS]; + mystring scanParameter[MAX_SCAN_LEVELS]; int nScanSteps[MAX_SCAN_LEVELS]; - float scanSteps[MAX_SCAN_LEVELS][MAX_SCAN_STEPS]; + mysteps scanSteps[MAX_SCAN_LEVELS]; int scanPrecision[MAX_SCAN_LEVELS]; + //////////////////////////////////////////////////////////////////////////////////////////////// /*offsets*/ @@ -298,7 +254,7 @@ typedef struct sharedSlsDetector { int ffoff; /** memory offsets for the flat filed coefficient errors */ int fferroff; - /** memory offsets for the module structures */ + /** memory offsets for the module structures */ int modoff; /** memory offsets for the dac arrays */ int dacoff; @@ -306,7 +262,7 @@ typedef struct sharedSlsDetector { int adcoff; /** memory offsets for the chip register arrays */ int chipoff; - /** memory offsets for the channel register arrays */ + /** memory offsets for the channel register arrays -trimbits*/ int chanoff; @@ -322,6 +278,25 @@ typedef struct sharedSlsDetector { + + + + + + + using slsDetectorUtils::getDetectorType; + using slsDetectorUtils::flatFieldCorrect; + using slsDetectorUtils::rateCorrect; + using slsDetectorUtils::setBadChannelCorrection; + using slsDetectorUtils::readAngularConversion; + using slsDetectorUtils::writeAngularConversion; + using slsDetectorUtils::resetMerging; + using slsDetectorUtils::finalizeMerging; + using slsDetectorUtils::addToMerging; + using slsDetectorUtils::readDataFile; + using slsDetectorUtils::writeDataFile; + using slsDetectorUtils::createFileName; + /** (default) constructor \param type is needed to define the size of the detector shared memory 9defaults to GENERIC i.e. the largest shared memory needed by any slsDetector is allocated \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 @@ -348,19 +323,16 @@ typedef struct sharedSlsDetector { /** sets the onlineFlag \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) */ - int setOnline(int const online=GET_ONLINE_FLAG); - /** sets the onlineFlag + int setOnline(int const online=GET_ONLINE_FLAG); + + /** returns if the detector already existed \returns 1 if the detector structure has already be initlialized, 0 otherwise */ int exists() {return thisDetector->alreadyExisting;}; - - /** - checks if detector id exists - \param i detector id - \returns 1 if the detector already exists, 0 otherwise - - - */ - static int exists(int i); + + /** returns 1 if the detetcor with id has already been allocated and initialized in shared memory + \param detector id + \returns 1 if the detector structure has already be initlialized, 0 otherwise */ + static int exists(int id); /** configures mac for gotthard readout @@ -421,7 +393,14 @@ typedef struct sharedSlsDetector { \returns actual port number */ int setPort(portType type, int num=-1); - + + /** returns the detector control port \sa sharedSlsDetector */ + int getControlPort() {return thisDetector->controlPort;}; + /** returns the detector stop port \sa sharedSlsDetector */ + int getStopPort() {return thisDetector->stopPort;}; + /** returns the detector data port \sa sharedSlsDetector */ + int getDataPort() {return thisDetector->dataPort;}; + /** Locks/Unlocks the connection to the server /param lock sets (1), usets (0), gets (-1) the lock /returns lock status of the server @@ -434,14 +413,9 @@ typedef struct sharedSlsDetector { string getLastClientIP(); /** returns the detector hostname \sa sharedSlsDetector */ - string getHostname() {return string(thisDetector->hostname);}; - /** returns the detector control port \sa sharedSlsDetector */ - int getControlPort() {return thisDetector->controlPort;}; - /** returns the detector stop port \sa sharedSlsDetector */ - int getStopPort() {return thisDetector->stopPort;}; - /** returns the detector data port \sa sharedSlsDetector */ - int getDataPort() {return thisDetector->dataPort;}; - + string getHostname(int ipos=-1) {return string(thisDetector->hostname);}; + /** returns the detector hostname \sa sharedSlsDetector */ + string setHostname(char *name, int ipos=-1) {setTCPSocket(string(name)); return string(thisDetector->hostname);}; /** connect to the control port */ int connectControl(); /** disconnect from the control port */ @@ -458,28 +432,37 @@ typedef struct sharedSlsDetector { int disconnectStop(); - /** returns the client IP address for gotthard \sa sharedSlsDetector */ - char* getClientIP() {return thisDetector->clientIP;}; - /** returns the client MAC address for gotthard \sa sharedSlsDetector */ - char* getClientMAC() {return thisDetector->clientMAC;}; - /** returns the server MAC address for gotthard \sa sharedSlsDetector */ - char* getServerMAC() {return thisDetector->serverMAC;}; - /** validates and sets the client IP address for gotthard \sa sharedSlsDetector */ - char* setClientIP(string clientIP); - /** validates the format of client MAC address and sets it for gotthard \sa sharedSlsDetector */ - char* setClientMAC(string clientMAC); - /** validates the format of server MAC address and sets it for gotthard \sa sharedSlsDetector */ - char* setServerMAC(string serverMAC); + char* setNetworkParameter(networkParameter index, string value); + + char* getNetworkParameter(networkParameter index); /* I/O */ + /** returns the detector trimbit/settings directory \sa sharedSlsDetector */ char* getSettingsDir() {return thisDetector->settingsDir;}; /** sets the detector trimbit/settings directory \sa sharedSlsDetector */ char* setSettingsDir(string s) {sprintf(thisDetector->settingsDir, s.c_str()); return thisDetector->settingsDir;}; + + + + /** + returns the location of the calibration files + \sa sharedSlsDetector + */ + char* getCalDir() {return thisDetector->calDir;}; + /** + sets the location of the calibration files + \sa sharedSlsDetector + */ + char* setCalDir(string s) {sprintf(thisDetector->calDir, s.c_str()); return thisDetector->calDir;}; + + + /** returns the number of trim energies and their value \sa sharedSlsDetector \param point to the array that will contain the trim energies (in ev) \returns number of trim energies + unused! \sa sharedSlsDetector @@ -518,6 +501,8 @@ typedef struct sharedSlsDetector { \sa ::sls_detector_module mythenDetector::writeSettingsFile(string, sls_detector_module) */ int writeSettingsFile(string fname, sls_detector_module mod); + + //virtual int writeSettingsFile(string fname, sls_detector_module mod); /** @@ -529,7 +514,6 @@ typedef struct sharedSlsDetector { \sa ::sls_detector_module sharedSlsDetector mythenDetector::writeSettingsFile(string, int) */ int writeSettingsFile(string fname, int imod); - //virtual int writeSettingsFile(string fname, int imod); /** @@ -544,204 +528,12 @@ typedef struct sharedSlsDetector { return thisDetector->settingsFile;\ }; - /** - sets the default output files path - \sa sharedSlsDetector - */ - char* setFilePath(string s) {sprintf(thisDetector->filePath, s.c_str()); return thisDetector->filePath;}; - /** - sets the default output files root name - \sa sharedSlsDetector - */ - char* setFileName(string s) {sprintf(thisDetector->fileName, s.c_str()); return thisDetector->fileName;}; + /** loads the modules settings/trimbits reading from a file - file name extension is automatically generated! */ + int loadSettingsFile(string fname, int nmod=0); - /** - sets the default output file index - \sa sharedSlsDetector - */ - int setFileIndex(int i) {thisDetector->fileIndex=i; return thisDetector->fileIndex;}; - - /** - returns the default output files path - \sa sharedSlsDetector - */ - char* getFilePath() {return thisDetector->filePath;}; - - /** - returns the default output files root name - \sa sharedSlsDetector - */ - char* getFileName() {return thisDetector->fileName;}; - - /** - returns the default output file index - \sa sharedSlsDetector - */ - int getFileIndex() {return thisDetector->fileIndex;}; - - - /** generates file name without extension - - always appends to file path and file name the run index. - - in case also appends the position index - - Filenames will be of the form: filepath/filename(_px)_i - where x is the position index and i is the run index - \param filepath outdir - \param filename file root name - \param aMask action mask (scans, positions) - \param sv0 scan variable 0 - \param prec0 scan precision 0 - \param sv1 scan variable 1 - \param prec1 scan precision 1 - \param pindex position index - \param number of positions - \param findex file index - \returns file name without extension - */ - static string createFileName(char *filepath, char *filename, int aMask, float sv0, int prec0, float sv1, int prec1, int pindex, int npos, int findex); - /** generates file name without extension - - always appends to file path and file name the run index. - - in case also appends the position index - - Filenames will be of the form: filepath/filename(_px)_i - where x is the position index and i is the run index - \returns file name without extension - */ - - string createFileName(); - - - - /** static function that returns the file index from the file name - \param fname file name - \returns file index*/ - static int getFileIndexFromFileName(string fname); - - /** static function that returns the variables from the file name - \param fname file name - \param index reference to index - \param p_index reference to position index - \param sv0 reference to scan variable 0 - \param sv1 reference to scan variable 1 - \returns file index - */ - static int getVariablesFromFileName(string fname, int &index, int &p_index, float &sv0, float &sv1); - - /** - - writes a data file - \param name of the file to be written - \param data array of data values - \param err array of arrors on the data. If NULL no errors will be written - - \param ang array of angular values. If NULL data will be in the form chan-val(-err) otherwise ang-val(-err) - \param dataformat format of the data: can be 'i' integer or 'f' float (default) - \param nch number of channels to be written to file. if -1 defaults to the number of installed channels of the detector - \returns OK or FAIL if it could not write the file or data=NULL - \sa mythenDetector::writeDataFile - - */ - virtual int writeDataFile(string fname, float *data, float *err=NULL, float *ang=NULL, char dataformat='f', int nch=-1); - - /** - - writes a data file - \param name of the file to be written - \param data array of data values - \returns OK or FAIL if it could not write the file or data=NULL - \sa mythenDetector::writeDataFile - */ - virtual int writeDataFile(string fname, int *data); - - /** - - reads a data file - \param name of the file to be read - \param data array of data values to be filled - \param err array of arrors on the data. If NULL no errors are expected on the file - - \param ang array of angular values. If NULL data are expected in the form chan-val(-err) otherwise ang-val(-err) - \param dataformat format of the data: can be 'i' integer or 'f' float (default) - \param nch number of channels to be written to file. if <=0 defaults to the number of installed channels of the detector - \returns OK or FAIL if it could not read the file or data=NULL - - \sa mythenDetector::readDataFile - */ - int readDataFile(string fname, float *data, float *err=NULL, float *ang=NULL, char dataformat='f'); - - /** - - reads a data file - \param name of the file to be read - \param data array of data values - \returns OK or FAIL if it could not read the file or data=NULL - \sa mythenDetector::readDataFile - */ - int readDataFile(string fname, int *data); - /** - - reads a data file - \param name of the file to be read - \param data array of data values to be filled - \param err array of arrors on the data. If NULL no errors are expected on the file - - \param ang array of angular values. If NULL data are expected in the form chan-val(-err) otherwise ang-val(-err) - \param dataformat format of the data: can be 'i' integer or 'f' float (default) - \param nch number of channels to be written to file. if <=0 defaults to the number of installed channels of the detector - \returns number of channels read or -1 if it could not read the file or data=NULL - - \sa mythenDetector::readDataFile - */ - static int readDataFile(int nch, string fname, float *data, float *err=NULL, float *ang=NULL, char dataformat='f'); - - /** - - reads a data file - \param name of the file to be read - \param data array of data values - \returns OK or FAIL if it could not read the file or data=NULL - \sa mythenDetector::readDataFile - */ - static int readDataFile(string fname, int *data, int nch); - - /** - returns the location of the calibration files - \sa sharedSlsDetector - */ - char* getCalDir() {return thisDetector->calDir;}; - - - /** - sets the location of the calibration files - \sa sharedSlsDetector - */ - char* setCalDir(string s) {sprintf(thisDetector->calDir, s.c_str()); return thisDetector->calDir;}; - /** - - reads a calibration file - \param fname file to be read - \param gain reference to the gain variable - \offset reference to the offset variable - \sa sharedSlsDetector mythenDetector::readCalibrationFile - */ - int readCalibrationFile(string fname, float &gain, float &offset); - //virtual int readCalibrationFile(string fname, float &gain, float &offset); - - /** - - writes a calibration file - \param fname file to be written - \param gain - \param offset - \sa sharedSlsDetector mythenDetector::writeCalibrationFile - */ - int writeCalibrationFile(string fname, float gain, float offset); - //virtual int writeCalibrationFile(string fname, float gain, float offset); + /** gets the modules settings/trimbits and writes them to file - file name extension is automatically generated! */ + int saveSettingsFile(string fname, int nmod=0); /** @@ -751,6 +543,18 @@ typedef struct sharedSlsDetector { \sa angleConversionConstant mythenDetector::readAngularConversion */ int readAngularConversion(string fname=""); + + + /** + + reads an angular conversion file + \param fname file to be read + \sa angleConversionConstant mythenDetector::readAngularConversion + */ + int readAngularConversion(ifstream& ifs); + + + /** Pure virtual function writes an angular conversion file @@ -759,6 +563,20 @@ typedef struct sharedSlsDetector { */ int writeAngularConversion(string fname=""); + + + /** + Pure virtual function + writes an angular conversion file + \param fname file to be written + \sa angleConversionConstant mythenDetector::writeAngularConversion + */ + int writeAngularConversion(ofstream &ofs); + + + + + /** Returns the number of channels per chip (without connecting to the detector) */ int getNChans(){return thisDetector->nChans;}; // @@ -769,6 +587,9 @@ typedef struct sharedSlsDetector { int getNMods(){return thisDetector->nMods;}; // + int getTotalNumberOfChannels(){return thisDetector->nChans*thisDetector->nChips*thisDetector->nMods;}; + + /* Communication to server */ @@ -1162,40 +983,6 @@ typedef struct sharedSlsDetector { */ int readAllNoWait(); - - /** - pops the data from the data queue - \returns pointer to the popped data or NULL if the queue is empty. - \sa dataQueue - */ - int* popDataQueue(); - - /** - pops the data from thepostprocessed data queue - \returns pointer to the popped data or NULL if the queue is empty. - \sa finalDataQueue - */ - detectorData* popFinalDataQueue(); - - - - - /** - resets the raw data queue - \sa dataQueue - */ - void resetDataQueue(); - - /** - resets the postprocessed data queue - \sa finalDataQueue - */ - void resetFinalDataQueue(); - - - - - @@ -1260,7 +1047,7 @@ typedef struct sharedSlsDetector { \param flag readout flag to be set \returns current flag */ - int setReadOutFlags(readOutFlags flag); + int setReadOutFlags(readOutFlags flag=GET_READOUT_FLAGS); /** execute trimming @@ -1275,15 +1062,7 @@ typedef struct sharedSlsDetector { //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 \param fname name of the flat field file (or "" if disable) @@ -1291,14 +1070,6 @@ s */ int setFlatFieldCorrection(string fname=""); - /** - get flat field corrections - \param corr if !=NULL will be filled with the correction coefficients - \param ecorr if !=NULL will be filled with the correction coefficients errors - \returns 0 if ff correction disabled, >0 otherwise - */ - 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) @@ -1307,22 +1078,15 @@ s */ int setFlatFieldCorrection(float *corr=NULL, float *ecorr=NULL); - /** - get flat field corrections file directory - \returns flat field correction file directory + + /** + get flat field corrections + \param corr if !=NULL will be filled with the correction coefficients + \param ecorr if !=NULL will be filled with the correction coefficients errors + \returns 0 if ff correction disabled, >0 otherwise */ - char *getFlatFieldCorrectionDir(){return thisDetector->flatFieldDir;}; - /** - set flat field corrections file directory - \param flat field correction file directory - */ - void setFlatFieldCorrectionDir(string dir){strcpy(thisDetector->flatFieldDir,dir.c_str());}; - - /** - get flat field corrections file name - \returns flat field correction file name - */ - char *getFlatFieldCorrectionFile(){ if (thisDetector->correctionMask&(1<flatFieldFile; else return "none";}; + int getFlatFieldCorrection(float *corr=NULL, float *ecorr=NULL); + /** set rate correction @@ -1351,15 +1115,6 @@ s */ 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 \param fname file with bad channel list ("" disable) @@ -1375,9 +1130,6 @@ s \returns 0 if bad channel disabled, >0 otherwise */ int setBadChannelCorrection(int nch, int *chs, int ff=0); - - - /** get bad channels correction @@ -1386,9 +1138,6 @@ 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");}; - /** pure virtual function @@ -1398,7 +1147,6 @@ s \sa mythenDetector::setAngularConversion */ int setAngularConversion(string fname=""); - /** pure virtual function get angular conversion @@ -1409,174 +1157,6 @@ s */ int getAngularConversion(int &direction, angleConversionConstant *angconv=NULL) ; - - /** - pure virtual function - returns the angular conversion file - \sa mythenDetector::getAngularConversion */ - string getAngularConversion(){if (thisDetector->correctionMask&(1<< ANGULAR_CONVERSION)) return string(thisDetector->angConvFile); else return string("none");}; - - /** - pure virtual function - set detector global offset - \sa mythenDetector::setGlobalOffset - */ - float setGlobalOffset(float f){thisDetector->globalOffset=f; return thisDetector->globalOffset;}; - - /** - pure virtual function - set detector fine offset - \sa mythenDetector::setFineOffset - */ - float setFineOffset(float f){thisDetector->fineOffset=f; return thisDetector->fineOffset;}; - /** - pure virtual function - get detector fine offset - \sa mythenDetector::getFineOffset - */ - float getFineOffset(){return thisDetector->fineOffset;}; - - /** - pure virtual function - get detector global offset - \sa mythenDetector::getGlobalOffset - */ - float getGlobalOffset(){return thisDetector->globalOffset;}; - - /** - pure virtual function - set positions for the acquisition - \param nPos number of positions - \param pos array with the encoder positions - \returns number of positions - \sa mythenDetector::setPositions - */ - int setPositions(int nPos, float *pos); - /** - pure virtual function - get positions for the acquisition - \param pos array which will contain the encoder positions - \returns number of positions - \sa mythenDetector::getPositions - */ - int getPositions(float *pos=NULL); - - - /** pure virtual function - set detector bin size used for merging (approx angular resolution) - \param bs bin size in degrees - \returns current bin size - \sa mythenDetector::setBinSize -*/ - float setBinSize(float bs){thisDetector->binSize=bs; return thisDetector->binSize;}; - - /** pure virtual function - return detector bin size used for merging (approx angular resolution) - \sa mythenDetector::getBinSize - */ - float getBinSize() {return thisDetector->binSize;}; - - - - - - /** - set action - \param iaction can be enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript, MAX_ACTIONS} - \param fname for script ("" disable) - \param par for script - \returns 0 if action disabled, >0 otherwise - */ - int setAction(int iaction, string fname="", string par=""); - - /** - set action - \param iaction can be enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript, MAX_ACTIONS} - \param fname for script ("" disable) - \returns 0 if action disabled, >0 otherwise - */ - int setActionScript(int iaction, string fname=""); - /** - set action - \param iaction can be enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript, MAX_ACTIONS} - \param par for script ("" disable) - \returns 0 if action disabled, >0 otherwise - */ - int setActionParameter(int iaction, string par=""); - - /** - returns action script - \param iaction can be enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript} - \returns action script - */ - string getActionScript(int iaction); - - /** - returns action parameter - \param iaction can be enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript} - \returns action parameter - */ - string getActionParameter(int iaction); - - /** - returns action mode - \param iaction can be enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript} - \returns action mode - */ - int getActionMode(int iaction); - - - /** - set scan - \param index of the scan (0,1) - \param fname for script ("" disables, "none" disables and overwrites current) - \param nvalues number of steps (0 disables, -1 leaves current value) - \param values pointer to steps (if NULL leaves current values) - \param par parameter for the scan script ("" leaves unchanged) - \returns 0 is scan disabled, >0 otherwise - */ - int setScan(int index, string script="", int nvalues=-1, float *values=NULL, string par="", int precision=-1); - - int setScanScript(int index, string script=""); - int setScanParameter(int index, string par=""); - int setScanPrecision(int index, int precision=-1); - int setScanSteps(int index, int nvalues=-1, float *values=NULL); - /** - returns scan script - \param iscan can be (0,1) - \returns scan script - */ - string getScanScript(int iscan); - - /** - returns scan parameter - \param iscan can be (0,1) - \returns scan parameter - */ - string getScanParameter(int iscan); - - /** - returns scan mode - \param iscan can be (0,1) - \returns scan mode - */ - int getScanMode(int iscan); - - /** - returns scan steps - \param iscan can be (0,1) - \param v is the pointer to the scan steps - \returns scan steps - */ - int getScanSteps(int iscan, float *v=NULL); - - - /** - returns scan precision - \param iscan can be (0,1) - \returns scan precision - */ - int getScanPrecision(int iscan); @@ -1591,17 +1171,6 @@ s - /** - flat field correct data - \param datain data - \param errin error on data (if<=0 will default to sqrt(datain) - \param dataout corrected data - \param errout error on corrected data - \param ffcoefficient flat field correction coefficient - \param fferr erro on ffcoefficient - \returns 0 - */ - static int flatFieldCorrect(float datain, float errin, float &dataout, float &errout, float ffcoefficient, float fferr); /** flat field correct data @@ -1615,18 +1184,7 @@ s - /** - rate correct data - \param datain data - \param errin error on data (if<=0 will default to sqrt(datain) - \param dataout corrected data - \param errout error on corrected data - \param tau dead time 9in ns) - \param t acquisition time (in ns) - \returns 0 - */ - static int rateCorrect(float datain, float errin, float &dataout, float &errout, float tau, float t); - + /** rate correct data \param datain data array @@ -1648,7 +1206,9 @@ s \returns OK or FAIL \sa mythenDetector::resetMerging */ + int resetMerging(float *mp, float *mv,float *me, int *mm); + /** pure virtual function merge dataset @@ -1684,7 +1244,7 @@ s /param delflag if 1 the data are processed, written to file and then deleted. If 0 they are added to the finalDataQueue \sa mythenDetector::processData */ - void* processData(int delflag=1); // thread function + // void* processData(int delflag=1); // thread function /** Allocates the memory for a sls_detector_module structure and initializes it \returns myMod the pointer to the allocate dmemory location @@ -1709,7 +1269,7 @@ s \sa mythenDetector::acquire() */ - void acquire(int delflag=1); + //void acquire(int delflag=1); /** calcualtes the total number of steps of the acquisition. called when number of frames, number of cycles, number of positions and scan steps change @@ -1720,29 +1280,9 @@ s float getCurrentProgress(); + float* convertAngles(float pos); - /** - type of action performed (for text client) - */ -enum {GET_ACTION, PUT_ACTION, READOUT_ACTION}; - - - /** - 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 string helpLine(int action=GET_ACTION); @@ -1763,14 +1303,17 @@ enum {GET_ACTION, PUT_ACTION, READOUT_ACTION}; /** Returns detector id - \return pointer to the data (or NULL if failed) + \returns detector id */ - int getDetectorId() {return detId;}; + int getDetectorId(int i=-1) {return detId;}; + + + /** Receives a data frame from the detector socket - \return pointer to the data (or NULL if failed) + \returns pointer to the data (or NULL if failed) */ int* getDataFromDetector(); @@ -1779,8 +1322,6 @@ enum {GET_ACTION, PUT_ACTION, READOUT_ACTION}; protected: - static const int64_t thisSoftwareVersion=0x20111124; - /** address of the detector structure in shared memory */ @@ -1816,66 +1357,16 @@ enum {GET_ACTION, PUT_ACTION, READOUT_ACTION}; */ MySocketTCP *dataSocket; - /** - data queue - */ - queue dataQueue; - /** - queue containing the postprocessed data - */ - queue finalDataQueue; - - + - /** - current position of the detector - */ - float currentPosition; - - /** - current position index of the detector - */ - int currentPositionIndex; - - /** - I0 measured - */ - float currentI0; - - - - - /** - current scan variable of the detector - */ - float currentScanVariable[MAX_SCAN_LEVELS]; - - /** - current scan variable index of the detector - */ - int currentScanIndex[MAX_SCAN_LEVELS]; - - - - - /** merging bins */ - float *mergingBins; - - /** merging counts */ - float *mergingCounts; - - /** merging errors */ - float *mergingErrors; - - /** merging multiplicity */ - int *mergingMultiplicity; - /** pointer to flat field coefficients */ float *ffcoefficients; /** pointer to flat field coefficient errors */ float *fferrors; + + /** pointer to detector module structures */ sls_detector_module *detectorModules; /** pointer to dac valuse */ @@ -1886,9 +1377,6 @@ enum {GET_ACTION, PUT_ACTION, READOUT_ACTION}; int *chipregs; /** pointer to channal registers */ int *chanregs; - /** pointer to bad channel mask 0 is channel is good 1 if it is bad \sa fillBadChannelMask() */ - int *badChannelMask; - /** Initializes the shared memory \param type is needed to define the size of the shared memory @@ -1934,39 +1422,27 @@ enum {GET_ACTION, PUT_ACTION, READOUT_ACTION}; */ int receiveModule(sls_detector_module*); - /** - start data processing thread - */ - //void startThread(); - - /** - fill bad channel mask (0 if channel is good, 1 if bad) - */ - int fillBadChannelMask(); - /** - start data processing thread - */ - void startThread(int delflag=1); // - /** the data processing thread */ - - pthread_t dataProcessingThread; - - /** sets when the acquisition is finished */ - int jointhread; - - /** data queue size */ - int queuesize; +/* /\** mutex to synchronize threads *\/ */ +/* pthread_mutex_t mp; */ - /** mutex to synchronize threads */ - pthread_mutex_t mp; - - + /** returns the client IP address for gotthard \sa sharedSlsDetector */ + char* getClientIP() {return thisDetector->clientIP;}; + /** returns the client MAC address for gotthard \sa sharedSlsDetector */ + char* getClientMAC() {return thisDetector->clientMAC;}; + /** returns the server MAC address for gotthard \sa sharedSlsDetector */ + char* getServerMAC() {return thisDetector->serverMAC;}; + /** validates and sets the client IP address for gotthard \sa sharedSlsDetector */ + char* setClientIP(string clientIP); + /** validates the format of client MAC address and sets it for gotthard \sa sharedSlsDetector */ + char* setClientMAC(string clientMAC); + /** validates the format of server MAC address and sets it for gotthard \sa sharedSlsDetector */ + char* setServerMAC(string serverMAC); @@ -1975,9 +1451,4 @@ enum {GET_ACTION, PUT_ACTION, READOUT_ACTION}; }; -static void* startProcessData(void *n); -static void* startProcessDataNoDelete(void *n); - - -//static void* startProcessData(void *n); #endif diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp new file mode 100644 index 000000000..15031a4de --- /dev/null +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp @@ -0,0 +1,3631 @@ +#include "slsDetectorCommand.h" + +#include + +slsDetectorCommand::slsDetectorCommand() { + + + int i=0; + + cmd=string("none"); + + /* Acquisition and status commands */ + + descrToFuncMap[i].m_pFuncName="test"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdUnderDevelopment; + i++; + + descrToFuncMap[i].m_pFuncName="acquire"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdAcquire; + i++; + + descrToFuncMap[i].m_pFuncName="data"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdData; + i++; + + descrToFuncMap[i].m_pFuncName="frame"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdFrame; + i++; + + descrToFuncMap[i].m_pFuncName="status"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdStatus; + i++; + + + /* Detector structure configuration and debugging commands */ + + descrToFuncMap[i].m_pFuncName="free";//OK + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdFree; + i++; + + + descrToFuncMap[i].m_pFuncName="add";//OK + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdAdd; + i++; + + descrToFuncMap[i].m_pFuncName="remove";//OK + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdRemove; + i++; + + + descrToFuncMap[i].m_pFuncName="hostname"; //OK + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdHostname; + i++; + + descrToFuncMap[i].m_pFuncName="id"; //OK + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdId; + i++; + + descrToFuncMap[i].m_pFuncName="master"; //OK + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdMaster; + i++; + + descrToFuncMap[i].m_pFuncName="sync"; //OK + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSync; + i++; + + descrToFuncMap[i].m_pFuncName="help";//OK + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdHelp; + i++; + + descrToFuncMap[i].m_pFuncName="exitserver";//OK + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdExitServer; + i++; + + /* data processing commands */ + descrToFuncMap[i].m_pFuncName="flatfield"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdFlatField; + i++; + + descrToFuncMap[i].m_pFuncName="ffdir"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdFlatField; + i++; + + descrToFuncMap[i].m_pFuncName="ratecorr"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdRateCorr; + i++; + + descrToFuncMap[i].m_pFuncName="badchannels"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdBadChannels; + i++; + + descrToFuncMap[i].m_pFuncName="angconv"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdAngConv; + i++; + + descrToFuncMap[i].m_pFuncName="globaloff"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdAngConv; + i++; + + descrToFuncMap[i].m_pFuncName="fineoff"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdAngConv; + i++; + + descrToFuncMap[i].m_pFuncName="binsize" ;// + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdAngConv; + i++; + + descrToFuncMap[i].m_pFuncName="threaded"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdThreaded; + i++; + + /* trim/cal directories */ + descrToFuncMap[i].m_pFuncName="trimdir"; //OK + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSettingsDir; + i++; + + descrToFuncMap[i].m_pFuncName="settingsdir"; //OK + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSettingsDir; + i++; + + descrToFuncMap[i].m_pFuncName="caldir"; //OK + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdCalDir; + i++; + + descrToFuncMap[i].m_pFuncName="trimen"; + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdUnderDevelopment; + i++; + + + /* file name */ + descrToFuncMap[i].m_pFuncName="outdir"; //OK + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdOutDir; + i++; + + descrToFuncMap[i].m_pFuncName="fname"; //OK + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdFileName; + i++; + + descrToFuncMap[i].m_pFuncName="index"; //OK + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdFileIndex; + i++; + + + descrToFuncMap[i].m_pFuncName="online"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdUnderDevelopment; + i++; + + /* Acquisition actions */ + + descrToFuncMap[i].m_pFuncName="positions"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdPositions; + i++; + + descrToFuncMap[i].m_pFuncName="startscript"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdScripts; + i++; + + descrToFuncMap[i].m_pFuncName="startscriptpar"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdScripts; + i++; + + descrToFuncMap[i].m_pFuncName="stopscript"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdScripts; + i++; + + descrToFuncMap[i].m_pFuncName="stopscriptpar"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdScripts; + i++; + + descrToFuncMap[i].m_pFuncName="scriptbefore"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdScripts; + i++; + + descrToFuncMap[i].m_pFuncName="scriptbeforepar"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdScripts; + i++; + + descrToFuncMap[i].m_pFuncName="scriptafter"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdScripts; + i++; + + descrToFuncMap[i].m_pFuncName="scriptafterpar"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdScripts; + i++; + + descrToFuncMap[i].m_pFuncName="headerafter"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdScripts; + i++; + + descrToFuncMap[i].m_pFuncName="headerafterpar"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdScripts; + i++; + + descrToFuncMap[i].m_pFuncName="headerbefore"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdScripts; + i++; + + descrToFuncMap[i].m_pFuncName="headerbeforepar"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdScripts; + i++; + + descrToFuncMap[i].m_pFuncName="scan0script"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdScans; + i++; + + descrToFuncMap[i].m_pFuncName="scan0par"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdScans; + i++; + + descrToFuncMap[i].m_pFuncName="scan0prec"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdScans; + i++; + + descrToFuncMap[i].m_pFuncName="scan0steps"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdScans; + i++; + + descrToFuncMap[i].m_pFuncName="scan0range"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdScans; + i++; + + descrToFuncMap[i].m_pFuncName="scan1script"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdScans; + i++; + + descrToFuncMap[i].m_pFuncName="scan1par"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdScans; + i++; + + descrToFuncMap[i].m_pFuncName="scan1prec"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdScans; + i++; + + descrToFuncMap[i].m_pFuncName="scan1steps"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdScans; + i++; + + descrToFuncMap[i].m_pFuncName="scan1range"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdScans; + i++; + + + /* communication configuration */ + + descrToFuncMap[i].m_pFuncName="clientip"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdNetworkParameter; + i++; + + descrToFuncMap[i].m_pFuncName="clientmac"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdNetworkParameter; + i++; + + descrToFuncMap[i].m_pFuncName="servermac"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdNetworkParameter; + i++; + + descrToFuncMap[i].m_pFuncName="configuremac"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdConfigureMac; + i++; + + descrToFuncMap[i].m_pFuncName="port"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdPort; + i++; + + descrToFuncMap[i].m_pFuncName="stopport"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdPort; + i++; + + descrToFuncMap[i].m_pFuncName="dataport"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdPort; + i++; + + descrToFuncMap[i].m_pFuncName="lock"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdLock; + i++; + + descrToFuncMap[i].m_pFuncName="lastclient"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdLastClient; + i++; + + + /* detector and data size */ + descrToFuncMap[i].m_pFuncName="nmod"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDetectorSize; + i++; + + descrToFuncMap[i].m_pFuncName="maxmod"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDetectorSize; + i++; + + descrToFuncMap[i].m_pFuncName="dr"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDetectorSize; + i++; + + /* flags */ + + descrToFuncMap[i].m_pFuncName="flags"; + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdAdvanced; + i++; + + descrToFuncMap[i].m_pFuncName="extsig"; /* find command! */ + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdAdvanced; + i++; + + /* versions/ serial numbers getId */ + + descrToFuncMap[i].m_pFuncName="moduleversion"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSN; + i++; + + descrToFuncMap[i].m_pFuncName="detectornumber"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSN; + i++; + + descrToFuncMap[i].m_pFuncName="modulenumber"; /* find command! */ + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSN; + i++; + + descrToFuncMap[i].m_pFuncName="detectorversion"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSN; + i++; + + descrToFuncMap[i].m_pFuncName="softwareversion"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSN; + i++; + + descrToFuncMap[i].m_pFuncName="thisversion"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSN; + i++; + + /* digital test and debugging */ + + descrToFuncMap[i].m_pFuncName="digitest"; // /* find command! */ + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDigiTest; + i++; + + descrToFuncMap[i].m_pFuncName="bustest"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDigiTest; + i++; + + descrToFuncMap[i].m_pFuncName="reg_rw"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdRegister; + i++; + + /* settings, threshold */ + + descrToFuncMap[i].m_pFuncName="settings"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSettings; + i++; + + descrToFuncMap[i].m_pFuncName="threshold"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSettings; + i++; + + descrToFuncMap[i].m_pFuncName="trimbits"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSettings; + i++; + + descrToFuncMap[i].m_pFuncName="trim"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSettings; + i++; + + /* pots */ + + descrToFuncMap[i].m_pFuncName="vthreshold"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDAC; + i++; + + descrToFuncMap[i].m_pFuncName="vcalibration"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDAC; + i++; + + descrToFuncMap[i].m_pFuncName="vtrimbit"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDAC; + i++; + + descrToFuncMap[i].m_pFuncName="vpreamp"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDAC; + i++; + + descrToFuncMap[i].m_pFuncName="vshaper1"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDAC; + i++; + + descrToFuncMap[i].m_pFuncName="vshaper2"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDAC; + i++; + + descrToFuncMap[i].m_pFuncName="vhighvoltage"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDAC; + i++; + + descrToFuncMap[i].m_pFuncName="vapower"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDAC; + i++; + + descrToFuncMap[i].m_pFuncName="vddpower"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDAC; + i++; + + descrToFuncMap[i].m_pFuncName="vshpower"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDAC; + i++; + + descrToFuncMap[i].m_pFuncName="viopower"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDAC; + i++; + + descrToFuncMap[i].m_pFuncName="vref_ds"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDAC; + i++; + + descrToFuncMap[i].m_pFuncName="vcascn_pb"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDAC; + i++; + + descrToFuncMap[i].m_pFuncName="vcascp_pb"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDAC; + i++; + + descrToFuncMap[i].m_pFuncName="vout_cm"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDAC; + i++; + + descrToFuncMap[i].m_pFuncName="vcasc_out"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDAC; + i++; + + descrToFuncMap[i].m_pFuncName="vin_cm"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDAC; + i++; + + descrToFuncMap[i].m_pFuncName="vref_comp"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDAC; + i++; + + descrToFuncMap[i].m_pFuncName="ib_test_c"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDAC; + i++; + + descrToFuncMap[i].m_pFuncName="temp_adc"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDAC; + i++; + + descrToFuncMap[i].m_pFuncName="temp_fpga"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDAC; + i++; + + /* r/w timers */ + + descrToFuncMap[i].m_pFuncName="exptime"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdTimer; + i++; + + descrToFuncMap[i].m_pFuncName="period"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdTimer; + i++; + + descrToFuncMap[i].m_pFuncName="delay"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdTimer; + i++; + + descrToFuncMap[i].m_pFuncName="gates"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdTimer; + i++; + + descrToFuncMap[i].m_pFuncName="frames"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdTimer; + i++; + + descrToFuncMap[i].m_pFuncName="cycles"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdTimer; + i++; + + descrToFuncMap[i].m_pFuncName="probes"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdTimer; + i++; + + /* read only timers */ + + descrToFuncMap[i].m_pFuncName="exptimel"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdTimeLeft; + i++; + + descrToFuncMap[i].m_pFuncName="periodl"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdTimeLeft; + i++; + + descrToFuncMap[i].m_pFuncName="delayl"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdTimeLeft; + i++; + + descrToFuncMap[i].m_pFuncName="gatesl"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdTimeLeft; + i++; + + descrToFuncMap[i].m_pFuncName="framesl"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdTimeLeft; + i++; + + descrToFuncMap[i].m_pFuncName="cyclesl"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdTimeLeft; + i++; + +// descrToFuncMap[i].m_pFuncName="progress"; +// descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdTimer; +// i++; + + descrToFuncMap[i].m_pFuncName="now"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdTimeLeft; + i++; + + descrToFuncMap[i].m_pFuncName="timestamp"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdTimeLeft; + i++; + + + /* speed */ + + descrToFuncMap[i].m_pFuncName="clkdivider"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSpeed; + i++; + + descrToFuncMap[i].m_pFuncName="setlength"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSpeed; + i++; + + descrToFuncMap[i].m_pFuncName="waitstates"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSpeed; + i++; + + descrToFuncMap[i].m_pFuncName="totdivider"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSpeed; + i++; + + descrToFuncMap[i].m_pFuncName="totdutycycle"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSpeed; + i++; + + /* settings dump/retrieve */ + descrToFuncMap[i].m_pFuncName="config"; + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdConfiguration; + i++; + + descrToFuncMap[i].m_pFuncName="parameters"; + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdConfiguration; + i++; + + descrToFuncMap[i].m_pFuncName="setup"; + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdConfiguration; + i++; + + numberOfCommands=i; + +#ifdef VERBOSE + cout << "Number of commands is " << numberOfCommands << endl; +#endif +} + + + + +string slsDetectorCommand::externalSignalType(externalSignalFlag f) { + switch(f) { + case SIGNAL_OFF: + return string( "off"); + case GATE_IN_ACTIVE_HIGH: + return string( "gate_in_active_high"); + case GATE_IN_ACTIVE_LOW: + return string( "gate_in_active_low"); + case TRIGGER_IN_RISING_EDGE: + return string( "trigger_in_rising_edge"); + case TRIGGER_IN_FALLING_EDGE: + return string( "trigger_in_falling_edge"); + case RO_TRIGGER_IN_RISING_EDGE: + return string( "ro_trigger_in_rising_edge"); + case RO_TRIGGER_IN_FALLING_EDGE: + return string( "ro_trigger_in_falling_edge"); + case GATE_OUT_ACTIVE_HIGH: + return string( "gate_out_active_high"); + case GATE_OUT_ACTIVE_LOW: + return string( "gate_out_active_low"); + case TRIGGER_OUT_RISING_EDGE: + return string( "trigger_out_rising_edge"); + case TRIGGER_OUT_FALLING_EDGE: + return string( "trigger_out_falling_edge"); + case RO_TRIGGER_OUT_RISING_EDGE: + return string( "ro_trigger_out_rising_edge"); + case RO_TRIGGER_OUT_FALLING_EDGE: + return string( "ro_trigger_out_falling_edge"); + default: + return string( "unknown"); + } +} + +externalSignalFlag slsDetectorCommand::externalSignalType(string sval) { + + externalSignalFlag flag=GET_EXTERNAL_SIGNAL_FLAG; + if (sval=="off") flag=SIGNAL_OFF; + else if (sval=="gate_in_active_high") flag=GATE_IN_ACTIVE_HIGH; + else if (sval=="gate_in_active_low") flag=GATE_IN_ACTIVE_LOW; + else if (sval=="trigger_in_rising_edge") flag=TRIGGER_IN_RISING_EDGE; + else if (sval=="trigger_in_falling_edge") flag=TRIGGER_IN_FALLING_EDGE; + else if (sval=="ro_trigger_in_rising_edge") flag=RO_TRIGGER_IN_RISING_EDGE; + else if (sval=="ro_trigger_in_falling_edge") flag=RO_TRIGGER_IN_FALLING_EDGE; + else if (sval=="gate_out_active_high") flag=GATE_OUT_ACTIVE_HIGH; + else if (sval=="gate_out_active_low") flag=GATE_OUT_ACTIVE_LOW; + else if (sval=="trigger_out_rising_edge") flag=TRIGGER_OUT_RISING_EDGE; + else if (sval=="trigger_out_falling_edge") flag=TRIGGER_OUT_FALLING_EDGE; + else if (sval=="ro_trigger_out_rising_edge") flag=RO_TRIGGER_OUT_RISING_EDGE; + else if (sval=="ro_trigger_out_falling_edge") flag=RO_TRIGGER_OUT_FALLING_EDGE; + return flag; +} + + + + + +string slsDetectorCommand::runStatusType(runStatus s) { + switch (s) { + case ERROR: + return string("error"); + case WAITING: + return string("waiting"); + case RUNNING: + return string("running"); + case TRANSMITTING: + return string("data"); + case RUN_FINISHED: + return string("finished"); + default: + return string("idle"); + } + +} + + +string slsDetectorCommand::getDetectorType(detectorType t){ + + switch (t) { + case MYTHEN: + return string("Mythen"); + break; + case PILATUS: + return string("Pilatus"); + break; + case EIGER: + return string("Eiger"); + break; + case GOTTHARD: + return string("Gotthard"); + break; + case AGIPD: + return string("Agipd"); + break; + default: + return string("Unknown"); + break; + } +}; + + +detectorType slsDetectorCommand::getDetectorType(string const type){ + detectorType dtype=GENERIC; + if (type=="Mythen") + dtype=MYTHEN; + else if (type=="Pilatus") + dtype=PILATUS; + else if (type=="Eiger") + dtype=EIGER; + else if (type=="Gotthard") + dtype=GOTTHARD; + else if (type=="Agipd") + dtype=AGIPD; + return dtype; +}; + + +synchronizationMode slsDetectorCommand::getSyncType(string const type){ + synchronizationMode s; + if (type=="none") + s=NONE; + else if (type=="gating") + s=MASTER_GATES; + else if (type=="trigger") + s=MASTER_TRIGGERS; + else if (type=="complementary") + s=SLAVE_STARTS_WHEN_MASTER_STOPS; + else + s=GET_SYNCHRONIZATION_MODE; + return s; +} + + + +string slsDetectorCommand::getSyncType(synchronizationMode s ){ + + switch(s) { + case NONE: + return string("none"); + case MASTER_GATES: + return string("gating"); + case MASTER_TRIGGERS: + return string("trigger"); + case SLAVE_STARTS_WHEN_MASTER_STOPS: + return string("complementary"); + default: + return string("unknown"); + } + +}; + +string slsDetectorCommand::getDetectorSettings(detectorSettings s ){ + + switch(s) { + case STANDARD: + return string("standard"); + case FAST: + return string("fast"); + case HIGHGAIN: + return string("highgain"); + case DYNAMICGAIN: + return string("dynamicgain"); + case LOWGAIN: + return string("lowgain"); + case MEDIUMGAIN: + return string("mediumgain"); + case VERYHIGHGAIN: + return string("veryhighgain"); + default: + return string("undefined"); + } + +}; + +detectorSettings slsDetectorCommand::getDetectorSettings(string s ){ + + + if (s=="standard") return STANDARD; + if (s=="fast") return FAST; + if (s=="highgain") return HIGHGAIN; + if (s=="dynamicgain") return DYNAMICGAIN; + if (s=="lowgain") return LOWGAIN; + if (s=="mediumgain") return MEDIUMGAIN; + if (s=="veryhighgain") return VERYHIGHGAIN; + + return GET_SETTINGS; +}; + + + + +string slsDetectorCommand::executeLine(int narg, char *args[], int action) { + + if (action==READOUT_ACTION) + return cmdAcquire(narg, args, action); + + + size_t s=string(args[0]).find(':'); + string key=string(args[0]).substr(0,s); // truncate at : + + if (action==PUT_ACTION && narg<1) + action=HELP_ACTION; + + + for(int i=0; i> ivar; + if (vvstr.fail()) + ivar=-1; //append at the end + } + + if (sscanf(args[1],"%d",&ival)) { + // add by detector id + os<< addSlsDetector(ival, ivar)<< endl;; + } else { + //add by hostname + os<< addSlsDetector(args[1], ivar)<< endl; + } + return os.str(); + } + return string("cannot get"); + +} + + +string slsDetectorCommand::helpAdd(int narg, char *args[], int action){ + return string("add[:i] det \t adds a detector in position i to the multi detector structure. i is the detector position, default is appended. det can either be the detector hostname or the detector id. Returns -1 if it fails or the total number of detectors in the multidetector structure\n"); +} + +string slsDetectorCommand::cmdRemove(int narg, char *args[], int action){ +#ifdef VERBOSE + cout << string("Executing command ")+string(args[0])+string(" ( ")+cmd+string(" )\n"); +#endif + + + ostringstream os; + int ivar, ival; + string var=string(args[0]); + + if (action==HELP_ACTION) { + return helpRemove(narg,args,HELP_ACTION); + } else if (action==PUT_ACTION) { + if (sscanf(args[1],"%d",&ival)) { + // remove detector in position ival + os << removeSlsDetector(ival); + } else { + // remove detector by hostname + os<< removeSlsDetector(args[1]); + } + return os.str(); + } + return string("cannot get"); + +} +string slsDetectorCommand::helpRemove(int narg, char *args[], int action){ + return string("remove det \t removes a detector. det can either be the detector hostname or the detector position. Returns the total number of detectors in the multidetector structure\n"); +} + +string slsDetectorCommand::cmdHostname(int narg, char *args[], int action){ +#ifdef VERBOSE + cout << string("Executing command ")+string(args[0])+string(" ( ")+cmd+string(" )\n"); +#endif + + if (action==HELP_ACTION) { + return helpHostname(narg,args,HELP_ACTION); + } + + ostringstream os; + int ivar, ival; + string var=string(args[0]); + char hostname[1000]; + + + size_t p=string(args[0]).find(':'); + if (p==string::npos) + ivar=-1; + else { + istringstream vvstr(var.substr(p+1)); + vvstr >> ivar; + if (vvstr.fail()) + ivar=-1; + } + + if (action==PUT_ACTION) { + //add by hostname + if (ivar==-1) { + strcpy(hostname,""); + for (int id=1; id> ivar; + if (vvstr.fail()) + ivar=-1; + } + + if (action==PUT_ACTION) { + //add by hostname + istringstream vvstr(args[1]); + + vvstr >> ival; + if (vvstr.fail()) + ival=-1; + + setDetectorId(ival, ivar); + } + os << getDetectorId(ivar); + + return os.str(); + +} + +string slsDetectorCommand::helpId(int narg, char *args[], int action){ + ostringstream os; + if (action==GET_ACTION || action==HELP_ACTION) + os << string("id[:i] \t returns the id of the detector structure. i is the detector position in a multi detector system\n"); + if (action==PUT_ACTION || action==HELP_ACTION) + os << string("id:i l]\t configures the id of the detector structure. i is the detector position in a multi detector system and l is the id of the detector to be added\n"); + + return os.str(); +} + +string slsDetectorCommand::cmdMaster(int narg, char *args[], int action){ +#ifdef VERBOSE + cout << string("Executing command ")+string(args[0])+string(" ( ")+cmd+string(" )\n"); + +#endif + + ostringstream os; + int ival; + + + if (action==HELP_ACTION) { + return helpMaster(narg,args,HELP_ACTION); + } + setOnline(ONLINE_FLAG); + if (action==PUT_ACTION) { + istringstream vvstr(args[1]); + vvstr >> ival; + if (vvstr.fail()) + return helpMaster(narg,args,HELP_ACTION); + setMaster(ival); + } + os << setMaster(); + return os.str(); + +} + + +string slsDetectorCommand::helpMaster(int narg, char *args[], int action){ + + ostringstream os; + if (action==GET_ACTION || action==HELP_ACTION) + os << string("master \t gets the master of the detector structure (-1 if none)\n"); + if (action==PUT_ACTION || action==HELP_ACTION) + os << string("master pos \t sets position of the master of the detector structure (-1 if none) \n"); + return os.str(); + +} + +string slsDetectorCommand::cmdSync(int narg, char *args[], int action){ +#ifdef VERBOSE + cout << string("Executing command ")+string(args[0])+string(" ( ")+cmd+string(" )\n"); +#endif + + if (action==HELP_ACTION) { + return helpSync(narg,args,HELP_ACTION); + } + setOnline(ONLINE_FLAG); + if (action==PUT_ACTION) { + if (getSyncType(string(args[1]))==GET_SYNCHRONIZATION_MODE) return helpSync(narg,args, action); + setSynchronization(getSyncType(string(args[1]))); + } + return getSyncType(setSynchronization()); + +} +string slsDetectorCommand::helpSync(int narg, char *args[], int action){ + + ostringstream os; + if (action==GET_ACTION || action==HELP_ACTION) + os << string("sync \t gets the synchronization mode of the structure\n"); + if (action==PUT_ACTION || action==HELP_ACTION) + os << string("sync mode \t sets synchronization mode of the structure. Cane be none, gating, trigger, complementary \n"); + return os.str(); +} + +string slsDetectorCommand::cmdHelp(int narg, char *args[], int action){ +#ifdef VERBOSE + cout << string("Executing command ")+string(args[0])+string(" ( ")+cmd+string(" )\n"); +#endif + return helpLine(narg, args, action); + + +} + +string slsDetectorCommand::cmdExitServer(int narg, char *args[], int action){ +#ifdef VERBOSE + cout << string("Executing command ")+string(args[0])+string(" ( ")+cmd+string(" )\n"); +#endif + if (action==HELP_ACTION) { + return helpExitServer(narg, args, action); + } + setOnline(ONLINE_FLAG); + if (action==PUT_ACTION) { + if (exitServer()!=OK) + return string("Server shut down."); + else + return string("Error closing server\n"); + } else + return ("cannot get"); + +} + +string slsDetectorCommand::helpExitServer(int narg, char *args[], int action){ + return string("exitserver \t shuts down all the detector servers. Don't use it!!!!"); +} + + +string slsDetectorCommand::cmdSettingsDir(int narg, char *args[], int action){ +#ifdef VERBOSE + cout << string("Executing command ")+string(args[0])+string(" ( ")+cmd+string(" )\n"); +#endif + if (action==HELP_ACTION) { + return helpSettingsDir(narg, args, action); + } + if (action==PUT_ACTION) { + setSettingsDir(string(args[1])); + } + if (getSettingsDir()==NULL) + return string("undefined"); + return string(getSettingsDir()); +} + + + +string slsDetectorCommand::helpSettingsDir(int narg, char *args[], int action){ + ostringstream os; + if (action==GET_ACTION || action==HELP_ACTION) + os << string("settingsdir \t gets the directory where the settings files are located\n"); + if (action==PUT_ACTION || action==HELP_ACTION) + os << string("settingsdir dir \t sets the directory where the settings files are located\n"); + if (action==GET_ACTION || action==HELP_ACTION) + os << string("trimdir \t obsolete for settingsdir\n"); + if (action==PUT_ACTION || action==HELP_ACTION) + os << string("trimdir dir \t obsolete for settingsdir\n"); + return os.str(); +} + + + +string slsDetectorCommand::cmdCalDir(int narg, char *args[], int action){ + + if (action==HELP_ACTION) { + return helpCalDir(narg, args, action); + } + if (action==PUT_ACTION) { + setCalDir(string(args[1])); + } + if (getCalDir()==NULL) + return string("undefined"); + return string(getCalDir()); +} + + + +string slsDetectorCommand::helpCalDir(int narg, char *args[], int action){ + ostringstream os; + if (action==GET_ACTION || action==HELP_ACTION) + os << string("caldir \t gets the directory where the calibration files are located\n"); + if (action==PUT_ACTION || action==HELP_ACTION) + os << string("caldir dir \t sets the directory where the calibration files are located\n"); + return os.str(); +} + + + +string slsDetectorCommand::cmdTrimEn(int narg, char *args[], int action){ + int ival; + int ip; + + char answer[1000]; + + if (action==HELP_ACTION) return helpTrimEn(narg,args,action); + + if (action==PUT_ACTION) { + if (sscanf(args[1],"%d",&ival)) { + int pos[ival]; + for (ip=0; ip1) + sval=string(args[1]); + else + sval="none"; + float corr[24*1280], ecorr[24*1280]; + if (getFlatFieldCorrection(corr,ecorr)) { + if (sval!="none") { + writeDataFile(sval,corr,ecorr,NULL,'i'); + return sval; + } + return string(getFlatFieldCorrectionFile()); + } else { + return string("none"); + } + } + } +} + + +string slsDetectorCommand::helpFlatField(int narg, char *args[], int action){ + + int t=0; + ostringstream os; + if (string(args[0])==string("ffdir")) { + t=1; + } else if (string(args[0])==string("flatfield")) { + t=2; + } + if (t!=1) { + + if (action==GET_ACTION || action==HELP_ACTION) { + os << string("flatfield [fn]\t gets the flat field file name. the coorection values and errors can be dumped to fn if specified. \n"); + } if (action==PUT_ACTION || action==HELP_ACTION) + os << string("flatfield s \t sets the flat field file name\n"); + } + if (t!=2) { + + if (action==GET_ACTION || action==HELP_ACTION) + os << string("ffdir \t gets the path for the flat field files \n"); + if (action==PUT_ACTION || action==HELP_ACTION) + os << string("ffdir s \t sets the path for flat field files\n"); + } + return os.str(); + +} + + + + + +string slsDetectorCommand::cmdRateCorr(int narg, char *args[], int action){ + + float fval; + char answer[1000]; + + if (action==PUT_ACTION) { + sscanf(args[1],"%f",&fval); + setRateCorrection(fval); + } + float t; + if (getRateCorrection(t)) { + sprintf(answer,"%f",t); + } else { + sprintf(answer,"%f",0.); + } + return string(answer); +} + + +string slsDetectorCommand::helpRateCorr(int narg, char *args[], int action){ + ostringstream os; + if (action==GET_ACTION || action==HELP_ACTION) + os << string("ratecorr \t returns the dead time used for rate correections in ns \n"); + if (action==PUT_ACTION || action==HELP_ACTION) + os << string("ratecorr ns \t sets the deadtime correction constant in ns\n"); + return os.str(); + +} + + + + +string slsDetectorCommand::cmdBadChannels(int narg, char *args[], int action){ + + string sval; + + + if (action==PUT_ACTION) { + sval=string(args[1]); + if (sval=="none") + sval=""; + setBadChannelCorrection(sval); + } else if (action==GET_ACTION) { + if (narg>1) + sval=string(args[1]); + else + sval="none"; + int bch[24*1280], nbch; + if ((nbch=getBadChannelCorrection(bch))) { + if (sval!="none") { + ofstream outfile; + outfile.open (sval.c_str(),ios_base::out); + if (outfile.is_open()) { + for (int ich=0; ich1) + sval=string(args[1]); + else + sval="none"; + int dir; + if (getAngularConversion(dir)) { + if (sval!="none") { + writeAngularConversion(sval.c_str()); + return sval; + } + return string(getAngularConversion()); + } else { + return string("none"); + } + } + } else if (string(args[0])==string("globaloff")) { + if (action==PUT_ACTION) { + if (sscanf(args[1],"%f",&fval)) + setGlobalOffset(fval); + } + sprintf(answer,"%f",getGlobalOffset()); + return string(answer); + + } else if (string(args[0])==string("fineoff")) { + if (action==PUT_ACTION) { + if (sscanf(args[1],"%f",&fval)) + setFineOffset(fval); + } + sprintf(answer,"%f",getFineOffset()); + return string(answer); + + } else if (string(args[0])==string("binsize")) { + if (action==PUT_ACTION) { + if (sscanf(args[1],"%f",&fval)) + setBinSize(fval); + } + sprintf(answer,"%f",getBinSize()); + return string(answer); + + } + +} + + +string slsDetectorCommand::helpAngConv(int narg, char *args[], int action){ + + + int t=0xffff; + ostringstream os; + + if (string(args[0])==string("angconv")) { + t=1; + } else if (string(args[0])==string("globaloff")) { + t=2; + } else if (string(args[0])==string("fineoff")) { + t=4; + } else if (string(args[0])==string("binsize")) { + t=8; + } + if (t&1) { + if (action==GET_ACTION || action==HELP_ACTION) + os << string("angconv [fn]\t returns the constants used for angular conversion prints them to the file fn if specified \n"); + if (action==PUT_ACTION || action==HELP_ACTION) + os << string("angconv fn\t sets the angualr conversion constants (none unsets) \n"); + } if (t&2) { + if (action==GET_ACTION || action==HELP_ACTION) + os << string("globaloff\t returns the global offset used for angular conversion \n"); + if (action==PUT_ACTION || action==HELP_ACTION) + os << string("globaloff f\t sets the global offset used for the angular conversion \n"); + + + } if (t&4) { + if (action==GET_ACTION || action==HELP_ACTION) + os << string("fineoff\t returns the fine offset used for angular conversion \n"); + if (action==PUT_ACTION || action==HELP_ACTION) + os << string("fineoff f\t sets the fine offset used for the angular conversion \n"); + + + + } if (t&8) { + if (action==GET_ACTION || action==HELP_ACTION) + os << string("binsize\t returns the bin size used for the angular conversion \n"); + if (action==PUT_ACTION || action==HELP_ACTION) + os << string("binsize f\t sets the bin size used for the angular conversion \n"); + + + + + } + + + return os.str(); +} + + +string slsDetectorCommand::cmdThreaded(int narg, char *args[], int action){ + int ival; + char answer[1000]; + + if (action==HELP_ACTION) + return helpThreaded(narg,args,action); + + if (action==PUT_ACTION) { + if (sscanf(args[1],"%d",&ival)) + setThreadedProcessing(ival); + } + sprintf(answer,"%d",setThreadedProcessing()); + return string(answer); + +} + + +string slsDetectorCommand::helpThreaded(int narg, char *args[], int action){ + ostringstream os; + if (action==GET_ACTION || action==HELP_ACTION) + os << string("threaded \t returns wether the data processing is threaded. \n"); + if (action==PUT_ACTION || action==HELP_ACTION) + os << string("threaded t \t sets the threading flag ( 1sets, 0 unsets).\n"); + + return os.str(); + +} + + + + +string slsDetectorCommand::cmdPositions(int narg, char *args[], int action){ + int ival; + int ip; + + char answer[1000]; + + if (action==HELP_ACTION) return helpPositions(narg,args,action); + + if (action==PUT_ACTION) { + if (sscanf(args[1],"%d",&ival)) { + float pos[ival]; + for (ip=0; ip=(i+2)) { + if (sscanf(args[i+2],"%f",values+i)) + ns++; + else + break; + } else + break; + } + setScanSteps(is, ns, values); + delete [] values; + } else { + return string("invalid number of steps ")+string(args[1]); + } + } + ns=getScanSteps(is); + values=new float[ns]; + ns=getScanSteps(is, values); + sprintf(answer,"%d ",ns); + for (int i=0; iMAX_SCAN_STEPS) + return string("too many steps required!"); + + if (fmax>fmin) + if (fstep<0) + fstep=-1*fstep; + + if (fmax0) + fstep=-1*fstep; + + + values=new float[ns]; + for (int i=0; i=2) { + string sval=string(args[1]); +#ifdef VERBOSE + std::cout<< " trimfile " << sval << std::endl; +#endif + if (action==GET_ACTION) { + //create file names + saveSettingsFile(sval, -1); + } else if (action==PUT_ACTION) { + loadSettingsFile(sval,-1); + } + } + return string(getSettingsFile()); + } else if (cmd=="trim") { + if (action==GET_ACTION) { + return string("cannot get!"); + + trimMode mode=NOISE_TRIMMING; + int par1=0, par2=0; + if (string(args[0]).find("trim:")==string::npos) + return helpSettings(narg,args,action); + else if (string(args[0]).find("noise")!=string::npos) { + // par1 is countlim; par2 is nsigma + mode=NOISE_TRIMMING; + par1=500; + par2=4; + } else if (string(args[0]).find("beam")!=string::npos){ + // par1 is countlim; par2 is nsigma + mode=BEAM_TRIMMING; + par1=1000; + par2=4; + } else if (string(args[0]).find("improve")!=string::npos) { + // par1 is maxit; if par2!=0 vthresh will be optimized + mode=IMPROVE_TRIMMING; + par1=5; + par2=0; + } else if (string(args[0]).find("fix")!=string::npos) { + // par1 is countlim; if par2<0 then trimwithlevel else trim with median + mode=FIXEDSETTINGS_TRIMMING; + par1=1000; + par2=1; + // }else if (string(args[0]).find("fix")!=string::npos) { + //mode=OFFLINE_TRIMMING; + } else { + return string("Unknown trim mode ")+cmd; + } + executeTrimming(mode, par1, par2); + string sval=string(args[1]); + saveSettingsFile(sval, -1); + return string("done"); + } + } + return string("unknown settings command ")+cmd; + +} + + +string slsDetectorCommand::helpSettings(int narg, char *args[], int action) { + + ostringstream os; + if (action==PUT_ACTION || action==HELP_ACTION) { + os << "settings s \n sets the settings of the detector - can be standard, fast, highgain, dynamicgain, lowgain, mediumgain, veryhighgain"<< std::endl; + os << "threshold eV\n sets the detector threshold in eV"<< std::endl; + os << "trimbits fname\n loads the trimfile fname to the detector. If no extension is specified, the serial number of each module will be attached."<< std::endl; + os << "trim:mode fname\n trims the detector according to mode (can be noise, beam, improve, fix) and saves the resulting trimbits to file fname."<< std::endl; + } + if (action==GET_ACTION || action==HELP_ACTION) { + os << "settings \n gets the settings of the detector"<< std::endl; + os << "threshold V\n gets the detector threshold"<< std::endl; + os << "trimbits [fname]\n returns the trimfile loaded on the detector. If fname is specified the trimbits are saved to file. If no extension is specified, the serial number of each module will be attached."<< std::endl; + } + return os.str(); + + +} + + + + + + + + + + +string slsDetectorCommand::cmdSN(int narg, char *args[], int action) { + + char answer[1000]; + + + if (action==PUT_ACTION) + return string("cannot set"); + + + if (action==HELP_ACTION) + return helpSN(narg, args, action); + + + if (cmd=="thisversion"){ + sprintf(answer,"%llx",getId(THIS_SOFTWARE_VERSION)); + return string(answer); + } + + setOnline(ONLINE_FLAG); + + + if (cmd=="moduleversion") { + int ival=-1; + if (sscanf(args[0],"moduleversion:%d",&ival)) { + sprintf(answer,"%llx",getId(MODULE_FIRMWARE_VERSION,ival)); + return string(answer); + } else + return string("undefined module number"); + } + if (cmd=="detectornumber") { + sprintf(answer,"%llx",getId(DETECTOR_SERIAL_NUMBER)); + return string(answer); + } + if (cmd.find("modulenumber")!=string::npos) { + int ival=-1; + if (sscanf(args[0],"modulenumber:%d",&ival)) { + sprintf(answer,"%llx",getId(MODULE_SERIAL_NUMBER,ival)); + return string(answer); + } else + return string("undefined module number"); + } + + if (cmd=="detectorversion") { + sprintf(answer,"%llx",getId(DETECTOR_FIRMWARE_VERSION)); + return string(answer); + } + + if (cmd=="softwareversion") { + sprintf(answer,"%llx",getId(DETECTOR_SOFTWARE_VERSION)); + return string(answer); + } + + return string("unknown id mode ")+cmd; + +} + +string slsDetectorCommand::helpSN(int narg, char *args[], int action) { + + ostringstream os; + if (action==GET_ACTION || action==HELP_ACTION) { + os << "moduleversion:i \n gets the firmwareversion of the module i"<< std::endl; + os << "modulenumber:i \n gets the serial number of the module i"<< std::endl; + os << "detectornumber \n gets the serial number of the detector (MAC)"<< std::endl; + os << "detectorversion \n gets the firmware version of the detector"<< std::endl; + os << "softwareversion \n gets the software version of the detector"<< std::endl; + os << "thisversion \n gets the version of this software"<< std::endl; + } + return os.str(); + + + +} + + +string slsDetectorCommand::cmdDigiTest(int narg, char *args[], int action) { + + char answer[1000]; + + + if (action==PUT_ACTION) + return string("cannot set"); + + + if (action==HELP_ACTION) + return helpSN(narg, args, action); + + + setOnline(ONLINE_FLAG); + + if (cmd=="bustest"){ + sprintf(answer,"%x",digitalTest(DETECTOR_BUS_TEST)); + return string(answer); + } + + if (cmd=="digitest") { + int ival=-1; + if (sscanf(args[0],"digitest:%d",&ival)) { + sprintf(answer,"%x",digitalTest(CHIP_TEST, ival)); + return string(answer); + } else + return string("undefined module number"); + } + + return string("unknown digital test mode ")+cmd; + +} + +string slsDetectorCommand::helpDigiTest(int narg, char *args[], int action) { + + + ostringstream os; + if (action==GET_ACTION || action==HELP_ACTION) { + os << "digitaltest:i \n performs digital test of the module i. Returns 0 if succeeded, otherwise error mask."<< std::endl; + os << "bustest \n performs test of the bus interface between FPGA and embedded Linux system. Can last up to a few minutes."<< std::endl; + } + return os.str(); +} + +string slsDetectorCommand::cmdRegister(int narg, char *args[], int action) { + + + if (action==HELP_ACTION) + return helpRegister(narg, args, action); + + int addr, val; + char answer[1000]; + + setOnline(ONLINE_FLAG); + + if (action==PUT_ACTION) { + if(narg<3) + return string("wrong usage: should specify both address and value (hexadecimal fomat) "); + if (sscanf(args[1],"%x",&addr)) + ; + else + return string("Could not scan address (hexadecimal fomat) ")+string(args[1]); + + if (sscanf(args[2],"%x",&val)) + ; + else + return string("Could not scan value (hexadecimal fomat) ")+string(args[2]); + + + sprintf(answer,"%x",writeRegister(addr,val)); + + } else { + if (narg<2) + return string("wrong usage: should specify address (hexadecimal fomat) "); + if (sscanf(args[1],"%x",&addr)) + ; + else + return string("Could not scan address (hexadecimal fomat) ")+string(args[1]); + + + sprintf(answer,"%x",readRegister(addr)); + + } + + return string(answer); + + +} + +string slsDetectorCommand::helpRegister(int narg, char *args[], int action) { + + ostringstream os; + if (action==PUT_ACTION || action==HELP_ACTION) { + os << "reg_rw addr val \n writes the register addr with the value val"<< std::endl; + } + if (action==GET_ACTION || action==HELP_ACTION) { + os << "reg_rw addr \n reads the register addr"<< std::endl; + } + return os.str(); + + + +} + + +string slsDetectorCommand::cmdDAC(int narg, char *args[], int action) { + + if (action==HELP_ACTION) + return helpRegister(narg, args, action); + + dacIndex dac; + float val=-1; + char answer[1000]; + + if (cmd=="vthreshold") + dac=THRESHOLD; + else if (cmd=="vcalibration") + dac=CALIBRATION_PULSE; + else if (cmd=="vtrimbit") + dac=TRIMBIT_SIZE; + else if (cmd=="vpreamp") + dac=PREAMP; + else if (cmd=="vshaper1") + dac=SHAPER1; + else if (cmd=="vshaper2") + dac=SHAPER2; + else if (cmd=="vhighvoltage") + dac=HV_POT; + else if (cmd=="vapower") + dac=VA_POT; + else if (cmd=="vddpower") + dac=VDD_POT; + else if (cmd=="vshpower") + dac=VSH_POT; + else if (cmd=="viopower") + dac=VIO_POT; + else if (cmd=="vrefds") + dac=G_VREF_DS; + else if (cmd=="vcascn_pb") + dac=G_VCASCN_PB; + else if (cmd=="vcascp_pb") + dac=G_VCASCP_PB; + else if (cmd=="vout_cm") + dac=G_VOUT_CM; + else if (cmd=="vcasc_out") + dac=G_VCASC_OUT; + else if (cmd=="vin_cm") + dac=G_VIN_CM; + else if (cmd=="vref_comp") + dac=G_VREF_COMP; + else if (cmd=="ib_test_c") + dac=G_IB_TESTC; + else if (cmd=="temp_adc") { + dac=TEMPERATURE_ADC; + if (action==PUT_ACTION) + return string("cannot set ")+cmd; + } else if (cmd=="temp_fpga") { + dac=TEMPERATURE_FPGA; + if (action==PUT_ACTION) + return string("cannot set ")+cmd; + } else + return string("cannot decode dac ")+cmd; + + if (action==PUT_ACTION) { + if (sscanf(args[1],"%f", &val)) + ; + else + return string("cannot scan DAC value ")+string(args[1]); + } + + setOnline(ONLINE_FLAG); + + sprintf(answer,"%f",setDAC(val,dac)); + return string(answer); + +} + +string slsDetectorCommand::helpDAC(int narg, char *args[], int action) { + + ostringstream os; + if (action==PUT_ACTION || action==HELP_ACTION) { + os << "vthreshold dacu\t sets the detector threshold in dac units (0-1024). The energy is approx 800-15*keV" << std::endl; + os << std::endl; + + os << "vcalibration " << "dacu\t sets the calibration pulse amplitude in dac units (0-1024)." << std::endl; + os << std::endl; + os << "vtrimbit " << "dacu\t sets the trimbit amplitude in dac units (0-1024)." << std::endl; + os << std::endl; + os << "vpreamp " << "dacu\t sets the preamp feedback voltage in dac units (0-1024)." << std::endl; + os << std::endl; + os << "vshaper1 " << "dacu\t sets the shaper1 feedback voltage in dac units (0-1024)." << std::endl; + os << std::endl; + os << "vshaper2 " << "dacu\t sets the shaper2 feedback voltage in dac units (0-1024)." << std::endl; + os << std::endl; + os << "vhighvoltage " << "dacu\t CHIPTEST BOARD ONLY - sets the detector HV in dac units (0-1024)." << std::endl; + os << std::endl; + os << "vapower " << "dacu\t CHIPTEST BOARD ONLY - sets the analog power supply in dac units (0-1024)." << std::endl; + os << std::endl; + os << "vddpower " << "dacu\t CHIPTEST BOARD ONLY - sets the digital power supply in dac units (0-1024)." << std::endl; + os << std::endl; + os << "vshpower " << "dacu\t CHIPTEST BOARD ONLY - sets the comparator power supply in dac units (0-1024)." << std::endl; + os << std::endl; + os << "viopower " << "dacu\t CHIPTEST BOARD ONLY - sets the FPGA I/O power supply in dac units (0-1024)." << std::endl; + + + + os << "vrefds " << "dacu\t sets vrefds" << std::endl; + os << "vcascn_pb " << "dacu\t sets vcascn_pb" << std::endl; + os << "vcascp_pb " << "dacu\t sets vcascp_pb" << std::endl; + os << "vout_cm " << "dacu\t sets vout_cm" << std::endl; + os << "vin_cm " << "dacu\t sets vin_cm" << std::endl; + os << "vcasc_out " << "dacu\t sets vcasc_out" << std::endl; + os << "vref_comp " << "dacu\t sets vref_comp" << std::endl; + os << "ib_test_c " << "dacu\t sets ib_test_c" << std::endl; + + } + if (action==GET_ACTION || action==HELP_ACTION) { + + + os << "vthreshold \t Gets the detector threshold in dac units (0-1024). The energy is approx 800-15*keV" << std::endl; + os << std::endl; + + os << "vcalibration " << "dacu\t gets the calibration pulse amplitude in dac units (0-1024)." << std::endl; + os << std::endl; + os << "vtrimbit " << "dacu\t gets the trimbit amplitude in dac units (0-1024)." << std::endl; + os << std::endl; + os << "vpreamp " << "dacu\t gets the preamp feedback voltage in dac units (0-1024)." << std::endl; + os << std::endl; + os << "vshaper1 " << "dacu\t gets the shaper1 feedback voltage in dac units (0-1024)." << std::endl; + os << std::endl; + os << "vshaper2 " << "dacu\t gets the shaper2 feedback voltage in dac units (0-1024)." << std::endl; + os << std::endl; + os << "vhighvoltage " << "dacu\t CHIPTEST BOARD ONLY - gets the detector HV in dac units (0-1024)." << std::endl; + os << std::endl; + os << "vapower " << "dacu\t CHIPTEST BOARD ONLY - gets the analog power supply in dac units (0-1024)." << std::endl; + os << std::endl; + os << "vddpower " << "dacu\t CHIPTEST BOARD ONLY - gets the digital power supply in dac units (0-1024)." << std::endl; + os << std::endl; + os << "vshpower " << "dacu\t CHIPTEST BOARD ONLY - gets the comparator power supply in dac units (0-1024)." << std::endl; + os << std::endl; + os << "viopower " << "dacu\t CHIPTEST BOARD ONLY - gets the FPGA I/O power supply in dac units (0-1024)." << std::endl; + os << std::endl; + + + os << "vrefds " << "\t gets vrefds" << std::endl; + os << "vcascn_pb " << "\t gets vcascn_pb" << std::endl; + os << "vcascp_pb " << "\t gets vcascp_pb" << std::endl; + os << "vout_cm " << "\t gets vout_cm" << std::endl; + os << "vin_cm " << "\t gets vin_cm" << std::endl; + os << "vcasc_out " << "\t gets vcasc_out" << std::endl; + os << "vref_comp " << "\t gets vref_comp" << std::endl; + os << "ib_test_c " << "\t gets ib_test_c" << std::endl; + os << "temp_adc " << "\t gets the temperature of the adc" << std::endl; + os << "temp_fpga " << "\t gets the temperature of the fpga" << std::endl; + + } + return os.str(); + + + +} + + + +string slsDetectorCommand::cmdTimer(int narg, char *args[], int action) { + timerIndex index; + int64_t t=-1, ret; + float val, rval; + + char answer[1000]; + + + if (action==HELP_ACTION) + return helpTimer(narg, args, action); + + if (cmd=="exptime") + index=ACQUISITION_TIME; + else if (cmd=="period") + index=FRAME_PERIOD; + else if (cmd=="delay") + index=DELAY_AFTER_TRIGGER; + else if (cmd=="gates") + index=GATES_NUMBER; + else if (cmd=="frames") + index=FRAME_NUMBER; + else if (cmd=="cycles") + index=CYCLES_NUMBER; + else if (cmd=="probes") + index=PROBES_NUMBER; + else + return string("could not decode timer ")+cmd; + + + if (action==PUT_ACTION) { + if (sscanf(args[1],"%f", &val)) + ; + else + return string("cannot scan timer value ")+string(args[1]); + if (index==ACQUISITION_TIME || index==FRAME_PERIOD || index==DELAY_AFTER_TRIGGER) + t=val*1E+9; + else t=val; + } + + + setOnline(ONLINE_FLAG); + + ret=setTimer(index,t); + if (index==ACQUISITION_TIME || index==FRAME_PERIOD || index==DELAY_AFTER_TRIGGER) + rval=(float)ret*1E-9; + else rval=ret; + + + sprintf(answer,"%0.9f",rval); + return string(answer); + + + + +} + + +string slsDetectorCommand::helpTimer(int narg, char *args[], int action) { + + ostringstream os; + if (action==PUT_ACTION || action==HELP_ACTION) { + os << "exptime t \t sets the exposure time in s" << std::endl; + os << "period t \t sets the frame period in s" << std::endl; + os << "delay t \t sets the delay after trigger in s" << std::endl; + os << "frames t \t sets the number of frames per cycle (e.g. after each trigger)" << std::endl; + os << "cycles t \t sets the number of cycles (e.g. number of triggers)" << std::endl; + os << "probes t \t sets the number of probes to accumulate (max 3! cycles should be set to 1, frames to the number of pump-probe events)" << std::endl; + os << std::endl; + + + } + if (action==GET_ACTION || action==HELP_ACTION) { + + os << "exptime \t gets the exposure time in s" << std::endl; + os << "period \t gets the frame period in s" << std::endl; + os << "delay \t gets the delay after trigger in s" << std::endl; + os << "frames \t gets the number of frames per cycle (e.g. after each trigger)" << std::endl; + os << "cycles \t gets the number of cycles (e.g. number of triggers)" << std::endl; + os << "probes \t gets the number of probes to accumulate" << std::endl; + os << std::endl; + + } + return os.str(); + + + + + + + + +} + + +string slsDetectorCommand::cmdTimeLeft(int narg, char *args[], int action) { + timerIndex index; + int64_t ret; + float rval; + + char answer[1000]; + + + if (action==HELP_ACTION) + return helpTimeLeft(narg, args, action); + + if (cmd=="exptimel") + index=ACQUISITION_TIME; + else if (cmd=="periodl") + index=FRAME_PERIOD; + else if (cmd=="delayl") + index=DELAY_AFTER_TRIGGER; + else if (cmd=="gatesl") + index=GATES_NUMBER; + else if (cmd=="framesl") + index=FRAME_NUMBER; + else if (cmd=="cyclesl") + index=CYCLES_NUMBER; + else if (cmd=="probesl") + index=PROBES_NUMBER; + else if (cmd=="now") + index=ACTUAL_TIME; + else if (cmd=="timestamp") + index=MEASUREMENT_TIME; + else + return string("could not decode timer ")+cmd; + + + if (action==PUT_ACTION) { + return string("cannot set ")+string(args[1]); + } + + + + + setOnline(ONLINE_FLAG); + + ret=getTimeLeft(index); + + if (index==ACQUISITION_TIME || index==FRAME_PERIOD || index==DELAY_AFTER_TRIGGER || index==ACTUAL_TIME || index==MEASUREMENT_TIME) + rval=(float)ret*1E-9; + else rval=ret; + + + sprintf(answer,"%0.9f",rval); + return string(answer); + + + + + +} + + +string slsDetectorCommand::helpTimeLeft(int narg, char *args[], int action) { + + + + ostringstream os; + if (action==GET_ACTION || action==HELP_ACTION) { + + os << "exptimel \t gets the exposure time left" << std::endl; + os << "periodl \t gets the frame period left" << std::endl; + os << "delayl \t gets the delay left" << std::endl; + os << "framesl \t gets the number of frames left" << std::endl; + os << "cyclesl \t gets the number of cycles left" << std::endl; + os << "probesl \t gets the number of probes left" << std::endl; + os << std::endl; + + } + return os.str(); + + + + +} + + + + + + + +string slsDetectorCommand::cmdSpeed(int narg, char *args[], int action) { + + speedVariable index; + int t=-1, ret; + + char answer[1000]; + + + if (action==HELP_ACTION) + return helpSpeed(narg, args, action); + + if (cmd=="clkdivider") + index=CLOCK_DIVIDER; + else if (cmd=="setlength") + index=SET_SIGNAL_LENGTH; + else if (cmd=="waitstates") + index=WAIT_STATES; + else if (cmd=="totdivider") + index=TOT_CLOCK_DIVIDER; + else if (cmd=="totdutycycle") + index=TOT_DUTY_CYCLE; + else + return string("could not decode speed variable ")+cmd; + + + if (action==PUT_ACTION) { + if (sscanf(args[1],"%d", &t)) + ; + else + return string("cannot scan speed value ")+string(args[1]); + } + + + setOnline(ONLINE_FLAG); + + ret=setSpeed(index,t); + + + sprintf(answer,"%d",ret); + return string(answer); + + + + +} + + +string slsDetectorCommand::helpSpeed(int narg, char *args[], int action) { + + ostringstream os; + if (action==PUT_ACTION || action==HELP_ACTION) { + + os << "clkdivider c \t sets readout clock divider" << std::endl; + os << "setlength c\t sets the length of the set/reset signals (in clock cycles)" << std::endl; + os << "waitstates c \t sets the waitstates of the bus interface" << std::endl; + os << "totdivider c\t sets the clock divider in tot mode" << std::endl; + os << "totdutycycle c\t sets the duty cycle of the tot clock" << std::endl; + os << std::endl; + + } + if (action==GET_ACTION || action==HELP_ACTION) { + + os << "clkdivider \t gets readout clock divider" << std::endl; + os << "setlength \t gets the length of the set/reset signals (in clock cycles)" << std::endl; + os << "waitstates \t gets the waitstates of the bus interface" << std::endl; + os << "totdivider \t gets the clock divider in tot mode" << std::endl; + os << "totdutycycle \t gets the duty cycle of the tot clock" << std::endl; + os << std::endl; + + } + return os.str(); + + + + + + + + +} + + + + +string slsDetectorCommand::cmdAdvanced(int narg, char *args[], int action) { + + + + if (action==HELP_ACTION) + return helpAdvanced(narg, args, action); + + if (cmd=="flags") { + + readOutFlags flag=GET_READOUT_FLAGS; + + if (action==PUT_ACTION) { + string sval=string(args[1]); + if (sval=="none") + flag=NORMAL_READOUT; + else if (sval=="storeinram") + flag=STORE_IN_RAM; + else if (sval=="tot") + flag=TOT_MODE; + else if (sval=="continous") + flag=CONTINOUS_RO; + else + return string("could not scan flag ")+string(args[1]); + } + + + setOnline(ONLINE_FLAG); + + switch (setReadOutFlags(flag)) { + case NORMAL_READOUT: + return string("none"); + case STORE_IN_RAM: + return string("storeinram"); + case TOT_MODE: + return string("tot"); + case CONTINOUS_RO: + return string("continous"); + default: + return string("unknown"); + } + + } else if (cmd=="extsig") { + externalSignalFlag flag=GET_EXTERNAL_SIGNAL_FLAG; + int is=-1; + if (sscanf(args[0],"extsig:%d",&is)) + ; + else + return string("could not scan signal number ")+string(args[0]); + + if (action==PUT_ACTION) { + flag=externalSignalType(args[1]); + if (flag==GET_EXTERNAL_SIGNAL_FLAG) + return string("could not scan external signal mode ")+string(args[1]); + } + setOnline(ONLINE_FLAG); + + return externalSignalType(setExternalSignalFlags(flag,is)); + + } else + return string("could not decode flag ")+cmd; + +} + + +string slsDetectorCommand::helpAdvanced(int narg, char *args[], int action) { + + ostringstream os; + if (action==PUT_ACTION || action==HELP_ACTION) { + + os << "extsig:i mode \t sets the mode of the external signal i. can be \n \t \t \t off, \n \t \t \t gate_in_active_high, \n \t \t \t gate_in_active_low, \n \t \t \t trigger_in_rising_edge, \n \t \t \t trigger_in_falling_edge, \n \t \t \t ro_trigger_in_rising_edge, \n \t \t \t ro_trigger_in_falling_edge, \n \t \t \t gate_out_active_high, \n \t \t \t gate_out_active_low, \n \t \t \t trigger_out_rising_edge, \n \t \t \t trigger_out_falling_edge, \n \t \t \t ro_trigger_out_rising_edge, \n \t \t \t ro_trigger_out_falling_edge" << std::endl; + os << "flags mode \t sets the readout flags to mode. can be none, storeinram, tot, continous, unknown" << std::endl; + + } + if (action==GET_ACTION || action==HELP_ACTION) { + + os << "extsig:i \t gets the mode of the external signal i. can be \n \t \t \t off, \n \t \t \t gate_in_active_high, \n \t \t \t gate_in_active_low, \n \t \t \t trigger_in_rising_edge, \n \t \t \t trigger_in_falling_edge, \n \t \t \t ro_trigger_in_rising_edge, \n \t \t \t ro_trigger_in_falling_edge, \n \t \t \t gate_out_active_high, \n \t \t \t gate_out_active_low, \n \t \t \t trigger_out_rising_edge, \n \t \t \t trigger_out_falling_edge, \n \t \t \t ro_trigger_out_rising_edge, \n \t \t \t ro_trigger_out_falling_edge" << std::endl; + os << "flags \t gets the readout flags. can be none, storeinram, tot, continous, unknown" << std::endl; + + } + return os.str(); + + + + + + + + +} + + + + +string slsDetectorCommand::cmdConfiguration(int narg, char *args[], int action) { + + + + if (action==HELP_ACTION) + return helpConfiguration(narg, args, action); + + string sval; + + if (narg<2) + return string("should specify I/O file"); + + setOnline(ONLINE_FLAG); + + if (cmd=="config") { + if (action==PUT_ACTION) { + sval=string(args[1]); + readConfigurationFile(sval); + } else if (action==GET_ACTION) { + sval=string(args[1]); + writeConfigurationFile(sval); + } + return sval; + } else if (cmd=="parameters") { + if (action==PUT_ACTION) { + sval=string(args[1]); + retrieveDetectorSetup(sval); + } else if (action==GET_ACTION) { + sval=string(args[1]); + dumpDetectorSetup(sval); + } + return sval; + } else if (cmd=="setup") { + if (action==PUT_ACTION) { + sval=string(args[1]); + retrieveDetectorSetup(sval,2); + } else if (action==GET_ACTION) { + sval=string(args[1]); + dumpDetectorSetup(sval,2); + } + return sval; + } + return string("could not decode conf mode"); + + +} + + +string slsDetectorCommand::helpConfiguration(int narg, char *args[], int action) { + + ostringstream os; + if (action==PUT_ACTION || action==HELP_ACTION) { + + os << "config fname \t sets the detector to the configuration contained in fname" << std::endl; + os << "parameters fname \t sets the detector parameters to those contained in fname" << std::endl; + os << "setup fname \t sets the detector complete detector setup to that contained in fname (extensions automatically generated), including trimfiles, ff coefficients etc." << std::endl; + + } + if (action==GET_ACTION || action==HELP_ACTION) { + + os << "config fname \t saves the detector to the configuration to fname" << std::endl; + os << "parameters fname \t saves the detector parameters to fname" << std::endl; + os << "setup fname \t saves the detector complete detector setup to fname (extensions automatically generated), including trimfiles, ff coefficients etc." << std::endl; + + } + + return os.str(); + + + + + + + + +} + + + + +// // string slsDetectorCommand::executeLine2(int narg, char *args[], int action) { + + + + + +// // } else if (var=="progress") { +// // if (action==PUT_ACTION) { +// // setTotalProgress(); +// // sprintf(answer,"Cannot set\n"); +// // } else +// // sprintf(answer,"%f",getCurrentProgress()); +// // return string(answer); +// // } + + + + + + + + +// // string slsDetectorCommand::helpLine2( int action) { + + +// // ostringstream os; + +// // if (action==READOUT_ACTION) { +// // os << "Usage is "<< std::endl << "mythen_acquire id " << std::endl; +// // os << "where id is the id of the detector " << std::endl; +// // os << "the detector will be started, the data acquired, processed and written to file according to the preferences configured " << std::endl; +// // } else if (action==PUT_ACTION) { +// // os << "help \t This help " << std::endl; +// // os << std::endl; +// // os << "config fname\t reads the configuration file specified and sets the values " << std::endl; +// // os << std::endl; +// // os << "parameters fname\t sets the detector parameters specified in the file " << std::endl; +// // os << std::endl; +// // os << "setup rootname\t reads the files specfied (and that could be created by get setup) and resets the complete detector configuration including flatfield corrections, badchannels, trimbits etc. " << std::endl; +// // os << std::endl; +// // os << "status s \t either start or stop " << std::endl; +// // os << std::endl; +// // os << "hostname name \t Sets the detector hostname (or IP address) " << std::endl; +// // os << std::endl; +// // os << "caldir path \t Sets path of the calibration files " << std::endl; +// // os << std::endl; +// // os << "trimdir path \t Sets path of the trim files " << std::endl; +// // os << std::endl; +// // os << "trimen nen [e0 e1...en] \t sets the number of energies for which trimbit files exist and their value"<< std::endl; +// // os << std::endl; + + + + + + + + +// // os << "startscript script \t sets script to execute at the beginning of the measurements - \"none\" to unset - will be launched as a system call with arguments nrun=fileindex par=startscriptpar"<< std::endl; +// // os << std::endl; +// // os << "startscriptpar par \t sets start script parameter (see startscript)"<< std::endl; +// // os << std::endl; + +// // os << "scan0script script \t sets script to launch at level 0 scan. If \"energy\" energy scan, if \"threshold\" threshold scan, if \"trimbits\" trimbits scan, \"none\" unsets otherwise will be launched as a system call with arguments nrun=fileindex fn=filename var=scan0var par=scan0par"<< std::endl; +// // os << std::endl; +// // os << "scan0par par\t sets the level 0 scan parameter. See scan0script"<< std::endl; +// // os << std::endl; +// // os << "scan0prec n \t sets the level 0 scan precision for the output file name. See scan0script"<< std::endl; +// // os << std::endl; +// // os << "scan0steps nsteps [s0 s1...] \t sets the level 0 scan steps. See scan0script - nsteps=0 unsets the scan level"<< std::endl; +// // os << std::endl; + + +// // os << "scan1script script \t sets script to launch at level 1 scan. If \"energy\" energy scan, if \"threshold\" threshold scan, if \"trimbits\" trimbits scan, \"none\" unsets otherwise will be launched as a system call with arguments nrun=fileindex fn=filename var=scan1var par=scan1par"<< std::endl; +// // os << std::endl; + +// // os << "scan1par par\t sets the level 1 scan parameter. See scan1script"<< std::endl; +// // os << std::endl; +// // os << "scan1prec n \t sets the level 1 scan precision for the output file name. See scan1script"<< std::endl; +// // os << std::endl; +// // os << "scan1steps nsteps [s0 s1...] \t sets the level 1 scan steps. See scan1script - nsteps=0 unsets the scan level"<< std::endl; +// // os << std::endl; + + +// // os << "scriptbefore script \t sets script to execute at the beginning of the realtime acquisition - \"none\" to unset - will be launched as a system call with arguments nrun=fileindex fn=filename par=scriptbeforepar sv0=scan0var sv1=scan1var p0=scan0par p1=scan1par"<< std::endl; +// // os << std::endl; +// // os << "scriptbeforepar \t sets script before parameter (see scriptbefore)"<< std::endl; +// // os << std::endl; + +// // os << "headerbefore script \n script to launch to acquire the headerfile just before the acquisition - \"none\" to unset - will be launched as a system call with arguments nrun=fileindex fn=filename acqtime=t gainmode=sett threshold=thr badfile=badf angfile=angf bloffset=bloffset fineoffset=fineoffset fffile=ffile tau=taucorr par=headerbeforepar"<< std::endl; +// // os << std::endl; +// // os << "headerbeforepar \t sets header before parameter (see headerbefore)"<< std::endl; +// // os << std::endl; + + +// // os << "headerafter script \n script to launch to acquire the headerfile just after the acquisition - \"none\" to unset - will be launched as a system call with arguments nrun=fileindex fn=filename acqtime=t gainmode=sett threshold=thr badfile=badf angfile=angf bloffset=bloffset fineoffset=fineoffset fffile=ffile tau=taucorr par=headerafterpar"<< std::endl; +// // os << std::endl; +// // os << "headerafterpar par \t sets header after parameter (see headerafter)"<< std::endl; +// // os << std::endl; + +// // os << "scriptafter script \t sets script to execute at the end of the realtime acquisition - \"none\" to unset - will be launched as a system call with arguments nrun=fileindex fn=filename par=scriptafterpar sv0=scan0var sv1=scan1var p0=scan0par p1=scan1par"<< std::endl; +// // os << std::endl; +// // os << "scriptafterpar par \t sets script after parameter (see scriptafter)"<< std::endl; +// // os << std::endl; + + +// // os << "stopscript script \t sets script to execute at the end of the measurements - \"none\" to unset - will be launched as a system call with arguments nrun=fileindex par=stopscriptpar"<< std::endl; +// // os << std::endl; +// // os << "stopscriptpar par\t sets stop script parameter (see stopscript)"<< std::endl; +// // os << std::endl; + + + + + +// // os << "outdir \t directory to which the files will be written by default" << std::endl; +// // os << std::endl; +// // os << "fname \t filename to which the files will be written by default (to which file and position indexes will eventually be attached)" << std::endl; +// // os << std::endl; +// // os << "index \t start index of the files (automatically incremented by the acquisition functions)" << std::endl; +// // os << std::endl; +// // os << "nmod n \t Sets number of detector modules " << std::endl; +// // os << std::endl; +// // os << "extsig:i mode \t Sets usage of the external digital signal i. mode can be: " << std::endl; +// // os << "\t off"; +// // os << std::endl; +// // os << "\t gate_in_active_high"; +// // os << std::endl; +// // os << "\t gate_in_active_low"; +// // os << std::endl; +// // os << "\t trigger_in_rising_edge"; +// // os << std::endl; +// // os << "\t trigger_in_falling_edge"; +// // os << std::endl; +// // os << "\t ro_trigger_in_rising_edge"; +// // os << std::endl; +// // os << "\t ro_trigger_in_falling_edge"; +// // os << std::endl; +// // os << "\t gate_out_active_high"; +// // os << std::endl; +// // os << "\t gate_out_active_low"; +// // os << std::endl; +// // os << "\t trigger_out_rising_edge"; +// // os << std::endl; +// // os << "\t trigger_out_falling_edge"; +// // os << std::endl; +// // os << "\t ro_trigger_out_rising_edge"; +// // os << std::endl; +// // os << "\t ro_trigger_out_falling_edge" << std::endl; +// // os << std::endl; +// // os << "settings sett \t Sets detector settings. Can be: " << std::endl; +// // os << "\t standard \t fast \t highgain" << std::endl; +// // os << "\t depending on trheshold energy and maximum count rate: please refere to manual for limit values!"<< std::endl; +// // os << std::endl; +// // os << "threshold ev \t Sets detector threshold in eV. Should be half of the beam energy. It is precise only if the detector is calibrated"<< std::endl; +// // os << std::endl; +// // os << "vthreshold dacu\t sets the detector threshold in dac units (0-1024). The energy is approx 800-15*keV" << std::endl; +// // os << std::endl; + +// // os << "vcalibration " << "dacu\t sets the calibration pulse amplitude in dac units (0-1024)." << std::endl; +// // os << std::endl; +// // os << "vtrimbit " << "dacu\t sets the trimbit amplitude in dac units (0-1024)." << std::endl; +// // os << std::endl; +// // os << "vpreamp " << "dacu\t sets the preamp feedback voltage in dac units (0-1024)." << std::endl; +// // os << std::endl; +// // os << "vshaper1 " << "dacu\t sets the shaper1 feedback voltage in dac units (0-1024)." << std::endl; +// // os << std::endl; +// // os << "vshaper2 " << "dacu\t sets the shaper2 feedback voltage in dac units (0-1024)." << std::endl; +// // os << std::endl; +// // os << "vhighvoltage " << "dacu\t CHIPTEST BOARD ONLY - sets the detector HV in dac units (0-1024)." << std::endl; +// // os << std::endl; +// // os << "vapower " << "dacu\t CHIPTEST BOARD ONLY - sets the analog power supply in dac units (0-1024)." << std::endl; +// // os << std::endl; +// // os << "vddpower " << "dacu\t CHIPTEST BOARD ONLY - sets the digital power supply in dac units (0-1024)." << std::endl; +// // os << std::endl; +// // os << "vshpower " << "dacu\t CHIPTEST BOARD ONLY - sets the comparator power supply in dac units (0-1024)." << std::endl; +// // os << std::endl; +// // os << "viopower " << "dacu\t CHIPTEST BOARD ONLY - sets the FPGA I/O power supply in dac units (0-1024)." << std::endl; + +// // os << std::endl; +// // os << "exptime t \t Sets the exposure time per frame (in s)"<< std::endl; +// // os << std::endl; +// // os << "period t \t Sets the frames period (in s)"<< std::endl; +// // os << std::endl; +// // os << "delay t \t Sets the delay after trigger (in s)"<< std::endl; +// // os << std::endl; +// // os << "gates n \t Sets the number of gates per frame"<< std::endl; +// // os << std::endl; +// // os << "frames n \t Sets the number of frames per cycle (e.g. after each trigger)"<< std::endl; +// // os << std::endl; +// // os << "cycles n \t Sets the number of cycles (e.g. number of triggers)"<< std::endl; +// // os << std::endl; +// // os << "probes n \t Sets the number of probes to accumulate (max 3)"<< std::endl; +// // os << std::endl; +// // os << "dr n \t Sets the dynamic range - can be 1, 4, 8,16 or 24 bits"<< std::endl; +// // os << std::endl; +// // os << "flags mode \t Sets the readout flags - can be none or storeinram"<< std::endl; +// // os << std::endl; +// // os << "ffdir dir \t Sets the default directory where the flat field are located"<< std::endl; +// // os << std::endl; +// // os << "flatfield fname \t Sets the flatfield file name - none disable flat field corrections"<< std::endl; +// // os << std::endl; +// // os << "ratecorr t \t Sets the rate corrections with dead time t ns (0 unsets, -1 uses default dead time for chosen settings"<< std::endl; +// // os << std::endl; +// // os << "badchannels fname \t Sets the badchannels file name - none disable bad channels corrections"<< std::endl; +// // os << std::endl; +// // os << "angconv fname \t Sets the angular conversion file name"<< std::endl; +// // os << std::endl; +// // os << "globaloff o \t sets the fixed angular offset of your encoder - should be almost constant!"<< std::endl; +// // os << std::endl; +// // os << "fineoff o \t sets a possible angular offset of your setup - should be small but can be senseful to modify"<< std::endl; +// // os << std::endl; +// // os << "binsize s\t sets the binning size of the angular conversion (otherwise defaults from the angualr conversion constants)"<< std::endl; +// // os << std::endl; +// // os << "positions np [pos0 pos1...posnp] \t sets the number of positions at which the detector is moved during the acquisition and their values"<< std::endl; +// // os << std::endl; +// // os << "threaded b \t sets whether the postprocessing and file writing of the data is done in a separate thread (0 sequencial, 1 threaded). Please remeber to set the threaded mode if you acquire long real time measurements and/or use the storeinram option otherwise you risk to lose your data"<< std::endl; +// // os << std::endl; +// // os << "online b\t sets the detector in online (1) or offline (0) state " << std::endl; +// // os << std::endl; +// // } else if (action==GET_ACTION) { +// // os << "help \t This help " << std::endl; + + +// // os << "status \t gets the detector status - can be: running, error, transmitting, finished, waiting or idle" << std::endl; +// // os << "data \t gets all data from the detector (if any) processes them and writes them to file according to the preferences already setup" << std::endl; +// // os << "frame \t gets a single frame from the detector (if any) processes it and writes it to file according to the preferences already setup" << std::endl; +// // os << "config fname\t writes the configuration file" << std::endl; +// // os << std::endl; +// // os << "parameters fname\t writes the main detector parameters for the measuremen tin the file " << std::endl; +// // os << std::endl; +// // os << "setup rootname\t writes the complete detector setup (including configuration, trimbits, flat field coefficients, badchannels etc.) in a set of files for which the extension is automatically generated " << std::endl; +// // os << std::endl; +// // os << "hostname \t Gets the detector hostname (or IP address) " << std::endl; +// // os << std::endl; +// // os << "caldir \t Gets path of the calibration files " << std::endl; +// // os << std::endl; +// // os << "trimdir \t Gets path of the trim files " << std::endl; +// // os << std::endl; +// // os << "trimen \t returns the number of energies for which trimbit files exist and their values"<< std::endl; + + + + + + +// // os << "startscript \t gets script to execute at the beginning of the measurements - \"none\" to unset - will be launched as a system call with arguments nrun=fileindex par=startscriptpar"<< std::endl; +// // os << std::endl; +// // os << "startscriptpar \t gets start script parameter (see startscript)"<< std::endl; +// // os << std::endl; + +// // os << "scan0script \t gets script to launch at level 0 scan. If \"energy\" energy scan, if \"threshold\" threshold scan, if \"trimbits\" trimbits scan, \"none\" unsets otherwise will be launched as a system call with arguments nrun=fileindex fn=filename var=scan0var par=scan0par"<< std::endl; +// // os << std::endl; +// // os << "scan0par \t gets the level 0 scan parameter. See scan0script"<< std::endl; +// // os << std::endl; +// // os << "scan0prec \t gets the level 0 scan precision for the output file name. See scan0script"<< std::endl; +// // os << std::endl; +// // os << "scan0steps \t gets the level 0 scan steps. See scan0script - nsteps=0 unsets the scan level"<< std::endl; +// // os << std::endl; + + +// // os << "scan1script \t gets script to launch at level 1 scan. If \"energy\" energy scan, if \"threshold\" threshold scan, if \"trimbits\" trimbits scan, \"none\" unsets otherwise will be launched as a system call with arguments nrun=fileindex fn=filename var=scan1var par=scan1par"<< std::endl; +// // os << std::endl; + +// // os << "scan1par \t gets the level 1 scan parameter. See scan1script"<< std::endl; +// // os << std::endl; +// // os << "scan1prec \t gets the level 1 scan precision for the output file name. See scan1script"<< std::endl; +// // os << std::endl; +// // os << "scan1steps \t gets the level 1 scan steps. See scan1script - nsteps=0 unsets the scan level"<< std::endl; +// // os << std::endl; + + +// // os << "scriptbefore \t gets script to execute at the beginning of the realtime acquisition - \"none\" to unset - will be launched as a system call with arguments nrun=fileindex fn=filename par=scriptbeforepar sv0=scan0var sv1=scan1var p0=scan0par p1=scan1par"<< std::endl; +// // os << std::endl; +// // os << "scriptbeforepar \t gets script before parameter (see scriptbefore)"<< std::endl; +// // os << std::endl; + +// // os << "headerbefore \n gets the script to launch to acquire the headerfile just before the acquisition - \"none\" to unset - will be launched as a system call with arguments nrun=fileindex fn=filename acqtime=t gainmode=sett threshold=thr badfile=badf angfile=angf bloffset=bloffset fineoffset=fineoffset fffile=ffile tau=taucorr par=headerbeforepar"<< std::endl; +// // os << std::endl; +// // os << "headerbeforepar \t gets header before parameter (see headerbefore)"<< std::endl; +// // os << std::endl; + + +// // os << "headerafter \n gets the script to launch to acquire the headerfile just after the acquisition - \"none\" to unset - will be launched as a system call with arguments nrun=fileindex fn=filename acqtime=t gainmode=sett threshold=thr badfile=badf angfile=angf bloffset=bloffset fineoffset=fineoffset fffile=ffile tau=taucorr par=headerafterpar"<< std::endl; +// // os << std::endl; +// // os << "headerafterpar \t gets header after parameter (see headerafter)"<< std::endl; +// // os << std::endl; + +// // os << "scriptafter \t gets script to execute at the end of the realtime acquisition - \"none\" to unset - will be launched as a system call with arguments nrun=fileindex fn=filename par=scriptafterpar sv0=scan0var sv1=scan1var p0=scan0par p1=scan1par"<< std::endl; +// // os << std::endl; +// // os << "scriptafterpar \t gets script after parameter (see scriptafter)"<< std::endl; +// // os << std::endl; + + +// // os << "stopscript \t gets script to execute at the end of the measurements - \"none\" to unset - will be launched as a system call with arguments nrun=fileindex par=stopscriptpar"<< std::endl; +// // os << std::endl; +// // os << "stopscriptpar\t gets stop script parameter (see stopscript)"<< std::endl; +// // os << std::endl; + + + + + + + + + + + + + + + + + + + + + +// // os << "outdir \t directory to which the files will be written by default" << std::endl; +// // os << std::endl; +// // os << "fname \t filename to which the files will be written by default (to which file and position indexes will eventually be attached)" << std::endl; +// // os << std::endl; +// // os << "index \t start index of the files (automatically incremented by the acquisition functions)" << std::endl; +// // os << std::endl; +// // os << "nmod \t Gets number of detector modules " << std::endl; +// // os << std::endl; +// // os << "maxmod \t Gets maximum number of detector modules " << std::endl; +// // os << std::endl; +// // os << "extsig:i\t Gets usage of the external digital signal i. The return value can be: " << std::endl; +// // os << "\t 0 off"; +// // os << std::endl; +// // os << "\t 1 gate_in_active_high"; +// // os << std::endl; +// // os << "\t 2 gate_in_active_low"; +// // os << std::endl; +// // os << "\t 3 trigger_in_rising_edge"; +// // os << std::endl; +// // os << "\t 4 trigger_in_falling_edge"; +// // os << std::endl; +// // os << "\t 5 ro_trigger_in_rising_edge"; +// // os << std::endl; +// // os << "\t 6 ro_trigger_in_falling_edge"; +// // os << std::endl; +// // os << "\t 7 gate_out_active_high"; +// // os << std::endl; +// // os << "\t 8 gate_out_active_low"; +// // os << std::endl; +// // os << "\t 9 trigger_out_rising_edge"; +// // os << std::endl; +// // os << "\t 10 trigger_out_falling_edge"; +// // os << std::endl; +// // os << "\t 11 ro_trigger_out_rising_edge"; +// // os << std::endl; +// // os << "\t 12 ro_trigger_out_falling_edge" << std::endl; +// // os << std::endl; +// // os << "modulenumber:i \t Gets the serial number of module i" << std::endl; +// // os << std::endl; +// // os << "moduleversion\t Gets the module version " << std::endl; +// // os << std::endl; +// // os << "detectornumber\t Gets the detector number (MAC address) " << std::endl; +// // os << std::endl; +// // os << "detectorversion\t Gets the detector firmware version " << std::endl; +// // os << std::endl; +// // os << "softwareversion\t Gets the detector software version " << std::endl; +// // os << std::endl; +// // os << "thisversion\t Gets the version of this software" << std::endl; +// // os << std::endl; +// // os << "digitest:i\t Makes a digital test of the detector module i. Returns 0 if it succeeds " << std::endl; +// // os << std::endl; +// // os << "bustest\t Makes a test of the detector bus. Returns 0 if it succeeds " << std::endl; +// // os << std::endl; +// // os << "settings\t Gets detector settings. Can be: " << std::endl; +// // os << "\t 0 standard \t 1 fast \t 2 highgain \t else undefined" << std::endl; +// // os << std::endl; +// // os << "threshold\t Gets detector threshold in eV. It is precise only if the detector is calibrated"<< std::endl; +// // os << std::endl; +// // os << "vthreshold \t Gets the detector threshold in dac units (0-1024). The energy is approx 800-15*keV" << std::endl; +// // os << std::endl; + +// // os << "vcalibration " << "dacu\t gets the calibration pulse amplitude in dac units (0-1024)." << std::endl; +// // os << std::endl; +// // os << "vtrimbit " << "dacu\t gets the trimbit amplitude in dac units (0-1024)." << std::endl; +// // os << std::endl; +// // os << "vpreamp " << "dacu\t gets the preamp feedback voltage in dac units (0-1024)." << std::endl; +// // os << std::endl; +// // os << "vshaper1 " << "dacu\t gets the shaper1 feedback voltage in dac units (0-1024)." << std::endl; +// // os << std::endl; +// // os << "vshaper2 " << "dacu\t gets the shaper2 feedback voltage in dac units (0-1024)." << std::endl; +// // os << std::endl; +// // os << "vhighvoltage " << "dacu\t CHIPTEST BOARD ONLY - gets the detector HV in dac units (0-1024)." << std::endl; +// // os << std::endl; +// // os << "vapower " << "dacu\t CHIPTEST BOARD ONLY - gets the analog power supply in dac units (0-1024)." << std::endl; +// // os << std::endl; +// // os << "vddpower " << "dacu\t CHIPTEST BOARD ONLY - gets the digital power supply in dac units (0-1024)." << std::endl; +// // os << std::endl; +// // os << "vshpower " << "dacu\t CHIPTEST BOARD ONLY - gets the comparator power supply in dac units (0-1024)." << std::endl; +// // os << std::endl; +// // os << "viopower " << "dacu\t CHIPTEST BOARD ONLY - gets the FPGA I/O power supply in dac units (0-1024)." << std::endl; +// // os << std::endl; + + +// // os << "exptime\t Gets the exposure time per frame (in s)"<< std::endl; +// // os << std::endl; +// // os << "period \t Gets the frames period (in s)"<< std::endl; +// // os << std::endl; +// // os << "delay \t Gets the delay after trigger (in s)"<< std::endl; +// // os << std::endl; +// // os << "gates \t Gets the number of gates per frame"<< std::endl; +// // os << std::endl; +// // os << "frames \t Gets the number of frames per cycle (e.g. after each trigger)"<< std::endl; +// // os << std::endl; +// // os << "cycles \t Gets the number of cycles (e.g. number of triggers)"<< std::endl; +// // os << std::endl; +// // os << "probes \t Gets the number of probes to accumulate (max 3)"<< std::endl; + + + + +// // os << "exptimel\t Gets the exposure time left in the current frame (in s)"<< std::endl; +// // os << std::endl; +// // os << "periodl \t Gets the period left in the current frame (in s)"<< std::endl; +// // os << std::endl; +// // os << "delayl \t Gets the delay after current trigger left (in s)"<< std::endl; +// // os << std::endl; +// // os << "gatesl \t Gets the number of gates left in the current frame"<< std::endl; +// // os << std::endl; +// // os << "framesl \t Gets the number of frames left (after the current trigger)"<< std::endl; +// // os << std::endl; +// // os << "cyclesl \t Gets the number of cycles left (e.g. number of triggers)"<< std::endl; +// // //os << std::endl; +// // //os << "progress \t Gets acquisition progress - to be implemented"<< std::endl; + +// // os << std::endl; +// // os << "now \t Gets the actual time of the detector (in s)"<< std::endl; + + +// // os << std::endl; +// // os << "timestamp \t Gets the time of the measurements of the detector (in s, -1 if no measurement left)"<< std::endl; + + + + + +// // os << std::endl; +// // os << "dr \t Gets the dynamic range"<< std::endl; +// // os << std::endl; +// // os << "trim:mode fname \t trims the detector and writes the trimfile fname.snxx "<< std::endl; +// // os << "\t mode can be:\t noise\t beam\t improve\t fix\t offline "<< std::endl; +// // os << "Check that the start conditions are OK!!!"<< std::endl; +// // os << std::endl; +// // os << "ffdir \t Returns the default directory where the flat field are located"<< std::endl; +// // os << std::endl; +// // os << "flatfield fname \t returns wether the flat field corrections are enabled and if so writes the coefficients to the specified filename. If fname is none it is not written"<< std::endl; +// // os << std::endl; +// // os << "ratecorr \t returns wether teh rate corrections are enabled and what is the dead time used in ns"<< std::endl; +// // os << std::endl; +// // os << "badchannels fname \t returns wether the bad channels corrections are enabled and if so writes the bad channels to the specified filename. If fname is none it is not written"<< std::endl; +// // os << std::endl; +// // os << "angconv fname \t returns wether the angular conversion is enabled and if so writes the angular conversion coefficients to the specified filename. If fname is none, it is not written"<< std::endl; +// // os << std::endl; +// // os << "globaloff \t returns the fixed angular offset of your encoder - should be almost constant!"<< std::endl; +// // os << std::endl; +// // os << "fineoff \t returns a possible angualr offset of your setup - should be small but can be senseful to modify"<< std::endl; +// // os << std::endl; +// // os << "binsize \t returns the binning size of the anular conversion"<< std::endl; +// // os << std::endl; +// // os << "positions \t returns the number of positions at which the detector is moved during the acquisition and their values"<< std::endl; +// // os << std::endl; +// // os << "threaded \t gets whether the postprocessing and file writing of the data is done in a separate thread (0 sequencial, 1 threaded). Check that it is set to 1 if you acquire long real time measurements and/or use the storeinram option otherwise you risk to lose your data"<< std::endl; +// // os << std::endl; +// // os << "online \t gets the detector online (1) or offline (0) state " << std::endl; +// // os << std::endl; + + +// // } + + +// // return os.str(); +// // } + + diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.h b/slsDetectorSoftware/slsDetector/slsDetectorCommand.h new file mode 100644 index 000000000..e7cd54961 --- /dev/null +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.h @@ -0,0 +1,429 @@ + +#ifndef SLS_DETECTOR_COMMAND_H +#define SLS_DETECTOR_COMMAND_H + + +#include "sls_detector_defs.h" +#include +#include +#include +#include + +using namespace std; + +class slsDetectorCommand; + + + +/* /\** This class handles the command line I/Os, help etc. */ +/* It is inherited by both slsDetector and multiSlsDetector */ + +/* *\/ */ + class slsDetectorCommand { + + public: + + + slsDetectorCommand(); + + + /* /\** */ +/* 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=HELP_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 string helpLine(int narg, char *args[], int action=HELP_ACTION); + + string cmdUnderDevelopment(int narg, char *args[], int action); + + string cmdUnknown(int narg, char *args[], int action); + + string cmdAcquire(int narg, char *args[], int action); + static string helpAcquire(int narg, char *args[], int action); + + string cmdData(int narg, char *args[], int action); + static string helpData(int narg, char *args[], int action); + + string cmdFrame(int narg, char *args[], int action); + static string helpFrame(int narg, char *args[], int action); + + string cmdStatus(int narg, char *args[], int action); + static string helpStatus(int narg, char *args[], int action); + + string cmdFree(int narg, char *args[], int action); + static string helpFree(int narg, char *args[], int action); + + string cmdAdd(int narg, char *args[], int action); + static string helpAdd(int narg, char *args[], int action); + + string cmdRemove(int narg, char *args[], int action); + static string helpRemove(int narg, char *args[], int action); + + string cmdHostname(int narg, char *args[], int action); + static string helpHostname(int narg, char *args[], int action); + + string cmdId(int narg, char *args[], int action); + static string helpId(int narg, char *args[], int action); + + string cmdMaster(int narg, char *args[], int action); + static string helpMaster(int narg, char *args[], int action); + + string cmdSync(int narg, char *args[], int action); + static string helpSync(int narg, char *args[], int action); + + string cmdHelp(int narg, char *args[], int action); + + string cmdExitServer(int narg, char *args[], int action); + static string helpExitServer(int narg, char *args[], int action); + + + string cmdSettingsDir(int narg, char *args[], int action); + static string helpSettingsDir(int narg, char *args[], int action); + + string cmdCalDir(int narg, char *args[], int action); + static string helpCalDir(int narg, char *args[], int action); + + + string cmdTrimEn(int narg, char *args[], int action); + static string helpTrimEn(int narg, char *args[], int action); + + string cmdOutDir(int narg, char *args[], int action); + static string helpOutDir(int narg, char *args[], int action); + + string cmdFileName(int narg, char *args[], int action); + static string helpFileName(int narg, char *args[], int action); + + + string cmdFileIndex(int narg, char *args[], int action); + static string helpFileIndex(int narg, char *args[], int action); + + string cmdFlatField(int narg, char *args[], int action); + static string helpFlatField(int narg, char *args[], int action); + + + string cmdRateCorr(int narg, char *args[], int action); + static string helpRateCorr(int narg, char *args[], int action); + + + string cmdBadChannels(int narg, char *args[], int action); + static string helpBadChannels(int narg, char *args[], int action); + + + string cmdAngConv(int narg, char *args[], int action); + static string helpAngConv(int narg, char *args[], int action); + + string cmdThreaded(int narg, char *args[], int action); + static string helpThreaded(int narg, char *args[], int action); + + string cmdPositions(int narg, char *args[], int action); + static string helpPositions(int narg, char *args[], int action); + + string cmdScripts(int narg, char *args[], int action); + static string helpScripts(int narg, char *args[], int action); + + string cmdScans(int narg, char *args[], int action); + static string helpScans(int narg, char *args[], int action); + + + string cmdNetworkParameter(int narg, char *args[], int action); + static string helpNetworkParameter(int narg, char *args[], int action); + + string cmdPort(int narg, char *args[], int action); + static string helpPort(int narg, char *args[], int action); + + + string cmdLock(int narg, char *args[], int action); + static string helpLock(int narg, char *args[], int action); + + + string cmdLastClient(int narg, char *args[], int action); + static string helpLastClient(int narg, char *args[], int action); + + + string cmdOnline(int narg, char *args[], int action); + static string helpOnline(int narg, char *args[], int action); + + + string cmdConfigureMac(int narg, char *args[], int action); + static string helpConfigureMac(int narg, char *args[], int action); + + + string cmdDetectorSize(int narg, char *args[], int action); + static string helpDetectorSize(int narg, char *args[], int action); + + + string cmdSettings(int narg, char *args[], int action); + static string helpSettings(int narg, char *args[], int action); + + + string cmdSN(int narg, char *args[], int action); + static string helpSN(int narg, char *args[], int action); + + + string cmdDigiTest(int narg, char *args[], int action); + static string helpDigiTest(int narg, char *args[], int action); + + string cmdRegister(int narg, char *args[], int action); + static string helpRegister(int narg, char *args[], int action); + + + string cmdDAC(int narg, char *args[], int action); + static string helpDAC(int narg, char *args[], int action); + + + string cmdTimer(int narg, char *args[], int action); + static string helpTimer(int narg, char *args[], int action); + + + string cmdTimeLeft(int narg, char *args[], int action); + static string helpTimeLeft(int narg, char *args[], int action); + + string cmdSpeed(int narg, char *args[], int action); + static string helpSpeed(int narg, char *args[], int action); + + string cmdAdvanced(int narg, char *args[], int action); + static string helpAdvanced(int narg, char *args[], int action); + + + string cmdConfiguration(int narg, char *args[], int action); + static string helpConfiguration(int narg, char *args[], int action); + + + + + + + + + + + + + + + + + + + + + + + + virtual int setOnline(int const online=GET_ONLINE_FLAG)=0; + virtual void acquire(int delflag)=0; + virtual int* readAll()=0; + virtual int* readFrame()=0; + virtual void* processData(int delflag)=0; + virtual int startAcquisition()=0; + virtual int stopAcquisition()=0; + virtual runStatus getRunStatus()=0; + virtual int freeSharedMemory()=0; + virtual int addSlsDetector(int, int pos=-1){return -1;}; + virtual int addSlsDetector(char*, int pos=-1){return -1;}; + virtual int removeSlsDetector(int pos=-1){return -1;}; + virtual int removeSlsDetector(char*){return -1;}; + virtual string setHostname(char*, int pos=-1)=0; + virtual string getHostname(int pos=-1)=0; + virtual int getDetectorId(int i=-1) =0; + virtual int setDetectorId(int ival, int i=-1){return -1;}; + virtual synchronizationMode setSynchronization(synchronizationMode sync=GET_SYNCHRONIZATION_MODE){return GET_SYNCHRONIZATION_MODE;}; + virtual int exitServer()=0; + virtual int setMaster(int i=-1){return -1;}; + virtual char* getSettingsDir()=0; + virtual char* setSettingsDir(string s)=0; + virtual char* getCalDir()=0; + virtual char* setCalDir(string s)=0; + virtual char* getFilePath()=0; + virtual char* setFilePath(string s)=0; + virtual char* getFileName()=0; + virtual char* setFileName(string s)=0; + virtual int getFileIndex()=0; + virtual int setFileIndex(int i)=0; + virtual int setFlatFieldCorrection(string fname="")=0; + virtual int getFlatFieldCorrection(float *corr=NULL, float *ecorr=NULL)=0; + virtual int setFlatFieldCorrection(float *corr=NULL, float *ecorr=NULL)=0; + virtual char *getFlatFieldCorrectionDir()=0; + virtual void setFlatFieldCorrectionDir(string dir)=0; + virtual char *getFlatFieldCorrectionFile()=0; + virtual int setRateCorrection(float t=0)=0; + virtual int getRateCorrection(float &t)=0; + virtual float getRateCorrectionTau()=0; + virtual int getRateCorrection()=0; + virtual int setBadChannelCorrection(string fname="")=0; + virtual int setBadChannelCorrection(int nch, int *chs, int ff=0)=0; + virtual int getBadChannelCorrection(int *bad=NULL)=0; + virtual string getBadChannelCorrectionFile()=0; + virtual int setAngularConversion(string fname="")=0; + virtual int getAngularConversion(int &direction, angleConversionConstant *angconv=NULL)=0; + virtual string getAngularConversion()=0; + virtual float setGlobalOffset(float f)=0; + virtual float setFineOffset(float f)=0; + virtual float getFineOffset()=0; + virtual float getGlobalOffset()=0; + virtual float setBinSize(float f)=0; + virtual float getBinSize()=0; + virtual int writeDataFile(string fname, float *data, float *err=NULL, float *ang=NULL, char dataformat='f', int nch=-1)=0; + virtual int writeAngularConversion(string fname)=0; + virtual int setThreadedProcessing(int i=-1)=0;; + virtual int setPositions(int nPos, float *pos)=0; + virtual int getPositions(float *pos=NULL)=0; + virtual int setActionScript(int iaction, string fname="")=0; + virtual int setActionParameter(int iaction, string par="")=0; + virtual string getActionScript(int iaction)=0; + virtual string getActionParameter(int iaction)=0; + virtual int setScanScript(int index, string script="")=0; + virtual int setScanParameter(int index, string par="")=0; + virtual int setScanPrecision(int index, int precision=-1)=0; + virtual int setScanSteps(int index, int nvalues=-1, float *values=NULL)=0; + virtual string getScanScript(int index)=0; + virtual string getScanParameter(int index)=0; + virtual int getScanPrecision(int index)=0; + virtual int getScanSteps(int index, float *values=NULL)=0; + virtual char *getNetworkParameter(networkParameter i)=0; + virtual char *setNetworkParameter(networkParameter i, string s)=0; + virtual int setPort(portType t, int i=-1)=0; + virtual int lockServer(int i=-1)=0; + virtual string getLastClientIP()=0; + virtual int configureMAC(int)=0; + virtual int setNumberOfModules(int i=-1, dimension d=X)=0; + virtual int getMaxNumberOfModules(dimension d=X)=0; + virtual int setDynamicRange(int i=-1)=0; + virtual detectorSettings getSettings(int imod=-1)=0; + virtual detectorSettings setSettings(detectorSettings isettings, int imod=-1)=0; + virtual int getThresholdEnergy(int imod=-1)=0; + virtual int setThresholdEnergy(int e_eV, int imod=-1, detectorSettings isettings=GET_SETTINGS)=0; + virtual int64_t getId(idMode mode, int imod=0)=0; + virtual int digitalTest(digitalTestMode mode, int imod=0)=0; + virtual int executeTrimming(trimMode mode, int par1, int par2, int imod=-1)=0; + virtual const char *getSettingsFile()=0; + virtual int loadSettingsFile(string fname, int imod=-1)=0; + virtual int saveSettingsFile(string fname, int imod=-1)=0; + virtual int writeRegister(int addr, int val)=0; + virtual int readRegister(int addr)=0; + virtual float setDAC(float , dacIndex, int imod=-1)=0; + virtual float getADC(dacIndex, int imod=0)=0; + virtual int64_t setTimer(timerIndex index, int64_t t=-1)=0; + virtual int64_t getTimeLeft(timerIndex index)=0; + virtual int setSpeed(speedVariable sp, int value=-1)=0; + virtual int setTrimEn(int nen, int *en=NULL)=0; + virtual int getTrimEn(int *en=NULL)=0; + virtual externalSignalFlag setExternalSignalFlags(externalSignalFlag pol=GET_EXTERNAL_SIGNAL_FLAG , int signalindex=0)=0; + virtual int setReadOutFlags(readOutFlags flag=GET_READOUT_FLAGS)=0; + virtual externalCommunicationMode setExternalCommunicationMode(externalCommunicationMode pol=GET_EXTERNAL_COMMUNICATION_MODE)=0; + virtual int readConfigurationFile(string const fname)=0; + virtual int writeConfigurationFile(string const fname)=0; + virtual int dumpDetectorSetup(string const fname, int level=0)=0; + virtual int retrieveDetectorSetup(string const fname, int level=0)=0; + + + + + + + + /** returns string from run status index + \param s can be ERROR, WAITING, RUNNING, TRANSMITTING, RUN_FINISHED + \returns string error, waiting, running, data, finished + */ + static string runStatusType(runStatus); + + /** returns detector type string from detector type index + \param type string can be Mythen, Pilatus, Eiger, Gotthard, Agipd, Unknown + \returns MYTHEN, PILATUS, EIGER, GOTTHARD, AGIPD, GENERIC + */ + static string getDetectorType(detectorType t); + + /** returns detector type index from detector type string + \param t can be MYTHEN, PILATUS, EIGER, GOTTHARD, AGIPD, GENERIC + \returns Mythen, Pilatus, Eiger, Gotthard, Agipd, Unknown + */ + static detectorType getDetectorType(string const type); + + + /** returns synchronization type index from string + \param t can be none, gating, trigger, complementary + \returns ONE, MASTER_GATES, MASTER_TRIGGERS, SLAVE_STARTS_WHEN_MASTER_STOPS + */ + static synchronizationMode getSyncType(string const type); + + + + /** returns synchronization type string from index + \param t can be NONE, MASTER_GATES, MASTER_TRIGGERS, SLAVE_STARTS_WHEN_MASTER_STOPS + \returns none, gating, trigger, complementary + */ + static string getSyncType(synchronizationMode s ); + + + /** returns string from external signal type index + \param f can be SIGNAL_OFF, GATE_IN_ACTIVE_HIGH, GATE_IN_ACTIVE_LOW, TRIGGER_IN_RISING_EDGE, TRIGGER_IN_FALLING_EDGE, RO_TRIGGER_IN_RISING_EDGE, RO_TRIGGER_IN_FALLING_EDGE, GATE_OUT_ACTIVE_HIGH, GATE_OUT_ACTIVE_LOW, =TRIGGER_OUT_RISING_EDGE, TRIGGER_OUT_FALLING_EDGE, RO_TRIGGER_OUT_RISING_EDGE, RO_TRIGGER_OUT_FALLING_EDGE + \returns string off, gate_in_active_high, gate_in_active_low, trigger_in_rising_edge, trigger_in_falling_edge, ro_trigger_in_rising_edge, ro_trigger_in_falling_edge, gate_out_active_high, gate_out_active_low, trigger_out_rising_edge, trigger_out_falling_edge, ro_trigger_out_rising_edge, ro_trigger_out_falling_edge, unknown + */ + static string externalSignalType(externalSignalFlag f); + + + + /** returns external signal type index from string + \param string off, gate_in_active_high, gate_in_active_low, trigger_in_rising_edge, trigger_in_falling_edge, ro_trigger_in_rising_edge, ro_trigger_in_falling_edge, gate_out_active_high, gate_out_active_low, trigger_out_rising_edge, trigger_out_falling_edge, ro_trigger_out_rising_edge, ro_trigger_out_falling_edge, unknown + \returns f can be SIGNAL_OFF, GATE_IN_ACTIVE_HIGH, GATE_IN_ACTIVE_LOW, TRIGGER_IN_RISING_EDGE, TRIGGER_IN_FALLING_EDGE, RO_TRIGGER_IN_RISING_EDGE, RO_TRIGGER_IN_FALLING_EDGE, GATE_OUT_ACTIVE_HIGH, GATE_OUT_ACTIVE_LOW, =TRIGGER_OUT_RISING_EDGE, TRIGGER_OUT_FALLING_EDGE, RO_TRIGGER_OUT_RISING_EDGE, RO_TRIGGER_OUT_FALLING_EDGE,GET_EXTERNAL_SIGNAL_FLAG (if unknown) + */ + + static externalSignalFlag externalSignalType(string sval); + + + /** returns synchronization type string from index + \param t can be NONE, MASTER_GATES, MASTER_TRIGGERS, SLAVE_STARTS_WHEN_MASTER_STOPS + \returns none, gating, trigger, complementary + */ + static detectorSettings getDetectorSettings(string s); + + /** returns detector settings string from index + \param t can be STANDARD, FAST, HIGHGAIN, DYNAMICGAIN, LOWGAIN, MEDIUMGAIN, VERYHIGHGAIN, GET_SETTINGS + \returns standard, fast, highgain, dynamicgain, lowgain, mediumgain, veryhighgain, undefined + */ + static string getDetectorSettings(detectorSettings s); + + + + + + + private: + int numberOfCommands; + string cmd; + + typedef string (slsDetectorCommand::*MemFuncGetter)(int narg, char *args[], int action); + + + struct FuncTable + { + string m_pFuncName; + //const char* m_pFuncName; + MemFuncGetter m_pFuncPtr; + }; + + + + FuncTable descrToFuncMap[1000]; + + + + + + +}; + + + +#endif + diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp new file mode 100644 index 000000000..e419f6d92 --- /dev/null +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp @@ -0,0 +1,2220 @@ +#include "slsDetectorUtils.h" +#include "usersFunctions.h" + +#include +#include + + +slsDetectorUtils::slsDetectorUtils() : queuesize(0), + currentPosition(0), + currentPositionIndex(0), + currentI0(0), + mergingBins(NULL), + mergingCounts(NULL), + mergingErrors(NULL), + mergingMultiplicity(NULL), + badChannelMask(NULL) + +{ + pthread_mutex_t mp1 = PTHREAD_MUTEX_INITIALIZER; + mp=mp1; + pthread_mutex_init(&mp, NULL); +} + + +int slsDetectorUtils::getPointers(int * const l_stoppedFlag, \ + int * const l_threadedProcessing, \ + int * const l_actionMask, \ + mystring * const l_actionScript, \ + mystring * const l_actionParameter, \ + int * const l_nScanSteps, \ + int * const l_scanMode, \ + mystring * const l_scanScript, \ + mystring * const l_scanParameter, \ + mysteps * const l_scanSteps, \ + int * const l_scanPrecision, \ + int * const l_numberOfPositions, \ + float * const l_detPositions, \ + char * const l_angConvFile, \ + int * const l_correctionMask, \ + float * const l_binSize, \ + float * const l_fineOffset, \ + float * const l_globalOffset, \ + int * const l_angDirection, \ + char * const l_flatFieldDir, \ + char * const l_flatFieldFile, \ + char * const l_badChanFile, \ + int64_t * const l_timerValue, \ + detectorSettings * const l_currentSettings, \ + int * const l_currentThresholdEV, \ + char * const l_filePath, \ + char * const l_fileName, \ + int * const l_fileIndex) +{ + + stoppedFlag=l_stoppedFlag; + threadedProcessing=l_threadedProcessing; + actionMask=l_actionMask; + actionScript=l_actionScript; + actionParameter=l_actionParameter; + + nScanSteps=l_nScanSteps; + scanSteps=l_scanSteps; + scanScript=l_scanScript; + scanParameter=l_scanParameter; + scanMode=l_scanMode; + scanPrecision=l_scanPrecision; + + numberOfPositions=l_numberOfPositions; + detPositions=l_detPositions; + angConvFile=l_angConvFile; + correctionMask=l_correctionMask; + binSize=l_binSize; + fineOffset=l_fineOffset; + globalOffset=l_globalOffset; + angDirection=l_angDirection; + flatFieldDir=l_flatFieldDir; + flatFieldFile=l_flatFieldFile; + badChanFile=l_badChanFile; + // nBadChans=l_nBadChans; + // badChansList=l_badChansList; + // nBadFF=l_nBadFF; + // badFFList=l_badFFList; + timerValue=l_timerValue; + currentSettings=l_currentSettings; + currentThresholdEV=l_currentThresholdEV; + filePath=l_filePath; + fileName=l_fileName; + fileIndex=l_fileIndex; + + return OK; + + +} + + + +string slsDetectorUtils::createFileName(char *filepath, char *filename, int aMask, float sv0, int prec0, float sv1, int prec1, int pindex, int npos, int findex) { + ostringstream osfn; + // string fn; + /*directory name +root file name */ + osfn << filepath << "/" << filename; + + // cout << osfn.str() << endl; + + // scan level 0 + if ( aMask& (1 << (MAX_ACTIONS))) + osfn << "_S" << fixed << setprecision(prec0) << sv0; + + //cout << osfn.str() << endl; + + //scan level 1 + if (aMask & (1 << (MAX_ACTIONS+1))) + osfn << "_s" << fixed << setprecision(prec1) << sv1; + + //cout << osfn.str() << endl; + + + //position + if (pindex>0 && pindex<=npos) + osfn << "_p" << pindex; + + //cout << osfn.str() << endl; + + // file index + osfn << "_" << findex; + + //cout << osfn.str() << endl; + + +#ifdef VERBOSE + cout << "created file name " << osfn.str() << endl; +#endif + + //cout << osfn.str() << endl; + //fn=oosfn.str()sfn.str(); + return osfn.str(); + +} + + + /* I/O */ + +/* generates file name without extension*/ + +string slsDetectorUtils::createFileName() { + return createFileName(filePath, \ + fileName, \ + *actionMask, \ + currentScanVariable[0], \ + scanPrecision[0], \ + currentScanVariable[1], \ + scanPrecision[1], \ + currentPositionIndex, \ + *numberOfPositions, \ + *fileIndex\ + ); + +} + + + +int slsDetectorUtils::getFileIndexFromFileName(string fname) { + int i; + size_t dot=fname.rfind("."); + if (dot==string::npos) + return -1; + size_t uscore=fname.rfind("_"); + if (uscore==string::npos) + return -1; + + if (sscanf( fname.substr(uscore+1,dot-uscore-1).c_str(),"%d",&i)) { + + return i; + } + //#ifdef VERBOSE + cout << "******************************** cannot parse file index" << endl; + //#endif + return 0; +} + +int slsDetectorUtils::getVariablesFromFileName(string fname, int &index, int &p_index, float &sv0, float &sv1) { + + int i; + float f; + string s; + + + index=-1; + p_index=-1; + sv0=-1; + sv1=-1; + + + // size_t dot=fname.rfind("."); + //if (dot==string::npos) + // return -1; + size_t uscore=fname.rfind("_"); + if (uscore==string::npos) + return -1; + s=fname; + + //if (sscanf(s.substr(uscore+1,dot-uscore-1).c_str(),"%d",&i)) { + if (sscanf(s.substr(uscore+1,s.size()-uscore-1).c_str(),"%d",&i)) { + index=i; +#ifdef VERBOSE + cout << "******************************** file index is " << index << endl; +#endif + //return i; + s=fname.substr(0,uscore); + } +#ifdef VERBOSE + else + cout << "******************************** cannot parse file index" << endl; + + cout << s << endl; +#endif + + + uscore=s.rfind("_"); + + + + + if (sscanf( s.substr(uscore+1,s.size()-uscore-1).c_str(),"p%d",&i)) { + p_index=i; +#ifdef VERBOSE + cout << "******************************** position index is " << p_index << endl; +#endif + s=fname.substr(0,uscore); + } +#ifdef VERBOSE + else + cout << "******************************** cannot parse position index" << endl; + + cout << s << endl; + + +#endif + + + + + uscore=s.rfind("_"); + + + + + if (sscanf( s.substr(uscore+1,s.size()-uscore-1).c_str(),"s%f",&f)) { + sv1=f; +#ifdef VERBOSE + cout << "******************************** scan variable 1 is " << sv1 << endl; +#endif + s=fname.substr(0,uscore); + } +#ifdef VERBOSE + else + cout << "******************************** cannot parse scan varable 1" << endl; + + cout << s << endl; + + +#endif + + uscore=s.rfind("_"); + + + + + if (sscanf( s.substr(uscore+1,s.size()-uscore-1).c_str(),"S%f",&f)) { + sv0=f; +#ifdef VERBOSE + cout << "******************************** scan variable 0 is " << sv0 << endl; +#endif + } +#ifdef VERBOSE + else + cout << "******************************** cannot parse scan varable 0" << endl; + +#endif + + + + return index; +} + + + + + +int slsDetectorUtils::flatFieldCorrect(float datain, float errin, float &dataout, float &errout, float ffcoefficient, float fferr){ + float e; + + dataout=datain*ffcoefficient; + + if (errin==0 && datain>=0) + e=sqrt(datain); + else + e=errin; + + if (dataout>0) + errout=sqrt(e*ffcoefficient*e*ffcoefficient+datain*fferr*datain*fferr); + else + errout=1.; + + return 0; +}; + + + int slsDetectorUtils::rateCorrect(float datain, float errin, float &dataout, float &errout, float tau, float t){ + + // float data; + float e; + + dataout=(datain*exp(tau*datain/t)); + + if (errin==0 && datain>=0) + e=sqrt(datain); + else + e=errin; + + if (dataout>0) + errout=e*dataout*sqrt((1/(datain*datain)+tau*tau/(t*t))); + else + errout=1.; + return 0; + +}; + + +int slsDetectorUtils::setBadChannelCorrection(string fname, int &nbad, int *badlist){ + ifstream infile; + string str; + int interrupt=0; + int ich; + int chmin,chmax; +#ifdef VERBOSE + std::cout << "Setting bad channel correction to " << fname << std::endl; +#endif + + if (fname=="") { + nbad=0; + return 0; + } else { + infile.open(fname.c_str(), ios_base::in); + if (infile.is_open()==0) { + std::cout << "could not open file " << fname <> chmin ; + ssstr.str(str.substr(str.find('-')+1,str.size())); + ssstr >> chmax; +#ifdef VERBOSE + std::cout << "channels between"<< chmin << " and " << chmax << std::endl; +#endif + for (ich=chmin; ich<=chmax; ich++) { + if (nbad> ich; +#ifdef VERBOSE + std::cout << "channel "<< ich << std::endl; +#endif + if (nbad0 && nbad> ss >> mod; + ssstr >> ss >> center; + ssstr >> ss >> ecenter; + ssstr >> ss >> r_conv; + ssstr >> ss >> er_conv; + ssstr >> ss >> off; + ssstr >> ss >> eoff; + if (mod=0) { + angOff[mod].center=center; + angOff[mod].r_conversion=r_conv; + angOff[mod].offset=off; + angOff[mod].ecenter=ecenter; + angOff[mod].er_conversion=er_conv; + angOff[mod].eoffset=eoff; + nm++; + } + } + return nm; + } + + + + + +int slsDetectorUtils:: writeAngularConversion(string fname, int nmod, angleConversionConstant *angOff) { + + ofstream outfile; + outfile.open (fname.c_str(),ios_base::out); + if (outfile.is_open()) + { + writeAngularConversion(outfile, nmod, angOff); + outfile.close(); + } else { + std::cout<< "Could not open file " << fname << "for writing"<< std::endl; + return -1; + } + //" module %i center %E +- %E conversion %E +- %E offset %f +- %f \n" + return 0; +} + + + + +int slsDetectorUtils:: writeAngularConversion(ofstream& outfile, int nmod, angleConversionConstant *angOff) { + + for (int imod=0; imod0) { + mp[np]=mp[ibin]/mm[ibin]; + mv[np]=mv[ibin]/mm[ibin]; + me[np]=me[ibin]/mm[ibin]; + me[np]=sqrt(me[ibin]); + mm[np]=mm[ibin]; + np++; + } + } + return np; +} + + + + + +int slsDetectorUtils::addToMerging(float *p1, float *v1, float *e1, float *mp, float *mv,float *me, int *mm, int nchans, float binsize,int angDir, int cm, int *badChanMask ) { + + float binmi=-180., binma; + int ibin=0; + int imod; + float ang=0; + + + binmi=-180.; + binma=binmi+binsize; + + + if (angDir>0) { + for (int ip=0; ip=0; ip--) { + if ((cm)&(1<< DISCARD_BAD_CHANNELS)) { + if (badChanMask[ip]) + continue; + + } + + while (binma0) + binsize=*binSize; + else + return FAIL; + + return resetMerging(mp, mv, me, mm, binsize); +} + + +int slsDetectorUtils::finalizeMerging(float *mp, float *mv, float *me, int *mm) { + float binsize; + + if (*binSize>0) + binsize=*binSize; + else + return FAIL; + + return finalizeMerging(mp, mv, me, mm, binsize); +} + + + + + + +int slsDetectorUtils::addToMerging(float *p1, float *v1, float *e1, float *mp, float *mv,float *me, int *mm) { + + float binsize; + + + + int ibin=0; + int imod; + + int del=0; + + if (*binSize>0) + binsize=*binSize; + else + return FAIL; + + if (p1==NULL) { + + del=1; + p1=convertAngles(currentPosition); + + } + + int ret=addToMerging(p1, v1, e1, mp, mv,me, mm,getTotalNumberOfChannels(), binsize,*angDirection, *correctionMask, badChannelMask ); + + + if (del) { + delete [] p1; + p1=NULL; + } + return ret; +} + + + + +int slsDetectorUtils::writeDataFile(string fname, int nch, float *data, float *err, float *ang, char dataformat){ + + + ofstream outfile; + int idata; + if (data==NULL) + return FAIL; + + // args|=0x10; // one line per channel! + + outfile.open (fname.c_str(),ios_base::out); + if (outfile.is_open()) + { + writeDataFile(outfile, nch, data, err, ang, dataformat); + return OK; + } else { + std::cout<< "Could not open file " << fname << "for writing"<< std::endl; + return FAIL; + } +}; + + +int slsDetectorUtils::writeDataFile(ofstream &outfile, int nch, float *data, float *err, float *ang, char dataformat){ + + + int idata; + if (data==NULL) + return FAIL; + + // args|=0x10; // one line per channel! + + + for (int ichan=0; ichan> ichan >> fdata; + ich=ichan; + if (ssstr.fail() || ssstr.bad()) { + interrupt=1; + break; + } + if (ich!=iline) + std::cout<< "Channel number " << ichan << " does not match with line number " << iline << " " << dataformat << std::endl; + } else { + ssstr >> fang >> fdata; + ich=iline; + } + if (ssstr.fail() || ssstr.bad()) { + interrupt=1; + break; + } + if (err) + ssstr >> ferr; + if (ssstr.fail() || ssstr.bad()) { + interrupt=1; + break; + } + if (ich> ichan >> idata; + if (ssstr.fail() || ssstr.bad()) { + interrupt=1; + break; + } + if (ichan!=iline) { + std::cout<< " Expected channel "<< iline <<" but read channel "<< ichan << std::endl; + interrupt=1; + break; + } else { + if (iline> offset >> gain; + infile.close(); + } else { + std::cout<< "Could not open calibration file "<< fname << std::endl; + gain=0.; + offset=0.; + return -1; + } + return 0; +}; + +int slsDetectorUtils::writeCalibrationFile(string fname, float gain, float offset){ + //std::cout<< "Function not yet implemented " << std::endl; + ofstream outfile; + + outfile.open (fname.c_str()); + + // >> i/o operations here << + if (outfile.is_open()) { + outfile << offset << " " << gain << std::endl; + } else { + std::cout<< "Could not open calibration file "<< fname << " for writing" << std::endl; + return -1; + } + + outfile.close(); + + return 0; +}; + + + + + + + +void slsDetectorUtils::acquire(int delflag){ + + + + void *status; + int trimbit; + + + + + char cmd[MAX_STR_LENGTH]; + int startindex=*fileIndex; + int nowindex=startindex, lastindex=startindex; + string fn; + + + + + //string sett; + if ((*correctionMask&(1<< ANGULAR_CONVERSION)) || (*correctionMask&(1<< I0_NORMALIZATION))) + connect_channels(); + + + + + progressIndex=0; + *stoppedFlag=0; + + + + resetFinalDataQueue(); + resetDataQueue(); + + + //cout << "main mutex lock line 6188" << endl; + pthread_mutex_lock(&mp); + jointhread=0; + queuesize=0; + pthread_mutex_unlock(&mp); + //cout << "main mutex unlock line 6188" << endl; + + + + + + if (*threadedProcessing) { + startThread(delflag); + } + + + + + //cout << "data thread started " << endl; + int np=1; + if (*numberOfPositions>0) + np=*numberOfPositions; + + int ns0=1; + if (*actionMask & (1 << MAX_ACTIONS)) { + ns0=nScanSteps[0]; + } + if (ns0<1) + ns0=1; + + + int ns1=1; + if (*actionMask & (1 << (MAX_ACTIONS+1))) { + ns1=nScanSteps[1]; + } + if (ns1<1) + ns1=1; + + + + + //cout << "action at start" << endl; + if (stoppedFlag==0) { + if (*actionMask & (1 << startScript)) { + //"Custom start script. The arguments are passed as nrun=n par=p."); + sprintf(cmd,"%s nrun=%d par=%s",getActionScript(startScript).c_str(),*fileIndex,getActionParameter(startScript).c_str()); +#ifdef VERBOSE + cout << "Executing start script " << cmd << endl; +#endif + system(cmd); + } + } + + for (int is0=0; is00) { + go_to_position (detPositions[ip]); + currentPositionIndex=ip+1; +#ifdef VERBOSE + std::cout<< "moving to position" << std::endl; +#endif + } + } else + break; + + //write header before? + //cmd=headerBeforeScript; + //Custom script to write the header. \n The arguments will be passed as nrun=n fn=filenam acqtime=t gainmode=g threshold=thr badfile=badf angfile=angf bloffset=blo fineoffset=fo fffile=fffn tau=deadtau par=p") + + // cout << "aaaaa" << endl; + //cout << createFileName() << endl; + //cout << "bbbbb" << endl; + fn=createFileName(); + //cout << fn << endl; + nowindex=*fileIndex; + + if (*stoppedFlag==0) { + + + if (*correctionMask&(1<< I0_NORMALIZATION)) + currentI0=get_i0(); + + // cout << "header " << endl; + if (*actionMask & (1 << headerBefore)) { + //Custom script after each frame. The arguments are passed as nrun=n fn=filename par=p sv0=scanvar0 sv1=scanvar1 p0=par0 p1=par1" + sprintf(cmd,"%s nrun=%d fn=%s acqtime=%f gainmode=%d threshold=%d badfile=%s angfile=%s bloffset=%f fineoffset=%f fffile=%s/%s tau=%f par=%s",\ + getActionScript(headerBefore).c_str(),\ + nowindex,\ + fn.c_str(), \ + ((float)timerValue[ACQUISITION_TIME])*1E-9, \ + *currentSettings, \ + *currentThresholdEV, \ + getBadChannelCorrectionFile().c_str(), \ + getAngularConversion().c_str(), \ + *globalOffset, \ + *fineOffset,\ + getFlatFieldCorrectionDir(),\ + getFlatFieldCorrectionFile(), \ + getRateCorrectionTau(),\ + getActionParameter(headerBefore).c_str()\ + ); +#ifdef VERBOSE + cout << "Executing header before " << cmd << endl; +#endif + system(cmd); + } + } else + break; + + + + if (*stoppedFlag==0) { + + // cout << "starting???? " << endl; + startAndReadAll(); + + if (*correctionMask&(1<< ANGULAR_CONVERSION)) + currentPosition=get_position(); + + if (*correctionMask&(1<< I0_NORMALIZATION)) + currentI0=get_i0()-currentI0; + + ////////////////// Reput in in case of unthreaded processing +// if (*threadedProcessing==0) +// processData(delflag); + + + } else + break; + + pthread_mutex_lock(&mp); + while (queuesize){ + pthread_mutex_unlock(&mp); + usleep(10000); + pthread_mutex_lock(&mp); + } + pthread_mutex_unlock(&mp); + + if (stoppedFlag==0) { + if (*actionMask & (1 << headerAfter)) { + //Custom script after each frame. The arguments are passed as nrun=n fn=filename par=p sv0=scanvar0 sv1=scanvar1 p0=par0 p1=par1" + sprintf(cmd,"%s nrun=%d fn=%s acqtime=%f gainmode=%d threshold=%d badfile=%s angfile=%s bloffset=%f fineoffset=%f fffile=%s/%s tau=%f par=%s", \ + getActionScript(headerAfter).c_str(), \ + nowindex, \ + fn.c_str(), \ + ((float)timerValue[ACQUISITION_TIME])*1E-9, \ + *currentSettings, \ + *currentThresholdEV, \ + getBadChannelCorrectionFile().c_str(), \ + getAngularConversion().c_str(), \ + *globalOffset, \ + *fineOffset, \ + getFlatFieldCorrectionDir(), \ + getFlatFieldCorrectionFile(), \ + getRateCorrectionTau(), \ + getActionParameter(headerAfter).c_str()); +#ifdef VERBOSE + cout << "Executing header after " << cmd << endl; +#endif + system(cmd); + + } + if (*fileIndex>lastindex) + lastindex=*fileIndex; + } else { + + + if (*fileIndex>lastindex) + lastindex=*fileIndex; + + break; + } + + + + if (*stoppedFlag) { +#ifdef VERBOSE + std::cout<< "exiting since the detector has been stopped" << std::endl; +#endif + break; + } else if (ip<(np-1)) { + *fileIndex=startindex; + } + } // loop on position finished + + //script after + if (*stoppedFlag==0) { + if (*actionMask & (1 << scriptAfter)) { + //Custom script after each frame. The arguments are passed as nrun=n fn=filename par=p sv0=scanvar0 sv1=scanvar1 p0=par0 p1=par1" + sprintf(cmd,"%s nrun=%d fn=%s par=%s sv0=%f sv1=%f p0=%s p1=%s",getActionScript(scriptAfter).c_str(),*fileIndex,createFileName().c_str(),getActionParameter(scriptAfter).c_str(),currentScanVariable[0],currentScanVariable[1],getScanParameter(0).c_str(),getScanParameter(1).c_str()); +#ifdef VERBOSE + cout << "Executing script after " << cmd << endl; +#endif + system(cmd); + } + } else + break; + + + if (*stoppedFlag) { +#ifdef VERBOSE + std::cout<< "exiting since the detector has been stopped" << std::endl; +#endif + break; + } else if (is1<(ns1-1)) { + *fileIndex=startindex; + } + + + } + + //end scan1 loop is1 + //currentScanVariable[MAX_SCAN_LEVELS]; + + + if (*stoppedFlag) { +#ifdef VERBOSE + std::cout<< "exiting since the detector has been stopped" << std::endl; +#endif + break; + } else if (is0<(ns0-1)) { + *fileIndex=startindex; + } + } //end scan0 loop is0 + + *fileIndex=lastindex; + if (*stoppedFlag==0) { + if (*actionMask & (1 << stopScript)) { + //Custom stop script. The arguments are passed as nrun=n par=p. + sprintf(cmd,"%s nrun=%d par=%s",getActionScript(stopScript).c_str(),*fileIndex,getActionParameter(stopScript).c_str()); +#ifdef VERBOSE + cout << "Executing stop script " << cmd << endl; +#endif + system(cmd); + } + } + + + if (*threadedProcessing) { + //#ifdef VERBOSE + // std::cout<< " ***********************waiting for data processing thread to finish " << queuesize <<" " << thisDetector->fileIndex << std::endl ; + //#endif + //cout << "main mutex lock line 6488" << endl; + pthread_mutex_lock(&mp); + jointhread=1; + pthread_mutex_unlock(&mp); + //cout << "main mutex unlock line 6488" << endl; + pthread_join(dataProcessingThread, &status); + // std::cout<< " ***********************data processing finished " << queuesize <<" " << thisDetector->fileIndex << std::endl ; + } + + if ((*correctionMask&(1<< ANGULAR_CONVERSION)) || (*correctionMask&(1<< I0_NORMALIZATION))) + disconnect_channels(); +} + + +void* slsDetectorUtils::processData(int delflag) { + + + //cout << "thread mutex lock line 6505" << endl; + pthread_mutex_lock(&mp); + queuesize=dataQueue.size(); + pthread_mutex_unlock(&mp); + //cout << "thread mutex unlock line 6505" << endl; + + int *myData; + float *fdata; + float *rcdata=NULL, *rcerr=NULL; + float *ffcdata=NULL, *ffcerr=NULL; + float *ang=NULL; + float bs=0.004; + int imod; + int nb; + int np; + detectorData *thisData; + int dum=1; + string ext; + string fname; + + +#ifdef ACQVERBOSE + std::cout<< " processing data - threaded mode " << *threadedProcessing; +#endif + + if (*correctionMask!=0) { + ext=".dat"; + } else { + ext=".raw"; + } + while(dum | *threadedProcessing) { // ???????????????????????? + + + // while( !dataQueue.empty() ) { + //cout << "thread mutex lock line 6539" << endl; + pthread_mutex_lock(&mp); + while((queuesize=dataQueue.size())>0) { + pthread_mutex_unlock(&mp); + //cout << "thread mutex unlock line 6543" << endl; + //queuesize=dataQueue.size(); + + /** Pop data queue */ + myData=dataQueue.front(); // get the data from the queue + if (myData) { + + + + progressIndex++; +#ifdef VERBOSE + cout << "Progress is " << getCurrentProgress() << " \%" << endl; +#endif + + //process data + /** decode data */ + fdata=decodeData(myData); + + fname=createFileName(); + + /** write raw data file */ + if (*correctionMask==0 && delflag==1) { + //cout << "line 6570----" << endl; + writeDataFile (fname+string(".raw"), getTotalNumberOfChannels(),fdata, NULL, NULL, 'i'); + delete [] fdata; + } else { + //cout << "line 6574----" << endl; + writeDataFile (fname+string(".raw"), getTotalNumberOfChannels(),fdata, NULL, NULL, 'i'); + + /** rate correction */ + if (*correctionMask&(1<0) + bs=*binSize; + //else // if (angOff[0].r_conversion>0) { +// bs=180./PI*atan(angOff[0].r_conversion); +// *binSize=bs; + // } + else + *binSize=bs; + + + nb=(int)(360./bs); + + mergingBins=new float[nb]; + mergingCounts=new float[nb]; + mergingErrors=new float[nb]; + mergingMultiplicity=new int[nb]; + + resetMerging(mergingBins, mergingCounts,mergingErrors, mergingMultiplicity, bs); + } + /* it would be better to create an ang0 with 0 encoder position and add to merging/write to file simply specifying that offset so that when it cycles writing the data or adding to merging it also calculates the angular position */ + + ang=convertAngles(currentPosition); + + if (*correctionMask!=0) { + //cout << "line 6633----" << endl; + if (*numberOfPositions>1) + writeDataFile (fname+string(".dat"), getTotalNumberOfChannels(), ffcdata, ffcerr,ang); + } + addToMerging(ang, ffcdata, ffcerr, mergingBins, mergingCounts,mergingErrors, mergingMultiplicity, getTotalNumberOfChannels(), bs, *angDirection, *correctionMask, badChannelMask ); + + if ((currentPositionIndex==*numberOfPositions) || (currentPositionIndex==0)) { + np=finalizeMerging(mergingBins, mergingCounts,mergingErrors, mergingMultiplicity, bs); + /** file writing */ + currentPositionIndex++; + fname=createFileName(); + if (*correctionMask!=0) { + // cout << "line 6643----" << endl; + writeDataFile (fname+string(".dat"),np,mergingCounts, mergingErrors, mergingBins,'f'); + } + if (delflag) { + delete [] mergingBins; + delete [] mergingCounts; + delete [] mergingErrors; + delete [] mergingMultiplicity; + } else { + thisData=new detectorData(mergingCounts,mergingErrors,mergingBins,getCurrentProgress(),(fname+string(ext)).c_str(),np);/* + if (thisDetector->*correctionMask!=0) { + //thisData=new detectorData(mergingCounts,mergingErrors,mergingBins,thisDetector->progressIndex+1,(fname().append(".dat")).c_str(),np); + thisData=new detectorData(mergingCounts,mergingErrors,mergingBins,getCurrentProgress(),(fname().append(".dat")).c_str(),np); + } else { + thisData=new detectorData(mergingCounts,mergingErrors,mergingBins,getCurrentProgress(),(fname().append(".raw")).c_str(),np); + //thisData=new detectorData(mergingCounts,mergingErrors,mergingBins,thisDetector->progressIndex+1,(fname().append(".raw")).c_str(),np); + }*/ + finalDataQueue.push(thisData); + } + } + + if (ffcdata) + delete [] ffcdata; + if (ffcerr) + delete [] ffcerr; + if (ang) + delete [] ang; + } else { + if (*correctionMask!=0) { + // cout << "line 6672----" << endl; + writeDataFile (fname+string(".dat"), getTotalNumberOfChannels(), ffcdata, ffcerr); + } + if (delflag) { + if (ffcdata) + delete [] ffcdata; + if (ffcerr) + delete [] ffcerr; + if (ang) + delete [] ang; + } else { + thisData=new detectorData(ffcdata,ffcerr,NULL,getCurrentProgress(),(fname+string(ext)).c_str(),getTotalNumberOfChannels()); + + /* + + if (thisDetector->*correctionMask!=0) { + thisData=new detectorData(ffcdata,ffcerr,NULL,getCurrentProgress(),(fname().append(".dat")).c_str(),thisDetector->nChans*thisDetector->nChips*thisDetector->nMods); + //thisData=new detectorData(ffcdata,ffcerr,NULL,thisDetector->progressIndex+1,(fname().append(".dat")).c_str(),thisDetector->nChans*thisDetector->nChips*thisDetector->nMods); + } else { + thisData=new detectorData(ffcdata,ffcerr,NULL,getCurrentProgress(),(fname().append(".raw")).c_str(),thisDetector->nChans*thisDetector->nChips*thisDetector->nMods); + //thisData=new detectorData(ffcdata,ffcerr,NULL,thisDetector->progressIndex+1,(fname().append(".raw")).c_str(),thisDetector->nChans*thisDetector->nChips*thisDetector->nMods); + } + + */ + + finalDataQueue.push(thisData); + } + } + } + *fileIndex++; + + /* + thisDetector->progressIndex++; +#ifdef VERBOSE + cout << "Progress is " << getCurrentProgress() << " \%" << endl; +#endif + */ + + delete [] myData; + myData=NULL; + dataQueue.pop(); //remove the data from the queue + //cout << "thread mutex lock line 6697" << endl; + pthread_mutex_lock(&mp); + queuesize=dataQueue.size(); + pthread_mutex_unlock(&mp); + //cout << "thread mutex unlock line 6697" << endl; + usleep(1000); + //pthread_mutex_unlock(&mp); + } + pthread_mutex_unlock(&mp); + //cout << "thread mutex unlock line 6706" << endl; + usleep(1000); + // cout << "PPPPPPPPPPPPPPPPPPPP " << queuesize << " " << thisDetector->fileIndex << endl; + } + pthread_mutex_unlock(&mp); + //cout << "thread mutex unlock line 6711" << endl; + //cout << "thread mutex lock line 6711" << endl; + pthread_mutex_lock(&mp); + if (jointhread) { + pthread_mutex_unlock(&mp); + //cout << "thread mutex unlock line 6715" << endl; + if (dataQueue.size()==0) + break; + } else + pthread_mutex_unlock(&mp); + //cout << "thread mutex unlock line 6720" << endl; + + dum=0; + } // ???????????????????????? + return 0; +} + + +int* slsDetectorUtils::popDataQueue() { + int *retval=NULL; + if( !dataQueue.empty() ) { + retval=dataQueue.front(); + dataQueue.pop(); + } + return retval; +} + +detectorData* slsDetectorUtils::popFinalDataQueue() { + detectorData *retval=NULL; + if( !finalDataQueue.empty() ) { + retval=finalDataQueue.front(); + finalDataQueue.pop(); + } + return retval; +} + +void slsDetectorUtils::resetDataQueue() { + int *retval=NULL; + while( !dataQueue.empty() ) { + retval=dataQueue.front(); + dataQueue.pop(); + delete [] retval; + } + +} + +void slsDetectorUtils::resetFinalDataQueue() { + detectorData *retval=NULL; + while( !finalDataQueue.empty() ) { + retval=finalDataQueue.front(); + finalDataQueue.pop(); + delete retval; + } + +} + + +void slsDetectorUtils::startThread(int delflag) { + pthread_attr_t tattr; + int ret; + sched_param param, mparam; + int policy= SCHED_OTHER; + + + // set the priority; others are unchanged + //newprio = 30; + mparam.sched_priority =1; + param.sched_priority =1; + + + /* Initialize and set thread detached attribute */ + pthread_attr_init(&tattr); + pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_JOINABLE); + + + + // param.sched_priority = 5; + // scheduling parameters of main thread + ret = pthread_setschedparam(pthread_self(), policy, &mparam); + //#ifdef VERBOSE + // printf("current priority is %d\n",param.sched_priority); + //#endif + if (delflag) + ret = pthread_create(&dataProcessingThread, &tattr,startProcessData, (void*)this); + else + ret = pthread_create(&dataProcessingThread, &tattr,startProcessDataNoDelete, (void*)this); + + pthread_attr_destroy(&tattr); + // scheduling parameters of target thread + ret = pthread_setschedparam(dataProcessingThread, policy, ¶m); + +} + + +int slsDetectorUtils::fillBadChannelMask() { + + int nbad=0; + + if (*correctionMask&(1<< DISCARD_BAD_CHANNELS)) { + nbad=getBadChannelCorrection(); + + if (nbad>0) { + + int *badChansList=new int[nbad]; + getBadChannelCorrection(badChansList); + + if (badChannelMask) + delete [] badChannelMask; + badChannelMask=new int[getTotalNumberOfChannels()]; + for (int ichan=0; ichan=0 ) { + if (badChannelMask[badChansList[ichan]]==0) + nbad++; + badChannelMask[badChansList[ichan]]=1; + + } + } + delete [] badChansList; + + } else { + if (badChannelMask) { + delete [] badChannelMask; + badChannelMask=NULL; + } + } + + } else { + if (badChannelMask) { + delete [] badChannelMask; + badChannelMask=NULL; + } + } + + return nbad; +} + + + + + + + /* + set positions for the acquisition + \param nPos number of positions + \param pos array with the encoder positions + \returns number of positions + */ +int slsDetectorUtils::setPositions(int nPos, float *pos){ + if (nPos>=0) + *numberOfPositions=nPos; + for (int ip=0; ip0 otherwise + */ +int slsDetectorUtils::setAction(int iaction, string fname, string par) { + + int am; + + + if (iaction>=0 && iaction=0 && iaction=0 && iaction=0 && iaction=0 && iaction0 otherwise + */ +int slsDetectorUtils::setScan(int iscan, string script, int nvalues, float *values, string par, int precision) { + if (iscan>=0 && iscan=0) { + if (nvalues==0) + scanMode[iscan]=0; + else { + nScanSteps[iscan]=nvalues; + if (nvalues>MAX_SCAN_STEPS) + nScanSteps[iscan]=MAX_SCAN_STEPS; + } + } + + if (values && scanMode[iscan]>0 ) { + for (int iv=0; iv=0) + scanPrecision[iscan]=precision; + + if (scanMode[iscan]>0){ + *actionMask |= 1<< (iscan+MAX_ACTIONS); + } else { + *actionMask &= ~(1 << (iscan+MAX_ACTIONS)); + } + + + + setTotalProgress(); + + + + + + + + + + + return scanMode[iscan]; + } else + return -1; + +} + +int slsDetectorUtils::setScanScript(int iscan, string script) { + if (iscan>=0 && iscan0){ + *actionMask |= (1 << (iscan+MAX_ACTIONS)); + } else { + *actionMask &= ~(1 << (iscan+MAX_ACTIONS)); + } + + setTotalProgress(); + +#ifdef VERBOSE + cout << "Action mask is " << hex << actionMask << dec << endl; +#endif + return scanMode[iscan]; + } else + return -1; +} + + + +int slsDetectorUtils::setScanParameter(int iscan, string par) { + + + if (iscan>=0 && iscan=0 && iscan=0) + scanPrecision[iscan]=precision; + return scanMode[iscan]; + } else + return -1; + +} + +int slsDetectorUtils::setScanSteps(int iscan, int nvalues, float *values) { + + if (iscan>=0 && iscan=0) { + if (nvalues==0) + scanMode[iscan]=0; + else { + nScanSteps[iscan]=nvalues; + if (nvalues>MAX_SCAN_STEPS) + nScanSteps[iscan]=MAX_SCAN_STEPS; + } + } + + if (values) { + for (int iv=0; iv0){ + *actionMask |= (1 << (iscan+MAX_ACTIONS)); + } else { + *actionMask &= ~(1 << (iscan+MAX_ACTIONS)); + } + +#ifdef VERBOSE + cout << "Action mask is " << hex << actionMask << dec << endl; +#endif + setTotalProgress(); + + + + + return scanMode[iscan]; + + + } else + return -1; + + + + +} + + + + /** + returns scan script + \param iscan can be (0,1) + \returns scan script + */ +string slsDetectorUtils::getScanScript(int iscan){ + if (iscan>=0 && iscan=0 && iscan=0 && iscan=0 && iscan=0 && iscan0) + nc=timerValue[CYCLES_NUMBER]; + + if (*numberOfPositions>0) + npos=*numberOfPositions; + + if ((nScanSteps[0]>0) && (*actionMask & (1 << MAX_ACTIONS))) + nscan[0]=nScanSteps[0]; + + if ((nScanSteps[1]>0) && (*actionMask & (1 << (MAX_ACTIONS+1)))) + nscan[1]=nScanSteps[1]; + + totalProgress=nf*nc*npos*nscan[0]*nscan[1]; + +#ifdef VERBOSE + cout << "nc " << nc << endl; + cout << "nf " << nf << endl; + cout << "npos " << npos << endl; + cout << "nscan[0] " << nscan[0] << endl; + cout << "nscan[1] " << nscan[1] << endl; + + cout << "Set total progress " << totalProgress << endl; +#endif + return totalProgress; +} + + + + + + + + + + + +float slsDetectorUtils::getCurrentProgress() { + + return 100.*((float)progressIndex)/((float)totalProgress); +} + + diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.h b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h new file mode 100644 index 000000000..267872a62 --- /dev/null +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h @@ -0,0 +1,912 @@ + + +#ifndef SLS_DETECTOR_UTILS_H +#define SLS_DETECTOR_UTILS_H + +//#include "MySocketTCP.h" +#include +#include +#include +#include +#include +#include + #include +extern "C" { + #include +} + #include + #include + #include + #include + #include +#include +using namespace std; + + +#include "sls_detector_defs.h" +#include "slsDetectorCommand.h" + +#define MAX_TIMERS 10 +#define MAX_ROIS 100 +#define MAX_BADCHANS 2000 +#define MAXPOS 50 +#define MAX_SCAN_LEVELS 2 + +#define NMODMAXX 24 +#define NMODMAXY 24 +#define MAXMODS 36 +#define NCHIPSMAX 10 +#define NCHANSMAX 65536 +#define NDACSMAX 16 + +#define DEFAULT_HOSTNAME "localhost" +#define DEFAULT_SHM_KEY 5678 + +#define defaultTDead {170,90,750} /**< should be changed in order to have it separate for the different detector types */ + + + +/** + data structure to hold the detector data after postprocessing (e.g. to plot, store in a root tree etc.) + */ +class detectorData { + public: + /** The constructor + \param val pointer to the data + \param err pointer to errors + \param ang pointer to the angles + \param f_ind file index + \param fname file name to which the data are saved + \param np number of points defaults to the number of detector channels + */ + detectorData(float *val=NULL, float *err=NULL, float *ang=NULL, float p_ind=-1, const char *fname="", int np=-1) : values(val), errors(err), angles(ang), progressIndex(p_ind), npoints(np){strcpy(fileName,fname);}; + /** + the destructor + deletes also the arrays pointing to data/errors/angles if not NULL + */ + ~detectorData() {if (values) delete [] values; if (errors) delete [] errors; if (angles) delete [] angles;}; + //private: + float *values; /**< pointer to the data */ + float *errors; /**< pointer to the errors */ + float *angles;/**< pointer to the angles */ + float progressIndex;/**< file index */ + char fileName[1000];/**< file name */ + int npoints;/**< number of points */ +}; + + + + + +class slsDetectorUtils : public slsDetectorCommand { + + + + public: + + slsDetectorUtils(); + + virtual ~slsDetectorUtils(){}; + + + + + + + + + + + + + + + + + /** generates file name without extension + + always appends to file path and file name the run index. + + in case also appends the position index + + Filenames will be of the form: filepath/filename(_px)_i + where x is the position index and i is the run index + \param filepath outdir + \param filename file root name + \param aMask action mask (scans, positions) + \param sv0 scan variable 0 + \param prec0 scan precision 0 + \param sv1 scan variable 1 + \param prec1 scan precision 1 + \param pindex position index + \param number of positions + \param findex file index + \returns file name without extension + */ + static string createFileName(char *filepath, char *filename, int aMask, float sv0, int prec0, float sv1, int prec1, int pindex, int npos, int findex); + + virtual string createFileName(); + + + /** static function that returns the file index from the file name + \param fname file name + \returns file index*/ + static int getFileIndexFromFileName(string fname); + + /** static function that returns the variables from the file name + \param fname file name + \param index reference to index + \param p_index reference to position index + \param sv0 reference to scan variable 0 + \param sv1 reference to scan variable 1 + \returns file index + */ + static int getVariablesFromFileName(string fname, int &index, int &p_index, float &sv0, float &sv1); + + + + + + /** + + writes a data file + \param name of the file to be written + \param data array of data values + \param err array of arrors on the data. If NULL no errors will be written + + \param ang array of angular values. If NULL data will be in the form chan-val(-err) otherwise ang-val(-err) + \param dataformat format of the data: can be 'i' integer or 'f' float (default) + \param nch number of channels to be written to file. if -1 defaults to the number of installed channels of the detector + \returns OK or FAIL if it could not write the file or data=NULL + \sa mythenDetector::writeDataFile + + */ + int writeDataFile(string fname, float *data, float *err=NULL, float *ang=NULL, char dataformat='f', int nch=-1); + + int writeDataFile(ofstream &outfile, float *data, float *err=NULL, float *ang=NULL, char dataformat='f', int nch=-1); + + + /** + + writes a data file + \param name of the file to be written + \param data array of data values + \returns OK or FAIL if it could not write the file or data=NULL + \sa mythenDetector::writeDataFile + */ + int writeDataFile(string fname, int *data); + + /** + + reads a data file + \param name of the file to be read + \param data array of data values to be filled + \param err array of arrors on the data. If NULL no errors are expected on the file + + \param ang array of angular values. If NULL data are expected in the form chan-val(-err) otherwise ang-val(-err) + \param dataformat format of the data: can be 'i' integer or 'f' float (default) + \param nch number of channels to be written to file. if <=0 defaults to the number of installed channels of the detector + \returns OK or FAIL if it could not read the file or data=NULL + + \sa mythenDetector::readDataFile + */ + int readDataFile(string fname, float *data, float *err=NULL, float *ang=NULL, char dataformat='f'); + + /** + + reads a data file + \param name of the file to be read + \param data array of data values + \returns OK or FAIL if it could not read the file or data=NULL + \sa mythenDetector::readDataFile + */ + int readDataFile(string fname, int *data); + + /** + + writes a data file + \param name of the file to be written + \param data array of data values + \param err array of arrors on the data. If NULL no errors will be written + + \param ang array of angular values. If NULL data will be in the form chan-val(-err) otherwise ang-val(-err) + \param dataformat format of the data: can be 'i' integer or 'f' float (default) + \param nch number of channels to be written to file. if -1 defaults to the number of installed channels of the detector + \returns OK or FAIL if it could not write the file or data=NULL + \sa mythenDetector::writeDataFile + + */ + + static int writeDataFile(string fname, int nch, float *data, float *err=NULL, float *ang=NULL, char dataformat='f'); + + /** + + writes a data file + \param name of the file to be written + \param data array of data values + \returns OK or FAIL if it could not write the file or data=NULL + \sa mythenDetector::writeDataFile + */ + static int writeDataFile(string fname,int nch, int *data); + + /** + + reads a data file + \param name of the file to be read + \param data array of data values to be filled + \param err array of arrors on the data. If NULL no errors are expected on the file + + \param ang array of angular values. If NULL data are expected in the form chan-val(-err) otherwise ang-val(-err) + \param dataformat format of the data: can be 'i' integer or 'f' float (default) + \param nch number of channels to be written to file. if <=0 defaults to the number of installed channels of the detector + \returns number of channels read or -1 if it could not read the file or data=NULL + + \sa mythenDetector::readDataFile + */ + static int readDataFile(int nch, string fname, float *data, float *err=NULL, float *ang=NULL, char dataformat='f'); + + /** + + reads a data file + \param name of the file to be read + \param data array of data values + \returns OK or FAIL if it could not read the file or data=NULL + \sa mythenDetector::readDataFile + */ + static int readDataFile(string fname, int *data, int nch); + /** + + reads an angular conversion file + \param fname file to be read + \sa angleConversionConstant mythenDetector::readAngularConversion + */ + static int readAngularConversion(string fname, int nmod, angleConversionConstant *angOff); + + /** + + reads an angular conversion file + \param fname file to be read + \sa angleConversionConstant mythenDetector::readAngularConversion + */ + static int readAngularConversion(ifstream& ifs, int nmod, angleConversionConstant *angOff); + /** + Pure virtual function + writes an angular conversion file + \param fname file to be written + \sa angleConversionConstant mythenDetector::writeAngularConversion + */ + static int writeAngularConversion(string fname, int nmod, angleConversionConstant *angOff); + /** + Pure virtual function + writes an angular conversion file + \param fname file to be written + \sa angleConversionConstant mythenDetector::writeAngularConversion + */ + static int writeAngularConversion(ofstream& ofs, int nmod, angleConversionConstant *angOff); + /** + 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); + /** + flat field correct data + \param datain data + \param errin error on data (if<=0 will default to sqrt(datain) + \param dataout corrected data + \param errout error on corrected data + \param ffcoefficient flat field correction coefficient + \param fferr erro on ffcoefficient + \returns 0 + */ + static int flatFieldCorrect(float datain, float errin, float &dataout, float &errout, float ffcoefficient, float fferr); + /** + rate correct data + \param datain data + \param errin error on data (if<=0 will default to sqrt(datain) + \param dataout corrected data + \param errout error on corrected data + \param tau dead time 9in ns) + \param t acquisition time (in ns) + \returns 0 + */ + static int rateCorrect(float datain, float errin, float &dataout, float &errout, float tau, float t); + /** + pure virtual function + sets the arrays of the merged data to 0. NB The array should be created with size >= 360./getBinSize(); + \param mp already merged postions + \param mv already merged data + \param me already merged errors (squared sum) + \param mm multiplicity of merged arrays + \returns OK or FAIL + \sa mythenDetector::resetMerging + */ + static int resetMerging(float *mp, float *mv,float *me, int *mm, float binsize); + int resetMerging(float *mp, float *mv,float *me, int *mm); + + /** + pure virtual function + merge dataset + \param p1 angular positions of dataset + \param v1 data + \param e1 errors + \param mp already merged postions + \param mv already merged data + \param me already merged errors (squared sum) + \param mm multiplicity of merged arrays + \sa mythenDetector::addToMerging + */ + + static int addToMerging(float *p1, float *v1, float *e1, float *mp, float *mv,float *me, int *mm, int nchans, float binsize,int angDirection, int correctionMask, int *badChanMask ); + + int addToMerging(float *p1, float *v1, float *e1, float *mp, float *mv,float *me, int *mm); + + /** pure virtual function + calculates the "final" positions, data value and errors for the emrged data + \param mp already merged postions + \param mv already merged data + \param me already merged errors (squared sum) + \param mm multiplicity of merged arrays + \returns FAIL or the number of non empty bins (i.e. points belonging to the pattern) + \sa mythenDetector::finalizeMerging + */ + + static int finalizeMerging(float *mp, float *mv,float *me, int *mm, float binsize); + + int finalizeMerging(float *mp, float *mv,float *me, int *mm); + + + + + + /** + + reads a calibration file + \param fname file to be read + \param gain reference to the gain variable + \offset reference to the offset variable + \sa sharedSlsDetector mythenDetector::readCalibrationFile + */ + static int readCalibrationFile(string fname, float &gain, float &offset); + //virtual int readCalibrationFile(string fname, float &gain, float &offset); + + /** + + writes a calibration file + \param fname file to be written + \param gain + \param offset + \sa sharedSlsDetector mythenDetector::writeCalibrationFile + */ + static int writeCalibrationFile(string fname, float gain, float offset); + //virtual int writeCalibrationFile(string fname, float gain, float offset); + + + + + /** + sets the default output files path + \sa sharedSlsDetector + */ + char* setFilePath(string s) {sprintf(filePath, s.c_str()); return filePath;}; + + /** + sets the default output files root name + \sa sharedSlsDetector + */ + char* setFileName(string s) {sprintf(fileName, s.c_str()); return fileName;}; + + /** + sets the default output file index + \sa sharedSlsDetector + */ + int setFileIndex(int i) {*fileIndex=i; return *fileIndex;}; + + /** + returns the default output files path + \sa sharedSlsDetector + */ + char* getFilePath() {return filePath;}; + + /** + returns the default output files root name + \sa sharedSlsDetector + */ + char* getFileName() {return fileName;}; + + /** + returns the default output file index + \sa sharedSlsDetector + */ + int getFileIndex() {return *fileIndex;}; + + + + + /** + pure virtual function + set positions for the acquisition + \param nPos number of positions + \param pos array with the encoder positions + \returns number of positions + \sa mythenDetector::setPositions + */ + int setPositions(int nPos, float *pos); + /** + pure virtual function + get positions for the acquisition + \param pos array which will contain the encoder positions + \returns number of positions + \sa mythenDetector::getPositions + */ + int getPositions(float *pos=NULL); + + + + + + /** + set action + \param iaction can be enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript, MAX_ACTIONS} + \param fname for script ("" disable) + \param par for script + \returns 0 if action disabled, >0 otherwise + */ + int setAction(int iaction, string fname="", string par=""); + + /** + set action + \param iaction can be enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript, MAX_ACTIONS} + \param fname for script ("" disable) + \returns 0 if action disabled, >0 otherwise + */ + int setActionScript(int iaction, string fname=""); + /** + set action + \param iaction can be enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript, MAX_ACTIONS} + \param par for script ("" disable) + \returns 0 if action disabled, >0 otherwise + */ + int setActionParameter(int iaction, string par=""); + + /** + returns action script + \param iaction can be enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript} + \returns action script + */ + string getActionScript(int iaction); + + /** + returns action parameter + \param iaction can be enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript} + \returns action parameter + */ + string getActionParameter(int iaction); + + /** + returns action mode + \param iaction can be enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript} + \returns action mode + */ + int getActionMode(int iaction); + + + /** + set scan + \param index of the scan (0,1) + \param fname for script ("" disables, "none" disables and overwrites current) + \param nvalues number of steps (0 disables, -1 leaves current value) + \param values pointer to steps (if NULL leaves current values) + \param par parameter for the scan script ("" leaves unchanged) + \returns 0 is scan disabled, >0 otherwise + */ + int setScan(int index, string script="", int nvalues=-1, float *values=NULL, string par="", int precision=-1); + + int setScanScript(int index, string script=""); + int setScanParameter(int index, string par=""); + int setScanPrecision(int index, int precision=-1); + int setScanSteps(int index, int nvalues=-1, float *values=NULL); + float getScanStep(int index, int istep){if (index=0) *threadedProcessing=b; return *threadedProcessing;} + + + + /** + pure virtual function + set detector global offset + \sa mythenDetector::setGlobalOffset + */ + float setGlobalOffset(float f){*globalOffset=f; return *globalOffset;}; + + /** + pure virtual function + set detector fine offset + \sa mythenDetector::setFineOffset + */ + float setFineOffset(float f){*fineOffset=f; return *fineOffset;}; + /** + pure virtual function + get detector fine offset + \sa mythenDetector::getFineOffset + */ + float getFineOffset(){return *fineOffset;}; + + /** + pure virtual function + get detector global offset + \sa mythenDetector::getGlobalOffset + */ + float getGlobalOffset(){return *globalOffset;}; + + + + /** pure virtual function + set detector bin size used for merging (approx angular resolution) + \param bs bin size in degrees + \returns current bin size + \sa mythenDetector::setBinSize +*/ + float setBinSize(float bs){*binSize=bs; return *binSize;}; + + /** pure virtual function + return detector bin size used for merging (approx angular resolution) + \sa mythenDetector::getBinSize + */ + float getBinSize() {return *binSize;}; + + + + + + /** + pure virtual function + returns the angular conversion file + \sa mythenDetector::getAngularConversion */ + string getAngularConversion(){if ((*correctionMask)&(1<< ANGULAR_CONVERSION)) return string(angConvFile); else return string("none");}; + + + /** returns the bad channel list file */ + string getBadChannelCorrectionFile() {if ((*correctionMask)&(1<< DISCARD_BAD_CHANNELS)) return string(badChanFile); else return string("none");}; + + + + + /** + get flat field corrections file directory + \returns flat field correction file directory + */ + char *getFlatFieldCorrectionDir(){return flatFieldDir;}; + /** + set flat field corrections file directory + \param flat field correction file directory + */ + void setFlatFieldCorrectionDir(string dir){strcpy(flatFieldDir,dir.c_str());}; + + /** + get flat field corrections file name + \returns flat field correction file name + */ + char *getFlatFieldCorrectionFile(){ if ((*correctionMask)&(1< dataQueue; + /** + queue containing the postprocessed data + */ + queue finalDataQueue; + + + + private: + + + + int totalProgress; + + int progressIndex; + int *stoppedFlag; + int *threadedProcessing; + + + int *actionMask; + mystring *actionScript; + mystring *actionParameter; + + int *nScanSteps; + mysteps *scanSteps; + int *scanMode; + int *scanPrecision; + mystring *scanScript; + mystring *scanParameter; + + int *numberOfPositions; + float *detPositions; + + + char *angConvFile; + int *correctionMask; + float *binSize; + float *fineOffset; + float *globalOffset; + int *angDirection; + + char *flatFieldDir; + char *flatFieldFile; + + char *badChanFile; + int *nBadChans; + int *badChansList; + int *nBadFF; + int *badFFList; + + int64_t *timerValue; + detectorSettings *currentSettings; + int *currentThresholdEV; + + char *filePath; + char *fileName; + int *fileIndex; + + + /** mutex to synchronize threads */ + pthread_mutex_t mp; + + + /** sets when the acquisition is finished */ + int jointhread; + + /** data queue size */ + int queuesize; + + + + + /** + current position of the detector + */ + float currentPosition; + + /** + current position index of the detector + */ + int currentPositionIndex; + + /** + I0 measured + */ + float currentI0; + + + + + /** + current scan variable of the detector + */ + float currentScanVariable[MAX_SCAN_LEVELS]; + + /** + current scan variable index of the detector + */ + int currentScanIndex[MAX_SCAN_LEVELS]; + + + + /** merging bins */ + float *mergingBins; + + /** merging counts */ + float *mergingCounts; + + /** merging errors */ + float *mergingErrors; + + /** merging multiplicity */ + int *mergingMultiplicity; + + + + + /** pointer to bad channel mask 0 is channel is good 1 if it is bad \sa fillBadChannelMask() */ + int *badChannelMask; + + + /** + start data processing thread + */ + void startThread(int delflag=1); // + /** the data processing thread */ + + pthread_t dataProcessingThread; + + /** + get bad channels correction + \param bad pointer to array that if bad!=NULL will be filled with the bad channel list + \returns 0 if bad channel disabled or no bad channels, >0 otherwise + */ + virtual int getBadChannelCorrection(int *bad=NULL)=0; + + + +}; + + +static void* startProcessData(void *n){\ + slsDetectorUtils *myDet=(slsDetectorUtils*)n;\ + myDet->processData(1);\ + pthread_exit(NULL);\ + +}; + +static void* startProcessDataNoDelete(void *n){\ + slsDetectorUtils *myDet=(slsDetectorUtils*)n;\ + myDet->processData(0);\ + pthread_exit(NULL);\ + +}; + + + +#endif