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

@ -12,44 +12,54 @@
#include <math.h>
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;
};