After some speed optimization...

git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@171 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
bergamaschi
2012-04-13 13:03:53 +00:00
parent 3ddafe3baf
commit ab4e569b6c
18 changed files with 714 additions and 362 deletions

View File

@ -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; ichan<thisDetector->nChans*thisDetector->nChips*thisDetector->nMods; ichan++) {
for (ichan=0; ichan<nch; ichan++) {
// dataout[ichan]=0;
ival=0;
for (ibyte=0; ibyte<2; ibyte++) {
@ -3959,40 +3969,18 @@ float* slsDetector::decodeData(int *datain) {
}
break;
default:
for (ichan=0; ichan<thisDetector->nChans*thisDetector->nChips*thisDetector->nMods; ichan++) {
for (ichan=0; ichan<nch; ichan++) {
ival=datain[ichan]&0xffffff;
dataout[ichan]=ival;
}
}
} else {
for (ichan=0; ichan<thisDetector->nChans*thisDetector->nChips*thisDetector->nMods; ichan++) {
for (ichan=0; ichan<nch; ichan++) {
dataout[ichan]=datain[ichan];
}
}
/*
if (nbits==32) {
for (ichan=0; ichan<thisDetector->nChans*thisDetector->nChips*thisDetector->nMods; ichan++)
dataout[ichan]=(datain[ichan]&0xffffff);
} else {
for (int ibyte=0; ibyte<thisDetector->dataBytes; ibyte++) {
for (int ibit=0; ibit<bytesize; ibit++) {
ival|=(ptr[ibyte]&(one<<ibit)>>ibit)<<ipos++;
if (ipos==thisDetector->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

View File

@ -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 <BR>
make package
<br>
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);

View File

@ -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 (index<MAX_SCAN_LEVELS && istep<MAX_SCAN_STEPS) return scanSteps[index][istep]; else return -1;};
/** set scan steps
\param index of the scan (0,1)
\param nvalues number of steps
\param values pointer to array of values
\returns 0 is scan disabled, >0 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<MAX_SCAN_LEVELS && index>=0 && istep>=0 && istep<MAX_SCAN_STEPS) return scanSteps[index][istep]; else return -1;};
/**
returns scan script
\param iscan can be (0,1)
@ -112,7 +148,7 @@ class slsDetectorActions : public slsDetectorDefs {
returns scan steps
\param iscan can be (0,1)
\param v is the pointer to the scan steps
\returns scan steps
\returns number of scan steps
*/
int getScanSteps(int iscan, float *v=NULL);
@ -125,25 +161,47 @@ class slsDetectorActions : public slsDetectorDefs {
int getScanPrecision(int iscan);
/** calculates the total number of steps for the acquisition
\returns total number of steps for the acquisitions
*/
virtual int setTotalProgress()=0;
/**
\returns the action mask
*/
int getActionMask() {if (actionMask) return *actionMask; return 0;};
/**
\param index scan level index
\returns value of the current scan variable
*/
float getCurrentScanVariable(int index) {return currentScanVariable[index];};
// int getScanPrecision(int index) {return scanPrecision[index];};
protected:
int *actionMask;
mystring *actionScript;
/** action mask */
int *actionMask;
/** array of action scripts */
mystring *actionScript;
/** array of actionparameters */
mystring *actionParameter;
/** pointer to number of steps [2] */
int *nScanSteps;
/** pointer to arrays of step values [2] */
mysteps *scanSteps;
/** pointer to array of scan mode [2] */
int *scanMode;
/** POINTER TO ARRAY OF SCAN PRECISION [2] */
int *scanPrecision;
/** pointer to array of scan scripts [2] */
mystring *scanScript;
/** pointer to array of scan parameters [2] */
mystring *scanParameter;

View File

@ -1,6 +1,50 @@
#ifndef SLS_DETECTOR_BASE_H
#define SLS_DETECTOR_BASE_H
/**
\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
\li the possibility of using a Qt-based graphical user interface (with eventually root analisys capabilities)
\li the possibility of running all 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
\li a Root library for data postprocessing and detector calibration (energy, angle).
\section howto_sec How to use it
The detectors can be simply operated by using the provided GUi or command line executable. <br>
In case you need to embed the detector control e.g in the beamline control software, compile these classes using
<BR>
make package
<br>
and link the shared library created to your software slsDetectorSoftware/bin/libSlsDetector.so
<br>
The software can also be installed (with super-user rights)<br>
make install
<br>
<br>
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) <br>
reads the encoder (iof required for angualr conversion) <br>
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

View File

@ -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<numberOfCommands; ++i) {
@ -681,62 +681,11 @@ string slsDetectorCommand::helpLine(int narg, char *args[], int action) {
os << endl;
return os.str();
}
return executeLine(narg,args,HELP_ACTION);
// os << helpAcquire(narg,args,action) << endl;
// os << helpData(narg,args,action) << endl;
// os << helpFrame(narg,args,action) << endl;
// os << helpStatus(narg,args,action) << endl;
// os << helpFree(narg,args,action) << endl;
// os << helpAdd(narg,args,action) << endl;
// os << helpRemove(narg,args,action) << endl;
// os << helpHostname(narg,args,action) << endl;
// os << helpId(narg,args,action) << endl;
// os << helpMaster(narg,args,action) << endl;
// os << helpSync(narg,args,action) << endl;
// os << helpExitServer(narg,args,action) << endl;
// os << helpSettingsDir(narg,args,action) << endl;
// os << helpCalDir(narg,args,action) << endl;
// os << helpOutDir(narg,args,action) << endl;
// os << helpFileName(narg,args,action) << endl;
// os << helpFileIndex(narg,args,action) << endl;
// os << helpFlatField(narg,args,action) << endl;
// os << helpRateCorr(narg,args,action) << endl;
// os << helpBadChannels(narg,args,action) << endl;
// os << helpAngConv(narg,args,action) << endl;
// os << helpThreaded(narg,args,action) << endl;
// os << helpPositions(narg,args,action) << endl;
// os << helpScripts(narg,args,action) << endl;
// os << helpScans(narg,args,action) << endl;
// os << helpNetworkParameter(narg,args,action) << endl;
// os << helpPort(narg,args,action) << endl;
// os << helpLock(narg,args,action) << endl;
// os << helpLastClient(narg,args,action) << endl;
// os << helpOnline(narg,args,action) << endl;
// os << helpConfigureMac(narg,args,action) << endl;
// os << helpDetectorSize(narg,args,action) << endl;
// os << helpSettings(narg,args,action) << endl;
// os << helpSN(narg,args,action) << endl;
// os << helpDigiTest(narg,args,action) << endl;
// os << helpRegister(narg,args,action) << endl;
// os << helpDAC(narg,args,action) << endl;
// os << helpTimer(narg,args,action) << endl;
// os << helpTiming(narg,args,action) << endl;
// os << helpTimeLeft(narg,args,action) << endl;
// os << helpSpeed(narg,args,action) << endl;
// os << helpAdvanced(narg,args,action) << endl;
// os << helpConfiguration(narg,args,action) << endl;
// os << helpImage(narg,args,action) << endl;
// os << helpADC(narg,args,action) << endl;
// return os.str();
}
@ -978,7 +927,7 @@ string slsDetectorCommand::cmdHostname(int narg, char *args[], int action){
if (vvstr.fail())
ivar=-1;
}
if (action==PUT_ACTION) {
//add by hostname
if (ivar==-1) {
@ -1010,6 +959,7 @@ string slsDetectorCommand::helpHostname(int narg, char *args[], int action){
return os.str();
}
string slsDetectorCommand::cmdId(int narg, char *args[], int action){
#ifdef VERBOSE
cout << string("Executing command ")+string(args[0])+string(" ( ")+cmd+string(" )\n");
@ -1130,7 +1080,14 @@ string slsDetectorCommand::cmdHelp(int narg, char *args[], int action){
#ifdef VERBOSE
cout << string("Executing command ")+string(args[0])+string(" ( ")+cmd+string(" )\n");
#endif
return helpLine(narg, args, action);
cout << narg << endl;
if (narg>=1)
return helpLine(narg-1, args+1, action);
else
return helpLine(0, args, action);
}

View File

@ -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:

View File

@ -477,6 +477,8 @@ float slsDetectorUtils::getCurrentProgress() {
return 100.*((float)progressIndex)/((float)totalProgress);
}
void slsDetectorUtils::incrementProgress() {
progressIndex++;
cout << fixed << setprecision(2) << setw (6) << getCurrentProgress() << " \%";

View File

@ -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);};