mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-25 15:50:03 +02:00
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:
parent
96d9e5d078
commit
91e5e35c73
@ -1,5 +1,5 @@
|
||||
CC = g++
|
||||
CLAGS += -DSLS_RECEIVER_FUNCTION_LIST -DGOTTHARDD -DUHRIXCALLBACK #-DTESTWRITE
|
||||
CLAGS += -DSLS_RECEIVER_FUNCTION_LIST -DGOTTHARDD #-DUHRIXCALLBACK #-DTESTWRITE
|
||||
LDLIBS += -lm -lstdc++ -lpthread
|
||||
|
||||
INCLUDES = -I ../MySocketTCP -I ../commonFiles -I ../usersFunctions -I ../slsDetectorAnalysis -I .
|
||||
|
@ -31,43 +31,40 @@ using namespace std;
|
||||
FILE* slsReceiverFunctionList::sfilefd(NULL);
|
||||
int slsReceiverFunctionList::listening_thread_running(0);
|
||||
|
||||
slsReceiverFunctionList::slsReceiverFunctionList(bool shortfname):
|
||||
maxFramesPerFile(MAX_FRAMES),
|
||||
enableFileWrite(1),
|
||||
shortFileName(shortfname),
|
||||
shortFileNameIndex(0),
|
||||
fileIndex(0),
|
||||
frameIndexNeeded(0),
|
||||
framesCaught(0),
|
||||
startFrameIndex(-1),
|
||||
frameIndex(0),
|
||||
totalFramesCaught(0),
|
||||
startAcquisitionIndex(-1),
|
||||
acquisitionIndex(0),
|
||||
framesInFile(0),
|
||||
prevframenum(0),
|
||||
status(IDLE),
|
||||
latestData(NULL),/**?*/
|
||||
udpSocket(NULL),
|
||||
server_port(DEFAULT_UDP_PORTNO),
|
||||
fifo(NULL),
|
||||
shortFrame(-1),
|
||||
bufferSize(BUFFER_SIZE),
|
||||
packetsPerFrame(2),
|
||||
guiRequiresData(0),
|
||||
currframenum(0),
|
||||
writeReceiverData(0),
|
||||
pwriteReceiverDataArg(0),
|
||||
startAcquisitionCallBack(NULL),
|
||||
pStartAcquisition(NULL),
|
||||
acquisitionFinishedCallBack(NULL),
|
||||
pAcquisitionFinished(NULL),
|
||||
rawDataReadyCallBack(NULL),
|
||||
pRawDataReady(NULL)
|
||||
slsReceiverFunctionList::slsReceiverFunctionList():
|
||||
maxFramesPerFile(MAX_FRAMES),
|
||||
enableFileWrite(1),
|
||||
fileIndex(0),
|
||||
frameIndexNeeded(0),
|
||||
framesCaught(0),
|
||||
startFrameIndex(-1),
|
||||
frameIndex(0),
|
||||
totalFramesCaught(0),
|
||||
startAcquisitionIndex(-1),
|
||||
acquisitionIndex(0),
|
||||
framesInFile(0),
|
||||
prevframenum(0),
|
||||
status(IDLE),
|
||||
latestData(NULL),/**?*/
|
||||
udpSocket(NULL),
|
||||
server_port(DEFAULT_UDP_PORTNO),
|
||||
fifo(NULL),
|
||||
shortFrame(-1),
|
||||
bufferSize(BUFFER_SIZE),
|
||||
packetsPerFrame(2),
|
||||
guiRequiresData(0),
|
||||
currframenum(0),
|
||||
writeReceiverData(0),
|
||||
pwriteReceiverDataArg(0),
|
||||
startAcquisitionCallBack(NULL),
|
||||
pStartAcquisition(NULL),
|
||||
acquisitionFinishedCallBack(NULL),
|
||||
pAcquisitionFinished(NULL),
|
||||
rawDataReadyCallBack(NULL),
|
||||
pRawDataReady(NULL)
|
||||
|
||||
{
|
||||
strcpy(savefilename,"");
|
||||
strcpy(actualfilename,"");
|
||||
strcpy(filePath,"");
|
||||
strcpy(fileName,"run");
|
||||
eth = new char[MAX_STR_LENGTH];
|
||||
@ -84,12 +81,12 @@ slsReceiverFunctionList::slsReceiverFunctionList(bool shortfname):
|
||||
|
||||
mem0=(char*)malloc(4096*FIFO_SIZE);
|
||||
if (mem0==NULL) {
|
||||
cout<<"++++++++++++++++++++++ COULD NOT ALLOCATE MEMORY!!!!!!!+++++++++++++++++++++" << endl;
|
||||
cout<<"++++++++++++++++++++++ COULD NOT ALLOCATE MEMORY!!!!!!!+++++++++++++++++++++" << endl;
|
||||
}
|
||||
buffer=mem0;
|
||||
while (buffer<(mem0+4096*(FIFO_SIZE-1))) {
|
||||
fifofree->push(buffer);
|
||||
buffer+=4096;
|
||||
fifofree->push(buffer);
|
||||
buffer+=4096;
|
||||
}
|
||||
|
||||
|
||||
@ -284,11 +281,10 @@ int slsReceiverFunctionList::startListening(){
|
||||
#endif
|
||||
// Variable and structure definitions
|
||||
int rc;
|
||||
// dataStruct *dataReadFrame;
|
||||
// dataStruct *dataReadFrame;
|
||||
|
||||
//reset variables for each acquisition
|
||||
startFrameIndex=-1;
|
||||
shortFileNameIndex=1;
|
||||
|
||||
|
||||
// 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.
|
||||
do {
|
||||
|
||||
if (strchr(eth,'.')!=NULL) strcpy(eth,"");
|
||||
if (strchr(eth,'.')!=NULL) strcpy(eth,"");
|
||||
|
||||
if(!strlen(eth)){
|
||||
cout<<"warning:eth is empty.listening to all"<<endl;
|
||||
@ -308,7 +304,7 @@ int slsReceiverFunctionList::startListening(){
|
||||
|
||||
if (udpSocket->getErrorStatus()){
|
||||
#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
|
||||
break;
|
||||
}
|
||||
@ -318,48 +314,48 @@ int slsReceiverFunctionList::startListening(){
|
||||
while (listening_thread_running) {
|
||||
status = RUNNING;
|
||||
if (!fifofree->isEmpty()) {
|
||||
fifofree->pop(buffer);
|
||||
fifofree->pop(buffer);
|
||||
|
||||
//receiver 2 half frames
|
||||
rc = udpSocket->ReceiveDataOnly(buffer,bufferSize);//sizeof(buffer));
|
||||
if( rc < 0)
|
||||
cerr << "recvfrom() failed" << endl;
|
||||
//receiver 2 half frames
|
||||
rc = udpSocket->ReceiveDataOnly(buffer,bufferSize);//sizeof(buffer));
|
||||
if( rc < 0)
|
||||
cerr << "recvfrom() failed" << endl;
|
||||
|
||||
//start for each scan
|
||||
if(startFrameIndex==-1){
|
||||
startFrameIndex=(int)(*((int*)buffer))-packetsPerFrame;
|
||||
//cout<<"startFrameIndex:"<<startFrameIndex<<endl;
|
||||
prevframenum=startFrameIndex;
|
||||
}
|
||||
//start for each scan
|
||||
if(startFrameIndex==-1){
|
||||
startFrameIndex=(int)(*((int*)buffer))-packetsPerFrame;
|
||||
//cout<<"startFrameIndex:"<<startFrameIndex<<endl;
|
||||
prevframenum=startFrameIndex;
|
||||
}
|
||||
|
||||
//start of acquisition
|
||||
if(startAcquisitionIndex==-1){
|
||||
startAcquisitionIndex=startFrameIndex;
|
||||
currframenum =startAcquisitionIndex;
|
||||
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);
|
||||
//start of acquisition
|
||||
if(startAcquisitionIndex==-1){
|
||||
startAcquisitionIndex=startFrameIndex;
|
||||
currframenum =startAcquisitionIndex;
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
} while (listening_thread_running);
|
||||
@ -399,8 +395,7 @@ int slsReceiverFunctionList::startWriting(){
|
||||
char *wbuf;
|
||||
|
||||
// Variable and structure definitions
|
||||
int ret,sleepnumber=0;//currframenum,ret;
|
||||
// dataStruct *dataWriteFrame;
|
||||
int ret,sleepnumber=0;
|
||||
char *guiData;
|
||||
//reset variables for each acquisition
|
||||
framesInFile=0;
|
||||
@ -408,21 +403,18 @@ int slsReceiverFunctionList::startWriting(){
|
||||
frameIndex=0;
|
||||
if(sfilefd) sfilefd=0;
|
||||
strcpy(savefilename,"");
|
||||
strcpy(actualfilename,"");
|
||||
|
||||
cout << "Max Frames Per File:" << maxFramesPerFile << endl;
|
||||
if (writeReceiverData)
|
||||
cout << "Note: Data Write has been defined exernally" << endl;
|
||||
cout << "Ready!" << endl;
|
||||
|
||||
//by default, we read/write everything
|
||||
cbAction=2;
|
||||
|
||||
//acquisition start
|
||||
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)
|
||||
cout << endl << "Note: Data will not be saved" << endl;
|
||||
|
||||
//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);
|
||||
//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);
|
||||
|
||||
//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){
|
||||
sfilefd = fopen((const char *) (actualfilename), "w");
|
||||
cout << actualfilename << endl;
|
||||
sfilefd = fopen((const char *) (savefilename), "w");
|
||||
cout << savefilename << endl;
|
||||
}
|
||||
|
||||
|
||||
@ -458,72 +443,65 @@ int slsReceiverFunctionList::startWriting(){
|
||||
//when it reaches maxFramesPerFile,start writing new file
|
||||
if (framesInFile == maxFramesPerFile) {
|
||||
|
||||
//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);
|
||||
//for sebastian
|
||||
if(!shortFileName) strcpy(actualfilename,savefilename);
|
||||
else sprintf(actualfilename, "%s/%s_%d_%09d.raw", filePath,fileName,fileIndex, shortFileNameIndex);
|
||||
shortFileNameIndex++;
|
||||
//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);
|
||||
|
||||
//start writing in new file
|
||||
if(enableFileWrite || cbAction>0){
|
||||
fclose(sfilefd);
|
||||
sfilefd = fopen((const char *) (actualfilename), "w");
|
||||
}
|
||||
if(enableFileWrite || cbAction>0){
|
||||
fclose(sfilefd);
|
||||
sfilefd = fopen((const char *) (savefilename), "w");
|
||||
}
|
||||
|
||||
//currframenum=(int)(*((int*)latestData));
|
||||
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;
|
||||
cout << savefilename << "\tpacket loss " << fixed << setprecision(4) << ((currframenum-prevframenum-(packetsPerFrame*framesInFile))/(double)(packetsPerFrame*framesInFile))*100.000 << "%\t\t"
|
||||
"framenum " << currframenum << "\t\t"
|
||||
"p " << prevframenum << endl;
|
||||
|
||||
prevframenum=currframenum;
|
||||
framesInFile = 0;
|
||||
prevframenum=currframenum;
|
||||
framesInFile = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//actual writing from fifo
|
||||
if(!fifo->isEmpty()){
|
||||
// dataWriteFrame = new dataStruct;
|
||||
//if(fifo->pop(dataWriteFrame)){
|
||||
if(fifo->pop(wbuf)){
|
||||
//cout<<"write buffer:"<<dataWriteFrame<<endl<<endl;
|
||||
|
||||
if(fifo->pop(wbuf)){
|
||||
framesCaught++;
|
||||
totalFramesCaught++;
|
||||
//currframenum = (int)(*((int*)dataWriteFrame->buffer));
|
||||
currframenum = (int)(*((int*)wbuf));
|
||||
if(guiRequiresData) {
|
||||
guiData=latestData;
|
||||
guiData=latestData;
|
||||
} else {
|
||||
guiData=NULL;
|
||||
guiData=NULL;
|
||||
}
|
||||
|
||||
//write data
|
||||
if(enableFileWrite){
|
||||
if (writeReceiverData) {
|
||||
writeReceiverData(wbuf,bufferSize, sfilefd, pwriteReceiverDataArg);
|
||||
}
|
||||
if (cbAction<2) {
|
||||
rawDataReadyCallBack(currframenum, wbuf,sfilefd, guiData,pRawDataReady);
|
||||
} else {
|
||||
fwrite(wbuf, 1, bufferSize, sfilefd);
|
||||
}
|
||||
if (writeReceiverData) {
|
||||
writeReceiverData(wbuf,bufferSize, sfilefd, pwriteReceiverDataArg);
|
||||
}
|
||||
if (cbAction<2) {
|
||||
rawDataReadyCallBack(currframenum, wbuf,sfilefd, guiData,pRawDataReady);
|
||||
} else {
|
||||
fwrite(wbuf, 1, bufferSize, sfilefd);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(guiRequiresData){
|
||||
if (cbAction>=2)
|
||||
memcpy(latestData,wbuf,bufferSize);
|
||||
//memcpy(latestData,wbuf,bufferSize);
|
||||
guiRequiresData=0;
|
||||
if (cbAction>=2)
|
||||
memcpy(latestData,wbuf,bufferSize);
|
||||
//memcpy(latestData,wbuf,bufferSize);
|
||||
guiRequiresData=0;
|
||||
}
|
||||
//cout<<"write index:"<<(int)(*(int*)latestData)<<endl;
|
||||
|
||||
framesInFile++;
|
||||
///ANNA?!?!??!
|
||||
// delete [] dataWriteFrame->buffer;
|
||||
fifofree->push(wbuf);
|
||||
}
|
||||
// delete dataWriteFrame;
|
||||
// delete dataWriteFrame;
|
||||
}
|
||||
else{
|
||||
sleepnumber++;
|
||||
@ -533,16 +511,16 @@ int slsReceiverFunctionList::startWriting(){
|
||||
|
||||
cout << "Total Frames Caught:"<< totalFramesCaught << endl;
|
||||
//close file
|
||||
|
||||
|
||||
if(sfilefd) fclose(sfilefd);
|
||||
|
||||
#ifdef VERBOSE
|
||||
cout << "sfield:" << (int)sfilefd << endl;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
//acquistion over
|
||||
if (acquisitionFinishedCallBack)
|
||||
acquisitionFinishedCallBack(totalFramesCaught, pAcquisitionFinished);
|
||||
acquisitionFinishedCallBack(totalFramesCaught, pAcquisitionFinished);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -555,22 +533,22 @@ int slsReceiverFunctionList::startWriting(){
|
||||
|
||||
|
||||
char* slsReceiverFunctionList::readFrame(char* c){
|
||||
//ask for data
|
||||
guiRequiresData=1;
|
||||
//ask for data
|
||||
guiRequiresData=1;
|
||||
|
||||
//wait for it to be ready, not indefinitely
|
||||
int i=0;
|
||||
for(i=0;i<10;i++){
|
||||
if(guiRequiresData)
|
||||
usleep(100000);
|
||||
else
|
||||
break;
|
||||
}
|
||||
//wait for it to be ready, not indefinitely
|
||||
int i=0;
|
||||
for(i=0;i<10;i++){
|
||||
if(guiRequiresData)
|
||||
usleep(100000);
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
//reset it back if not already reset
|
||||
guiRequiresData=0;
|
||||
//reset it back if not already reset
|
||||
guiRequiresData=0;
|
||||
|
||||
//if no more data //if(guiRequiresData) // retun NULL;
|
||||
//if no more data //if(guiRequiresData) // retun NULL;
|
||||
//cout<<"latestdata:"<<(int)(*(int*)latestData)<<endl;
|
||||
strcpy(c,savefilename);
|
||||
return latestData;
|
||||
|
@ -25,9 +25,8 @@ class slsReceiverFunctionList : private virtual slsDetectorDefs {
|
||||
public:
|
||||
/**
|
||||
* Constructor
|
||||
* @param shortfname true if short file name required
|
||||
*/
|
||||
slsReceiverFunctionList(bool shortfname);
|
||||
slsReceiverFunctionList();
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
@ -199,15 +198,6 @@ private:
|
||||
/** Complete File name */
|
||||
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*/
|
||||
char fileName[MAX_STR_LENGTH];
|
||||
|
||||
|
@ -44,7 +44,6 @@ slsReceiverFuncs::slsReceiverFuncs(int argc, char *argv[], int &success):
|
||||
success=slsDetectorDefs::OK;
|
||||
|
||||
string fname = "";
|
||||
bool shortfname = false;
|
||||
|
||||
//parse command line for config
|
||||
for(int iarg=1;iarg<argc;iarg++){
|
||||
@ -55,8 +54,6 @@ slsReceiverFuncs::slsReceiverFuncs(int argc, char *argv[], int &success):
|
||||
}
|
||||
fname.assign(argv[iarg+1]);
|
||||
}
|
||||
if(!strcasecmp(argv[iarg],"-shortfname"))
|
||||
shortfname = true;
|
||||
}
|
||||
|
||||
if(!fname.empty()){
|
||||
@ -123,7 +120,7 @@ slsReceiverFuncs::slsReceiverFuncs(int argc, char *argv[], int &success):
|
||||
strcpy(mess,"dummy message");
|
||||
|
||||
function_table();
|
||||
slsReceiverList = new slsReceiverFunctionList(shortfname);
|
||||
slsReceiverList = new slsReceiverFunctionList();
|
||||
|
||||
#ifdef VERBOSE
|
||||
cout << "Function table assigned." << endl;
|
||||
|
Loading…
x
Reference in New Issue
Block a user