mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-05-07 21:30:05 +02:00
updated rxr to use 10 times less memory for moench and plugged possible memory leaks
git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@634 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
parent
adcf1e2e8c
commit
b5fb6be6df
@ -2,10 +2,10 @@
|
|||||||
#define SVNURL "file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware/eigerDetectorServer"
|
#define SVNURL "file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware/eigerDetectorServer"
|
||||||
//#define SVNREPPATH ""
|
//#define SVNREPPATH ""
|
||||||
#define SVNREPUUID "951219d9-93cf-4727-9268-0efd64621fa3"
|
#define SVNREPUUID "951219d9-93cf-4727-9268-0efd64621fa3"
|
||||||
//#define SVNREV 0x631
|
//#define SVNREV 0x632
|
||||||
//#define SVNKIND ""
|
//#define SVNKIND ""
|
||||||
//#define SVNSCHED ""
|
//#define SVNSCHED ""
|
||||||
#define SVNAUTH "l_maliakal_d"
|
#define SVNAUTH "l_maliakal_d"
|
||||||
#define SVNREV 0x631
|
#define SVNREV 0x632
|
||||||
#define SVNDATE 0x20130711
|
#define SVNDATE 0x20130711
|
||||||
//
|
//
|
||||||
|
@ -2,10 +2,10 @@
|
|||||||
#define SVNURL "file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware/gotthardDetectorServer"
|
#define SVNURL "file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware/gotthardDetectorServer"
|
||||||
//#define SVNREPPATH ""
|
//#define SVNREPPATH ""
|
||||||
#define SVNREPUUID "951219d9-93cf-4727-9268-0efd64621fa3"
|
#define SVNREPUUID "951219d9-93cf-4727-9268-0efd64621fa3"
|
||||||
//#define SVNREV 0x628
|
//#define SVNREV 0x632
|
||||||
//#define SVNKIND ""
|
//#define SVNKIND ""
|
||||||
//#define SVNSCHED ""
|
//#define SVNSCHED ""
|
||||||
#define SVNAUTH "l_maliakal_d"
|
#define SVNAUTH "l_maliakal_d"
|
||||||
#define SVNREV 0x628
|
#define SVNREV 0x632
|
||||||
#define SVNDATE 0x20130625
|
#define SVNDATE 0x20130711
|
||||||
//
|
//
|
||||||
|
@ -2,10 +2,10 @@
|
|||||||
#define SVNURL "file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware/moenchDetectorServer"
|
#define SVNURL "file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware/moenchDetectorServer"
|
||||||
//#define SVNREPPATH ""
|
//#define SVNREPPATH ""
|
||||||
#define SVNREPUUID "951219d9-93cf-4727-9268-0efd64621fa3"
|
#define SVNREPUUID "951219d9-93cf-4727-9268-0efd64621fa3"
|
||||||
//#define SVNREV 0x629
|
//#define SVNREV 0x632
|
||||||
//#define SVNKIND ""
|
//#define SVNKIND ""
|
||||||
//#define SVNSCHED ""
|
//#define SVNSCHED ""
|
||||||
#define SVNAUTH "l_maliakal_d"
|
#define SVNAUTH "l_maliakal_d"
|
||||||
#define SVNREV 0x629
|
#define SVNREV 0x632
|
||||||
#define SVNDATE 0x20130710
|
#define SVNDATE 0x20130711
|
||||||
//
|
//
|
||||||
|
@ -2,10 +2,10 @@
|
|||||||
#define SVNURL "file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware/mythenDetectorServer"
|
#define SVNURL "file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware/mythenDetectorServer"
|
||||||
//#define SVNREPPATH ""
|
//#define SVNREPPATH ""
|
||||||
#define SVNREPUUID "951219d9-93cf-4727-9268-0efd64621fa3"
|
#define SVNREPUUID "951219d9-93cf-4727-9268-0efd64621fa3"
|
||||||
//#define SVNREV 0x628
|
//#define SVNREV 0x632
|
||||||
//#define SVNKIND ""
|
//#define SVNKIND ""
|
||||||
//#define SVNSCHED ""
|
//#define SVNSCHED ""
|
||||||
#define SVNAUTH "l_maliakal_d"
|
#define SVNAUTH "l_maliakal_d"
|
||||||
#define SVNREV 0x628
|
#define SVNREV 0x632
|
||||||
#define SVNDATE 0x20130625
|
#define SVNDATE 0x20130711
|
||||||
//
|
//
|
||||||
|
@ -2,10 +2,10 @@
|
|||||||
#define SVNURLLIB "file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware"
|
#define SVNURLLIB "file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware"
|
||||||
//#define SVNREPPATH ""
|
//#define SVNREPPATH ""
|
||||||
#define SVNREPUUIDLIB "951219d9-93cf-4727-9268-0efd64621fa3"
|
#define SVNREPUUIDLIB "951219d9-93cf-4727-9268-0efd64621fa3"
|
||||||
//#define SVNREV 0x631
|
//#define SVNREV 0x633
|
||||||
//#define SVNKIND ""
|
//#define SVNKIND ""
|
||||||
//#define SVNSCHED ""
|
//#define SVNSCHED ""
|
||||||
#define SVNAUTHLIB "l_maliakal_d"
|
#define SVNAUTHLIB "l_maliakal_d"
|
||||||
#define SVNREVLIB 0x631
|
#define SVNREVLIB 0x633
|
||||||
#define SVNDATELIB 0x20130711
|
#define SVNDATELIB 0x20130711
|
||||||
//
|
//
|
||||||
|
@ -17,14 +17,19 @@
|
|||||||
|
|
||||||
#include "sls_detector_defs.h"
|
#include "sls_detector_defs.h"
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
/** Circular Fifo (a.k.a. Circular Buffer)
|
/** Circular Fifo (a.k.a. Circular Buffer)
|
||||||
* Thread safe for one reader, and one writer */
|
* Thread safe for one reader, and one writer */
|
||||||
template<typename Element, unsigned int Size>
|
template<typename Element>
|
||||||
class CircularFifo {
|
class CircularFifo {
|
||||||
public:
|
public:
|
||||||
enum {Capacity = Size+1};
|
|
||||||
|
|
||||||
CircularFifo() : tail(0), head(0){}
|
CircularFifo(unsigned int Size) : tail(0), head(0){
|
||||||
|
Capacity = Size + 1;
|
||||||
|
array.resize(Capacity);
|
||||||
|
}
|
||||||
virtual ~CircularFifo() {}
|
virtual ~CircularFifo() {}
|
||||||
|
|
||||||
bool push(Element*& item_);
|
bool push(Element*& item_);
|
||||||
@ -35,8 +40,9 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
volatile unsigned int tail; // input index
|
volatile unsigned int tail; // input index
|
||||||
Element* array[Capacity];
|
vector <Element*> array;
|
||||||
volatile unsigned int head; // output index
|
volatile unsigned int head; // output index
|
||||||
|
unsigned int Capacity;
|
||||||
|
|
||||||
unsigned int increment(unsigned int idx_) const;
|
unsigned int increment(unsigned int idx_) const;
|
||||||
};
|
};
|
||||||
@ -50,8 +56,8 @@ private:
|
|||||||
*
|
*
|
||||||
* \param item_ copy by reference the input item
|
* \param item_ copy by reference the input item
|
||||||
* \return whether operation was successful or not */
|
* \return whether operation was successful or not */
|
||||||
template<typename Element, unsigned int Size>
|
template<typename Element>
|
||||||
bool CircularFifo<Element, Size>::push(Element*& item_)
|
bool CircularFifo<Element>::push(Element*& item_)
|
||||||
{
|
{
|
||||||
int nextTail = increment(tail);
|
int nextTail = increment(tail);
|
||||||
if(nextTail != head)
|
if(nextTail != head)
|
||||||
@ -71,8 +77,8 @@ bool CircularFifo<Element, Size>::push(Element*& item_)
|
|||||||
*
|
*
|
||||||
* \param item_ return by reference the wanted item
|
* \param item_ return by reference the wanted item
|
||||||
* \return whether operation was successful or not */
|
* \return whether operation was successful or not */
|
||||||
template<typename Element, unsigned int Size>
|
template<typename Element>
|
||||||
bool CircularFifo<Element, Size>::pop(Element*& item_)
|
bool CircularFifo<Element>::pop(Element*& item_)
|
||||||
{
|
{
|
||||||
if(head == tail)
|
if(head == tail)
|
||||||
return false; // empty queue
|
return false; // empty queue
|
||||||
@ -87,8 +93,8 @@ bool CircularFifo<Element, Size>::pop(Element*& item_)
|
|||||||
* as the Procuder adds more items.
|
* as the Procuder adds more items.
|
||||||
*
|
*
|
||||||
* \return true if circular buffer is empty */
|
* \return true if circular buffer is empty */
|
||||||
template<typename Element, unsigned int Size>
|
template<typename Element>
|
||||||
bool CircularFifo<Element, Size>::isEmpty() const
|
bool CircularFifo<Element>::isEmpty() const
|
||||||
{
|
{
|
||||||
return (head == tail);
|
return (head == tail);
|
||||||
}
|
}
|
||||||
@ -98,8 +104,8 @@ bool CircularFifo<Element, Size>::isEmpty() const
|
|||||||
* as the Consumer catches up.
|
* as the Consumer catches up.
|
||||||
*
|
*
|
||||||
* \return true if circular buffer is full. */
|
* \return true if circular buffer is full. */
|
||||||
template<typename Element, unsigned int Size>
|
template<typename Element>
|
||||||
bool CircularFifo<Element, Size>::isFull() const
|
bool CircularFifo<Element>::isFull() const
|
||||||
{
|
{
|
||||||
int tailCheck = (tail+1) % Capacity;
|
int tailCheck = (tail+1) % Capacity;
|
||||||
return (tailCheck == head);
|
return (tailCheck == head);
|
||||||
@ -110,8 +116,8 @@ bool CircularFifo<Element, Size>::isFull() const
|
|||||||
*
|
*
|
||||||
* \param idx_ the index to the incremented/wrapped
|
* \param idx_ the index to the incremented/wrapped
|
||||||
* \return new value for the index */
|
* \return new value for the index */
|
||||||
template<typename Element, unsigned int Size>
|
template<typename Element>
|
||||||
unsigned int CircularFifo<Element, Size>::increment(unsigned int idx_) const
|
unsigned int CircularFifo<Element>::increment(unsigned int idx_) const
|
||||||
{
|
{
|
||||||
// increment or wrap
|
// increment or wrap
|
||||||
// =================
|
// =================
|
||||||
|
@ -14,9 +14,7 @@
|
|||||||
|
|
||||||
//all max frames defined in sls_detector_defs.h. 20000 gotthard, 100000 for short gotthard, 1000 for moench
|
//all max frames defined in sls_detector_defs.h. 20000 gotthard, 100000 for short gotthard, 1000 for moench
|
||||||
|
|
||||||
#define FIFO_SIZE 25000
|
#define GOTTHARD_FIFO_SIZE 25000
|
||||||
|
|
||||||
|
|
||||||
#define GOTTHARD_ALIGNED_FRAME_SIZE 4096
|
#define GOTTHARD_ALIGNED_FRAME_SIZE 4096
|
||||||
#define GOTTHARD_PACKETS_PER_FRAME 2
|
#define GOTTHARD_PACKETS_PER_FRAME 2
|
||||||
#define GOTTHARD_BUFFER_SIZE (1286*GOTTHARD_PACKETS_PER_FRAME)
|
#define GOTTHARD_BUFFER_SIZE (1286*GOTTHARD_PACKETS_PER_FRAME)
|
||||||
@ -32,7 +30,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#define MOENCH_FIFO_SIZE 2500
|
||||||
#define MOENCH_ALIGNED_FRAME_SIZE 65536
|
#define MOENCH_ALIGNED_FRAME_SIZE 65536
|
||||||
#define MOENCH_PACKETS_PER_FRAME 40
|
#define MOENCH_PACKETS_PER_FRAME 40
|
||||||
#define MOENCH_BUFFER_SIZE (1286*MOENCH_PACKETS_PER_FRAME)
|
#define MOENCH_BUFFER_SIZE (1286*MOENCH_PACKETS_PER_FRAME)
|
||||||
|
@ -44,6 +44,8 @@ slsReceiverFunctionList::slsReceiverFunctionList(detectorType det,bool moenchwit
|
|||||||
udpSocket(NULL),
|
udpSocket(NULL),
|
||||||
server_port(DEFAULT_UDP_PORTNO),
|
server_port(DEFAULT_UDP_PORTNO),
|
||||||
fifo(NULL),
|
fifo(NULL),
|
||||||
|
fifofree(NULL),
|
||||||
|
fifosize(GOTTHARD_FIFO_SIZE),
|
||||||
shortFrame(-1),
|
shortFrame(-1),
|
||||||
bufferSize(GOTTHARD_BUFFER_SIZE),
|
bufferSize(GOTTHARD_BUFFER_SIZE),
|
||||||
packetsPerFrame(GOTTHARD_PACKETS_PER_FRAME),
|
packetsPerFrame(GOTTHARD_PACKETS_PER_FRAME),
|
||||||
@ -63,7 +65,11 @@ slsReceiverFunctionList::slsReceiverFunctionList(detectorType det,bool moenchwit
|
|||||||
frameIndexOffset(GOTTHARD_FRAME_INDEX_OFFSET)
|
frameIndexOffset(GOTTHARD_FRAME_INDEX_OFFSET)
|
||||||
|
|
||||||
{
|
{
|
||||||
|
int aligned_frame_size = GOTTHARD_ALIGNED_FRAME_SIZE;
|
||||||
|
|
||||||
if(myDetectorType == MOENCH){
|
if(myDetectorType == MOENCH){
|
||||||
|
aligned_frame_size = MOENCH_ALIGNED_FRAME_SIZE;
|
||||||
|
fifosize = MOENCH_FIFO_SIZE;
|
||||||
maxFramesPerFile = MOENCH_MAX_FRAMES_PER_FILE;
|
maxFramesPerFile = MOENCH_MAX_FRAMES_PER_FILE;
|
||||||
bufferSize = MOENCH_BUFFER_SIZE;
|
bufferSize = MOENCH_BUFFER_SIZE;
|
||||||
packetsPerFrame = MOENCH_PACKETS_PER_FRAME;
|
packetsPerFrame = MOENCH_PACKETS_PER_FRAME;
|
||||||
@ -71,7 +77,6 @@ slsReceiverFunctionList::slsReceiverFunctionList(detectorType det,bool moenchwit
|
|||||||
frameIndexMask = MOENCH_FRAME_INDEX_MASK;
|
frameIndexMask = MOENCH_FRAME_INDEX_MASK;
|
||||||
frameIndexOffset = MOENCH_FRAME_INDEX_OFFSET;
|
frameIndexOffset = MOENCH_FRAME_INDEX_OFFSET;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(savefilename,"");
|
strcpy(savefilename,"");
|
||||||
@ -83,20 +88,17 @@ slsReceiverFunctionList::slsReceiverFunctionList(detectorType det,bool moenchwit
|
|||||||
strcpy(eth,"");
|
strcpy(eth,"");
|
||||||
|
|
||||||
latestData = new char[bufferSize];
|
latestData = new char[bufferSize];
|
||||||
fifofree = new CircularFifo<char,FIFO_SIZE>();
|
fifofree = new CircularFifo<char>(fifosize);
|
||||||
fifo = new CircularFifo<char,FIFO_SIZE>();
|
fifo = new CircularFifo<char>(fifosize);
|
||||||
|
|
||||||
int aligned_frame_size = GOTTHARD_ALIGNED_FRAME_SIZE;
|
|
||||||
if (det == MOENCH)
|
|
||||||
aligned_frame_size = MOENCH_ALIGNED_FRAME_SIZE;
|
|
||||||
|
|
||||||
|
|
||||||
mem0=(char*)malloc(aligned_frame_size*FIFO_SIZE);
|
|
||||||
|
mem0=(char*)malloc(aligned_frame_size*fifosize);
|
||||||
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+aligned_frame_size*(FIFO_SIZE-1))) {
|
while (buffer<(mem0+aligned_frame_size*(fifosize-1))) {
|
||||||
fifofree->push(buffer);
|
fifofree->push(buffer);
|
||||||
buffer+=aligned_frame_size;
|
buffer+=aligned_frame_size;
|
||||||
}
|
}
|
||||||
@ -284,7 +286,7 @@ int slsReceiverFunctionList::stopReceiver(){
|
|||||||
#endif
|
#endif
|
||||||
//stop listening thread
|
//stop listening thread
|
||||||
listening_thread_running=0;
|
listening_thread_running=0;
|
||||||
udpSocket->ShutDownSocket();
|
if(udpSocket) udpSocket->ShutDownSocket();
|
||||||
pthread_join(listening_thread,NULL);
|
pthread_join(listening_thread,NULL);
|
||||||
status = IDLE;
|
status = IDLE;
|
||||||
|
|
||||||
@ -357,6 +359,7 @@ int slsReceiverFunctionList::startListening(){
|
|||||||
if (!fifofree->isEmpty()) {
|
if (!fifofree->isEmpty()) {
|
||||||
fifofree->pop(buffer);
|
fifofree->pop(buffer);
|
||||||
|
|
||||||
|
|
||||||
//receiver 2 half frames / 1 short frame / 40 moench frames
|
//receiver 2 half frames / 1 short frame / 40 moench frames
|
||||||
rc = udpSocket->ReceiveDataOnly(buffer,bufferSize);
|
rc = udpSocket->ReceiveDataOnly(buffer,bufferSize);
|
||||||
if( rc < 0)
|
if( rc < 0)
|
||||||
@ -440,7 +443,7 @@ int slsReceiverFunctionList::startWriting(){
|
|||||||
framesInFile=0;
|
framesInFile=0;
|
||||||
framesCaught=0;
|
framesCaught=0;
|
||||||
frameIndex=0;
|
frameIndex=0;
|
||||||
if(sfilefd) sfilefd=0;
|
if(sfilefd) sfilefd=NULL;
|
||||||
strcpy(savefilename,"");
|
strcpy(savefilename,"");
|
||||||
|
|
||||||
//reset this before each acq or you send old data
|
//reset this before each acq or you send old data
|
||||||
@ -478,8 +481,10 @@ int slsReceiverFunctionList::startWriting(){
|
|||||||
|
|
||||||
if(enableFileWrite && cbAction > DO_NOTHING){
|
if(enableFileWrite && cbAction > DO_NOTHING){
|
||||||
|
|
||||||
if(sfilefd)
|
if(sfilefd){
|
||||||
fclose(sfilefd);
|
fclose(sfilefd);
|
||||||
|
sfilefd = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (NULL == (sfilefd = fopen((const char *) (savefilename), "w"))){
|
if (NULL == (sfilefd = fopen((const char *) (savefilename), "w"))){
|
||||||
cout << "Error: Could not create file " << savefilename << endl;
|
cout << "Error: Could not create file " << savefilename << endl;
|
||||||
@ -594,11 +599,13 @@ int slsReceiverFunctionList::startWriting(){
|
|||||||
cout << "Total Frames Caught:"<< totalFramesCaught << endl;
|
cout << "Total Frames Caught:"<< totalFramesCaught << endl;
|
||||||
|
|
||||||
|
|
||||||
if(sfilefd)
|
if(sfilefd){
|
||||||
fclose(sfilefd);
|
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
cout << "sfield:" << (int)sfilefd << endl;
|
cout << "sfield:" << (int)sfilefd << endl;
|
||||||
#endif
|
#endif
|
||||||
|
fclose(sfilefd);
|
||||||
|
sfilefd = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
//acquistion over call back
|
//acquistion over call back
|
||||||
if (acquisitionFinishedCallBack)
|
if (acquisitionFinishedCallBack)
|
||||||
|
@ -291,11 +291,13 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
/** circular fifo to read and write data*/
|
/** circular fifo to read and write data*/
|
||||||
//CircularFifo<dataStruct,FIFO_SIZE>* fifo;
|
CircularFifo<char>* fifo;
|
||||||
CircularFifo<char,FIFO_SIZE>* fifo;
|
|
||||||
|
|
||||||
/** circular fifo to read and write data*/
|
/** circular fifo to read and write data*/
|
||||||
CircularFifo<char,FIFO_SIZE>* fifofree;
|
CircularFifo<char>* fifofree;
|
||||||
|
|
||||||
|
/** fifo size */
|
||||||
|
unsigned int fifosize;
|
||||||
|
|
||||||
/** short frames */
|
/** short frames */
|
||||||
int shortFrame;
|
int shortFrame;
|
||||||
|
@ -2,10 +2,10 @@
|
|||||||
#define SVNURL "file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware/slsReceiver"
|
#define SVNURL "file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware/slsReceiver"
|
||||||
//#define SVNREPPATH ""
|
//#define SVNREPPATH ""
|
||||||
#define SVNREPUUID "951219d9-93cf-4727-9268-0efd64621fa3"
|
#define SVNREPUUID "951219d9-93cf-4727-9268-0efd64621fa3"
|
||||||
//#define SVNREV 0x629
|
//#define SVNREV 0x632
|
||||||
//#define SVNKIND ""
|
//#define SVNKIND ""
|
||||||
//#define SVNSCHED ""
|
//#define SVNSCHED ""
|
||||||
#define SVNAUTH "l_maliakal_d"
|
#define SVNAUTH "l_maliakal_d"
|
||||||
#define SVNREV 0x629
|
#define SVNREV 0x632
|
||||||
#define SVNDATE 0x20130710
|
#define SVNDATE 0x20130711
|
||||||
//
|
//
|
||||||
|
Loading…
x
Reference in New Issue
Block a user