mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-23 01:58:00 +02:00
changes to receiver works for data compression. needs optimizing
git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@699 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
@ -16,7 +16,7 @@
|
||||
#define CIRCULARFIFO_H_
|
||||
|
||||
//#include "sls_detector_defs.h"
|
||||
|
||||
#include <semaphore.h>
|
||||
#include <vector>
|
||||
using namespace std;
|
||||
|
||||
@ -35,6 +35,7 @@ public:
|
||||
CircularFifo(unsigned int Size) : tail(0), head(0){
|
||||
Capacity = Size + 1;
|
||||
array.resize(Capacity);
|
||||
sem_init(&free_mutex,0,0);
|
||||
}
|
||||
virtual ~CircularFifo() {}
|
||||
|
||||
@ -49,6 +50,7 @@ private:
|
||||
vector <Element*> array;
|
||||
volatile unsigned int head; // output index
|
||||
unsigned int Capacity;
|
||||
sem_t free_mutex;
|
||||
|
||||
unsigned int increment(unsigned int idx_) const;
|
||||
};
|
||||
@ -70,6 +72,7 @@ bool CircularFifo<Element>::push(Element*& item_)
|
||||
{
|
||||
array[tail] = item_;
|
||||
tail = nextTail;
|
||||
sem_post(&free_mutex);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -86,8 +89,9 @@ bool CircularFifo<Element>::push(Element*& item_)
|
||||
template<typename Element>
|
||||
bool CircularFifo<Element>::pop(Element*& item_)
|
||||
{
|
||||
if(head == tail)
|
||||
return false; // empty queue
|
||||
// if(head == tail)
|
||||
// return false; // empty queue
|
||||
sem_wait(&free_mutex);
|
||||
|
||||
item_ = array[head];
|
||||
head = increment(head);
|
||||
|
@ -11,15 +11,18 @@
|
||||
#define CREATE_FILES 1
|
||||
#define DO_EVERYTHING 2
|
||||
|
||||
#define BUF_SIZE (16*1024*1024) //16mb
|
||||
#define BUF_SIZE (16*1024*1024) //16mb
|
||||
#define SAMPLE_TIME_IN_NS 100000000//100ms
|
||||
#define MAX_JOBS_PER_THREAD 1000
|
||||
#define HEADER_SIZE_NUM_FRAMES 2
|
||||
#define HEADER_SIZE_NUM_PACKETS 1
|
||||
|
||||
|
||||
//all max frames defined in sls_detector_defs.h. 20000 gotthard, 100000 for short gotthard, 1000 for moench
|
||||
|
||||
|
||||
|
||||
//#define GOTTHARD_FIFO_SIZE 25000
|
||||
#define GOTTHARD_FIFO_SIZE 11
|
||||
#define GOTTHARD_ALIGNED_FRAME_SIZE 4096
|
||||
#define GOTTHARD_FIFO_SIZE 25000 //cannot be less than max jobs per thread = 1000
|
||||
/*#define GOTTHARD_ALIGNED_FRAME_SIZE 4096*/
|
||||
#define GOTTHARD_PACKETS_PER_FRAME 2
|
||||
#define GOTTHARD_ONE_PACKET_SIZE 1286
|
||||
#define GOTTHARD_BUFFER_SIZE (GOTTHARD_ONE_PACKET_SIZE*GOTTHARD_PACKETS_PER_FRAME) //1286*2
|
||||
@ -37,13 +40,9 @@
|
||||
#define GOTTHARD_PACKET_INDEX_MASK 0x1
|
||||
|
||||
|
||||
//#define GOTTHARD_NUM_JOBS_P_THREAD 5000//20000
|
||||
#define GOTTHARD_NUM_JOBS_P_THREAD 3//with 25 frames
|
||||
#define GOTTHARD_SHORT_NUM_JOBS_P_THREAD 2500//40000
|
||||
#define MOENCH_NUM_JOBS_P_THREAD 1000//10000
|
||||
|
||||
#define MOENCH_FIFO_SIZE 2500
|
||||
#define MOENCH_ALIGNED_FRAME_SIZE 65536
|
||||
#define MOENCH_FIFO_SIZE 2500 //cannot be less than max jobs per thread = 1000
|
||||
/*#define MOENCH_ALIGNED_FRAME_SIZE 65536*/
|
||||
#define MOENCH_PACKETS_PER_FRAME 40
|
||||
#define MOENCH_ONE_PACKET_SIZE 1286
|
||||
#define MOENCH_BUFFER_SIZE (MOENCH_ONE_PACKET_SIZE*MOENCH_PACKETS_PER_FRAME) //1286*40
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -185,6 +185,18 @@ public:
|
||||
*/
|
||||
int startWriting();
|
||||
|
||||
/**
|
||||
* Creates new file
|
||||
*\returns OK for succces or FAIL for failure
|
||||
*/
|
||||
int createNewFile();
|
||||
|
||||
/**
|
||||
* Copy frames to gui
|
||||
* uses semaphore for nth frame mode
|
||||
*/
|
||||
void copyFrameToGui(char* startbuf);
|
||||
|
||||
/**
|
||||
* Returns the buffer-current frame read by receiver
|
||||
* @param c pointer to current file name
|
||||
@ -198,24 +210,33 @@ public:
|
||||
*/
|
||||
int setShortFrame(int i);
|
||||
|
||||
/**
|
||||
* Set the variable to send every nth frame to gui
|
||||
* or if 0,send frame only upon gui request
|
||||
*/
|
||||
int setNFrameToGui(int i){if(i>=0) nFrameToGui = i; return nFrameToGui;};
|
||||
|
||||
/** set status to transmitting and
|
||||
* when fifo is empty later, sets status to run_finished */
|
||||
void startReadout();
|
||||
|
||||
/** enabl data compression, by saving only hits */
|
||||
void enableDataCompression(bool enable){dataCompression = enable;filter->enableCompression(enable);};
|
||||
void enableDataCompression(bool enable){dataCompression = enable;if(filter)filter->enableCompression(enable);};
|
||||
|
||||
/** get data compression, by saving only hits */
|
||||
bool getDataCompression(){ return dataCompression;};
|
||||
|
||||
/** Set Number of Jobs Per Thread */
|
||||
void setNumberOfJobsPerThread(int i){userDefinedNumJobsPerThread = i; numJobsPerThread = i;};
|
||||
/**
|
||||
* Set the variable to send every nth frame to gui
|
||||
* or if 0,send frame only upon gui request
|
||||
*/
|
||||
int setNFrameToGui(int i);
|
||||
|
||||
/** set acquisition period if a positive number */
|
||||
int64_t setAcquisitionPeriod(int64_t index);
|
||||
|
||||
/** set up fifo according to the new numjobsperthread */
|
||||
void setupFifoStructure ();
|
||||
|
||||
/** free fifo buffer, called back from single photon filter */
|
||||
static void freeFifoBufferCallBack (char* fbuffer, void *this_pointer){((slsReceiverFunctionList*)this_pointer)->freeFifoBuffer(fbuffer);};
|
||||
void freeFifoBuffer(char* fbuffer){fifofree->push(fbuffer);};
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
@ -264,15 +285,15 @@ private:
|
||||
/** Total packets caught for an entire acquisition (including all scans) */
|
||||
int totalPacketsCaught;
|
||||
|
||||
/** Frames currently in current file, starts new file when it reaches max */
|
||||
int framesInFile;
|
||||
|
||||
/** Frame index at start of an entire acquisition (including all scans) */
|
||||
uint32_t startAcquisitionIndex;
|
||||
|
||||
/** Actual current frame index of an entire acquisition (including all scans) */
|
||||
uint32_t acquisitionIndex;
|
||||
|
||||
/** Packets currently in current file, starts new file when it reaches max */
|
||||
int packetsInFile;
|
||||
|
||||
/** Previous Frame number from buffer */
|
||||
uint32_t prevframenum;
|
||||
|
||||
@ -375,8 +396,8 @@ private:
|
||||
/** Number of jobs per thread for data compression */
|
||||
int numJobsPerThread;
|
||||
|
||||
/** user defined number of jobs per thread for data compression */
|
||||
int userDefinedNumJobsPerThread;
|
||||
/** acquisition period */
|
||||
int64_t acquisitionPeriod;
|
||||
|
||||
/**
|
||||
callback arguments are
|
||||
|
@ -41,7 +41,7 @@ slsReceiverFuncs::slsReceiverFuncs(int argc, char *argv[], int &success):
|
||||
string sLine,sargname;
|
||||
int iline = 0;
|
||||
bool dcompr = false;
|
||||
int jobthread = -1;
|
||||
/*int jobthread = -1;*/
|
||||
|
||||
|
||||
success=OK;
|
||||
@ -67,7 +67,7 @@ slsReceiverFuncs::slsReceiverFuncs(int argc, char *argv[], int &success):
|
||||
getline(infile,sLine);
|
||||
iline++;
|
||||
#ifdef VERBOSE
|
||||
cout << str << endl;
|
||||
cout << sLine << endl;
|
||||
#endif
|
||||
if(sLine.find('#')!=string::npos){
|
||||
#ifdef VERBOSE
|
||||
@ -184,7 +184,7 @@ slsReceiverFuncs::slsReceiverFuncs(int argc, char *argv[], int &success):
|
||||
}
|
||||
}
|
||||
}
|
||||
//jobstothread
|
||||
/*//jobstothread
|
||||
else if(!strcasecmp(argv[iarg],"-jobthread")){
|
||||
if(iarg+1==argc){
|
||||
cout << "no value given after -jobthread in command line. Exiting." << endl;
|
||||
@ -197,7 +197,7 @@ slsReceiverFuncs::slsReceiverFuncs(int argc, char *argv[], int &success):
|
||||
success=FAIL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
else{
|
||||
cout << "Unknown argument:" << argv[iarg] << endl;
|
||||
success=FAIL;
|
||||
@ -227,8 +227,8 @@ slsReceiverFuncs::slsReceiverFuncs(int argc, char *argv[], int &success):
|
||||
cout << "Help Commands " << 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 << "compression:\t Data Compression. Saving only hits. Option:yes, no" << endl;
|
||||
cout << "jobthread:\t Number of jobs given to a thread for compression." << 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;*/
|
||||
}
|
||||
|
||||
|
||||
@ -250,7 +250,7 @@ slsReceiverFuncs::slsReceiverFuncs(int argc, char *argv[], int &success):
|
||||
slsReceiverList = new slsReceiverFunctionList(myDetectorType);
|
||||
|
||||
if(dcompr) slsReceiverList->enableDataCompression(dcompr);
|
||||
if(jobthread!=-1) slsReceiverList->setNumberOfJobsPerThread(jobthread);
|
||||
/*if(jobthread!=-1) slsReceiverList->setNumberOfJobsPerThread(jobthread);*/
|
||||
|
||||
#ifdef VERBOSE
|
||||
cout << "Function table assigned." << endl;
|
||||
@ -318,6 +318,8 @@ int slsReceiverFuncs::function_table(){
|
||||
flist[F_GET_ID] = &slsReceiverFuncs::get_version;
|
||||
flist[F_CONFIGURE_MAC] = &slsReceiverFuncs::set_short_frame;
|
||||
flist[F_START_READOUT] = &slsReceiverFuncs::start_readout;
|
||||
flist[F_SET_TIMER] = &slsReceiverFuncs::set_acquisition_period;
|
||||
|
||||
|
||||
//General Functions
|
||||
flist[F_LOCK_SERVER] = &slsReceiverFuncs::lock_receiver;
|
||||
@ -1427,6 +1429,55 @@ int slsReceiverFuncs::start_readout(){
|
||||
|
||||
|
||||
|
||||
int slsReceiverFuncs::set_acquisition_period() {
|
||||
ret=OK;
|
||||
int64_t retval = -1;
|
||||
int64_t index = -1;
|
||||
strcpy(mess,"Could not set acquisition period in receiver\n");
|
||||
|
||||
|
||||
// receive arguments
|
||||
if(socket->ReceiveDataOnly(&index,sizeof(index)) < 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 (lockStatus==1 && socket->differentClients==1){//necessary???
|
||||
sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP);
|
||||
ret=FAIL;
|
||||
}
|
||||
else
|
||||
retval=slsReceiverList->setAcquisitionPeriod(index);
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
if(ret!=FAIL)
|
||||
cout << "acquisition period:" << retval << endl;
|
||||
else
|
||||
cout << mess << endl;
|
||||
#endif
|
||||
#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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -147,6 +147,9 @@ public:
|
||||
* when fifo is empty later, sets status to run_finished */
|
||||
int start_readout();
|
||||
|
||||
/** set acquisition period to find the value of n */
|
||||
int set_acquisition_period();
|
||||
|
||||
|
||||
//General Functions
|
||||
/** Locks Receiver */
|
||||
|
Reference in New Issue
Block a user