frame index in file name, increments instead of file index for real time acquisitions

git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@330 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
bergamaschi
2012-10-30 15:52:40 +00:00
parent 2f9dea8341
commit 96d08d61d0
14 changed files with 307 additions and 124 deletions

View File

@ -10,7 +10,7 @@
*/
class detectorData {
public:
/** The constructor
/** @short The constructor
\param val pointer to the data
\param err pointer to errors
\param ang pointer to the angles
@ -21,18 +21,18 @@ class detectorData {
*/
detectorData(double *val=NULL, double *err=NULL, double *ang=NULL, double p_ind=-1, const char *fname="", int np=-1, int ny=1) : values(val), errors(err), angles(ang), progressIndex(p_ind), npoints(np), npy(ny){strcpy(fileName,fname);};
/**
the destructor
@short The destructor
deletes also the arrays pointing to data/errors/angles if not NULL
*/
~detectorData() {if (values) delete [] values; if (errors) delete [] errors; if (angles) delete [] angles;};
//private:
double *values; /**< pointer to the data */
double *errors; /**< pointer to the errors */
double *angles;/**< pointer to the angles */
double progressIndex;/**< file index */
char fileName[1000];/**< file name */
int npoints;/**< number of points */
int npy;/**< dimensions in y coordinate*/
double *values; /**< @short pointer to the data */
double *errors; /**< @short pointer to the errors */
double *angles;/**< @short pointer to the angles (NULL if no angular conversion) */
double progressIndex;/**< @short file index */
char fileName[1000];/**< @short file name */
int npoints;/**< @short number of points */
int npy;/**< @short dimensions in y coordinate*/
};

View File

@ -69,6 +69,9 @@ int fileIO::writeDataFile(string fname, int *data){
return fileIOStatic::writeDataFile(fname, getTotalNumberOfChannels(), data);
}
int fileIO::writeDataFile(ofstream &outfile, int *data, int offset){
return fileIOStatic::writeDataFile(outfile, getTotalNumberOfChannels(), data, offset);
@ -76,6 +79,41 @@ int fileIO::writeDataFile(ofstream &outfile, int *data, int offset){
int fileIO::writeDataFile(void *data, int iframe) {
if (iframe>=0)
frameIndex=iframe;
if (*framesPerFile<2)
frameIndex=-1;
if ((frameIndex%(*framesPerFile))==0 || (frameIndex<0)) {
createFileName();
filefd = fopen(currentFileName.c_str(), "w");
}
if (filefd){
if (iframe%(*framesPerFile)) {
fileIOStatic::writeBinaryDataFile(filefd,getDataBytes() , data);
frameIndex++;
}
}
if ((frameIndex%(*framesPerFile)==0) || (frameIndex<0)) {
if (filefd)
fclose(filefd);
filefd=NULL;
}
}
int fileIO::closeDataFile() {
if (filefd)
fclose(filefd);
filefd=NULL;
}
int fileIO::writeDataFile(string fname, short int *data){
@ -83,6 +121,14 @@ int fileIO::writeDataFile(string fname, short int *data){
return fileIOStatic::writeDataFile(fname, getTotalNumberOfChannels(), data);
}
int fileIO::writeDataFile(ofstream &outfile, short int *data, int offset){
return fileIOStatic::writeDataFile(outfile, getTotalNumberOfChannels(), data, offset);
@ -91,6 +137,12 @@ int fileIO::writeDataFile(ofstream &outfile, short int *data, int offset){
int fileIO::readDataFile(string fname, double *data, double *err, double *ang, char dataformat) {
return fileIOStatic::readDataFile(getTotalNumberOfChannels(), fname, data, err, ang, dataformat);

View File

@ -22,8 +22,16 @@ class fileIO : public fileIOStatic, public virtual slsDetectorBase {
public:
/* enum rawFileFormat { */
/* ASCII, */
/* BINARY */
/* } */
/** default constructor */
fileIO(): fileIOStatic(){frameIndex=-1;detIndex=-1;};
fileIO(): fileIOStatic(){frameIndex=-1;detIndex=-1; framesPerFile=&nframes; nframes=1; };
/** virtual destructor */
virtual ~fileIO(){};
@ -62,6 +70,13 @@ class fileIO : public fileIOStatic, public virtual slsDetectorBase {
*/
virtual int setFrameIndex(int i) {frameIndex=i; return frameIndex;};
/**
sets the default output file index
\param i frame index to be set
\returns actual frame index
*/
virtual int setFramesPerFile(int i) {if (i>0) *framesPerFile=i; return *framesPerFile;};
/**
sets the default output file index
\param i detector index to be set
@ -74,7 +89,6 @@ class fileIO : public fileIOStatic, public virtual slsDetectorBase {
*/
virtual string getFilePath() {return string(filePath);};
/**
\returns the output files root name
*/
@ -102,17 +116,14 @@ class fileIO : public fileIOStatic, public virtual slsDetectorBase {
/**
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' double (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, double *data, double *err=NULL, double *ang=NULL, char dataformat='f', int nch=-1);
@ -120,7 +131,7 @@ class fileIO : public fileIOStatic, public virtual slsDetectorBase {
/**
writes a data file
\paramoutfile output file stream
\param outfile output file stream
\param data array of data values
\param err array of arrors on the data. If NULL no errors will be written
@ -142,6 +153,10 @@ class fileIO : public fileIOStatic, public virtual slsDetectorBase {
*/
virtual int writeDataFile(string fname, int *data);
virtual int writeDataFile(void *data, int iframe=-1);
int closeDataFile();
/**
writes a data file
\param outfile output file stream
@ -161,6 +176,12 @@ class fileIO : public fileIOStatic, public virtual slsDetectorBase {
*/
virtual int writeDataFile(string fname, short int *data);
/**
writes a data file of short ints
\param outfile output file stream
@ -200,8 +221,10 @@ class fileIO : public fileIOStatic, public virtual slsDetectorBase {
\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); /**
yes */
virtual int readDataFile(string fname, int *data);
/**
reads a raw data file
\param infile input file stream
\param data array of data values
@ -227,6 +250,7 @@ class fileIO : public fileIOStatic, public virtual slsDetectorBase {
*/
int readDataFile(ifstream &infile, short int *data, int offset=0);
virtual int getDataBytes ( )=0;
friend class slsDetector;
protected:
@ -238,28 +262,40 @@ class fileIO : public fileIOStatic, public virtual slsDetectorBase {
void incrementDetectorIndex() { (detIndex)++; };
string getCurrentFileName(){return currentFileName;};
string getCurrentFileName(){return currentFileName;};
string getCurrentReceiverFilePrefix(){return currentReceiverFilePrefix;};
string getCurrentReceiverFilePrefix(){return currentReceiverFilePrefix;};
string currentFileName;
string currentFileName;
string currentReceiverFilePrefix;
string currentReceiverFilePrefix;
/** output directory */
char *filePath;
/** file root name */
char *fileName;
/** file index */
int *fileIndex;
/** frame index */
int frameIndex;
/** detector id */
int detIndex;
/** output directory */
char *filePath;
/** file root name */
char *fileName;
/** file index */
int *fileIndex;
/** frame index */
int frameIndex;
/** detector id */
int detIndex;
/** frames per file */
int *framesPerFile;
// int *fileFormat;
private:
FILE *filefd;
ofstream fstream;
int nframes;
// int fformat;
};

View File

@ -59,11 +59,11 @@ class fileIOStatic {
static string createFileName(char *filepath, char *filename, int aMask, double sv0, int prec0, double sv1, int prec1, int pindex, int npos, int findex, int frameindex=-1, int detindex=-1){ \
ostringstream osfn; \
osfn << filepath << "/" << filename; \
if(detindex!=-1) osfn << "_d"<< detindex; \
if(detindex>=0) osfn << "_d"<< detindex; \
if ( aMask& (1 << (slsDetectorDefs::MAX_ACTIONS))) osfn << "_S" << fixed << setprecision(prec0) << sv0; \
if (aMask & (1 << (slsDetectorDefs::MAX_ACTIONS+1))) osfn << "_s" << fixed << setprecision(prec1) << sv1; \
if (pindex>0 && pindex<=npos) osfn << "_p" << pindex; \
if(frameindex!=-1) osfn << "_f" << frameindex; \
if(frameindex>=0) osfn << "_f" << frameindex; \
osfn << "_" << findex; \
return osfn.str(); \
};
@ -278,6 +278,9 @@ class fileIOStatic {
} \
};
/**
writes a data file
\param outfile output file stream
@ -340,7 +343,30 @@ class fileIOStatic {
} \
};
/**
writes a raw data file in binary format
\param fname of the file to be written
\param number of bytes to write
\param data array of data values
\returns OK or FAIL if it could not write the file or data=NULL
*/
static int writeBinaryDataFile(string fname, size_t nbytes, void *data){ \
FILE *sfilefd; \
if (data==NULL) return slsDetectorDefs::FAIL; \
sfilefd = fopen(fname.c_str(), "w"); \
if (sfilefd) { \
writeBinaryDataFile(sfilefd, nbytes, data); \
fclose(sfilefd); \
return slsDetectorDefs::OK; \
} \
return slsDetectorDefs::FAIL; \
};
static int writeBinaryDataFile(FILE *sfilefd, size_t nbytes, void *data){ \
fwrite(data, 1, nbytes, sfilefd); \
return slsDetectorDefs::OK; \
};
/**
writes a raw data file
\param outfile output file stream
@ -396,8 +422,6 @@ class fileIOStatic {
return slsDetectorDefs::OK; \
};
/**
reads a data file
\param nch number of channels

View File

@ -62,65 +62,71 @@ void postProcessing::processFrame(int *myData, int delflag) {
/** decode data */
fdata=decodeData(myData, fdata);
if (getDetectorsType()==MYTHEN) {
fdata=decodeData(myData, fdata);
#ifdef VERBOSE
cout << "decode"<< endl;
cout << "decode"<< endl;
#endif
if (rawDataReady) {
//#ifdef VERBOSE
cout << "raw data ready..." << endl;
//#endif
rawDataReady(fdata,numberOfChannels, pRawDataArg);
//#ifdef VERBOSE
cout << "done" << endl;
cout << "NO FILE WRITING AND/OR DATA PROCESSING DONE BY SLS DETECTOR SOFTWARE!!!" << endl;
//#endif
} else
fdata=NULL;
} else {
if (rawDataReady) {
//#ifdef VERBOSE
cout << "raw data ready..." << endl;
//#endif
rawDataReady(fdata,numberOfChannels, pRawDataArg);
//#ifdef VERBOSE
cout << "done" << endl;
cout << "NO FILE WRITING AND/OR DATA PROCESSING DONE BY SLS DETECTOR SOFTWARE!!!" << endl;
//#endif
} else {
pthread_mutex_lock(&mp);
fname=createFileName();
pthread_mutex_unlock(&mp);
pthread_mutex_lock(&mp);
fname=createFileName();
pthread_mutex_unlock(&mp);
#ifdef VERBOSE
cout << "fname is " << fname << endl;
cout << "fname is " << fname << endl;
#endif
//Checking for write flag
if((*correctionMask)&(1<<WRITE_FILE)) {
//Checking for write flag
if((*correctionMask)&(1<<WRITE_FILE)) {
#ifdef VERBOSE
cout << "writing raw data " << endl;
#endif
//uses static function?!?!?!?
writeDataFile (fname+string(".raw"),fdata, NULL, NULL, 'i');
#ifdef VERBOSE
cout << "done " << endl;
#endif
}
if ((*correctionMask) & ~(1<<WRITE_FILE)) {
doProcessing(fdata,delflag, fname);
} else
if (dataReady) {
thisData=new detectorData(fdata,NULL,NULL,getCurrentProgress(),(fname+string(".raw")).c_str(),getTotalNumberOfChannels());
dataReady(thisData, pCallbackArg);
delete thisData;
fdata=NULL;
if (fdata) {
//uses static function?!?!?!?
writeDataFile (fname+string(".raw"),fdata, NULL, NULL, 'i');
} else {
writeDataFile ((void*)myData);
}
#ifdef VERBOSE
cout << "findex incremented " << endl;
cout << "done " << endl;
#endif
if(*correctionMask&(1<<WRITE_FILE))
IncrementFileIndex();
}
}
if ((*correctionMask) & ~(1<<WRITE_FILE)) {
doProcessing(fdata,delflag, fname);
} else
if (dataReady) {
thisData=new detectorData(fdata,NULL,NULL,getCurrentProgress(),(fname+string(".raw")).c_str(),getTotalNumberOfChannels());
dataReady(thisData, pCallbackArg);
delete thisData;
fdata=NULL;
}
// #ifdef VERBOSE
// cout << "findex incremented " << endl;
// #endif
// if(*correctionMask&(1<<WRITE_FILE))
// IncrementFileIndex();
}
if (getFrameIndex()>=0)
incrementFrameIndex();
delete [] myData;
if (fdata)
@ -179,7 +185,7 @@ void postProcessing::doProcessing(double *lfdata, int delflag, string fname) {
cout << "exptime is "<< t << endl;
#endif
if (GetCurrentPositionIndex()<=1) {
if (GetCurrentPositionIndex()<=1 || npos<2) {
#ifdef VERBOSE
cout << "init dataset" << endl;
#endif
@ -199,25 +205,26 @@ void postProcessing::doProcessing(double *lfdata, int delflag, string fname) {
cout << "add frame" << endl;
#endif
addFrame(lfdata,currentPosition, currentI0, t, fname, 0);
if ((GetCurrentPositionIndex()>=npos && positionFinished() && dataQueueSize()) || npos==0) {
addFrame(lfdata,currentPosition, currentI0, t, fname, 0);
if ((GetCurrentPositionIndex()>=npos && positionFinished() && dataQueueSize()) || npos<2) {
#ifdef VERBOSE
cout << "finalize dataset" << endl;
#endif
finalizeDataset(ang, val, err, np);
//if (npos<2) {
IncrementPositionIndex();
pthread_mutex_lock(&mp);
fname=createFileName();
pthread_mutex_unlock(&mp);
//}
if((*correctionMask)&(1<<WRITE_FILE)) {
writeDataFile (fname+ext,np,val, err,ang,'f');
}
}
if (dataReady) {
@ -236,10 +243,6 @@ void postProcessing::doProcessing(double *lfdata, int delflag, string fname) {
if (err)
delete [] err;
}
}

View File

@ -257,8 +257,7 @@ s
void addFrame(double *data, double pos, double i0, double t, string fname, double var);
void finalizeDataset(double *a, double *v, double *e, int &np);
virtual detectorType getDetectorsType(int pos=-1)=0;
protected: