diff --git a/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp b/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp index a6edbbda1..2ee7d776c 100644 --- a/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp +++ b/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp @@ -166,15 +166,14 @@ slsReceiverFunctionList::slsReceiverFunctionList(detectorType det): slsReceiverFunctionList::~slsReceiverFunctionList(){ - closeFile(-1); + createListeningThreads(true); + createWriterThreads(true); for(int i=0;iinitEventTree(savefilename, &iframe); + sprintf(temp, "%s_fxxx_%d_%d",fileName,fileIndex,ithr); + myTree[ithr]=singlePhotonDet[ithr]->initEventTree(temp, &iframe); //resets the pedestalSubtraction array and the commonModeSubtraction singlePhotonDet[ithr]->newDataSet(); if(myFile[ithr]==NULL){ @@ -879,30 +893,33 @@ void slsReceiverFunctionList::closeFile(int ithr){ //datacompression else{ #ifdef MYROOT1 - if(ithr == -1){ - for(int i=0;iGetCurrentFile(); - if(myFile[ithr]->Write()) - cout << "Thread " << ithr <<" wrote frames to file" << endl; - else - cout << "Thread " << ithr << " could not write frames to file" << endl; - }else - cout << "Thread " << ithr << " could not write frames to file: No file or No Tree" << endl; - //close file - if(myTree[ithr] && myFile[ithr]) - myFile[ithr] = myTree[ithr]->GetCurrentFile(); - if(myFile[ithr] != NULL) - myFile[ithr]->Close(); - myFile[ithr] = NULL; - myTree[ithr] = NULL; - } + pthread_mutex_lock(&write_mutex); + //write to file + if(myTree[ithr] && myFile[ithr]){ + myFile[ithr] = myTree[ithr]->GetCurrentFile(); + + if(myFile[ithr]->Write()) + //->Write(tall->GetName(),TObject::kOverwrite); + cout << "Thread " << ithr <<": wrote frames to file" << endl; + else + cout << "Thread " << ithr << ": could not write frames to file" << endl; + + }else + cout << "Thread " << ithr << ": could not write frames to file: No file or No Tree" << endl; + //close file + if(myTree[ithr] && myFile[ithr]) + myFile[ithr] = myTree[ithr]->GetCurrentFile(); + if(myFile[ithr] != NULL) + myFile[ithr]->Close(); + myFile[ithr] = NULL; + myTree[ithr] = NULL; + pthread_mutex_unlock(&write_mutex); + #endif } +#ifdef VERBOSE + cout << ithr << " out of close file" << endl; +#endif } @@ -937,13 +954,14 @@ int slsReceiverFunctionList::startReceiver(char message[]){ sprintf(message,"Could not create file %s.\n",savefilename); return FAIL; } + cout << "Successfully created file(s)" << endl; //done to give the gui some proper name instead of always the last file name if(dataCompression) sprintf(savefilename, "%s/%s_fxxx_%d_xx.root", filePath,fileName,fileIndex); //initialize semaphore - sem_init(&smp,0,1); + sem_init(&smp,1,0); //status pthread_mutex_lock(&status_mutex); @@ -956,15 +974,10 @@ int slsReceiverFunctionList::startReceiver(char message[]){ //start listening /writing sem_post(&listensmp); - - /*int k;*/ - for(int i=0; i < numWriterThreads; ++i){ - - /*sem_getvalue(&writersmp[i],&k);*/ sem_post(&writersmp[i]); - /*sem_getvalue(&writersmp[i],&k);*/ } + cout << "Receiver Started.\nStatus:" << status << endl; return OK; @@ -1268,6 +1281,7 @@ int slsReceiverFunctionList::startWriting(){ char *data=new char[bufferSize]; int iFrame = 0; int xmax=0,ymax=0; + int ret; while(1){ @@ -1320,9 +1334,7 @@ int slsReceiverFunctionList::startWriting(){ //all threads need to close file, reset mask and exit loop - pthread_mutex_lock(&write_mutex); closeFile(ithread); - pthread_mutex_unlock(&write_mutex); pthread_mutex_lock(&status_mutex); writerthreads_mask^=(1<> frameIndexOffset)<newFrame(); @@ -1456,9 +1469,7 @@ int slsReceiverFunctionList::startWriting(){ if (thisEvent==PHOTON_MAX) { iFrame=receiverdata[ithread]->getFrameNumber(buff); - pthread_mutex_lock(&write_mutex); myTree[ithread]->Fill(); - pthread_mutex_unlock(&write_mutex); //cout << "Fill in event: frmNr: " << iFrame << " ix " << ix << " iy " << iy << " type " << thisEvent << endl; } } @@ -1494,17 +1505,54 @@ int slsReceiverFunctionList::startWriting(){ #endif } } - - /*int k; - sem_getvalue(&writersmp[ithread],&k); - cout<