compression extended to client side with r_compression

git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@742 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
l_maliakal_d 2014-02-24 14:58:36 +00:00
parent 792e0f3845
commit a892a8854c
12 changed files with 262 additions and 98 deletions

View File

@ -29,6 +29,7 @@ using namespace std;
#define FILE_PATH_DOES_NOT_EXIST 0x0400000000000000ULL #define FILE_PATH_DOES_NOT_EXIST 0x0400000000000000ULL
#define COULDNOT_CREATE_UDP_SOCKET 0x0200000000000000ULL #define COULDNOT_CREATE_UDP_SOCKET 0x0200000000000000ULL
#define COULDNOT_CREATE_FILE 0x0100000000000000ULL #define COULDNOT_CREATE_FILE 0x0100000000000000ULL
#define COULDNOT_ENABLE_COMPRESSION 0x0080000000000000ULL
@ -84,6 +85,9 @@ public:
if(slsErrorMask&COULDNOT_CREATE_FILE) if(slsErrorMask&COULDNOT_CREATE_FILE)
retval.append("Could not create file to start receiver.\nCheck permissions of output directory\n"); retval.append("Could not create file to start receiver.\nCheck permissions of output directory\n");
if(slsErrorMask&COULDNOT_ENABLE_COMPRESSION)
retval.append("Could not enable/disable data compression in receiver.\nThread creation failed.\n");

View File

@ -134,7 +134,9 @@ enum {
F_CALIBRATE_PEDESTAL, /**< starts acquistion, calibrates pedestal and write back to fpga */ F_CALIBRATE_PEDESTAL, /**< starts acquistion, calibrates pedestal and write back to fpga */
F_READ_RECEIVER_FREQUENCY /**< sets the frequency of receiver sending frames to gui */ F_READ_RECEIVER_FREQUENCY, /**< sets the frequency of receiver sending frames to gui */
F_ENABLE_COMPRESSION /**< enable compression in receiver */
/* Always append functions hereafter!!! */ /* Always append functions hereafter!!! */
}; };

View File

@ -4734,3 +4734,17 @@ int multiSlsDetector::setReadReceiverFrequency(int getFromReceiver,int i){
int multiSlsDetector::enableReceiverCompression(int i){
int ret=-100,ret1;
for (int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++)
if (detectors[idet]){
ret1=detectors[idet]->enableReceiverCompression(i);
if(detectors[idet]->getErrorMask())
setErrorMask(getErrorMask()|(1<<idet));
if(ret==-100)
ret=ret1;
else if (ret!=ret1)
ret=-1;
}
return ret;
}

View File

@ -1209,6 +1209,12 @@ class multiSlsDetector : public slsDetectorUtils {
/** updates the multidetector offsets */ /** updates the multidetector offsets */
void updateOffsets(); void updateOffsets();
/** enable/disable or get data compression in receiver
* @param i is -1 to get, 0 to disable and 1 to enable
/returns data compression in receiver
*/
int enableReceiverCompression(int i = -1);
protected: protected:

View File

@ -6486,3 +6486,21 @@ int slsDetector::setReadReceiverFrequency(int getFromReceiver,int i){
} }
int slsDetector::enableReceiverCompression(int i){
int fnum=F_ENABLE_COMPRESSION;
int ret = FAIL;
int retval=-1;
if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){
#ifdef VERBOSE
std::cout << "Getting/Enabling/Disabling Receiver Compression with argument " << i << std::endl;
#endif
if (connectData() == OK)
ret=thisReceiver->sendInt(fnum,retval,i);
if(ret==FAIL)
setErrorMask((getErrorMask())|(COULDNOT_ENABLE_COMPRESSION));
}
return retval;
}

View File

@ -1609,6 +1609,12 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
*/ */
int setReadReceiverFrequency(int getFromReceiver, int i=-1); int setReadReceiverFrequency(int getFromReceiver, int i=-1);
/** enable/disable or get data compression in receiver
* @param i is -1 to get, 0 to disable and 1 to enable
/returns data compression in receiver
*/
int enableReceiverCompression(int i = -1);
protected: protected:

View File

@ -847,6 +847,11 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) {
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdReceiver; descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdReceiver;
i++; i++;
descrToFuncMap[i].m_pFuncName="r_compression"; //
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdReceiver;
i++;
numberOfCommands=i; numberOfCommands=i;
// #ifdef VERBOSE // #ifdef VERBOSE
@ -4005,6 +4010,17 @@ string slsDetectorCommand::cmdReceiver(int narg, char *args[], int action) {
sprintf(answer,"%d",myDet->setReadReceiverFrequency(1)); sprintf(answer,"%d",myDet->setReadReceiverFrequency(1));
return string(answer); return string(answer);
}
else if(cmd=="r_compression"){
if (action==PUT_ACTION){
if (!sscanf(args[1],"%d",&ival))
return string("Could not scan receiver compression input ")+string(args[1]);
if(ival>=0)
sprintf(answer,"%d",myDet->enableReceiverCompression(ival));
}else
sprintf(answer,"%d",myDet->enableReceiverCompression());
return string(answer);
} }

View File

@ -683,7 +683,11 @@ virtual ROI* getROI(int &n)=0;
virtual int setReadReceiverFrequency(int getFromReceiver, int i=-1)=0; virtual int setReadReceiverFrequency(int getFromReceiver, int i=-1)=0;
/** enable/disable or get data compression in receiver
* @param i is -1 to get, 0 to disable and 1 to enable
/returns data compression in receiver
*/
virtual int enableReceiverCompression(int i = -1)=0;
protected: protected:

View File

@ -77,6 +77,8 @@ slsReceiverFunctionList::slsReceiverFunctionList(detectorType det):
sfilefd(NULL), sfilefd(NULL),
writerthreads_mask(0x0), writerthreads_mask(0x0),
listening_thread_running(0), listening_thread_running(0),
killListeningThread(0),
killAllWritingThreads(0),
cbAction(DO_EVERYTHING), cbAction(DO_EVERYTHING),
startAcquisitionCallBack(NULL), startAcquisitionCallBack(NULL),
pStartAcquisition(NULL), pStartAcquisition(NULL),
@ -317,8 +319,8 @@ int64_t slsReceiverFunctionList::setAcquisitionPeriod(int64_t index){
/******************* need to look at exit strategy **************************/
void slsReceiverFunctionList::enableDataCompression(bool enable){ int slsReceiverFunctionList::enableDataCompression(bool enable){
cout << "Data compression "; cout << "Data compression ";
if(enable) if(enable)
cout << "enabled" << endl; cout << "enabled" << endl;
@ -341,13 +343,15 @@ void slsReceiverFunctionList::enableDataCompression(bool enable){
if(createWriterThreads() == FAIL){ if(createWriterThreads() == FAIL){
cout << "ERROR: Could not create writer threads" << endl; cout << "ERROR: Could not create writer threads" << endl;
exit (-1); return FAIL;
} }
setThreadPriorities(); setThreadPriorities();
if(enable) if(enable)
setupFilter(); setupFilter();
return OK;
} }
@ -583,15 +587,18 @@ int slsReceiverFunctionList::createUDPSocket(){
int slsReceiverFunctionList::createListeningThreads(bool destroy){ int slsReceiverFunctionList::createListeningThreads(bool destroy){
void* status;
killListeningThread = 0;
if(!destroy){
pthread_mutex_lock(&status_mutex); pthread_mutex_lock(&status_mutex);
listening_thread_running = 0; listening_thread_running = 0;
pthread_mutex_unlock(&(status_mutex)); pthread_mutex_unlock(&(status_mutex));
if(!destroy){
//listening thread //listening thread
cout << "Creating Listening Thread" << endl; cout << "Creating Listening Thread" << endl;
sem_init(&listensmp,0,0); sem_init(&listensmp,0,1);
if(pthread_create(&listening_thread, NULL,startListeningThread, (void*) this)){ if(pthread_create(&listening_thread, NULL,startListeningThread, (void*) this)){
cout << "Could not create listening thread" << endl; cout << "Could not create listening thread" << endl;
return FAIL; return FAIL;
@ -601,11 +608,12 @@ int slsReceiverFunctionList::createListeningThreads(bool destroy){
#endif #endif
}else{ }else{
cout<<"Destroying Listening Thread"<<endl; cout<<"Destroying Listening Thread"<<endl;
killListeningThread = 1;
sem_post(&listensmp); sem_post(&listensmp);
sem_destroy(&listensmp); pthread_join(listening_thread, &status);
cout << "Threads destroyed" << endl; killListeningThread = 0;
if(pthread_cancel(listening_thread)!=0) cout << "Listening thread destroyed" << endl;
cout << "Unable to cancel listening Thread " << endl;
} }
return OK; return OK;
@ -619,21 +627,24 @@ int slsReceiverFunctionList::createListeningThreads(bool destroy){
int slsReceiverFunctionList::createWriterThreads(bool destroy){ int slsReceiverFunctionList::createWriterThreads(bool destroy){
int i; int i;
void* status;
if(!destroy){ killAllWritingThreads = 0;
pthread_mutex_lock(&status_mutex); pthread_mutex_lock(&status_mutex);
writerthreads_mask = 0x0; writerthreads_mask = 0x0;
pthread_mutex_unlock(&(status_mutex)); pthread_mutex_unlock(&(status_mutex));
if(!destroy){
//start writer threads //start writer threads
cout << "Creating Writer Threads"; cout << "Creating Writer Threads";
currentWriterThreadIndex = -1; currentWriterThreadIndex = -1;
for(i = 0; i < numWriterThreads; ++i){ for(i = 0; i < numWriterThreads; ++i){
sem_init(&writersmp[i],0,0); sem_init(&writersmp[i],0,1);
thread_started = 0; thread_started = 0;
currentWriterThreadIndex = i; currentWriterThreadIndex = i;
if(pthread_create(&writing_thread[i], NULL,startWritingThread, (void*) this)){ if(pthread_create(&writing_thread[i], NULL,startWritingThread, (void*) this)){
@ -652,12 +663,14 @@ int slsReceiverFunctionList::createWriterThreads(bool destroy){
}else{ }else{
cout << "Destroying Writer Thread" << endl; cout << "Destroying Writer Thread" << endl;
killAllWritingThreads = 1;
for(i = 0; i < numWriterThreads; ++i){ for(i = 0; i < numWriterThreads; ++i){
sem_post(&writersmp[i]); sem_post(&writersmp[i]);
sem_destroy(&writersmp[i]); pthread_join(writing_thread[i],&status);
if(pthread_cancel(writing_thread[i])!=0) cout <<"."<<flush;
cout << "Unable to cancel Thread of index" << i << endl;
} }
killAllWritingThreads = 0;
cout << endl << "Writer threads destroyed" << endl;
} }
return OK; return OK;
@ -714,9 +727,11 @@ int slsReceiverFunctionList::setupWriter(){
guiDataReady=0; guiDataReady=0;
strcpy(guiFileName,""); strcpy(guiFileName,"");
cbAction = DO_EVERYTHING; cbAction = DO_EVERYTHING;
writerthreads_mask = 0x0;
int ret,ret1 = OK; int ret,ret1 = OK;
pthread_mutex_lock(&status_mutex);
writerthreads_mask = 0x0;
pthread_mutex_unlock(&status_mutex);
//printouts //printouts
cout << "Max Packets Per File:" << maxPacketsPerFile << endl; cout << "Max Packets Per File:" << maxPacketsPerFile << endl;
@ -745,7 +760,9 @@ int slsReceiverFunctionList::setupWriter(){
ret = createNewFile(); ret = createNewFile();
else{ else{
for(int i=0;i<numWriterThreads;i++){ for(int i=0;i<numWriterThreads;i++){
pthread_mutex_lock(&write_mutex);
ret1 = createCompressionFile(i,0); ret1 = createCompressionFile(i,0);
pthread_mutex_unlock(&write_mutex);
if(ret1 == FAIL) if(ret1 == FAIL)
ret = FAIL; ret = FAIL;
} }
@ -845,6 +862,9 @@ int slsReceiverFunctionList::createNewFile(){
void slsReceiverFunctionList::closeFile(int ithr){ void slsReceiverFunctionList::closeFile(int ithr){
#ifdef VERBOSE
cout << "In closeFile for thread " << ithr << endl;
#endif
if(!dataCompression){ if(!dataCompression){
//close file //close file
if(sfilefd){ if(sfilefd){
@ -936,8 +956,14 @@ int slsReceiverFunctionList::startReceiver(char message[]){
//start listening /writing //start listening /writing
sem_post(&listensmp); sem_post(&listensmp);
/*int k;*/
for(int i=0; i < numWriterThreads; ++i){ for(int i=0; i < numWriterThreads; ++i){
/*sem_getvalue(&writersmp[i],&k);*/
sem_post(&writersmp[i]); sem_post(&writersmp[i]);
/*sem_getvalue(&writersmp[i],&k);*/
} }
cout << "Receiver Started.\nStatus:" << status << endl; cout << "Receiver Started.\nStatus:" << status << endl;
@ -1207,6 +1233,9 @@ int slsReceiverFunctionList::startListening(){
sem_wait(&listensmp); sem_wait(&listensmp);
//make sure its not exiting thread
if(killListeningThread)
pthread_exit(NULL);
} }
return OK; return OK;
@ -1260,12 +1289,14 @@ int slsReceiverFunctionList::startWriting(){
while((1<<ithread)&writerthreads_mask){ while((1<<ithread)&writerthreads_mask){
#ifdef VERYDEBUG
cout << ithread << " ***waiting to pop out of fifo" << endl;
#endif
//pop //pop
fifo->pop(wbuf); fifo->pop(wbuf);
numpackets = (uint16_t)(*((uint16_t*)wbuf)); numpackets = (uint16_t)(*((uint16_t*)wbuf));
#ifdef VERYDEBUG #ifdef VERYDEBUG
cout << "numpackets:" << dec << numpackets << endl; cout << ithread << " numpackets:" << dec << numpackets << endl;
cout << ithread << " *** popped from fifo " << numpackets << endl; cout << ithread << " *** popped from fifo " << numpackets << endl;
#endif #endif
@ -1277,23 +1308,25 @@ int slsReceiverFunctionList::startWriting(){
//last dummy packet //last dummy packet
if(numpackets == 0xFFFF){ if(numpackets == 0xFFFF){
#ifdef VERYDEBUG #ifdef VERYDEBUG
cout << "**********************popped last dummy frame:" << (void*)wbuf << " from thread " << ithread << endl; cout << ithread << " **********************popped last dummy frame:" << (void*)wbuf << endl;
#endif #endif
//free fifo //free fifo
while(!fifoFree->push(wbuf)); while(!fifoFree->push(wbuf));
#ifdef VERYDEBUG #ifdef VERYDEBUG
cout << "fifo freed:" << (void*)wbuf << " from thread " << ithread << endl; cout << ithread << " fifo freed:" << (void*)wbuf << endl;
#endif #endif
//all threads need to close file, reset mask and exit loop //all threads need to close file, reset mask and exit loop
pthread_mutex_lock(&status_mutex); pthread_mutex_lock(&write_mutex);
closeFile(ithread); closeFile(ithread);
pthread_mutex_unlock(&write_mutex);
pthread_mutex_lock(&status_mutex);
writerthreads_mask^=(1<<ithread); writerthreads_mask^=(1<<ithread);
#ifdef VERYDEBUG #ifdef VERYDEBUG
cout <<"Resetting mask of current thread " << ithread << ". New Mask: " << writerthreads_mask << endl; cout << ithread << " Resetting mask of current thread. New Mask: " << writerthreads_mask << endl;
#endif #endif
pthread_mutex_unlock(&status_mutex); pthread_mutex_unlock(&status_mutex);
@ -1423,7 +1456,9 @@ int slsReceiverFunctionList::startWriting(){
if (thisEvent==PHOTON_MAX) { if (thisEvent==PHOTON_MAX) {
iFrame=receiverdata[ithread]->getFrameNumber(buff); iFrame=receiverdata[ithread]->getFrameNumber(buff);
pthread_mutex_lock(&write_mutex);
myTree[ithread]->Fill(); myTree[ithread]->Fill();
pthread_mutex_unlock(&write_mutex);
//cout << "Fill in event: frmNr: " << iFrame << " ix " << ix << " iy " << iy << " type " << thisEvent << endl; //cout << "Fill in event: frmNr: " << iFrame << " ix " << ix << " iy " << iy << " type " << thisEvent << endl;
} }
} }
@ -1431,13 +1466,13 @@ int slsReceiverFunctionList::startWriting(){
nf++; nf++;
pthread_mutex_lock(&write_mutex); pthread_mutex_lock(&progress_mutex);
packetsInFile += packetsPerFrame; packetsInFile += packetsPerFrame;
packetsCaught += packetsPerFrame; packetsCaught += packetsPerFrame;
totalPacketsCaught += packetsPerFrame; totalPacketsCaught += packetsPerFrame;
pthread_mutex_unlock(&write_mutex); pthread_mutex_unlock(&progress_mutex);
if(!once){ if(!once){
copyFrameToGui(buff); copyFrameToGui(buff);
once = 1; once = 1;
@ -1460,9 +1495,16 @@ int slsReceiverFunctionList::startWriting(){
} }
} }
/*int k;
sem_getvalue(&writersmp[ithread],&k);
cout<<ithread<<" waiting for sem:"<<k <<endl;*/
//wait //wait
sem_wait(&writersmp[ithread]); sem_wait(&writersmp[ithread]);
if(killAllWritingThreads)
pthread_exit(NULL);
} }
@ -1472,6 +1514,15 @@ int slsReceiverFunctionList::startWriting(){
void slsReceiverFunctionList::writeToFile_withoutCompression(char* buf,int numpackets){ void slsReceiverFunctionList::writeToFile_withoutCompression(char* buf,int numpackets){
int packetsToSave, offset,tempframenum,lastpacket; int packetsToSave, offset,tempframenum,lastpacket;

View File

@ -168,8 +168,9 @@ public:
int64_t setAcquisitionPeriod(int64_t index); int64_t setAcquisitionPeriod(int64_t index);
/** enabl data compression, by saving only hits /** enabl data compression, by saving only hits
/returns if failed
*/ */
void enableDataCompression(bool enable); int enableDataCompression(bool enable);
/** get data compression, by saving only hits /** get data compression, by saving only hits
*/ */
@ -465,8 +466,27 @@ private:
/** total frame count the listening thread has listened to */ /** total frame count the listening thread has listened to */
int totalListeningFrameCount; int totalListeningFrameCount;
/** mask showing which threads are running */
volatile uint32_t writerthreads_mask;
/** 0 if listening thread is idle, 1 otherwise */
int listening_thread_running;
/** variable used to self terminate threads waiting for semaphores */
int killListeningThread;
/** variable used to self terminate threads waiting for semaphores */
int killAllWritingThreads;
//filter
singlePhotonDetector<uint16_t> *singlePhotonDet[MAX_NUM_WRITER_THREADS];
slsReceiverData<uint16_t> *receiverdata[MAX_NUM_WRITER_THREADS];
moenchCommonMode *cmSub;
bool commonModeSubtractionEnable;
//semaphores //semaphores
@ -477,6 +497,7 @@ private:
/** semaphore to synchronize writer threads */ /** semaphore to synchronize writer threads */
sem_t writersmp[MAX_NUM_WRITER_THREADS]; sem_t writersmp[MAX_NUM_WRITER_THREADS];
//mutex //mutex
/** guiDataReady mutex */ /** guiDataReady mutex */
pthread_mutex_t dataReadyMutex; pthread_mutex_t dataReadyMutex;
@ -491,6 +512,20 @@ private:
pthread_mutex_t write_mutex; pthread_mutex_t write_mutex;
#ifdef MYROOT1
/** Tree where the hits are stored */
TTree *myTree[MAX_NUM_WRITER_THREADS];
/** File where the tree is saved */
TFile *myFile[MAX_NUM_WRITER_THREADS];
#endif
/** File Descriptor */
FILE *sfilefd;
/** /**
callback arguments are callback arguments are
filepath filepath
@ -533,34 +568,9 @@ private:
* 2 we open, close, write file, callback does not do anything */ * 2 we open, close, write file, callback does not do anything */
int cbAction; int cbAction;
//filter
singlePhotonDetector<uint16_t> *singlePhotonDet[MAX_NUM_WRITER_THREADS];
slsReceiverData<uint16_t> *receiverdata[MAX_NUM_WRITER_THREADS];
moenchCommonMode *cmSub;
bool commonModeSubtractionEnable;
public: public:
#ifdef MYROOT1
/** Tree where the hits are stored */
TTree *myTree[MAX_NUM_WRITER_THREADS];
/** File where the tree is saved */
TFile *myFile[MAX_NUM_WRITER_THREADS];
#endif
/** File Descriptor */
FILE *sfilefd;
/** mask showing which threads are running */
volatile uint32_t writerthreads_mask;
/** 0 if listening thread is idle, 1 otherwise */
int listening_thread_running;
/** /**
callback arguments are callback arguments are

View File

@ -24,9 +24,6 @@ int slsReceiverFuncs::socketDescriptor(-1);
slsReceiverFuncs::~slsReceiverFuncs() { slsReceiverFuncs::~slsReceiverFuncs() {
/*if(file_des != -1){close(file_des);file_des = -1;}
//shutdown(socketDescriptor,SHUT_RDWR);
close(socketDescriptor);*/
if(socket) delete socket; if(socket) delete socket;
closeFile(0); closeFile(0);
} }
@ -45,7 +42,6 @@ slsReceiverFuncs::slsReceiverFuncs(int argc, char *argv[], int &success):
string sLine,sargname; string sLine,sargname;
int iline = 0; int iline = 0;
bool dcompr = false; bool dcompr = false;
/*int jobthread = -1;*/
success=OK; success=OK;
@ -115,9 +111,14 @@ slsReceiverFuncs::slsReceiverFuncs(int argc, char *argv[], int &success):
} }
} }
} }
//compression
else if(sargname=="compression"){
if(sstr.good()) {
sstr >> sargname;
if((!strcasecmp(sargname.c_str(),"yes"))||(!strcasecmp(sargname.c_str(),"y")))
dcompr = true;
}
}
} }
} }
infile.close(); infile.close();
@ -176,10 +177,7 @@ slsReceiverFuncs::slsReceiverFuncs(int argc, char *argv[], int &success):
cout << "no value given after -compression in command line. Exiting." << endl; cout << "no value given after -compression in command line. Exiting." << endl;
success=FAIL; success=FAIL;
}else { }else {
if(!strcasecmp(argv[iarg+1],"yes")){ if((!strcasecmp(argv[iarg+1],"yes"))||(!strcasecmp(argv[iarg+1],"y"))){
dcompr = true;
iarg++;
}else if(!strcasecmp(argv[iarg+1],"no")){
dcompr = true; dcompr = true;
iarg++; iarg++;
}else{ }else{
@ -188,20 +186,6 @@ slsReceiverFuncs::slsReceiverFuncs(int argc, char *argv[], int &success):
} }
} }
} }
/*//jobstothread
else if(!strcasecmp(argv[iarg],"-jobthread")){
if(iarg+1==argc){
cout << "no value given after -jobthread in command line. Exiting." << endl;
success=FAIL;
}else {
if(sscanf(argv[iarg+1],"%d",&jobthread)){
iarg++;
}else{
cout << "could not decode value for jobthread in command line. \n\nExiting." << endl;
success=FAIL;
}
}
}*/
else{ else{
cout << "Unknown argument:" << argv[iarg] << endl; cout << "Unknown argument:" << argv[iarg] << endl;
success=FAIL; success=FAIL;
@ -232,7 +216,6 @@ slsReceiverFuncs::slsReceiverFuncs(int argc, char *argv[], int &success):
cout << "type:\t\t Type of receiver. Default: Gotthard. Options: Moench" << endl; cout << "type:\t\t Type of receiver. Default: Gotthard. Options: Moench" << endl;
cout << "rx_tcpport:\t TCP Communication Port with the client. Default:1954. " << endl; cout << "rx_tcpport:\t TCP Communication Port with the client. Default:1954. " << endl;
cout << "compression:\t Data Compression. Saving only hits. Option:yes, no" << endl << endl;; cout << "compression:\t Data Compression. Saving only hits. Option:yes, no" << endl << endl;;
/*cout << "jobthread:\t Number of jobs given to a thread for compression." << endl << endl;*/
} }
@ -256,8 +239,8 @@ slsReceiverFuncs::slsReceiverFuncs(int argc, char *argv[], int &success):
//Catch signal SIGINT to close files properly //Catch signal SIGINT to close files properly
signal(SIGINT,staticCloseFile); signal(SIGINT,staticCloseFile);
/*if(dcompr)*/ slsReceiverList->enableDataCompression(dcompr); if(dcompr)
/*if(jobthread!=-1) slsReceiverList->setNumberOfJobsPerThread(jobthread);*/ slsReceiverList->enableDataCompression(dcompr);
#ifdef VERBOSE #ifdef VERBOSE
cout << "Function table assigned." << endl; cout << "Function table assigned." << endl;
@ -326,7 +309,7 @@ int slsReceiverFuncs::function_table(){
flist[F_CONFIGURE_MAC] = &slsReceiverFuncs::set_short_frame; flist[F_CONFIGURE_MAC] = &slsReceiverFuncs::set_short_frame;
flist[F_START_READOUT] = &slsReceiverFuncs::start_readout; flist[F_START_READOUT] = &slsReceiverFuncs::start_readout;
flist[F_SET_TIMER] = &slsReceiverFuncs::set_acquisition_period; flist[F_SET_TIMER] = &slsReceiverFuncs::set_acquisition_period;
flist[F_ENABLE_COMPRESSION] = &slsReceiverFuncs::enable_compression;
//General Functions //General Functions
flist[F_LOCK_SERVER] = &slsReceiverFuncs::lock_receiver; flist[F_LOCK_SERVER] = &slsReceiverFuncs::lock_receiver;
@ -405,7 +388,7 @@ void slsReceiverFuncs::closeFile(int p){
cout<<"Closing Files... "<<endl; cout<<"Closing Files... "<<endl;
slsReceiverList->closeFile(); slsReceiverList->closeFile();
cout << "Goodbye!" << endl; cout << "Goodbye!" << endl;
exit(1); exit(-1);
} }
void slsReceiverFuncs::staticCloseFile(int p){ void slsReceiverFuncs::staticCloseFile(int p){
@ -545,7 +528,7 @@ int slsReceiverFuncs::set_file_index() {
// execute action if the arguments correctly arrived // execute action if the arguments correctly arrived
#ifdef SLS_RECEIVER_FUNCTION_LIST #ifdef SLS_RECEIVER_FUNCTION_LIST
if (ret==OK) { if (ret==OK) {
if (lockStatus==1 && socket->differentClients==1){//necessary??? if (lockStatus==1 && socket->differentClients==1){
sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP);
ret=FAIL; ret=FAIL;
} }
@ -598,7 +581,7 @@ int slsReceiverFuncs::set_frame_index() {
// execute action if the arguments correctly arrived // execute action if the arguments correctly arrived
#ifdef SLS_RECEIVER_FUNCTION_LIST #ifdef SLS_RECEIVER_FUNCTION_LIST
if (ret==OK) { if (ret==OK) {
if (lockStatus==1 && socket->differentClients==1){//necessary??? if (lockStatus==1 && socket->differentClients==1){
sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP);
ret=FAIL; ret=FAIL;
} }
@ -655,7 +638,7 @@ int slsReceiverFuncs::setup_udp(){
// execute action if the arguments correctly arrived // execute action if the arguments correctly arrived
#ifdef SLS_RECEIVER_FUNCTION_LIST #ifdef SLS_RECEIVER_FUNCTION_LIST
if (ret==OK) { if (ret==OK) {
if (lockStatus==1 && socket->differentClients==1){//necessary??? if (lockStatus==1 && socket->differentClients==1){
sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP);
ret=FAIL; ret=FAIL;
} }
@ -922,7 +905,7 @@ int slsReceiverFuncs::set_short_frame() {
// execute action if the arguments correctly arrived // execute action if the arguments correctly arrived
#ifdef SLS_RECEIVER_FUNCTION_LIST #ifdef SLS_RECEIVER_FUNCTION_LIST
if (ret==OK) { if (ret==OK) {
if (lockStatus==1 && socket->differentClients==1){//necessary??? if (lockStatus==1 && socket->differentClients==1){
sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP);
ret=FAIL; ret=FAIL;
} }
@ -1301,7 +1284,7 @@ int slsReceiverFuncs::set_read_frequency(){
// execute action if the arguments correctly arrived // execute action if the arguments correctly arrived
#ifdef SLS_RECEIVER_FUNCTION_LIST #ifdef SLS_RECEIVER_FUNCTION_LIST
if (ret==OK) { if (ret==OK) {
if (lockStatus==1 && socket->differentClients==1){//necessary??? if (lockStatus==1 && socket->differentClients==1){
sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP);
ret=FAIL; ret=FAIL;
}/* }/*
@ -1351,7 +1334,7 @@ int slsReceiverFuncs::enable_file_write(){
// execute action if the arguments correctly arrived // execute action if the arguments correctly arrived
#ifdef SLS_RECEIVER_FUNCTION_LIST #ifdef SLS_RECEIVER_FUNCTION_LIST
if (ret==OK) { if (ret==OK) {
if (lockStatus==1 && socket->differentClients==1){//necessary??? if (lockStatus==1 && socket->differentClients==1){
sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP);
ret=FAIL; ret=FAIL;
} }
@ -1453,7 +1436,7 @@ int slsReceiverFuncs::set_acquisition_period() {
// execute action if the arguments correctly arrived // execute action if the arguments correctly arrived
#ifdef SLS_RECEIVER_FUNCTION_LIST #ifdef SLS_RECEIVER_FUNCTION_LIST
if (ret==OK) { if (ret==OK) {
if (lockStatus==1 && socket->differentClients==1){//necessary??? if (lockStatus==1 && socket->differentClients==1){
sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP);
ret=FAIL; ret=FAIL;
} }
@ -1488,6 +1471,53 @@ int slsReceiverFuncs::set_acquisition_period() {
int slsReceiverFuncs::enable_compression() {
ret=OK;
int enable=-1;
int retval=-100;
strcpy(mess,"Could not enable/disable compression for receiver\n");
// receive arguments
if(socket->ReceiveDataOnly(&enable,sizeof(enable)) < 0 ){
strcpy(mess,"Error reading from socket\n");
ret = FAIL;
}
// execute action if the arguments correctly arrived
#ifdef SLS_RECEIVER_FUNCTION_LIST
if (ret==OK) {
if(enable >= 0){
if (lockStatus==1 && socket->differentClients==1){
sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP);
ret=FAIL;
}
else if(slsReceiverList->getStatus()==RUNNING){
strcpy(mess,"Cannot enable/disable compression while status is running\n");
ret=FAIL;
}
else
ret = slsReceiverList->enableDataCompression(enable);
}
retval=slsReceiverList->getDataCompression();
}
#endif
if(ret==OK && socket->differentClients){
cout << "Force update" << endl;
ret=FORCE_UPDATE;
}
// send answer
socket->SendDataOnly(&ret,sizeof(ret));
if(ret==FAIL)
socket->SendDataOnly(mess,sizeof(mess));
socket->SendDataOnly(&retval,sizeof(retval));
//return ok/fail
return ret;
}

View File

@ -154,6 +154,9 @@ public:
/** set acquisition period to find the value of n */ /** set acquisition period to find the value of n */
int set_acquisition_period(); int set_acquisition_period();
/** enable compression */
int enable_compression();
//General Functions //General Functions
/** Locks Receiver */ /** Locks Receiver */