got rid of short file name

git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@485 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
l_maliakal_d 2013-03-07 10:45:33 +00:00
parent 96d9e5d078
commit 91e5e35c73
4 changed files with 133 additions and 168 deletions

View File

@ -1,5 +1,5 @@
CC = g++ CC = g++
CLAGS += -DSLS_RECEIVER_FUNCTION_LIST -DGOTTHARDD -DUHRIXCALLBACK #-DTESTWRITE CLAGS += -DSLS_RECEIVER_FUNCTION_LIST -DGOTTHARDD #-DUHRIXCALLBACK #-DTESTWRITE
LDLIBS += -lm -lstdc++ -lpthread LDLIBS += -lm -lstdc++ -lpthread
INCLUDES = -I ../MySocketTCP -I ../commonFiles -I ../usersFunctions -I ../slsDetectorAnalysis -I . INCLUDES = -I ../MySocketTCP -I ../commonFiles -I ../usersFunctions -I ../slsDetectorAnalysis -I .

View File

@ -31,43 +31,40 @@ using namespace std;
FILE* slsReceiverFunctionList::sfilefd(NULL); FILE* slsReceiverFunctionList::sfilefd(NULL);
int slsReceiverFunctionList::listening_thread_running(0); int slsReceiverFunctionList::listening_thread_running(0);
slsReceiverFunctionList::slsReceiverFunctionList(bool shortfname): slsReceiverFunctionList::slsReceiverFunctionList():
maxFramesPerFile(MAX_FRAMES), maxFramesPerFile(MAX_FRAMES),
enableFileWrite(1), enableFileWrite(1),
shortFileName(shortfname), fileIndex(0),
shortFileNameIndex(0), frameIndexNeeded(0),
fileIndex(0), framesCaught(0),
frameIndexNeeded(0), startFrameIndex(-1),
framesCaught(0), frameIndex(0),
startFrameIndex(-1), totalFramesCaught(0),
frameIndex(0), startAcquisitionIndex(-1),
totalFramesCaught(0), acquisitionIndex(0),
startAcquisitionIndex(-1), framesInFile(0),
acquisitionIndex(0), prevframenum(0),
framesInFile(0), status(IDLE),
prevframenum(0), latestData(NULL),/**?*/
status(IDLE), udpSocket(NULL),
latestData(NULL),/**?*/ server_port(DEFAULT_UDP_PORTNO),
udpSocket(NULL), fifo(NULL),
server_port(DEFAULT_UDP_PORTNO), shortFrame(-1),
fifo(NULL), bufferSize(BUFFER_SIZE),
shortFrame(-1), packetsPerFrame(2),
bufferSize(BUFFER_SIZE), guiRequiresData(0),
packetsPerFrame(2), currframenum(0),
guiRequiresData(0), writeReceiverData(0),
currframenum(0), pwriteReceiverDataArg(0),
writeReceiverData(0), startAcquisitionCallBack(NULL),
pwriteReceiverDataArg(0), pStartAcquisition(NULL),
startAcquisitionCallBack(NULL), acquisitionFinishedCallBack(NULL),
pStartAcquisition(NULL), pAcquisitionFinished(NULL),
acquisitionFinishedCallBack(NULL), rawDataReadyCallBack(NULL),
pAcquisitionFinished(NULL), pRawDataReady(NULL)
rawDataReadyCallBack(NULL),
pRawDataReady(NULL)
{ {
strcpy(savefilename,""); strcpy(savefilename,"");
strcpy(actualfilename,"");
strcpy(filePath,""); strcpy(filePath,"");
strcpy(fileName,"run"); strcpy(fileName,"run");
eth = new char[MAX_STR_LENGTH]; eth = new char[MAX_STR_LENGTH];
@ -84,12 +81,12 @@ slsReceiverFunctionList::slsReceiverFunctionList(bool shortfname):
mem0=(char*)malloc(4096*FIFO_SIZE); mem0=(char*)malloc(4096*FIFO_SIZE);
if (mem0==NULL) { if (mem0==NULL) {
cout<<"++++++++++++++++++++++ COULD NOT ALLOCATE MEMORY!!!!!!!+++++++++++++++++++++" << endl; cout<<"++++++++++++++++++++++ COULD NOT ALLOCATE MEMORY!!!!!!!+++++++++++++++++++++" << endl;
} }
buffer=mem0; buffer=mem0;
while (buffer<(mem0+4096*(FIFO_SIZE-1))) { while (buffer<(mem0+4096*(FIFO_SIZE-1))) {
fifofree->push(buffer); fifofree->push(buffer);
buffer+=4096; buffer+=4096;
} }
@ -284,11 +281,10 @@ int slsReceiverFunctionList::startListening(){
#endif #endif
// Variable and structure definitions // Variable and structure definitions
int rc; int rc;
// dataStruct *dataReadFrame; // dataStruct *dataReadFrame;
//reset variables for each acquisition //reset variables for each acquisition
startFrameIndex=-1; startFrameIndex=-1;
shortFileNameIndex=1;
// A do/while(FALSE) loop is used to make error cleanup easier. The // A do/while(FALSE) loop is used to make error cleanup easier. The
@ -296,7 +292,7 @@ int slsReceiverFunctionList::startListening(){
// very end of the program. // very end of the program.
do { do {
if (strchr(eth,'.')!=NULL) strcpy(eth,""); if (strchr(eth,'.')!=NULL) strcpy(eth,"");
if(!strlen(eth)){ if(!strlen(eth)){
cout<<"warning:eth is empty.listening to all"<<endl; cout<<"warning:eth is empty.listening to all"<<endl;
@ -308,7 +304,7 @@ int slsReceiverFunctionList::startListening(){
if (udpSocket->getErrorStatus()){ if (udpSocket->getErrorStatus()){
#ifdef VERBOSE #ifdef VERBOSE
std::cout<< "Could not create UDP socket "<< server_port << std::endl; std::cout<< "Could not create UDP socket "<< server_port << std::endl;
#endif #endif
break; break;
} }
@ -318,48 +314,48 @@ int slsReceiverFunctionList::startListening(){
while (listening_thread_running) { while (listening_thread_running) {
status = RUNNING; status = RUNNING;
if (!fifofree->isEmpty()) { if (!fifofree->isEmpty()) {
fifofree->pop(buffer); fifofree->pop(buffer);
//receiver 2 half frames //receiver 2 half frames
rc = udpSocket->ReceiveDataOnly(buffer,bufferSize);//sizeof(buffer)); rc = udpSocket->ReceiveDataOnly(buffer,bufferSize);//sizeof(buffer));
if( rc < 0) if( rc < 0)
cerr << "recvfrom() failed" << endl; cerr << "recvfrom() failed" << endl;
//start for each scan //start for each scan
if(startFrameIndex==-1){ if(startFrameIndex==-1){
startFrameIndex=(int)(*((int*)buffer))-packetsPerFrame; startFrameIndex=(int)(*((int*)buffer))-packetsPerFrame;
//cout<<"startFrameIndex:"<<startFrameIndex<<endl; //cout<<"startFrameIndex:"<<startFrameIndex<<endl;
prevframenum=startFrameIndex; prevframenum=startFrameIndex;
} }
//start of acquisition //start of acquisition
if(startAcquisitionIndex==-1){ if(startAcquisitionIndex==-1){
startAcquisitionIndex=startFrameIndex; startAcquisitionIndex=startFrameIndex;
currframenum =startAcquisitionIndex; currframenum =startAcquisitionIndex;
cout<<"startAcquisitionIndex:"<<startAcquisitionIndex<<endl; cout<<"startAcquisitionIndex:"<<startAcquisitionIndex<<endl;
}
//so that it doesnt write the last frame twice
if(listening_thread_running){
//s.assign(buffer);
if(fifo->isFull())
;//cout<<"**********************FIFO FULLLLLLLL************************"<<endl;
else{
//cout<<"read index:"<<dec<<(int)(*(int*)buffer)<<endl;
/** dataReadFrame = new dataStruct;
dataReadFrame->buffer=buffer;
dataReadFrame->rc=rc;
//cout<<"read buffer:"<<dataReadFrame<<endl;
fifo->push(dataReadFrame);
*/
fifo->push(buffer);
} }
} //so that it doesnt write the last frame twice
if(listening_thread_running){
//s.assign(buffer);
if(fifo->isFull())
;//cout<<"**********************FIFO FULLLLLLLL************************"<<endl;
else{
//cout<<"read index:"<<dec<<(int)(*(int*)buffer)<<endl;
/** dataReadFrame = new dataStruct;
dataReadFrame->buffer=buffer;
dataReadFrame->rc=rc;
//cout<<"read buffer:"<<dataReadFrame<<endl;
fifo->push(dataReadFrame);
*/
fifo->push(buffer);
}
}
} }
} }
} while (listening_thread_running); } while (listening_thread_running);
@ -399,8 +395,7 @@ int slsReceiverFunctionList::startWriting(){
char *wbuf; char *wbuf;
// Variable and structure definitions // Variable and structure definitions
int ret,sleepnumber=0;//currframenum,ret; int ret,sleepnumber=0;
// dataStruct *dataWriteFrame;
char *guiData; char *guiData;
//reset variables for each acquisition //reset variables for each acquisition
framesInFile=0; framesInFile=0;
@ -408,21 +403,18 @@ int slsReceiverFunctionList::startWriting(){
frameIndex=0; frameIndex=0;
if(sfilefd) sfilefd=0; if(sfilefd) sfilefd=0;
strcpy(savefilename,""); strcpy(savefilename,"");
strcpy(actualfilename,"");
cout << "Max Frames Per File:" << maxFramesPerFile << endl; cout << "Max Frames Per File:" << maxFramesPerFile << endl;
if (writeReceiverData) if (writeReceiverData)
cout << "Note: Data Write has been defined exernally" << endl; cout << "Note: Data Write has been defined exernally" << endl;
cout << "Ready!" << endl; cout << "Ready!" << endl;
//by default, we read/write everything
cbAction=2; cbAction=2;
//acquisition start
if (startAcquisitionCallBack) if (startAcquisitionCallBack)
cbAction=startAcquisitionCallBack(filePath,fileName,fileIndex,bufferSize,pStartAcquisition); cbAction=startAcquisitionCallBack(filePath,fileName,fileIndex,bufferSize,pStartAcquisition);
@ -433,22 +425,15 @@ int slsReceiverFunctionList::startWriting(){
if(enableFileWrite==0 || cbAction==0) if(enableFileWrite==0 || cbAction==0)
cout << endl << "Note: Data will not be saved" << endl; cout << endl << "Note: Data will not be saved" << endl;
//create file name //create file name
if(frameIndexNeeded==-1) if(frameIndexNeeded==-1) sprintf(savefilename, "%s/%s_%d.raw", filePath,fileName,fileIndex);
sprintf(savefilename, "%s/%s_%d.raw", filePath,fileName,fileIndex); else sprintf(savefilename, "%s/%s_f%012d_%d.raw", filePath,fileName,framesCaught,fileIndex);
else
sprintf(savefilename, "%s/%s_f%012d_%d.raw", filePath,fileName,framesCaught,fileIndex);
//for sebastian
if(!shortFileName)
strcpy(actualfilename,savefilename);
else
sprintf(actualfilename, "%s/%s_%d_%09d.raw", filePath,fileName,fileIndex, 0);
//start writing //start writing
if(enableFileWrite || cbAction>0){ if(enableFileWrite || cbAction>0){
sfilefd = fopen((const char *) (actualfilename), "w"); sfilefd = fopen((const char *) (savefilename), "w");
cout << actualfilename << endl; cout << savefilename << endl;
} }
@ -458,72 +443,65 @@ int slsReceiverFunctionList::startWriting(){
//when it reaches maxFramesPerFile,start writing new file //when it reaches maxFramesPerFile,start writing new file
if (framesInFile == maxFramesPerFile) { if (framesInFile == maxFramesPerFile) {
//create file name //create file name
if(frameIndexNeeded==-1) sprintf(savefilename, "%s/%s_%d.raw", filePath,fileName,fileIndex); 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); else sprintf(savefilename, "%s/%s_f%012d_%d.raw", filePath,fileName,framesCaught,fileIndex);
//for sebastian
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 || cbAction>0){ if(enableFileWrite || cbAction>0){
fclose(sfilefd); fclose(sfilefd);
sfilefd = fopen((const char *) (actualfilename), "w"); sfilefd = fopen((const char *) (savefilename), "w");
} }
//currframenum=(int)(*((int*)latestData)); //currframenum=(int)(*((int*)latestData));
cout << actualfilename << "\tpacket loss " << fixed << setprecision(4) << ((currframenum-prevframenum-(packetsPerFrame*framesInFile))/(double)(packetsPerFrame*framesInFile))*100.000 << "%\t\t" cout << savefilename << "\tpacket loss " << fixed << setprecision(4) << ((currframenum-prevframenum-(packetsPerFrame*framesInFile))/(double)(packetsPerFrame*framesInFile))*100.000 << "%\t\t"
"framenum " << currframenum << "\t\t" "framenum " << currframenum << "\t\t"
"p " << prevframenum << endl; "p " << prevframenum << endl;
prevframenum=currframenum; prevframenum=currframenum;
framesInFile = 0; framesInFile = 0;
} }
//actual writing from fifo //actual writing from fifo
if(!fifo->isEmpty()){ if(!fifo->isEmpty()){
// dataWriteFrame = new dataStruct;
//if(fifo->pop(dataWriteFrame)){ if(fifo->pop(wbuf)){
if(fifo->pop(wbuf)){
//cout<<"write buffer:"<<dataWriteFrame<<endl<<endl;
framesCaught++; framesCaught++;
totalFramesCaught++; totalFramesCaught++;
//currframenum = (int)(*((int*)dataWriteFrame->buffer));
currframenum = (int)(*((int*)wbuf)); currframenum = (int)(*((int*)wbuf));
if(guiRequiresData) { if(guiRequiresData) {
guiData=latestData; guiData=latestData;
} else { } else {
guiData=NULL; guiData=NULL;
} }
//write data
if(enableFileWrite){ if(enableFileWrite){
if (writeReceiverData) { if (writeReceiverData) {
writeReceiverData(wbuf,bufferSize, sfilefd, pwriteReceiverDataArg); writeReceiverData(wbuf,bufferSize, sfilefd, pwriteReceiverDataArg);
} }
if (cbAction<2) { if (cbAction<2) {
rawDataReadyCallBack(currframenum, wbuf,sfilefd, guiData,pRawDataReady); rawDataReadyCallBack(currframenum, wbuf,sfilefd, guiData,pRawDataReady);
} else { } else {
fwrite(wbuf, 1, bufferSize, sfilefd); fwrite(wbuf, 1, bufferSize, sfilefd);
} }
} }
if(guiRequiresData){ if(guiRequiresData){
if (cbAction>=2) if (cbAction>=2)
memcpy(latestData,wbuf,bufferSize); memcpy(latestData,wbuf,bufferSize);
//memcpy(latestData,wbuf,bufferSize); //memcpy(latestData,wbuf,bufferSize);
guiRequiresData=0; guiRequiresData=0;
} }
//cout<<"write index:"<<(int)(*(int*)latestData)<<endl;
framesInFile++; framesInFile++;
///ANNA?!?!??!
// delete [] dataWriteFrame->buffer; // delete [] dataWriteFrame->buffer;
fifofree->push(wbuf); fifofree->push(wbuf);
} }
// delete dataWriteFrame; // delete dataWriteFrame;
} }
else{ else{
sleepnumber++; sleepnumber++;
@ -533,16 +511,16 @@ int slsReceiverFunctionList::startWriting(){
cout << "Total Frames Caught:"<< totalFramesCaught << endl; cout << "Total Frames Caught:"<< totalFramesCaught << endl;
//close file //close file
if(sfilefd) fclose(sfilefd); if(sfilefd) fclose(sfilefd);
#ifdef VERBOSE #ifdef VERBOSE
cout << "sfield:" << (int)sfilefd << endl; cout << "sfield:" << (int)sfilefd << endl;
#endif #endif
//acquistion over
if (acquisitionFinishedCallBack) if (acquisitionFinishedCallBack)
acquisitionFinishedCallBack(totalFramesCaught, pAcquisitionFinished); acquisitionFinishedCallBack(totalFramesCaught, pAcquisitionFinished);
return 0; return 0;
} }
@ -555,22 +533,22 @@ int slsReceiverFunctionList::startWriting(){
char* slsReceiverFunctionList::readFrame(char* c){ char* slsReceiverFunctionList::readFrame(char* c){
//ask for data //ask for data
guiRequiresData=1; guiRequiresData=1;
//wait for it to be ready, not indefinitely //wait for it to be ready, not indefinitely
int i=0; int i=0;
for(i=0;i<10;i++){ for(i=0;i<10;i++){
if(guiRequiresData) if(guiRequiresData)
usleep(100000); usleep(100000);
else else
break; break;
} }
//reset it back if not already reset //reset it back if not already reset
guiRequiresData=0; guiRequiresData=0;
//if no more data //if(guiRequiresData) // retun NULL; //if no more data //if(guiRequiresData) // retun NULL;
//cout<<"latestdata:"<<(int)(*(int*)latestData)<<endl; //cout<<"latestdata:"<<(int)(*(int*)latestData)<<endl;
strcpy(c,savefilename); strcpy(c,savefilename);
return latestData; return latestData;

View File

@ -25,9 +25,8 @@ class slsReceiverFunctionList : private virtual slsDetectorDefs {
public: public:
/** /**
* Constructor * Constructor
* @param shortfname true if short file name required
*/ */
slsReceiverFunctionList(bool shortfname); slsReceiverFunctionList();
/** /**
* Destructor * Destructor
@ -199,15 +198,6 @@ private:
/** Complete File name */ /** Complete File name */
char savefilename[MAX_STR_LENGTH]; char savefilename[MAX_STR_LENGTH];
/** Actual Complete File name. This is used if you need a simple filename */
char actualfilename[MAX_STR_LENGTH];
/** if short file name is needed, filename= filepath/filename_fileindex_shortFileNameIndex.raw */
bool shortFileName;
/** If short file name is used, different index used instead of frame index */
int shortFileNameIndex;
/** File Name without frame index, file index and extension*/ /** File Name without frame index, file index and extension*/
char fileName[MAX_STR_LENGTH]; char fileName[MAX_STR_LENGTH];

View File

@ -44,7 +44,6 @@ slsReceiverFuncs::slsReceiverFuncs(int argc, char *argv[], int &success):
success=slsDetectorDefs::OK; success=slsDetectorDefs::OK;
string fname = ""; string fname = "";
bool shortfname = false;
//parse command line for config //parse command line for config
for(int iarg=1;iarg<argc;iarg++){ for(int iarg=1;iarg<argc;iarg++){
@ -55,8 +54,6 @@ slsReceiverFuncs::slsReceiverFuncs(int argc, char *argv[], int &success):
} }
fname.assign(argv[iarg+1]); fname.assign(argv[iarg+1]);
} }
if(!strcasecmp(argv[iarg],"-shortfname"))
shortfname = true;
} }
if(!fname.empty()){ if(!fname.empty()){
@ -123,7 +120,7 @@ slsReceiverFuncs::slsReceiverFuncs(int argc, char *argv[], int &success):
strcpy(mess,"dummy message"); strcpy(mess,"dummy message");
function_table(); function_table();
slsReceiverList = new slsReceiverFunctionList(shortfname); slsReceiverList = new slsReceiverFunctionList();
#ifdef VERBOSE #ifdef VERBOSE
cout << "Function table assigned." << endl; cout << "Function table assigned." << endl;