From ab4e569b6cee22dbf333d8c31ecb07c56b5e13e5 Mon Sep 17 00:00:00 2001 From: bergamaschi Date: Fri, 13 Apr 2012 13:03:53 +0000 Subject: [PATCH] After some speed optimization... git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@171 951219d9-93cf-4727-9268-0efd64621fa3 --- .../commonFiles/sls_detector_defs.h | 28 +- slsDetectorSoftware/doxy.config | 4 +- .../multiSlsDetector/multiSlsDetector.cpp | 47 ++- .../multiSlsDetector/multiSlsDetector.h | 2 +- .../slsDetector/slsDetector.cpp | 44 +-- slsDetectorSoftware/slsDetector/slsDetector.h | 41 +-- .../slsDetector/slsDetectorActions.h | 98 ++++-- .../slsDetector/slsDetectorBase.h | 53 ++- .../slsDetector/slsDetectorCommand.cpp | 67 +--- .../slsDetector/slsDetectorCommand.h | 5 +- .../slsDetector/slsDetectorUtils.cpp | 2 + .../slsDetector/slsDetectorUtils.h | 11 +- .../slsDetectorAnalysis/angularConversion.h | 258 +++++++++++---- .../slsDetectorAnalysis/detectorData.h | 4 +- .../slsDetectorAnalysis/energyConversion.h | 23 +- .../slsDetectorAnalysis/fileIO.h | 311 +++++++++++++----- .../slsDetectorAnalysis/postProcessing.cpp | 68 ++-- .../slsDetectorAnalysis/postProcessing.h | 10 +- 18 files changed, 714 insertions(+), 362 deletions(-) diff --git a/slsDetectorSoftware/commonFiles/sls_detector_defs.h b/slsDetectorSoftware/commonFiles/sls_detector_defs.h index 21af10e43..699c1d072 100755 --- a/slsDetectorSoftware/commonFiles/sls_detector_defs.h +++ b/slsDetectorSoftware/commonFiles/sls_detector_defs.h @@ -33,6 +33,8 @@ and to the server programs running on the detector #define GET_FLAG -1 #ifdef __cplusplus + +/** @short class containing all the structures, constants and enum definitions */ class slsDetectorDefs { public: @@ -47,7 +49,8 @@ class slsDetectorDefs { /** - structure for a detector channel + @short structure for a detector channel + should not be used by unexperienced users \see ::channelRegisterBit @@ -60,7 +63,8 @@ class slsDetectorDefs { } sls_detector_channel; /** - structure for a detector chip + @short structure for a detector chip + should not be used by unexperienced users \see ::chipRegisterBit ::channelRegisterBit */ @@ -75,7 +79,8 @@ class slsDetectorDefs { } sls_detector_chip; /** - structure for a detector module + @short structure for a detector module + should not be used by unexperienced users \see :: moduleRegisterBit ::chipRegisterBit :channelRegisterBit @@ -108,7 +113,7 @@ typedef struct { } sls_detector_module; /** - structure for a region of interest + @short structure for a region of interest xmin,xmax,ymin,ymax define the limits of the region */ @@ -119,14 +124,13 @@ typedef struct { int ymax; /**< is the roi ymax (in channel number)*/ } ROI ; -/** - structure for a generic integer array - -*/ -typedef struct { - int len; /**< is the number of elements of the array */ - int *iptr; /**< is the pointer to the array */ -} iarray ; +/* /\* */ +/* @short structure for a generic integer array */ +/* *\/ */ +/* typedef struct { */ +/* int len; /\**< is the number of elements of the array *\/ */ +/* int *iptr; /\**< is the pointer to the array *\/ */ +/* } iarray ; */ /** diff --git a/slsDetectorSoftware/doxy.config b/slsDetectorSoftware/doxy.config index 6f84fb41f..6fe021723 100644 --- a/slsDetectorSoftware/doxy.config +++ b/slsDetectorSoftware/doxy.config @@ -80,9 +80,7 @@ LATEX_HIDE_INDICES = YES PREDEFINED = __cplusplus -INPUT = slsDetector/slsDetectorBase.h commonFiles/sls_detector_defs.h - -#INPUT = slsDetector/slsDetector.h MySocketTCP/MySocketTCP.h usersFunctions/usersFunctions.h multiSlsDetector/multiSlsDetector.h commonFiles/sls_detector_defs.h slsDetector/slsDetectorUtils.h slsDetector/slsDetectorBase.h slsDetector/slsDetectorCommand.h multiSlsDetector/multiSlsDetector.h +INPUT = slsDetector/slsDetectorBase.h commonFiles/sls_detector_defs.h slsDetector/slsDetector.h MySocketTCP/MySocketTCP.h usersFunctions/usersFunctions.h multiSlsDetector/multiSlsDetector.h commonFiles/sls_detector_defs.h slsDetector/slsDetectorUtils.h slsDetector/slsDetectorBase.h slsDetector/slsDetectorCommand.h slsDetector/slsDetectorActions.h multiSlsDetector/multiSlsDetector.h slsDetectorAnalysis/detectorData.h slsDetectorAnalysis/energyConversion.h slsDetectorAnalysis/postProcessing.h slsDetectorAnalysis/angularConversion.h slsDetectorAnalysis/fileIO.h OUTPUT_DIRECTORY = docs diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index bfc35d665..549239b9b 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -1402,22 +1402,30 @@ int multiSlsDetector::setROI(int nroi, int *xmin, int *xmax, int *ymin, int *yma */ -float* multiSlsDetector::decodeData(int *datain) { - float *dataout=new float[thisMultiDetector->numberOfChannels]; - int ich=0; - float *detp; +float* multiSlsDetector::decodeData(int *datain, float *fdata) { + float *dataout; + if (fdata) + dataout=fdata; + else + dataout=new float[thisMultiDetector->numberOfChannels]; + + // int ich=0; + + float *detp=dataout; int *datap=datain; - + for (int i=0; inumberOfDetectors; i++) { if (detectors[i]) { - detp=detectors[i]->decodeData(datap); + detectors[i]->decodeData(datap, detp); datap+=detectors[i]->getDataBytes()/sizeof(int); - for (int j=0; jgetTotalNumberOfChannels(); j++) { - dataout[ich]=detp[j]; - ich++; - } - delete [] detp; + detp+=detectors[i]->getTotalNumberOfChannels(); + +// for (int j=0; jgetTotalNumberOfChannels(); j++) { +// dataout[ich]=detp[j]; +// ich++; +// } + //delete [] detp; } } @@ -3339,7 +3347,7 @@ int multiSlsDetector::writeDataFile(string fname, float *data, float *err, float ofstream outfile; int choff=0, off=0; //idata, float *pe=err, *pa=ang; - int nch_left=nch, n; + int nch_left=nch, n, nd; if (nch_left<=0) nch_left=getTotalNumberOfChannels(); @@ -3348,28 +3356,35 @@ int multiSlsDetector::writeDataFile(string fname, float *data, float *err, float if (data==NULL) return FAIL; - // args|=0x10; // one line per channel! - outfile.open (fname.c_str(),ios_base::out); if (outfile.is_open()) { for (int i=0; inumberOfDetectors; i++) { + if (detectors[i]) { n=detectors[i]->getTotalNumberOfChannels(); - if (nch_leftwriteDataFile(outfile,n, data+off, pe, pa, dataformat, choff); + nch_left-=n; + choff+=detectors[i]->getMaxNumberOfChannels(); + off+=n; + if (pe) pe=pe+off; + if (pa) pa=pa+off; + } + } - + outfile.close(); return OK; } else { diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h index 6c0df4d00..44da43619 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h @@ -721,7 +721,7 @@ class multiSlsDetector : public slsDetectorUtils { \param datain data from the detector \returns pointer to a float array with a data per channel */ - float* decodeData(int *datain); + float* decodeData(int *datain, float *fdata=NULL); diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index 4ff9feba4..8ad7d8b95 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -3199,14 +3199,16 @@ int* slsDetector::startAndReadAll(){ int* retval; +#ifdef VERBOSE int i=0; +#endif startAndReadAllNoWait(); //#ifdef VERBOSE // std::cout<< "started" << std::endl; //#endif while ((retval=getDataFromDetector())){ - i++; #ifdef VERBOSE + i++; std::cout<< i << std::endl; //#else //std::cout<< "-" << flush; @@ -3907,8 +3909,14 @@ int slsDetector::executeTrimming(trimMode mode, int par1, int par2, int imod){ }; -float* slsDetector::decodeData(int *datain) { - float *dataout=new float[thisDetector->nChans*thisDetector->nChips*thisDetector->nMods]; +float* slsDetector::decodeData(int *datain, float *fdata) { + + float *dataout; + if (fdata) + dataout=fdata; + else + dataout=new float[thisDetector->nChans*thisDetector->nChips*thisDetector->nMods]; + const int bytesize=8; int ival=0; @@ -3916,7 +3924,9 @@ float* slsDetector::decodeData(int *datain) { char iptr; int nbits=thisDetector->dynamicRange; + int nch=thisDetector->nChans*thisDetector->nChips*thisDetector->nMods; int ipos=0, ichan=0, ibyte; + if (thisDetector->timerValue[PROBES_NUMBER]==0) { switch (nbits) { case 1: @@ -3948,7 +3958,7 @@ float* slsDetector::decodeData(int *datain) { } break; case 16: - for (ichan=0; ichannChans*thisDetector->nChips*thisDetector->nMods; ichan++) { + for (ichan=0; ichannChans*thisDetector->nChips*thisDetector->nMods; ichan++) { + for (ichan=0; ichannChans*thisDetector->nChips*thisDetector->nMods; ichan++) { + for (ichan=0; ichannChans*thisDetector->nChips*thisDetector->nMods; ichan++) - dataout[ichan]=(datain[ichan]&0xffffff); - } else { - for (int ibyte=0; ibytedataBytes; ibyte++) { - for (int ibit=0; ibit>ibit)<dynamicRange) { - ipos=0; - dataout[ichan]=ival; - ichan++; - ival=0; - if (ichan>thisDetector->nChans*thisDetector->nChips*thisDetector->nMods){ - std::cout<< "error: decoding too many channels!" << ichan; - break; - } - } - } - } - } - */ #ifdef VERBOSE std::cout<< "decoded "<< ichan << " channels" << std::endl; #endif diff --git a/slsDetectorSoftware/slsDetector/slsDetector.h b/slsDetectorSoftware/slsDetector/slsDetector.h index 3cb1b96dc..f328abf82 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.h +++ b/slsDetectorSoftware/slsDetector/slsDetector.h @@ -10,40 +10,11 @@ #include "MySocketTCP.h" -//using namespace std; -/** - \mainpage Common C++ library for SLS detectors data acquisition - * - * \section intro_sec Introduction - - * \subsection mot_sec Motivation - Although the SLS detectors group delvelops several types of detectors (1/2D, counting/integrating etc.) it is common interest of the group to use a common platfor for data acquisition - \subsection arch_sec System Architecture - The architecture of the acquisitions system is intended as follows: - \li A socket server running on the detector (or more than one in some special cases) - \li C++ classes common to all detectors for client-server communication. These can be supplied to users as libraries and embedded also in acquisition systems which are not developed by the SLS \sa MySocketTCP slsDetector - \li the possibility of using a Qt-based graphical user interface (with eventually root analisys capabilities) - \li the possibility of runnin alla commands from command line. In order to ensure a fast operation of this so called "text client" the detector parameters should not be re-initialized everytime. For this reason a shared memory block is allocated where the main detector flags and parameters are stored \sa slsDetector::sharedSlsDetector - \section howto_sec How to use it - The best way to operate the slsDetectors is to use the software (text client or GUI) developed by the sls detectors group. -In case you need to embed the detector control in a previously existing software, compile these classes using
-make package -
-and link the shared library created to your software bin/libSlsDetector.so.1.0.1 -Then in your software you should use the class related to the detector you want to control (mythenDetector or eigerDetector). - - @author Anna Bergamaschi - -*/ - /** * - * -@libdoc The slsDetector class is expected to become the interface class for all SLS Detectors acquisition (and analysis) software. - * - * @short This is the base class for all SLS detector functionalities + * @short the slsDetector class takes care of the communication with the detector and all kind actions related with a single detector controller * @author Anna Bergamaschi * @version 0.1alpha */ @@ -54,6 +25,10 @@ Then in your software you should use the class related to the detector you want #define NCHANSMAX 65536 #define NDACSMAX 16 + +/** + @short complete detector functionalities for a single module detector +*/ class slsDetector : public slsDetectorUtils, public energyConversion { @@ -69,7 +44,9 @@ class slsDetector : public slsDetectorUtils, public energyConversion { /** - @short Structure allocated in shared memory to store detector settings and be accessed in parallel by several applications (take care of possible conflicts!) + @short Structure allocated in shared memory to store detector settings. + +Structure allocated in shared memory to store detector settings and be accessed in parallel by several applications on the same machine (take care of possible conflicts, particularly if things are run on different machines!) */ typedef struct sharedSlsDetector { @@ -1162,7 +1139,7 @@ typedef struct sharedSlsDetector { \param datain data from the detector \returns pointer to a float array with a data per channel */ - float* decodeData(int *datain); + float* decodeData(int *datain, float *fdata=NULL); diff --git a/slsDetectorSoftware/slsDetector/slsDetectorActions.h b/slsDetectorSoftware/slsDetector/slsDetectorActions.h index 50402c0b0..31183fe27 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorActions.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorActions.h @@ -15,14 +15,17 @@ using namespace std; /** -class implementing the script and scan utilities of the detectors +@short class implementing the script and scan utilities of the detectors */ class slsDetectorActions : public slsDetectorDefs { public : + /** default constructor */ slsDetectorActions(){}; + + /** virtual destructor */ virtual ~slsDetectorActions(){}; /** @@ -35,20 +38,23 @@ class slsDetectorActions : public slsDetectorDefs { int setAction(int iaction, string fname="", string par=""); /** - set action + set action script \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) + \param par for script \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} @@ -62,31 +68,61 @@ class slsDetectorActions : public slsDetectorDefs { \returns action parameter */ string getActionParameter(int iaction); - - /** - returns action mode - \param iaction can be enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript} - \returns action mode - */ + + /** + 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 script fname for script ("" disables, "none" disables and overwrites current, "threshold" threshold scan, "trimbits", trimbits scan) \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) + \param precision to write the scan varaible in the scan name (-1 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=""); + /** set scan script + \param index of the scan (0,1) + \param script fname for script ("" disables, "none" disables and overwrites current, "threshold" threshold scan, "trimbits", trimbits scan) + \returns 0 is scan disabled, >0 otherwise + */ + int setScanScript(int index, string script=""); + /** set scan script parameter + \param index of the scan (0,1) + \param script parameter for scan + \returns 0 is scan disabled, >0 otherwise + */ + int setScanParameter(int index, string par=""); + /** set scan script parameter + \param index of the scan (0,1) + \param precision scan varaible precision to be printed in file name + \returns 0 is scan disabled, >0 otherwise + */ int setScanPrecision(int index, int precision=-1); - int setScanSteps(int index, int nvalues=-1, float *values=NULL); - float getScanStep(int index, int istep){if (index0 otherwise + */ + int setScanSteps(int index, int nvalues=-1, float *values=NULL); + + /** get scan step + \param index of the scan (0,1) + \param istep step number + \returns value of the scan variable + */ + float getScanStep(int index, int istep){if (index=0 && istep>=0 && istep +In case you need to embed the detector control e.g in the beamline control software, compile these classes using +
+make package +
+and link the shared library created to your software slsDetectorSoftware/bin/libSlsDetector.so +
+The software can also be installed (with super-user rights)
+make install +
+
+Most methods of interest for the user are implemented in the ::slsDetectorBase interface class, but the classes to be implemented in the main program are either ::slsDetector (for single controller detectors) or ::multiSlsDetector (for multiple controllers, but can work also for single controllers). + +@author Anna Bergamaschi +@version 0.1alpha + +*/ + + + +/** + * + * + * + * @author Anna Bergamaschi + * @version 0.1alpha + */ #include "sls_detector_defs.h" @@ -11,8 +55,13 @@ using namespace std; /** +@libdoc The slsDetectorBase class is a minimal purely virtual interface class which should be instantiated by the users in their acquisition software (EPICS, spec etc.). More advanced configuration functions are not implemented and can be written in a configuration file tha can be read/written. + + This class contains the functions accessible by the users to control the slsDetectors (both multiSlsDetector and slsDetector) + * @short This is the base class for detector functionalities of interest for the users. + */ @@ -42,10 +91,10 @@ class slsDetectorBase : public slsDetectorDefs reads the IC (if required)
reads the encoder (iof required for angualr conversion)
processes the data (flat field, rate, angular conversion and merging ::processData()) - \param delflag 0 leaves the data in the final data queue + \param delflag 0 leaves the data in the final data queue (default is 1) \returns nothing */ - virtual void acquire(int delflag)=0; + virtual void acquire(int delflag=1)=0; /** asks and receives a data frame from the detector, writes it to disk and processes the data diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp index 6e833ea93..ca37127c6 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp @@ -653,7 +653,7 @@ string slsDetectorCommand::executeLine(int narg, char *args[], int action) { string slsDetectorCommand::cmdUnknown(int narg, char *args[], int action) { - return string("Unknown command ")+string(args[0])+string("\n");//+helpLine(narg, args, action); + return string("Unknown command ")+string(args[0])+string("\n")+helpLine(0, args, action); } string slsDetectorCommand::cmdUnderDevelopment(int narg, char *args[], int action) { @@ -672,7 +672,7 @@ string slsDetectorCommand::helpLine(int narg, char *args[], int action) { return helpAcquire(narg,args,HELP_ACTION); } - + if (narg==0) { os << "Command can be: " << endl; for(int i=0; i=1) + return helpLine(narg-1, args+1, action); + else + return helpLine(0, args, action); + } diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.h b/slsDetectorSoftware/slsDetector/slsDetectorCommand.h index f3ac8ed08..d7bb4b378 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorCommand.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.h @@ -8,10 +8,9 @@ using namespace std; -/* /\** This class handles the command line I/Os, help etc. */ -/* It is inherited by both slsDetector and multiSlsDetector */ +/** @short This class handles the command line I/Os, help etc. of the text clients */ + -/* *\/ */ class slsDetectorCommand : public slsDetectorDefs { public: diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp index 377a26431..de032fb0a 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp @@ -477,6 +477,8 @@ float slsDetectorUtils::getCurrentProgress() { return 100.*((float)progressIndex)/((float)totalProgress); } + + void slsDetectorUtils::incrementProgress() { progressIndex++; cout << fixed << setprecision(2) << setw (6) << getCurrentProgress() << " \%"; diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.h b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h index 32396ce84..aa99c634c 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h @@ -52,7 +52,11 @@ using namespace std; #define DEFAULT_HOSTNAME "localhost" #define DEFAULT_SHM_KEY 5678 +/** + @short class containing all the possible detector functionalities + (used in the PSi command line interface) +*/ class slsDetectorUtils : public slsDetectorActions, public postProcessing, public slsDetectorBase { @@ -87,6 +91,11 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing, publi int getScanPrecision(int i){return slsDetectorActions::getScanPrecision(i);}; + int getActionMask() {return slsDetectorActions::getActionMask();}; + float getCurrentScanVariable(int i) {return slsDetectorActions::getCurrentScanVariable(i);}; + int getCurrentPositionIndex(){return angularConversion::getCurrentPositionIndex();}; + int getNumberOfPositions(){return angularConversion::getNumberOfPositions();}; + string getFlatFieldCorrectionDir(){return postProcessing::getFlatFieldCorrectionDir();}; string setFlatFieldCorrectionDir(string s){return postProcessing::setFlatFieldCorrectionDir(s);}; @@ -374,7 +383,7 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing, publi \returns nothing */ - void acquire(int delflag); + void acquire(int delflag=1); // float* convertAngles(){return convertAngles(currentPosition);}; diff --git a/slsDetectorSoftware/slsDetectorAnalysis/angularConversion.h b/slsDetectorSoftware/slsDetectorAnalysis/angularConversion.h index 4a0fe84f0..256a449e8 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/angularConversion.h +++ b/slsDetectorSoftware/slsDetectorAnalysis/angularConversion.h @@ -15,7 +15,7 @@ using namespace std; /** - angular conversion constant for a module + @short Angular conversion constants needed for a detector module */ typedef struct { float center; /**< center of the module (channel at which the radius is perpendicular to the module surface) */ @@ -30,14 +30,20 @@ typedef struct { /** - class containing the methods to set/unset the angular conversion and merge the data - The angular conversion itself is stored in the slsDetector/multiSlsDetector class! +@short methods to set/unset the angular conversion and merge the data +class containing the methods to set/unset the angular conversion and merge the data + + +The angular conversion itself is defined by the angle() function defined in usersFunctions.cpp + */ class angularConversion : public slsDetectorDefs { public: + /** default constructor */ angularConversion(); + /** virtual destructor */ virtual ~angularConversion(); @@ -51,45 +57,68 @@ class angularConversion : public slsDetectorDefs { reads an angular conversion file \param fname file to be read + \param nmod number of modules (maximum) to be read + \param angOff pointer to array of angleConversionConstants + \returns OK or FAIL */ static int readAngularConversion(string fname, int nmod, angleConversionConstant *angOff); /** - - MOVE TO ANGULAR CALIBRATION?!?!??!? reads an angular conversion file - \param fname file to be read + \param ifstream input file stream to be read + \param nmod number of modules (maximum) to be read + \param angOff pointer to array of angleConversionConstants + \returns OK or FAIL + */ static int readAngularConversion(ifstream& ifs, int nmod, angleConversionConstant *angOff); /** - MOVE TO ANGULAR CALIBRATION?!?!??!? writes an angular conversion file \param fname file to be written - \sa angleConversionConstant mythenDetector::writeAngularConversion + \param nmod number of modules to be written + \param angOff pointer to array of angleConversionConstants + \returns OK or FAIL */ static int writeAngularConversion(string fname, int nmod, angleConversionConstant *angOff); + /** - MOVE TO ANGULAR CALIBRATION?!?!??!? writes an angular conversion file - \param fname file to be written - \sa angleConversionConstant mythenDetector::writeAngularConversion + \param ofstream output file stream + \param nmod number of modules to be written + \param angOff pointer to array of angleConversionConstants + \returns OK or FAIL */ static int writeAngularConversion(ofstream& ofs, int nmod, angleConversionConstant *angOff); + /** + pure virtual function + \param file name to be written (nmod and array of angular conversion constants default to the ones ot the slsDetector + */ virtual int writeAngularConversion(string fname)=0; /** - MOVE TO ANGULAR CALIBRATION?!?!??!? - 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 - */ + sets the arrays of the merged data to 0. NB The array should be created with size nbins >= 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 + \param nbins number of bins + \returns OK or FAIL + */ static int resetMerging(float *mp, float *mv,float *me, int *mm, int nbins); + /** + 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 + */ int resetMerging(float *mp, float *mv,float *me, int *mm); + + /** + creates the arrays for merging the data and sets them to 0. + */ int resetMerging(); /** @@ -110,92 +139,152 @@ class angularConversion : public slsDetectorDefs { static int addToMerging(float *p1, float *v1, float *e1, float *mp, float *mv,float *me, int *mm, int nchans, float binsize,int nb, int *badChanMask ); + /** + 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 + \param badChanMask badchannelmask (if NULL does not correct for bad channels) + \returns OK or FAIL + */ + int addToMerging(float *p1, float *v1, float *e1, float *mp, float *mv,float *me, int *mm, int *badChanMask); + /** + merge dataset + \param p1 angular positions of dataset + \param v1 data + \param e1 errors + \param badChanMask badchannelmask (if NULL does not correct for bad channels) + \returns OK or FAIL + */ int addToMerging(float *p1, float *v1, float *e1,int *badChanMask); /** - MOVE TO ANGULAR CALIBRATION?!?!??!? - calculates the "final" positions, data value and errors for the emrged data + calculates the "final" positions, data value and errors for the merged data + \param mp already merged postions + \param mv already merged data + \param me already merged errors (squared sum) + \param mm multiplicity of merged arrays + \param nb number of bins + \returns FAIL or the number of non empty bins (i.e. points belonging to the pattern) + */ + + static int finalizeMerging(float *mp, float *mv,float *me, int *mm, int nb); + /** + calculates the "final" positions, data value and errors for the merged 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, int nb); + int finalizeMerging(float *mp, float *mv,float *me, int *mm); + +/** + calculates the "final" positions, data value and errors for the merged data + \returns FAIL or the number of non empty bins (i.e. points belonging to the pattern) + */ - int finalizeMerging(float *mp, float *mv,float *me, int *mm); int finalizeMerging(); /** - pure virtual function set detector global offset - \sa mythenDetector::setGlobalOffset + \param f global offset to be set + \returns actual global offset */ float setGlobalOffset(float f){return setAngularConversionParameter(GLOBAL_OFFSET,f);}; + /** - pure virtual function set detector fine offset - \sa mythenDetector::setFineOffset + \param f global fine to be set + \returns actual fine offset */ float setFineOffset(float f){return setAngularConversionParameter(FINE_OFFSET,f);}; + /** - pure virtual function get detector fine offset - \sa mythenDetector::getFineOffset + \returns actual fine offset */ float getFineOffset(){return getAngularConversionParameter(FINE_OFFSET);}; /** - pure virtual function get detector global offset - \sa mythenDetector::getGlobalOffset + \returns actual global offset */ float getGlobalOffset(){return getAngularConversionParameter(GLOBAL_OFFSET);}; /** - set detector bin size used for merging (approx angular resolution) - \param bs bin size in degrees - \returns current bin size - \sa mythenDetector::setBinSize -*/ + set detector bin size + \param bs bin size to be set + \returns actual bin size + */ float setBinSize(float bs){return setAngularConversionParameter(BIN_SIZE,bs);}; /** - return detector bin size used for merging (approx angular resolution) - \sa mythenDetector::getBinSize + get detector bin size + \returns detector bin size used for merging (approx angular resolution) */ float getBinSize() {return getAngularConversionParameter(BIN_SIZE);}; + /** + + get angular direction + \returns actual angular direction (1 is channel number increasing with angle, -1 decreasing) + */ int getAngularDirection(){return (int)getAngularConversionParameter(ANGULAR_DIRECTION);}; + /** + + set angular direction + \param d angular direction to be set (1 is channel number increasing with angle, -1 decreasing) + \returns actual angular direction (1 is channel number increasing with angle, -1 decreasing) + */ int setAngularDirection(int d){return (int)setAngularConversionParameter(ANGULAR_DIRECTION, (float)d);}; - + /** + \returns number of angular bins in the merging (360./binsize) + */ int getNumberOfAngularBins(){return nBins;}; /** - get angular conversion - \param direction reference to diffractometer direction + get angular conversion + \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 */ virtual int getAngularConversion(int &direction, angleConversionConstant *angconv=NULL)=0; - float setAngularConversionParameter(angleConversionParameter c, float v); + /** + set angular conversion parameter + \param c parameter type (globaloffset, fineoffset, binsize, angular direction, move flag) + \param v value to be set + \returns actual value + */ + float setAngularConversionParameter(angleConversionParameter c, float v); + /** + get angular conversion parameter + \param c parameter type (globaloffset, fineoffset, binsize, angular direction, move flag) + \returns actual value + */ float getAngularConversionParameter(angleConversionParameter c); - + /** + pure virtual function + \returns total number of channels of the (multi)detector + */ virtual int getTotalNumberOfChannels()=0; @@ -214,10 +303,23 @@ class angularConversion : public slsDetectorDefs { */ virtual int getPositions(float *pos=NULL); + /** + deletes the array of merged data + \returns OK + */ int deleteMerging(); + /** + \returns pointer to the array o merged positions + */ float *getMergedPositions(){return mergingBins;}; + /** + \returns pointer to the array of merged counts + */ float *getMergedCounts(){return mergingCounts;}; + /** + \returns pointer to the array of merged errors + */ float *getMergedErrors(){return mergingErrors;}; @@ -237,42 +339,86 @@ class angularConversion : public slsDetectorDefs { string getAngularConversionFile(){if (setAngularCorrectionMask()) return string(angConvFile); else return string("none");}; + /** + reads teh angular conversion file for the (multi)detector and writes it to shared memory + */ virtual int readAngularConversionFile(string fname="")=0; - // int setAngularConversionPointer(angleConversionConstant *p, int *nm, int nch, int idet=0); - + /** + \returns number of modules of the (multi)detector + */ virtual int getNMods()=0; + + /** + returns number of channels in the module + \param imod module number + \returns number of channels in the module + */ virtual int getChansPerMod(int imod=0)=0; + + /** + get the angular conversion contant of one modules + \param imod module number + \returns pointer to the angular conversion constant + */ virtual angleConversionConstant *getAngularConversionPointer(int imod=0)=0; + /** + converts channel number to angle + \param pos encoder position + \returns array of angles corresponding to the channels + */ float* convertAngles(float pos); - + /** + converts channel number to angle for the current encoder position + \returns array of angles corresponding to the channels + */ float *convertAngles(){return convertAngles(currentPosition);}; + /** + \param imod module number + \returns move flag of the module (1 encoder is added to the angle, 0 not) + */ virtual int getMoveFlag(int imod)=0; + /** + returns current position index + */ int getCurrentPositionIndex() {return currentPositionIndex;}; + + /** + returns number of positions + */ int getNumberOfPositions() {return *numberOfPositions;}; protected: - + /** pointer to number of positions for the acquisition*/ int *numberOfPositions; + + /** pointer to the detector positions for the acquisition*/ float *detPositions; + /** pointer to angular conversion file name*/ char *angConvFile; + /** pointer to angular bin size*/ float *binSize; + + /** pointer to beamlien fine offset*/ float *fineOffset; + /** pointer to beamlien global offset*/ float *globalOffset; + /** pointer to beamlien angular direction*/ int *angDirection; + /** pointer to detector move flag (1 moves with encoder, 0 not)*/ int *moveFlag; - + /** number of bins for angular conversion (360./binsize)*/ int nBins; @@ -287,6 +433,12 @@ class angularConversion : public slsDetectorDefs { */ int currentPositionIndex; + + /** + enables/disable the angular conversion + \param i 1 sets, 0 unsets,, -1 gets + \returns actual angular conversion flag + */ virtual int setAngularCorrectionMask(int i=-1)=0; @@ -303,12 +455,6 @@ class angularConversion : public slsDetectorDefs { /** merging multiplicity */ int *mergingMultiplicity; - /** pointer to the angular conversion constants for the (multi)detector class*/ - -/* angleConversionConstant *angOff[MAXDET]; */ -/* int *nMods[MAXDET]; */ -/* int nCh[MAXDET]; */ - }; diff --git a/slsDetectorSoftware/slsDetectorAnalysis/detectorData.h b/slsDetectorSoftware/slsDetectorAnalysis/detectorData.h index febe62883..dfc8ae586 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/detectorData.h +++ b/slsDetectorSoftware/slsDetectorAnalysis/detectorData.h @@ -3,7 +3,9 @@ #include /** - data structure to hold the detector data after postprocessing (e.g. to plot, store in a root tree etc.) + @short data structure to hold the detector data after postprocessing + + (e.g. to plot, store in a root tree etc.) */ class detectorData { public: diff --git a/slsDetectorSoftware/slsDetectorAnalysis/energyConversion.h b/slsDetectorSoftware/slsDetectorAnalysis/energyConversion.h index 2584de613..aacbbb5cf 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/energyConversion.h +++ b/slsDetectorSoftware/slsDetectorAnalysis/energyConversion.h @@ -5,19 +5,23 @@ #include using namespace std; - +/** + @short class handling the energy calibration and trim files IO +*/ class energyConversion: public slsDetectorDefs { public: + /** default constrauctor */ energyConversion(){}; + /** default destructor */ virtual ~energyConversion(){}; /** - reads a calibration file MOVE TO ENERGY CALIBRATION?!?!??!? + reads a calibration file \param fname file to be read \param gain reference to the gain variable \offset reference to the offset variable @@ -26,7 +30,7 @@ class energyConversion: public slsDetectorDefs { /** - writes a calibration file MOVE TO ENERGY CALIBRATION?!?!??!? + writes a calibration file \param fname file to be written \param gain \param offset @@ -37,9 +41,9 @@ class energyConversion: public slsDetectorDefs { /** reads a trim/settings file \param fname name of the file to be read + \param myDetectorType detector type (needed for number of channels, chips, dacs etc.) \param myMod pointer to the module structure which has to be set.
If it is NULL a new module structure will be created \returns the pointer to myMod or NULL if reading the file failed - \sa mythenDetector::readSettingsFile */ sls_detector_module* readSettingsFile(string fname, detectorType myDetectorType, sls_detector_module* myMod=NULL); @@ -47,6 +51,7 @@ class energyConversion: public slsDetectorDefs { /** writes a trim/settings file \param fname name of the file to be written + \param myDetectorType detector type (needed for number of channels, chips, dacs etc.) \param mod module structure which has to be written to file \returns OK or FAIL if the file could not be written @@ -54,12 +59,20 @@ class energyConversion: public slsDetectorDefs { */ int writeSettingsFile(string fname, detectorType myDetectorType, sls_detector_module mod); - + /** allocates the momery for a detector module structure + \param myDetectorType detector type (needed for number of channels, chips, dacs etc.) + \returns pointer to detector module + */ virtual sls_detector_module* createModule(detectorType myDetectorType)=0; + /** + frees the memory of a detector module structure + \param myMod pointer to memeory to be freed + */ virtual void deleteModule(sls_detector_module *myMod)=0; protected: + /** pointer to settings file name */ char *settingsFile; diff --git a/slsDetectorSoftware/slsDetectorAnalysis/fileIO.h b/slsDetectorSoftware/slsDetectorAnalysis/fileIO.h index 15254439d..d4ce84194 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/fileIO.h +++ b/slsDetectorSoftware/slsDetectorAnalysis/fileIO.h @@ -12,44 +12,54 @@ #include using namespace std; - +/** + @short class handling the data file I/O flags +*/ class fileIO : public slsDetectorDefs { public: + /** default constructor */ fileIO(){}; + /** virtual destructor */ virtual ~fileIO(){}; /** sets the default output files path + \param s file path + \return actual file path */ string setFilePath(string s) {sprintf(filePath, s.c_str()); return string(filePath);}; /** sets the default output files root name + \param s file name to be set + \returns actual file name */ string setFileName(string s) {sprintf(fileName, s.c_str()); return string(fileName);}; /** sets the default output file index + \param i start file index to be set + \returns actual file index */ int setFileIndex(int i) {*fileIndex=i; return *fileIndex;}; /** - returns the default output files path - \sa sharedSlsDetector + \returns the output files path + */ string getFilePath() {return string(filePath);}; /** - returns the default output files root name + \returns the output files root name */ string getFileName() {return string(fileName);}; /** - returns the default output file index + \returns the output file index */ int getFileIndex() {return *fileIndex;}; @@ -62,10 +72,10 @@ class fileIO : public slsDetectorDefs { always appends to file path and file name the run index. - in case also appends the position index + in case also appends the position index and the two level of scan varaibles with the specified precision - Filenames will be of the form: filepath/filename(_px)_i - where x is the position index and i is the run index + Filenames will be of the form: filepath/filename(_Sy_sw_px)_i + where y is the scan0 variable, W is the scan 1 variable, 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) @@ -80,13 +90,16 @@ class fileIO : public slsDetectorDefs { */ 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 */ virtual string createFileName(); - /** static function that returns the file index from the file name + /** static function that returns the file index from the file name \param fname file name - \returns file index*/ - static int getFileIndexFromFileName(string fname); + \returns file index + */ + static int getFileIndexFromFileName(string fname); /** static function that returns the variables from the file name \param fname file name @@ -96,187 +109,307 @@ class fileIO : public slsDetectorDefs { \param sv1 reference to scan variable 1 \returns file index */ - static int getVariablesFromFileName(string fname, int &index, int &p_index, float &sv0, float &sv1); + 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 - + writes a data file + \param fname 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); - int writeDataFile(ofstream &outfile, float *data, float *err=NULL, float *ang=NULL, char dataformat='f', int nch=-1, int offset=0); /** - - 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 + + writes a data file + \paramoutfile output file stream + \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 + \param offset start channel number + \returns OK or FAIL if it could not write the file or data=NULL + + */ + int writeDataFile(ofstream &outfile, float *data, float *err=NULL, float *ang=NULL, char dataformat='f', int nch=-1, int offset=0); + + + /** + writes a data file + \param fname 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 */ virtual int writeDataFile(string fname, int *data); + + /** + writes a data file + \param outfile output file stream + \param data array of data values + \param offset start channel number + \returns OK or FAIL if it could not write the file or data=NULL + */ int writeDataFile(ofstream &outfile, int *data, int offset=0); /** - - writes a data file - \param name of the file to be written + writes a data file of short ints + \param fname 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, short int *data); + virtual int writeDataFile(string fname, short int *data); + + /** + writes a data file of short ints + \param outfile output file stream + \param data array of data values + \param offset start channel number + \returns OK or FAIL if it could not write the file or data=NULL + */ int writeDataFile(ofstream &outfile, short int *data, int offset=0); /** - reads a data file - \param name of the file to be read + \param fname 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 - */ virtual int readDataFile(string fname, float *data, float *err=NULL, float *ang=NULL, char dataformat='f'); + + /** + reads a data file + \param ifstream input file stream + \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 offset start channel number to be expected + \returns OK or FAIL if it could not read the file or data=NULL + */ int readDataFile(ifstream& infile, float *data, float *err=NULL, float *ang=NULL, char dataformat='f', int offset=0); /** - - reads a data file - \param name of the file to be read + reads a raw data file + \param fname 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 */ - virtual int readDataFile(string fname, int *data); + virtual int readDataFile(string fname, int *data); /** + reads a raw data file + \param infile input file stream + \param data array of data values + \param offset first channel number to be expected + \returns OK or FAIL if it could not read the file or data=NULL + */ int readDataFile(ifstream &infile, int *data, int offset=0); /** - reads a data file - \param name of the file to be read + reads a short int raw data file + \param fname 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 */ - virtual int readDataFile(string fname, short int *data); + virtual int readDataFile(string fname, short int *data); + /** + reads a short int raw data file + \param infile input file stream + \param data array of data values + \param offset first channel number to be expected + \returns OK or FAIL if it could not read the file or data=NULL + */ int readDataFile(ifstream &infile, short int *data, int offset=0); /** writes a data file - \param name of the file to be written + \param fname of the file to be written + \param nch number of channels 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 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'); + static int writeDataFile(string fname, int nch, float *data, float *err=NULL, float *ang=NULL, char dataformat='f'); + /** + writes a data file + \param outfile output file stream + \param nch number of channels 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 offset start channel number + \returns OK or FAIL if it could not write the file or data=NULL + */ static int writeDataFile(ofstream &outfile, int nch, float *data, float *err=NULL, float *ang=NULL, char dataformat='f', int offset=0); /** - - writes a data file - \param name of the file to be written + writes a raw data file + \param fname of the file to be written + \param nch number of channels \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); + static int writeDataFile(string fname,int nch, int *data); + + /** + writes a raw data file + \param outfile output file stream + \param nch number of channels + \param data array of data values + \param offset start channel number + \returns OK or FAIL if it could not write the file or data=NULL + */ static int writeDataFile(ofstream &outfile,int nch, int *data, int offset=0); - /** - writes a data file - \param name of the file to be written + writes a short int raw data file + \param fname of the file to be written + \param nch number of channels \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, short int *data); + static int writeDataFile(string fname,int nch, short int *data); + + /** + writes a short int raw data file + \param outfile output file stream + \param nch number of channels + \param data array of data values + \param offset start channel number + \returns OK or FAIL if it could not write the file or data=NULL + */ static int writeDataFile(ofstream &outfile,int nch, short int *data, int offset=0); - /** - + + + /** reads a data file - \param name of the file to be read + \param nch number of channels + \param fname 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'); + static int readDataFile(int nch, string fname, float *data, float *err=NULL, float *ang=NULL, char dataformat='f'); + /** + reads a data file + \param nch number of channels + \param infile input file stream + \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 offset start channel number + \returns number of channels read or -1 if it could not read the file or data=NULL + + */ static int readDataFile(int nch, ifstream &infile, float *data, float *err=NULL, float *ang=NULL, char dataformat='f', int offset=0); /** - - reads a data file - \param name of the file to be read + reads a raw data file + \param fname of the file to be read \param data array of data values + \param nch number of channels \returns OK or FAIL if it could not read the file or data=NULL */ static int readDataFile(string fname, int *data, int nch); + + /** + reads a raw data file + \param infile input file stream + \param data array of data values + \param nch number of channels + \param offset start channel value + \returns OK or FAIL if it could not read the file or data=NULL + */ static int readDataFile(ifstream &infile, int *data, int nch, int offset); /** - - reads a data file + reads a short int rawdata file \param name of the file to be read \param data array of data values + \param nch number of channels \returns OK or FAIL if it could not read the file or data=NULL - \sa mythenDetector::readDataFile */ - static int readDataFile(string fname, short int *data, int nch); + static int readDataFile(string fname, short int *data, int nch); + /** + reads a short int raw data file + \param infile input file stream + \param data array of data values + \param nch number of channels + \param offset start channel value + \returns OK or FAIL if it could not read the file or data=NULL + */ static int readDataFile(ifstream &infile, short int *data, int nch, int offset); + + /** + \returns action mask + */ + virtual int getActionMask()=0;// {return 0;}; + /** + \param index scan level index + \returns current scan variable + */ + virtual float getCurrentScanVariable(int index)=0;// {return 0;}; + /** + \param index scan level index + \returns current scan variable precision (for file name) + */ + virtual int getScanPrecision(int index)=0;// {return 0;}; + /** + \returns current position index + */ + virtual int getCurrentPositionIndex()=0;// {return 0;}; + /** + \returns number of positions + */ + virtual int getNumberOfPositions()=0;// {return 0;}; - virtual int getActionMask() {return 0;}; - - virtual float getCurrentScanVariable(int index) {return 0;}; - virtual int getScanPrecision(int index) {return 0;}; - - virtual int getCurrentPositionIndex() {return 0;}; - virtual int getNumberOfPositions() {return 0;}; - + /** + \returns total number of channels + */ virtual int getTotalNumberOfChannels()=0; protected: - - - char *filePath; - char *fileName; - int *fileIndex; + + /** output directory */ + char *filePath; + /** file root name */ + char *fileName; + /** file index */ + int *fileIndex; }; diff --git a/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp b/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp index 411acb802..4b7e9063d 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp +++ b/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp @@ -127,34 +127,34 @@ int postProcessing::setBadChannelCorrection(string fname, int &nbad, int *badlis void postProcessing::processFrame(int *myData, int delflag) { string fname; - float *fdata; + // float *fdata=NULL; - incrementProgress(); - - /** decode data */ - fdata=decodeData(myData); - - fname=createFileName(); - + incrementProgress(); + + /** decode data */ + + fdata=decodeData(myData, fdata); + + fname=createFileName(); + //uses static function?!?!?!? - // writeDataFile (fname+string(".raw"), getTotalNumberOfChannels(),fdata, NULL, NULL, 'i'); writeDataFile (fname+string(".raw"),fdata, NULL, NULL, 'i'); - doProcessing(fdata,delflag); + doProcessing(fdata,delflag); - delete [] myData; - myData=NULL; + delete [] myData; + myData=NULL; #ifdef VERBOSE // cout << "Pop data queue " << *fileIndex << endl; #endif - + pthread_mutex_lock(&mp); dataQueue.pop(); //remove the data from the queue queuesize=dataQueue.size(); pthread_mutex_unlock(&mp); - + } @@ -174,20 +174,15 @@ void postProcessing::doProcessing(float *fdata, int delflag) { detectorData *thisData; - - if (*correctionMask!=0) { - ext=".dat"; - } else { - ext=".raw"; - } - - fname=createFileName(); - /** write raw data file */ if (*correctionMask==0 && delflag==1) { - delete [] fdata; + // delete [] fdata; + ; } else { + ext=".dat"; + fname=createFileName(); + /** rate correction */ if (*correctionMask&(1<0) { - /** Pop data queue */ myData=dataQueue.front(); // get the data from the queue pthread_mutex_unlock(&mp); - - + if (myData) { - processFrame(myData,delflag); - - usleep(1000); + //usleep(1000); } - pthread_mutex_unlock(&mp); - usleep(1000); + pthread_mutex_lock(&mp); } - - pthread_mutex_unlock(&mp); + + /* IF THERE ARE NO DATA look if acquisition is finished */ pthread_mutex_lock(&mp); if (jointhread) { if (dataQueue.size()==0) { pthread_mutex_unlock(&mp); break; } - - pthread_mutex_unlock(&mp); } else { pthread_mutex_unlock(&mp); } dum=0; } + + if (fdata) + delete [] fdata; return 0; } diff --git a/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.h b/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.h index 3663f1655..da1b6cd8b 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.h +++ b/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.h @@ -25,6 +25,12 @@ using namespace std; #define defaultTDead {170,90,750} /**< should be changed in order to have it separate for the different detector types */ + +/** + @short methods for data postprocessing + + (including thread for writing data files and plotting in parallel with the acquisition) +*/ class postProcessing : public angularConversion, public fileIO { @@ -232,7 +238,7 @@ s virtual int setTotalProgress()=0; - virtual float* decodeData(int *datain)=0; + virtual float* decodeData(int *datain, float *fdata=NULL)=0; virtual int getTotalNumberOfChannels()=0; @@ -353,7 +359,7 @@ s */ float currentI0; - + float *fdata;