From 1ef4ace390dd5c9e4a3d9740e96a24f0066edba4 Mon Sep 17 00:00:00 2001 From: l_maliakal_d Date: Tue, 26 Feb 2013 16:08:03 +0000 Subject: [PATCH] updated bug-crashing when file write disabled and included file pointer in call back function git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@474 951219d9-93cf-4727-9268-0efd64621fa3 --- .../gotthardDetectorServer/svnInfoGotthard.h | 4 +- .../mythenDetectorServer/svnInfoMythen.h | 4 +- .../slsDetector/slsDetectorUsers.cpp | 1 - .../slsDetector/slsDetectorUsers.h | 9 +--- slsDetectorSoftware/slsDetector/svnInfoLib.h | 4 +- .../slsReceiver/slsReceiverFunctionList.cpp | 47 +++++++++---------- .../slsReceiver/slsReceiverFunctionList.h | 4 +- .../slsReceiver/svnInfoReceiver.h | 4 +- .../usersFunctions/usersFunctions.cpp | 2 +- .../usersFunctions/usersFunctions.h | 9 ++-- 10 files changed, 41 insertions(+), 47 deletions(-) diff --git a/slsDetectorSoftware/gotthardDetectorServer/svnInfoGotthard.h b/slsDetectorSoftware/gotthardDetectorServer/svnInfoGotthard.h index 9b2d757ad..4910fe10c 100644 --- a/slsDetectorSoftware/gotthardDetectorServer/svnInfoGotthard.h +++ b/slsDetectorSoftware/gotthardDetectorServer/svnInfoGotthard.h @@ -2,10 +2,10 @@ #define SVNURL "file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware/gotthardDetectorServer" //#define SVNREPPATH "" #define SVNREPUUID "951219d9-93cf-4727-9268-0efd64621fa3" -//#define SVNREV 0x471 +//#define SVNREV 0x472 //#define SVNKIND "" //#define SVNSCHED "" #define SVNAUTH "l_maliakal_d" -#define SVNREV 0x471 +#define SVNREV 0x472 #define SVNDATE 0x20130226 // diff --git a/slsDetectorSoftware/mythenDetectorServer/svnInfoMythen.h b/slsDetectorSoftware/mythenDetectorServer/svnInfoMythen.h index b0f6174dc..950b7d4a4 100644 --- a/slsDetectorSoftware/mythenDetectorServer/svnInfoMythen.h +++ b/slsDetectorSoftware/mythenDetectorServer/svnInfoMythen.h @@ -2,10 +2,10 @@ #define SVNURL "file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware/mythenDetectorServer" //#define SVNREPPATH "" #define SVNREPUUID "951219d9-93cf-4727-9268-0efd64621fa3" -//#define SVNREV 0x471 +//#define SVNREV 0x472 //#define SVNKIND "" //#define SVNSCHED "" #define SVNAUTH "l_maliakal_d" -#define SVNREV 0x471 +#define SVNREV 0x472 #define SVNDATE 0x20130226 // diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUsers.cpp b/slsDetectorSoftware/slsDetector/slsDetectorUsers.cpp index f8ff5a130..82cbe0968 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUsers.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorUsers.cpp @@ -230,7 +230,6 @@ void slsDetectorUsers::registerRawDataCallback(int( *userCallback)(double*, int, myDetector->registerRawDataCallback(userCallback,pArg); } - void slsDetectorUsers::registerAcquisitionFinishedCallback(int( *func)(double,int, void*), void *pArg){ myDetector->registerAcquisitionFinishedCallback(func,pArg); } diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUsers.h b/slsDetectorSoftware/slsDetector/slsDetectorUsers.h index 9e5f1794f..66bf1b8a3 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUsers.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorUsers.h @@ -394,18 +394,11 @@ class slsDetectorUsers /** @short register callback for accessing raw data - if the rawDataCallback is registered, no filewriting/postprocessing will be carried on automatically by the software - the raw data are deleted by the software - \param userCallback function for postprocessing and saving the data - p is the pointer to the data, n is the number of channels + \param userCallback function for postprocessing and saving the data - p is the pointer to the data, n is the number of channels */ void registerRawDataCallback(int( *userCallback)(double* p, int n, void*), void *pArg); - /** - @short register callback for writing receiver data - if the rawDataCallback is registered, no receiver data writing will be carried on automatically by the software - the receiver data are deleted by the software - \param userCallback function for writing the receiver data - p is the pointer to the data, n is the number of bytes to write - */ - - void registerWriteReceiverDataCallback(int( *userCallback)(char* p, int n, void*), void *pArg); - /** @short function to initalize a set of measurements (reset binning if angular conversion, reset summing otherwise) - can be overcome by the user's functions thanks to the virtual property \param refresh if 1, all parameters like ffcoefficients, badchannels, ratecorrections etc. are reset (should be called at least onece with this option), if 0 simply reset merging/ summation diff --git a/slsDetectorSoftware/slsDetector/svnInfoLib.h b/slsDetectorSoftware/slsDetector/svnInfoLib.h index 8ae94d7f8..4376c6a45 100644 --- a/slsDetectorSoftware/slsDetector/svnInfoLib.h +++ b/slsDetectorSoftware/slsDetector/svnInfoLib.h @@ -2,10 +2,10 @@ #define SVNURLLIB "file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware" //#define SVNREPPATH "" #define SVNREPUUIDLIB "951219d9-93cf-4727-9268-0efd64621fa3" -//#define SVNREV 0x471 +//#define SVNREV 0x473 //#define SVNKIND "" //#define SVNSCHED "" #define SVNAUTHLIB "l_maliakal_d" -#define SVNREVLIB 0x471 +#define SVNREVLIB 0x473 #define SVNDATELIB 0x20130226 // diff --git a/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp b/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp index 730f5b13f..7a36a7193 100644 --- a/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp +++ b/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp @@ -166,7 +166,7 @@ int slsReceiverFunctionList::startReceiver(){ #ifdef VERBOSE cout << "Starting Receiver" << endl; #endif - + cout << endl; int err = 0; if(!listening_thread_running){ @@ -263,7 +263,7 @@ void* slsReceiverFunctionList::startListeningThread(void* this_pointer){ int slsReceiverFunctionList::startListening(){ #ifdef VERYVERBOSE -i cout << "In startListening()\n"); + cout << "In startListening()\n"); #endif // Variable and structure definitions int rc; @@ -388,15 +388,14 @@ int slsReceiverFunctionList::startWriting(){ strcpy(savefilename,""); strcpy(actualfilename,""); - if (!writeReceiverData) - cout << "Max Frames Per File:" << maxFramesPerFile << endl; - else - cout << "Note: Writing Data has been defined exernally" << endl; - + cout << "Max Frames Per File:" << maxFramesPerFile << endl; + if (writeReceiverData) + cout << "Note: Data Write has been defined exernally" << endl; cout << "Ready!" << endl; + if(!enableFileWrite) + cout << endl << "Note: Data will not be saved" << endl; - if(enableFileWrite){ //create file name if(frameIndexNeeded==-1) sprintf(savefilename, "%s/%s_%d.raw", filePath,fileName,fileIndex); else sprintf(savefilename, "%s/%s_f%012d_%d.raw", filePath,fileName,framesCaught,fileIndex); @@ -406,10 +405,9 @@ int slsReceiverFunctionList::startWriting(){ else sprintf(actualfilename, "%s/%s_%d_%09d.raw", filePath,fileName,fileIndex, 0); //start writing - if (!writeReceiverData){ - sfilefd = fopen((const char *) (actualfilename), "w"); - cout << "Saving to " << actualfilename << endl; - } + if(enableFileWrite){ + sfilefd = fopen((const char *) (actualfilename), "w"); + cout << actualfilename << endl; } @@ -417,10 +415,8 @@ int slsReceiverFunctionList::startWriting(){ while(listening_thread_running){ //when it reaches maxFramesPerFile,start writing new file - if ((!writeReceiverData)&& (framesInFile == maxFramesPerFile)) { + if (framesInFile == maxFramesPerFile) { - if(enableFileWrite){ - fclose(sfilefd); //create file name if(frameIndexNeeded==-1) sprintf(savefilename, "%s/%s_%d.raw", filePath,fileName,fileIndex); else sprintf(savefilename, "%s/%s_f%012d_%d.raw", filePath,fileName,framesCaught,fileIndex); @@ -428,13 +424,15 @@ int slsReceiverFunctionList::startWriting(){ if(!shortFileName) strcpy(actualfilename,savefilename); else sprintf(actualfilename, "%s/%s_%d_%09d.raw", filePath,fileName,fileIndex, shortFileNameIndex); shortFileNameIndex++; - //start writing in new file + + //start writing in new file + if(enableFileWrite){ + fclose(sfilefd); sfilefd = fopen((const char *) (actualfilename), "w"); - cout << "saving to " << actualfilename << "\t"; } //currframenum=(int)(*((int*)latestData)); - cout << "packet loss " << fixed << setprecision(4) << ((currframenum-prevframenum-(packetsPerFrame*framesInFile))/(double)(packetsPerFrame*framesInFile))*100.000 << "%\t\t" + cout << actualfilename << "\tpacket loss " << fixed << setprecision(4) << ((currframenum-prevframenum-(packetsPerFrame*framesInFile))/(double)(packetsPerFrame*framesInFile))*100.000 << "%\t\t" "framenum " << currframenum << "\t\t" "p " << prevframenum << endl; @@ -452,17 +450,18 @@ int slsReceiverFunctionList::startWriting(){ framesCaught++; totalFramesCaught++; currframenum = (int)(*((int*)dataWriteFrame->buffer)); + + if(enableFileWrite){ + if (writeReceiverData) + writeReceiverData(dataWriteFrame->buffer,dataWriteFrame->rc, sfilefd, pwriteReceiverDataArg); + else + fwrite(dataWriteFrame->buffer, 1, dataWriteFrame->rc, sfilefd); + } if(guiRequiresData){ memcpy(latestData,dataWriteFrame->buffer,bufferSize); guiRequiresData=0; } //cout<<"write index:"<<(int)(*(int*)latestData)<buffer,dataWriteFrame->rc, pwriteReceiverDataArg); - else - fwrite(dataWriteFrame->buffer, 1, dataWriteFrame->rc, sfilefd); - } framesInFile++; ///ANNA?!?!??! // delete [] dataWriteFrame->buffer; diff --git a/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.h b/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.h index afb323e12..49acf12a5 100644 --- a/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.h +++ b/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.h @@ -184,7 +184,7 @@ public: /** * Register call back function to write receiver data */ - void registerWriteReceiverDataCallback(int( *userCallback)(char*, int, void*), void *pArg) {writeReceiverData = userCallback; pwriteReceiverDataArg = pArg;}; + void registerWriteReceiverDataCallback(int( *userCallback)(char*, int, FILE*, void*), void *pArg) {writeReceiverData = userCallback; pwriteReceiverDataArg = pArg;}; private: @@ -299,7 +299,7 @@ private: int currframenum; /** register for call back to get data */ - int (*writeReceiverData)(char*,int,void*); + int (*writeReceiverData)(char*,int,FILE*,void*); void *pwriteReceiverDataArg; public: diff --git a/slsDetectorSoftware/slsReceiver/svnInfoReceiver.h b/slsDetectorSoftware/slsReceiver/svnInfoReceiver.h index deb7fdb71..adb10f8fa 100644 --- a/slsDetectorSoftware/slsReceiver/svnInfoReceiver.h +++ b/slsDetectorSoftware/slsReceiver/svnInfoReceiver.h @@ -2,10 +2,10 @@ #define SVNURL "file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware/slsReceiver" //#define SVNREPPATH "" #define SVNREPUUID "951219d9-93cf-4727-9268-0efd64621fa3" -//#define SVNREV 0x471 +//#define SVNREV 0x473 //#define SVNKIND "" //#define SVNSCHED "" #define SVNAUTH "l_maliakal_d" -#define SVNREV 0x471 +#define SVNREV 0x473 #define SVNDATE 0x20130226 // diff --git a/slsDetectorSoftware/usersFunctions/usersFunctions.cpp b/slsDetectorSoftware/usersFunctions/usersFunctions.cpp index 50bb425cb..e0c28fb42 100644 --- a/slsDetectorSoftware/usersFunctions/usersFunctions.cpp +++ b/slsDetectorSoftware/usersFunctions/usersFunctions.cpp @@ -336,7 +336,7 @@ int defaultRawDataReadyFunc(double* d, int np, void* p) { -int defaultWriteReceiverDataFunc(char* d, int np, void* p){ +int defaultWriteReceiverDataFunc(char* d, int np, FILE* f, void* p){ //#ifdef VERBOSE printf("UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU Receiver Data received \n"); if (d==NULL) diff --git a/slsDetectorSoftware/usersFunctions/usersFunctions.h b/slsDetectorSoftware/usersFunctions/usersFunctions.h index ec5b9f9cd..1b3a92dff 100644 --- a/slsDetectorSoftware/usersFunctions/usersFunctions.h +++ b/slsDetectorSoftware/usersFunctions/usersFunctions.h @@ -7,7 +7,9 @@ Functions depending on the experimental setup should be defined here ******************************************************************/ //#define PI 3.14159265358979323846 - +#ifdef __cplusplus +#include +#endif #ifdef EPICS #include @@ -40,8 +42,9 @@ extern "C" { int defaultDataReadyFunc(detectorData* d, int i, void* p); int defaultRawDataReadyFunc(double* d, int np, void* p); - int defaultWriteReceiverDataFunc(char* d, int np, void* p); - +#ifdef __cplusplus + int defaultWriteReceiverDataFunc(char* d, int np, FILE* f, void* p); +#endif #ifdef __cplusplus };