From 13344152aa60819bb43a81138f9fae75a8066ac2 Mon Sep 17 00:00:00 2001 From: bergamaschi Date: Fri, 23 Mar 2012 11:44:24 +0000 Subject: [PATCH] cretated the class slsDetectorDefs, more advanced funcs moved from slsDetectorBase to slsDetectorUtils, separated function index enum from other definitions (share with dectris?) git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@162 951219d9-93cf-4727-9268-0efd64621fa3 --- slsDetectorSoftware/MySocketTCP/MySocketTCP.h | 16 ++ .../commonFiles/sls_detector_defs.h | 171 ++++---------- .../commonFiles/sls_detector_funcs.h | 108 +++++++++ slsDetectorSoftware/doxy.config | 28 ++- .../multiSlsDetector/multiSlsDetector.cpp | 8 +- .../multiSlsDetector/multiSlsDetector.h | 4 +- .../mythenDetectorServer/sls_detector_funcs.h | 1 + .../slsDetector/slsDetector.cpp | 44 ++-- slsDetectorSoftware/slsDetector/slsDetector.h | 7 +- .../slsDetector/slsDetectorBase.h | 223 +++++++----------- .../slsDetector/slsDetectorCommand.h | 8 +- .../slsDetector/slsDetectorUtils.cpp | 96 ++++---- .../slsDetector/slsDetectorUtils.h | 110 +++++++-- 13 files changed, 466 insertions(+), 358 deletions(-) create mode 100644 slsDetectorSoftware/commonFiles/sls_detector_funcs.h create mode 120000 slsDetectorSoftware/mythenDetectorServer/sls_detector_funcs.h diff --git a/slsDetectorSoftware/MySocketTCP/MySocketTCP.h b/slsDetectorSoftware/MySocketTCP/MySocketTCP.h index 0f16d6856..6e003e6b1 100644 --- a/slsDetectorSoftware/MySocketTCP/MySocketTCP.h +++ b/slsDetectorSoftware/MySocketTCP/MySocketTCP.h @@ -43,10 +43,26 @@ using namespace std; added a function which really does not close the socket between send/receive (senddataonly, receivedataonly) */ +#ifdef __CINT__ +//class sockaddr_in; +class socklen_t; +class uint32_t; +class uint32_t_ss; +// CINT view of types: +class sockaddr_in; +// { +// unsigned short int sa_family; +// unsigned char sa_data[14]; +// }; +#else #include #include #include +#endif + + + #include diff --git a/slsDetectorSoftware/commonFiles/sls_detector_defs.h b/slsDetectorSoftware/commonFiles/sls_detector_defs.h index 4d7f31530..a87bd07ed 100755 --- a/slsDetectorSoftware/commonFiles/sls_detector_defs.h +++ b/slsDetectorSoftware/commonFiles/sls_detector_defs.h @@ -29,7 +29,17 @@ and to the server programs running on the detector /** get flag form most functions */ #define GET_FLAG -1 -enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript, MAX_ACTIONS}; +#ifdef __cplusplus +class slsDetectorDefs { + + public: + + slsDetectorDefs(){}; + +#endif + + + enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript, MAX_ACTIONS}; @@ -39,28 +49,28 @@ enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScri \see ::channelRegisterBit */ -typedef struct { - int chan; /**< is the channel number */ - int chip; /**< is the chip number */ - int module; /**< is the module number */ - int64_t reg; /**< is the is the channel register (e.g. trimbits, calibration enable, comparator enable...) */ -} sls_detector_channel; - -/** + typedef struct { + int chan; /**< is the channel number */ + int chip; /**< is the chip number */ + int module; /**< is the module number */ + int64_t reg; /**< is the is the channel register (e.g. trimbits, calibration enable, comparator enable...) */ + } sls_detector_channel; + + /** structure for a detector chip should not be used by unexperienced users \see ::chipRegisterBit ::channelRegisterBit */ -typedef struct { - int chip; /**< is the chip number */ - int module; /**< is the module number */ - int nchan; /**< is the number of channels in the chip */ - int reg; /**0 otherwise */ - int setFlatFieldCorrection(float *corr=NULL, float *ecorr=NULL); + int setFlatFieldCorrection(float *corr, float *ecorr=NULL); /** get flat field corrections diff --git a/slsDetectorSoftware/mythenDetectorServer/sls_detector_funcs.h b/slsDetectorSoftware/mythenDetectorServer/sls_detector_funcs.h new file mode 120000 index 000000000..844b67129 --- /dev/null +++ b/slsDetectorSoftware/mythenDetectorServer/sls_detector_funcs.h @@ -0,0 +1 @@ +../commonFiles/sls_detector_funcs.h \ No newline at end of file diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index 111bdb11b..7db3e4b08 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -1,3 +1,4 @@ + #include "slsDetector.h" #include "usersFunctions.h" #include "slsDetectorCommand.h" @@ -268,7 +269,7 @@ slsDetector::slsDetector(char *name, int id, int cport) : slsDetectorUtils(), } -detectorType slsDetector::getDetectorType(char *name, int cport) { +slsDetectorDefs::detectorType slsDetector::getDetectorType(char *name, int cport) { int retval=FAIL; detectorType t=GENERIC; @@ -377,7 +378,7 @@ int slsDetector::exists(int id) { -detectorType slsDetector::getDetectorType(int id) { +slsDetectorDefs::detectorType slsDetector::getDetectorType(int id) { detectorType t=GENERIC; @@ -740,7 +741,7 @@ int slsDetector::initializeDetectorStructure() { return 0; } -sls_detector_module* slsDetector::createModule() { +slsDetectorDefs::sls_detector_module* slsDetector::createModule() { sls_detector_module *myMod=(sls_detector_module*)malloc(sizeof(sls_detector_module)); float *dacs=new float[thisDetector->nDacs]; @@ -1364,7 +1365,7 @@ enum externalSignalFlag { }{}; */ - externalSignalFlag slsDetector::setExternalSignalFlags(externalSignalFlag pol, int signalindex){ +slsDetectorDefs::externalSignalFlag slsDetector::setExternalSignalFlags(externalSignalFlag pol, int signalindex){ @@ -1436,7 +1437,7 @@ enum externalSignalFlag { */ - externalCommunicationMode slsDetector::setExternalCommunicationMode( externalCommunicationMode pol){ +slsDetectorDefs::externalCommunicationMode slsDetector::setExternalCommunicationMode( externalCommunicationMode pol){ @@ -2030,7 +2031,7 @@ int slsDetector::setChannel(sls_detector_channel chan){ -sls_detector_channel slsDetector::getChannel(int ichan, int ichip, int imod){ +slsDetectorDefs::sls_detector_channel slsDetector::getChannel(int ichan, int ichip, int imod){ int fnum=F_GET_CHANNEL; @@ -2167,7 +2168,7 @@ int slsDetector::setChip(sls_detector_chip chip){ }; - sls_detector_chip slsDetector::getChip(int ichip, int imod){ + slsDetectorDefs::sls_detector_chip slsDetector::getChip(int ichip, int imod){ int fnum=F_GET_CHIP; sls_detector_chip myChip; @@ -2395,7 +2396,7 @@ int slsDetector::setModule(sls_detector_module module){ return retval; }; -sls_detector_module *slsDetector::getModule(int imod){ +slsDetectorDefs::sls_detector_module *slsDetector::getModule(int imod){ #ifdef VERBOSE std::cout << "slsDetector get module " << std::endl; @@ -2603,7 +2604,7 @@ int slsDetector::setThresholdEnergy(int e_eV, int imod, detectorSettings isetti /* select detector settings */ - detectorSettings slsDetector::getSettings(int imod){ + slsDetectorDefs::detectorSettings slsDetector::getSettings(int imod){ int fnum=F_SET_SETTINGS; @@ -2644,7 +2645,7 @@ int slsDetector::setThresholdEnergy(int e_eV, int imod, detectorSettings isetti -detectorSettings slsDetector::setSettings( detectorSettings isettings, int imod){ +slsDetectorDefs::detectorSettings slsDetector::setSettings( detectorSettings isettings, int imod){ #ifdef VERBOSE std::cout<< "slsDetector setSettings "<< std::endl; #endif @@ -2954,7 +2955,7 @@ int slsDetector::startReadOut(){ }; -runStatus slsDetector::getRunStatus(){ +slsDetectorDefs::runStatus slsDetector::getRunStatus(){ int fnum=F_GET_RUN_STATUS; int ret=FAIL; char mess[100]; @@ -3012,7 +3013,8 @@ int* slsDetector::readFrame(){ int* slsDetector::getDataFromDetector(int *retval){ int nel=thisDetector->dataBytes/sizeof(int); int n; - + + int *r=retval; // int* retval=new int[nel]; @@ -3042,7 +3044,7 @@ int* slsDetector::getDataFromDetector(int *retval){ std::cout<< "Detector successfully returned: " << mess << " " << n << std::endl; #endif } - if (retval==NULL) { + if (r==NULL) { delete [] retval; } return NULL; @@ -3056,7 +3058,7 @@ int* slsDetector::getDataFromDetector(int *retval){ std::cout<< "wrong data size received: received " << n << " but expected " << thisDetector->dataBytes << std::endl; thisDetector->stoppedFlag=1; ret=FAIL; - if (retval==NULL) { + if (r==NULL) { delete [] retval; } return NULL; @@ -3101,8 +3103,8 @@ int* slsDetector::readAll(){ } #ifdef VERBOSE std::cout<< "received "<< i<< " frames" << std::endl; -#else - std::cout << std::endl; + //#else + // std::cout << std::endl; #endif return dataQueue.front(); // check what we return! @@ -3160,8 +3162,8 @@ int* slsDetector::startAndReadAll(){ #ifdef VERBOSE std::cout<< "received "<< i<< " frames" << std::endl; -#else - std::cout << std::endl; + //#else + // std::cout << std::endl; #endif return dataQueue.front(); // check what we return! /* while ((retval=getDataFromDetectorNoWait())) @@ -5147,7 +5149,7 @@ int slsDetector::retrieveDetectorSetup(string fname1, int level){ /* I/O */ - sls_detector_module* slsDetector::readSettingsFile(string fname, sls_detector_module *myMod){ + slsDetectorDefs::sls_detector_module* slsDetector::readSettingsFile(string fname, sls_detector_module *myMod){ int nflag=0; @@ -5466,7 +5468,7 @@ int slsDetector::saveSettingsFile(string fname, int imod) { \param flag can be GET_MASTER, NO_MASTER, IS_MASTER, IS_SLAVE \returns master flag of the detector */ -masterFlags slsDetector::setMaster(masterFlags flag) { +slsDetectorDefs::masterFlags slsDetector::setMaster(masterFlags flag) { int fnum=F_SET_MASTER; @@ -5511,7 +5513,7 @@ masterFlags slsDetector::setMaster(masterFlags flag) { \param sync syncronization mode can be GET_SYNCHRONIZATION_MODE, NO_SYNCHRONIZATION, MASTER_GATES, MASTER_TRIGGERS, SLAVE_STARTS_WHEN_MASTER_STOPS \returns current syncronization mode */ -synchronizationMode slsDetector::setSynchronization(synchronizationMode flag) { +slsDetectorDefs::synchronizationMode slsDetector::setSynchronization(synchronizationMode flag) { diff --git a/slsDetectorSoftware/slsDetector/slsDetector.h b/slsDetectorSoftware/slsDetector/slsDetector.h index 3db279ecb..725c57126 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.h +++ b/slsDetectorSoftware/slsDetector/slsDetector.h @@ -4,8 +4,11 @@ #ifndef SLS_DETECTOR_H #define SLS_DETECTOR_H -#include "MySocketTCP.h" + +class MySocketTCP; + #include "slsDetectorUtils.h" +#include "MySocketTCP.h" //#include "slsDetectorCommand.h" @@ -1096,7 +1099,7 @@ typedef struct sharedSlsDetector { \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); + int setFlatFieldCorrection(float *corr, float *ecorr=NULL); /** diff --git a/slsDetectorSoftware/slsDetector/slsDetectorBase.h b/slsDetectorSoftware/slsDetector/slsDetectorBase.h index 6d00d84d7..10e76cfd1 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorBase.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorBase.h @@ -16,7 +16,8 @@ This class contains the functions accessible by the users to control the slsDete */ -class slsDetectorBase { +class slsDetectorBase : public slsDetectorDefs + { public: @@ -28,7 +29,7 @@ class slsDetectorBase { virtual ~slsDetectorBase(){}; /** 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) + \param online 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_FLAG or OFFLINE_FLAG */ virtual int setOnline(int const online=GET_ONLINE_FLAG)=0; @@ -61,12 +62,17 @@ class slsDetectorBase { */ virtual int* readFrame()=0; - /** processes the data - \param delflag 0 leaves the data in the final data queue - \returns nothing +/* /\** processes the data */ +/* \param delflag 0 leaves the data in the final data queue */ +/* \returns nothing */ - */ - virtual void* processData(int delflag)=0; +/* *\/ */ +/* virtual void* processData(int delflag)=0; */ + + + + + /** @@ -86,43 +92,43 @@ class slsDetectorBase { */ virtual runStatus getRunStatus()=0; - /** Frees the shared memory - should not be used except for debugging*/ - virtual int freeSharedMemory()=0; +/* /\** Frees the shared memory - should not be used except for debugging*\/ */ +/* virtual int freeSharedMemory()=0; */ - /** adds the detector with ID id in postion pos - \param id of the detector to be added (should already exist!) - \param pos position where it should be added (normally at the end of the list (default to -1) - \returns the actual number of detectors or -1 if it failed (always for slsDetector) - */ - virtual int addSlsDetector(int id, int pos=-1){return -1;}; +/* /\** adds the detector with ID id in postion pos */ +/* \param id of the detector to be added (should already exist!) */ +/* \param pos position where it should be added (normally at the end of the list (default to -1) */ +/* \returns the actual number of detectors or -1 if it failed (always for slsDetector) */ +/* *\/ */ +/* virtual int addSlsDetector(int id, int pos=-1){return -1;}; */ - /** adds the detector name in position pos - \param name of the detector to be added (should already exist in shared memory or at least be online) - \param pos position where it should be added (normally at the end of the list (default to -1) - \return the actual number of detectors or -1 if it failed (always for slsDetector) - */ - virtual int addSlsDetector(char* name, int pos=-1){return -1;}; +/* /\** adds the detector name in position pos */ +/* \param name of the detector to be added (should already exist in shared memory or at least be online) */ +/* \param pos position where it should be added (normally at the end of the list (default to -1) */ +/* \return the actual number of detectors or -1 if it failed (always for slsDetector) */ +/* *\/ */ +/* virtual int addSlsDetector(char* name, int pos=-1){return -1;}; */ - /** - removes the detector in position pos from the multidetector - \param pos position of the detector to be removed from the multidetector system (defaults to -1 i.e. last detector) - \returns the actual number of detectors or -1 if it failed (always for slsDetector) - */ - virtual int removeSlsDetector(int pos=-1){return -1;}; +/* /\** */ +/* removes the detector in position pos from the multidetector */ +/* \param pos position of the detector to be removed from the multidetector system (defaults to -1 i.e. last detector) */ +/* \returns the actual number of detectors or -1 if it failed (always for slsDetector) */ +/* *\/ */ +/* virtual int removeSlsDetector(int pos=-1){return -1;}; */ - /**removes the detector in position pos from the multidetector - \param name is the name of the detector - \returns the actual number of detectors or -1 if it failed (always for slsDetector) - */ - virtual int removeSlsDetector(char* name){return -1;}; +/* /\**removes the detector in position pos from the multidetector */ +/* \param name is the name of the detector */ +/* \returns the actual number of detectors or -1 if it failed (always for slsDetector) */ +/* *\/ */ +/* virtual int removeSlsDetector(char* name){return -1;}; */ /** returns the detector hostname \param pos position in the multi detector structure (is -1 returns concatenated hostnames divided by a +) - \retruns hostname + \returns hostname */ virtual string getHostname(int pos=-1)=0; @@ -160,10 +166,6 @@ class slsDetectorBase { */ virtual synchronizationMode setSynchronization(synchronizationMode sync=GET_SYNCHRONIZATION_MODE)=0; - /** - Turns off the server - do not use except for debugging! - */ - virtual int exitServer()=0; /** returns the detector trimbit/settings directory @@ -223,7 +225,7 @@ class slsDetectorBase { /** set flat field corrections file directory - \param flat field correction file directory + \param dir flat field correction file directory \returns flat field correction file directory */ virtual char *setFlatFieldCorrectionDir(string dir)=0; @@ -255,7 +257,7 @@ class slsDetectorBase { \param ecorr if !=NULL the flat field correction errors will be filled with ecorr (1 otherwise) \returns 0 if ff correction disabled, >0 otherwise */ - virtual int setFlatFieldCorrection(float *corr=NULL, float *ecorr=NULL)=0; + virtual int setFlatFieldCorrection(float *corr, float *ecorr=NULL)=0; /** set rate correction @@ -320,7 +322,7 @@ class slsDetectorBase { /** get angular conversion - \param reference to diffractometer direction + \param direction reference to diffractometer direction \param angconv array that will be filled with the angular conversion constants \returns 0 if angular conversion disabled, >0 otherwise */ @@ -349,33 +351,33 @@ class slsDetectorBase { */ virtual float getAngularConversionParameter(angleConversionParameter c)=0; - /** - writes a data file - \param name of the file to be written - \param data array of data values - \param err array of arrors on the data. If NULL no errors will be written +/* /\** */ +/* writes a data file */ +/* \param name of the file to be written */ +/* \param data array of data values */ +/* \param err array of arrors on the data. If NULL no errors will be written */ - \param ang array of angular values. If NULL data will be in the form chan-val(-err) otherwise ang-val(-err) - \param dataformat format of the data: can be 'i' integer or 'f' float (default) - \param nch number of channels to be written to file. if -1 defaults to the number of installed channels of the detector - \returns OK or FAIL if it could not write the file or data=NULL - */ - virtual int writeDataFile(string fname, float *data, float *err=NULL, float *ang=NULL, char dataformat='f', int nch=-1)=0; +/* \param ang array of angular values. If NULL data will be in the form chan-val(-err) otherwise ang-val(-err) */ +/* \param dataformat format of the data: can be 'i' integer or 'f' float (default) */ +/* \param nch number of channels to be written to file. if -1 defaults to the number of installed channels of the detector */ +/* \returns OK or FAIL if it could not write the file or data=NULL */ +/* *\/ */ +/* virtual int writeDataFile(string fname, float *data, float *err=NULL, float *ang=NULL, char dataformat='f', int nch=-1)=0; */ - /** - writes an angular conversion file - \param fname file to be written - \return OK/FAIL - */ - virtual int writeAngularConversion(string fname)=0; +/* /\** */ +/* writes an angular conversion file */ +/* \param fname file to be written */ +/* \return OK/FAIL */ +/* *\/ */ +/* virtual int writeAngularConversion(string fname)=0; */ - /** - set/get if the data processing and file writing should be done by a separate thread - do not use except for debugging! - \param b 0 sequencial data acquisition and file writing, 1 separate thread, -1 get - \returns thread flag - */ - virtual int setThreadedProcessing(int i=-1)=0; - +/* /\** */ +/* set/get if the data processing and file writing should be done by a separate thread - do not use except for debugging! */ +/* \param i 0 sequencial data acquisition and file writing, 1 separate thread, -1 get */ +/* \returns thread flag */ +/* *\/ */ +/* virtual int setThreadedProcessing(int i=-1)=0; */ + /** set positions for the acquisition \param nPos number of positions @@ -424,7 +426,7 @@ class slsDetectorBase { /** set scan script \param index is the scan index (0 or 1) - \param fname for script ("" disable, "none" disables and overwrites current, "threshold" makes threshold scan, "trimbits" make trimbits scan, "energy" makes energy scan) + \param script fname for script ("" disable, "none" disables and overwrites current, "threshold" makes threshold scan, "trimbits" make trimbits scan, "energy" makes energy scan) \returns 0 if scan disabled, >0 otherwise */ virtual int setScanScript(int index, string script="")=0; @@ -502,8 +504,8 @@ class slsDetectorBase { /** changes/gets the port number - \param type port type can be CONTROL_PORT, DATA_PORT, STOP_PORT - \param num new port number (<1024 gets) + \param t type port type can be CONTROL_PORT, DATA_PORT, STOP_PORT + \param i new port number (<1024 gets) \returns actual port number */ virtual int setPort(portType t, int i=-1)=0; @@ -531,7 +533,7 @@ class slsDetectorBase { /** set/get the size of the detector - \param n number of modules + \param i number of modules \param d dimension \returns current number of modules in direction d */ @@ -548,10 +550,8 @@ class slsDetectorBase { /** set/get dynamic range - \param n dynamic range (-1 get) + \param i dynamic range (-1 get) \returns current dynamic range - updates the size of the data expected from the detector - \sa sharedSlsDetector */ virtual int setDynamicRange(int i=-1)=0; @@ -642,25 +642,6 @@ class slsDetectorBase { - /** - write register - \param addr address - \val value - \returns current register value - - DO NOT USE!!! ONLY EXPERT USER!!! - */ - virtual int writeRegister(int addr, int val)=0; - - - /** - read register - \param addr address - \returns current register value - - DO NOT USE!!! ONLY EXPERT USER!!! - */ - virtual int readRegister(int addr)=0; /** @@ -670,7 +651,7 @@ class slsDetectorBase { \param imod module number (if -1 alla modules) \returns current DAC value */ - virtual float setDAC(float , dacIndex, int imod=-1)=0; + virtual float setDAC(float val, dacIndex index , int imod=-1)=0; /** @@ -679,7 +660,7 @@ class slsDetectorBase { \param imod module number \returns current ADC value */ - virtual float getADC(dacIndex, int imod=0)=0; + virtual float getADC(dacIndex index, int imod=0)=0; /** @@ -722,7 +703,7 @@ class slsDetectorBase { virtual int setTrimEn(int nen, int *en=NULL)=0; /** returns the number of trim energies and their value \sa sharedSlsDetector - \param point to the array that will contain the trim energies (in ev) + \param en pointer to the array that will contain the trim energies (in ev) \returns number of trim energies unused! @@ -733,7 +714,7 @@ class slsDetectorBase { /** set/get the use of an external signal \param pol meaning of the signal \sa externalSignalFlag - \param signalIndex index of the signal + \param signalindex index of the signal \returns current meaning of signal signalIndex */ virtual externalSignalFlag setExternalSignalFlags(externalSignalFlag pol=GET_EXTERNAL_SIGNAL_FLAG , int signalindex=0)=0; @@ -790,35 +771,12 @@ class slsDetectorBase { /** Loads dark image or gain image to the detector \param index can be DARK_IMAGE or GAIN_IMAGE - \fname file name to load data from + \param fname file name to load data from \returns OK or FAIL */ virtual int loadImageToDetector(imageType index,string const fname)=0; + - - /** - writes the counter memory block from the detector - \param startACQ is 1 to start acquisition after reading counter - \fname file fname to load data from - \returns OK or FAIL - */ - virtual int writeCounterBlockFile(string const fname,int startACQ=0)=0; - - - /** - Resets counter memory block in detector - \param startACQ is 1 to start acquisition after resetting counter - \returns OK or FAIL - */ - virtual int resetCounterBlock(int startACQ=0)=0; - - - /** - function to test acquisition - */ - virtual int testFunction(int itimes=0)=0; - - /************************************************************************ STATIC FUNCTIONS @@ -840,7 +798,7 @@ class slsDetectorBase { }}; /** returns detector type string from detector type index - \param type string can be Mythen, Pilatus, Eiger, Gotthard, Agipd, Unknown + \param t string can be Mythen, Pilatus, Eiger, Gotthard, Agipd, Unknown \returns MYTHEN, PILATUS, EIGER, GOTTHARD, AGIPD, GENERIC */ static string getDetectorType(detectorType t){\ @@ -854,7 +812,7 @@ class slsDetectorBase { }}; /** returns detector type index from detector type string - \param t can be MYTHEN, PILATUS, EIGER, GOTTHARD, AGIPD, GENERIC + \param type can be MYTHEN, PILATUS, EIGER, GOTTHARD, AGIPD, GENERIC \returns Mythen, Pilatus, Eiger, Gotthard, Agipd, Unknown */ static detectorType getDetectorType(string const type){\ @@ -868,7 +826,7 @@ class slsDetectorBase { /** returns synchronization type index from string - \param t can be none, gating, trigger, complementary + \param type can be none, gating, trigger, complementary \returns ONE, MASTER_GATES, MASTER_TRIGGERS, SLAVE_STARTS_WHEN_MASTER_STOPS */ static synchronizationMode getSyncType(string const type){\ @@ -880,8 +838,8 @@ class slsDetectorBase { }; /** 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 + \param s can be NONE, MASTER_GATES, MASTER_TRIGGERS, SLAVE_STARTS_WHEN_MASTER_STOPS + \returns none, gating, trigger, complementary, unknown */ static string getSyncType(synchronizationMode s ){\ switch(s) { \ @@ -923,8 +881,8 @@ class slsDetectorBase { /** 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, gnd, vcc, sync, 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, OUTPUT_LOW, OUTPUT_HIGH, MASTER_SLAVE_SYNCHRONIZATION, GET_EXTERNAL_SIGNAL_FLAG (if unknown) + \param sval 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, gnd, vcc, sync, unknown + \returns 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, OUTPUT_LOW, OUTPUT_HIGH, MASTER_SLAVE_SYNCHRONIZATION, GET_EXTERNAL_SIGNAL_FLAG (if unknown) */ static externalSignalFlag externalSignalType(string sval){\ @@ -946,11 +904,11 @@ class slsDetectorBase { if (sval=="vcc") return OUTPUT_HIGH;\ return GET_EXTERNAL_SIGNAL_FLAG ;}; - - /** 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 + /** returns detector settings string from index + \param s can be standard, fast, highgain, dynamicgain, lowgain, mediumgain, veryhighgain, undefined + \returns STANDARD, FAST, HIGHGAIN, DYNAMICGAIN, LOWGAIN, MEDIUMGAIN, VERYHIGHGAIN, GET_SETTINGS */ + static detectorSettings getDetectorSettings(string s){\ if (s=="standard") return STANDARD;\ if (s=="fast") return FAST;\ @@ -963,7 +921,7 @@ class slsDetectorBase { }; /** returns detector settings string from index - \param t can be STANDARD, FAST, HIGHGAIN, DYNAMICGAIN, LOWGAIN, MEDIUMGAIN, VERYHIGHGAIN, GET_SETTINGS + \param s 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){\ @@ -1000,7 +958,7 @@ class slsDetectorBase { /** returns external communication mode index from string - \param s can be auto, trigger, ro_trigger, gating, triggered_gating + \param sval can be auto, trigger, ro_trigger, gating, triggered_gating \returns AUTO_TIMING, TRIGGER_EXPOSURE, TRIGGER_READOUT, GATE_FIX_NUMBER, GATE_WITH_START_TRIGGER, GET_EXTERNAL_COMMUNICATION_MODE */ @@ -1012,6 +970,5 @@ class slsDetectorBase { if (sval=="triggered_gating") return GATE_WITH_START_TRIGGER;\ return GET_EXTERNAL_COMMUNICATION_MODE;}; - }; #endif diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.h b/slsDetectorSoftware/slsDetector/slsDetectorCommand.h index 5fac16b7f..f3ac8ed08 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorCommand.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.h @@ -4,7 +4,7 @@ #include "sls_detector_defs.h" -#include "slsDetectorBase.h" +#include "slsDetectorUtils.h" using namespace std; @@ -12,12 +12,12 @@ using namespace std; /* It is inherited by both slsDetector and multiSlsDetector */ /* *\/ */ -class slsDetectorCommand { +class slsDetectorCommand : public slsDetectorDefs { public: - slsDetectorCommand(slsDetectorBase *det); + slsDetectorCommand(slsDetectorUtils *det); /* /\** */ @@ -100,7 +100,7 @@ class slsDetectorCommand { private: - slsDetectorBase *myDet; + slsDetectorUtils *myDet; string cmdUnderDevelopment(int narg, char *args[], int action); string cmdUnknown(int narg, char *args[], int action); diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp index 215bb490e..fd5198379 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp @@ -19,6 +19,8 @@ slsDetectorUtils::slsDetectorUtils() : queuesize(0), pthread_mutex_t mp1 = PTHREAD_MUTEX_INITIALIZER; mp=mp1; pthread_mutex_init(&mp, NULL); + mg=mp1; + pthread_mutex_init(&mg, NULL); } @@ -1852,57 +1854,57 @@ void* slsDetectorUtils::processData(int delflag) { // cout << "Write angular converted file for position " << currentPositionIndex << endl; #endif - writeDataFile (fname+string(".dat"), ffcdata, ffcerr,ang); + writeDataFile (fname+string(".dat"), ffcdata, ffcerr,ang); // } // } #ifdef VERBOSE // cout << "add to merging "<< currentPositionIndex << endl; #endif - if (*numberOfPositions>0 || delflag==0) { - addToMerging(ang, ffcdata, ffcerr, mergingBins, mergingCounts,mergingErrors, mergingMultiplicity, getTotalNumberOfChannels(), bs, *angDirection, *correctionMask, badChannelMask ); + if (*numberOfPositions>0 || delflag==0) { + addToMerging(ang, ffcdata, ffcerr, mergingBins, mergingCounts,mergingErrors, mergingMultiplicity, getTotalNumberOfChannels(), bs, *angDirection, *correctionMask, badChannelMask ); #ifdef VERBOSE - cout << currentPositionIndex << " " << (*numberOfPositions) << endl; + cout << currentPositionIndex << " " << (*numberOfPositions) << endl; #endif + + pthread_mutex_lock(&mp); + if ((currentPositionIndex>=(*numberOfPositions) && posfinished==1 && queuesize==1)) { - pthread_mutex_lock(&mp); - if ((currentPositionIndex>=(*numberOfPositions) && posfinished==1 && queuesize==1)) { - - - // if ((currentPositionIndex>=(*numberOfPositions)) || (currentPositionIndex==0)) { + + // if ((currentPositionIndex>=(*numberOfPositions)) || (currentPositionIndex==0)) { #ifdef VERBOSE // cout << "finalize merging " << currentPositionIndex<< endl; #endif - np=finalizeMerging(mergingBins, mergingCounts,mergingErrors, mergingMultiplicity, bs); + np=finalizeMerging(mergingBins, mergingCounts,mergingErrors, mergingMultiplicity, bs); /** file writing */ + + - - - - currentPositionIndex++; - pthread_mutex_unlock(&mp); - - - fname=createFileName(); + + currentPositionIndex++; + pthread_mutex_unlock(&mp); + + fname=createFileName(); + #ifdef VERBOSE - // cout << "writing merged data file" << endl; + // cout << "writing merged data file" << endl; #endif - writeDataFile (fname+string(".dat"),np,mergingCounts, mergingErrors, mergingBins,'f'); + writeDataFile (fname+string(".dat"),np,mergingCounts, mergingErrors, mergingBins,'f'); #ifdef VERBOSE // cout << " done" << endl; #endif + + - - - if (delflag) { + if (delflag) { #ifdef VERBOSE - // cout << mergingBins<< " " << mergingCounts<< " " << mergingErrors << " " << mergingMultiplicity << " " << endl; + // cout << mergingBins<< " " << mergingCounts<< " " << mergingErrors << " " << mergingMultiplicity << " " << endl; #endif - + if (mergingBins) { #ifdef VERBOSE // cout << "deleting merged bins "<< mergingBins << " size " << sizeof(mergingBins) << endl; @@ -1932,24 +1934,26 @@ void* slsDetectorUtils::processData(int delflag) { mergingMultiplicity=NULL; } #ifdef VERBOSE - // cout << "deleting merged data done " << endl; + // cout << "deleting merged data done " << endl; - // cout << mergingBins<< " " << mergingCounts<< " " << mergingErrors << " " << mergingMultiplicity << " " << endl; - + // cout << mergingBins<< " " << mergingCounts<< " " << mergingErrors << " " << mergingMultiplicity << " " << endl; + #endif } - } else { - thisData=new detectorData(mergingCounts,mergingErrors,mergingBins,getCurrentProgress(),(fname+string(ext)).c_str(),np); - - finalDataQueue.push(thisData); - } - pthread_mutex_lock(&mp); - } - pthread_mutex_unlock(&mp); - - + } else { + thisData=new detectorData(mergingCounts,mergingErrors,mergingBins,getCurrentProgress(),(fname+string(ext)).c_str(),np); + + pthread_mutex_lock(&mg); + finalDataQueue.push(thisData); + pthread_mutex_unlock(&mg); + } + pthread_mutex_lock(&mp); + } + pthread_mutex_unlock(&mp); + + #ifdef VERBOSE - // cout << "delete data" << ffcdata << endl; + // cout << "delete data" << ffcdata << endl; #endif if (ffcdata) @@ -1965,11 +1969,11 @@ void* slsDetectorUtils::processData(int delflag) { #ifdef VERBOSE // cout << "delete ang " << ang << endl; #endif - if (ang) + if (ang) delete [] ang; - ang=NULL; - - + ang=NULL; + + } else { if (*correctionMask!=0) { writeDataFile (fname+string(".dat"), ffcdata, ffcerr); @@ -1983,7 +1987,9 @@ void* slsDetectorUtils::processData(int delflag) { delete [] ang; } else { thisData=new detectorData(ffcdata,ffcerr,NULL,getCurrentProgress(),(fname+string(ext)).c_str(),getTotalNumberOfChannels()); + pthread_mutex_lock(&mg); finalDataQueue.push(thisData); + pthread_mutex_unlock(&mg); } } } @@ -2054,10 +2060,12 @@ int* slsDetectorUtils::popDataQueue() { detectorData* slsDetectorUtils::popFinalDataQueue() { detectorData *retval=NULL; + pthread_mutex_unlock(&mg); if( !finalDataQueue.empty() ) { retval=finalDataQueue.front(); finalDataQueue.pop(); } + pthread_mutex_unlock(&mg); return retval; } @@ -2073,11 +2081,13 @@ void slsDetectorUtils::resetDataQueue() { void slsDetectorUtils::resetFinalDataQueue() { detectorData *retval=NULL; + pthread_mutex_lock(&mg); while( !finalDataQueue.empty() ) { retval=finalDataQueue.front(); finalDataQueue.pop(); delete retval; } + pthread_mutex_unlock(&mg); } diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.h b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h index 5b444a2e8..0d48b3542 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h @@ -3,6 +3,29 @@ #ifndef SLS_DETECTOR_UTILS_H #define SLS_DETECTOR_UTILS_H + +#ifdef __CINT__ +class pthread_mutex_t; +class pthread_t; +#endif + +extern "C" { +#include +} + +#include +#include +#include +#include +#include + + +#ifdef __MAKECINT__ +#pragma link off class _FTCOMSTAT-; +#pragma link off class _FTDCB-; +#endif + + //#include "MySocketTCP.h" #include #include @@ -10,16 +33,9 @@ #include #include #include - #include -extern "C" { - #include -} - #include - #include - #include - #include - #include +#include #include + using namespace std; @@ -95,12 +111,44 @@ class slsDetectorUtils : public slsDetectorBase { + using slsDetectorBase::setBadChannelCorrection; + using slsDetectorBase::getAngularConversion; + /** adds the detector with ID id in postion pos + \param id of the detector to be added (should already exist!) + \param pos position where it should be added (normally at the end of the list (default to -1) + \returns the actual number of detectors or -1 if it failed (always for slsDetector) + */ + virtual int addSlsDetector(int id, int pos=-1){return -1;}; + /** adds the detector name in position pos + \param name of the detector to be added (should already exist in shared memory or at least be online) + \param pos position where it should be added (normally at the end of the list (default to -1) + \return the actual number of detectors or -1 if it failed (always for slsDetector) + */ + virtual int addSlsDetector(char* name, int pos=-1){return -1;}; + /** + removes the detector in position pos from the multidetector + \param pos position of the detector to be removed from the multidetector system (defaults to -1 i.e. last detector) + \returns the actual number of detectors or -1 if it failed (always for slsDetector) + */ + virtual int removeSlsDetector(int pos=-1){return -1;}; + + /**removes the detector in position pos from the multidetector + \param name is the name of the detector + \returns the actual number of detectors or -1 if it failed (always for slsDetector) + */ + virtual int removeSlsDetector(char* name){return -1;}; + + /** + Turns off the server - do not use except for debugging! + */ + virtual int exitServer()=0; + @@ -287,10 +335,9 @@ class slsDetectorUtils : public slsDetectorBase { \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); - static int readDataFile(ifstream &infile, int *data, int nch, int offset=0); + static int readDataFile(ifstream &infile, int *data, int nch, int offset); /** @@ -301,7 +348,7 @@ class slsDetectorUtils : public slsDetectorBase { \sa mythenDetector::readDataFile */ static int readDataFile(string fname, short int *data, int nch); - static int readDataFile(ifstream &infile, short int *data, int nch, int offset=0); + static int readDataFile(ifstream &infile, short int *data, int nch, int offset); /** @@ -768,6 +815,9 @@ s */ int* popDataQueue(); + + + /** pops the data from thepostprocessed data queue \returns pointer to the popped data or NULL if the queue is empty. @@ -776,8 +826,6 @@ s detectorData* popFinalDataQueue(); - - /** resets the raw data queue \sa dataQueue @@ -790,6 +838,16 @@ s */ void resetFinalDataQueue(); + + + + + + + + + + /* virtual string getScanScript(int iscan)=0; */ /* virtual string getScanParameter(int iscan)=0; */ /* virtual string getActionScript(int iscan)=0; */ @@ -803,6 +861,25 @@ s /** temporary test fucntion */ int testFunction(int times=0); + /** + write register + \param addr address + \param val value + \returns current register value + + DO NOT USE!!! ONLY EXPERT USER!!! + */ + virtual int writeRegister(int addr, int val)=0; + + + /** + read register + \param addr address + \returns current register value + + DO NOT USE!!! ONLY EXPERT USER!!! + */ + virtual int readRegister(int addr)=0; protected: static const int64_t thisSoftwareVersion=0x20120124; @@ -904,10 +981,11 @@ s char *fileName; int *fileIndex; - - /** mutex to synchronize threads */ + /** mutex to synchronize main and data processing threads */ pthread_mutex_t mp; + /** mutex to synchronizedata processing and plotting threads */ + pthread_mutex_t mg; /** sets when the acquisition is finished */ int jointhread;