mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-23 06:50:02 +02:00
slsReceiver: remove static members in Listener, DataProcessing and DataStreamer:
* Needed when more than one receiver is created by process * Replace NumberofXxxx by explicit index in constructor * Remove Error[Mask], use return value in constructor signature * Replace RunningMask by individual Running flags * Remove obsolete Mutex objects
This commit is contained in:
parent
62a88dadba
commit
b5909044f6
@ -44,7 +44,7 @@ class BinaryFileStatic {
|
||||
{
|
||||
ostringstream osfn;
|
||||
osfn << fpath << "/" << fnameprefix;
|
||||
if (dindex >= 0) osfn << "_d" << ((unitindex >= numunits) ? unitindex : (dindex * numunits + unitindex)); //if unit index > numunits, all receivers in one program (userReceiver)
|
||||
if (dindex >= 0) osfn << "_d" << (dindex * numunits + unitindex);
|
||||
if (frindexenable) osfn << "_f" << setfill('0') << setw(12) << fnum;
|
||||
osfn << "_" << findex;
|
||||
osfn << ".raw";
|
||||
|
@ -24,6 +24,8 @@ class DataProcessor : private virtual slsReceiverDefs, public ThreadObject {
|
||||
/**
|
||||
* Constructor
|
||||
* Calls Base Class CreateThread(), sets ErrorMask if error and increments NumberofDataProcessors
|
||||
* @param ret OK or FAIL if thread creation succeeded or failed
|
||||
* @param ind self index
|
||||
* @param f address of Fifo pointer
|
||||
* @param ftype pointer to file format type
|
||||
* @param fwenable file writer enable
|
||||
@ -35,7 +37,7 @@ class DataProcessor : private virtual slsReceiverDefs, public ThreadObject {
|
||||
* @param dataReadycb pointer to data ready call back function
|
||||
* @param pDataReadycb pointer to arguments of data ready call back function. To write/stream a smaller size of processed data, change this value (only smaller value is allowed).
|
||||
*/
|
||||
DataProcessor(Fifo*& f, fileFormat* ftype, bool fwenable, bool* dsEnable, bool* gpEnable, uint32_t* dr,
|
||||
DataProcessor(int& ret, int ind, Fifo*& f, fileFormat* ftype, bool fwenable, bool* dsEnable, bool* gpEnable, uint32_t* dr,
|
||||
uint32_t* freq, uint32_t* timer,
|
||||
void (*dataReadycb)(uint64_t, uint32_t, uint32_t, uint64_t,
|
||||
uint64_t, uint16_t, uint16_t, uint16_t, uint16_t,
|
||||
@ -54,32 +56,13 @@ class DataProcessor : private virtual slsReceiverDefs, public ThreadObject {
|
||||
~DataProcessor();
|
||||
|
||||
|
||||
//*** static functions ***
|
||||
/**
|
||||
* Get ErrorMask
|
||||
* @return ErrorMask
|
||||
*/
|
||||
static uint64_t GetErrorMask();
|
||||
|
||||
/**
|
||||
* Get RunningMask
|
||||
* @return RunningMask
|
||||
*/
|
||||
static uint64_t GetRunningMask();
|
||||
|
||||
/**
|
||||
* Reset RunningMask
|
||||
*/
|
||||
static void ResetRunningMask();
|
||||
|
||||
/**
|
||||
* Set Silent Mode
|
||||
* @param mode 1 sets 0 unsets
|
||||
*/
|
||||
static void SetSilentMode(bool mode);
|
||||
|
||||
//*** non static functions ***
|
||||
//*** getters ***
|
||||
/**
|
||||
* Returns if the thread is currently running
|
||||
* @returns true if thread is running, else false
|
||||
*/
|
||||
bool IsRunning();
|
||||
|
||||
/**
|
||||
* Get acquisition started flag
|
||||
* @return acquisition started flag
|
||||
@ -177,7 +160,7 @@ class DataProcessor : private virtual slsReceiverDefs, public ThreadObject {
|
||||
* @param findex pointer to file index
|
||||
* @param owenable pointer to over write enable
|
||||
* @param dindex pointer to detector index
|
||||
* @param nunits pointer to number of theads/ units per detector
|
||||
* @param nunits pointer to number of threads/ units per detector
|
||||
* @param nf pointer to number of images in acquisition
|
||||
* @param dr pointer to dynamic range
|
||||
* @param portno pointer to udp port number
|
||||
@ -213,6 +196,12 @@ class DataProcessor : private virtual slsReceiverDefs, public ThreadObject {
|
||||
*/
|
||||
void SetPixelDimension();
|
||||
|
||||
/**
|
||||
* Set Silent Mode
|
||||
* @param mode 1 sets 0 unsets
|
||||
*/
|
||||
void SetSilentMode(bool mode);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
@ -222,12 +211,6 @@ class DataProcessor : private virtual slsReceiverDefs, public ThreadObject {
|
||||
*/
|
||||
std::string GetType();
|
||||
|
||||
/**
|
||||
* Returns if the thread is currently running
|
||||
* @returns true if thread is running, else false
|
||||
*/
|
||||
bool IsRunning();
|
||||
|
||||
/**
|
||||
* Record First Indices (firstAcquisitionIndex, firstMeasurementIndex)
|
||||
* @param fnum frame index to record
|
||||
@ -292,17 +275,8 @@ class DataProcessor : private virtual slsReceiverDefs, public ThreadObject {
|
||||
/** type of thread */
|
||||
static const std::string TypeName;
|
||||
|
||||
/** Total Number of DataProcessor Objects */
|
||||
static int NumberofDataProcessors;
|
||||
|
||||
/** Mask of errors on any object eg.thread creation */
|
||||
static uint64_t ErrorMask;
|
||||
|
||||
/** Mask of all listener objects running */
|
||||
static uint64_t RunningMask;
|
||||
|
||||
/** mutex to update static items among objects (threads)*/
|
||||
static pthread_mutex_t Mutex;
|
||||
/** Object running status */
|
||||
bool runningFlag;
|
||||
|
||||
/** GeneralData (Detector Data) object */
|
||||
const GeneralData* generalData;
|
||||
@ -310,9 +284,6 @@ class DataProcessor : private virtual slsReceiverDefs, public ThreadObject {
|
||||
/** Fifo structure */
|
||||
Fifo* fifo;
|
||||
|
||||
/** Silent Mode */
|
||||
static bool SilentMode;
|
||||
|
||||
|
||||
//individual members
|
||||
/** File writer implemented as binary or hdf5 File */
|
||||
@ -380,6 +351,8 @@ class DataProcessor : private virtual slsReceiverDefs, public ThreadObject {
|
||||
uint64_t currentFrameIndex;
|
||||
|
||||
|
||||
/** Silent Mode */
|
||||
bool silentMode;
|
||||
|
||||
//call back
|
||||
/**
|
||||
|
@ -20,6 +20,8 @@ class DataStreamer : private virtual slsReceiverDefs, public ThreadObject {
|
||||
/**
|
||||
* Constructor
|
||||
* Calls Base Class CreateThread(), sets ErrorMask if error and increments NumberofDataStreamers
|
||||
* @param ret OK or FAIL if thread creation succeeded or failed
|
||||
* @param ind self index
|
||||
* @param f address of Fifo pointer
|
||||
* @param dr pointer to dynamic range
|
||||
* @param sEnable pointer to short frame enable
|
||||
@ -27,7 +29,7 @@ class DataStreamer : private virtual slsReceiverDefs, public ThreadObject {
|
||||
* @param fd flipped data enable for x and y dimensions
|
||||
* @param ajh additional json header
|
||||
*/
|
||||
DataStreamer(Fifo*& f, uint32_t* dr, int* sEnable, uint64_t* fi, int* fd, char* ajh);
|
||||
DataStreamer(int& ret, int ind, Fifo*& f, uint32_t* dr, int* sEnable, uint64_t* fi, int* fd, char* ajh);
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
@ -35,34 +37,12 @@ class DataStreamer : private virtual slsReceiverDefs, public ThreadObject {
|
||||
*/
|
||||
~DataStreamer();
|
||||
|
||||
|
||||
//*** static functions ***
|
||||
/**
|
||||
* Get RunningMask
|
||||
* @return RunningMask
|
||||
*/
|
||||
static uint64_t GetErrorMask();
|
||||
|
||||
/**
|
||||
* Get RunningMask
|
||||
* @return RunningMask
|
||||
*/
|
||||
static uint64_t GetRunningMask();
|
||||
|
||||
/**
|
||||
* Reset RunningMask
|
||||
*/
|
||||
static void ResetRunningMask();
|
||||
|
||||
/**
|
||||
* Set Silent Mode
|
||||
* @param mode 1 sets 0 unsets
|
||||
*/
|
||||
static void SetSilentMode(bool mode);
|
||||
|
||||
//*** non static functions ***
|
||||
//*** getters ***
|
||||
|
||||
/**
|
||||
* Returns if the thread is currently running
|
||||
* @returns true if thread is running, else false
|
||||
*/
|
||||
bool IsRunning();
|
||||
|
||||
|
||||
//*** setters ***
|
||||
@ -123,7 +103,13 @@ class DataStreamer : private virtual slsReceiverDefs, public ThreadObject {
|
||||
* Restream stop dummy packet
|
||||
* @return OK or FAIL
|
||||
*/
|
||||
int restreamStop();
|
||||
int RestreamStop();
|
||||
|
||||
/**
|
||||
* Set Silent Mode
|
||||
* @param mode 1 sets 0 unsets
|
||||
*/
|
||||
void SetSilentMode(bool mode);
|
||||
|
||||
private:
|
||||
|
||||
@ -133,12 +119,6 @@ class DataStreamer : private virtual slsReceiverDefs, public ThreadObject {
|
||||
*/
|
||||
std::string GetType();
|
||||
|
||||
/**
|
||||
* Returns if the thread is currently running
|
||||
* @returns true if thread is running, else false
|
||||
*/
|
||||
bool IsRunning();
|
||||
|
||||
/**
|
||||
* Record First Indices (firstAcquisitionIndex, firstMeasurementIndex)
|
||||
* @param fnum frame index to record
|
||||
@ -179,17 +159,8 @@ class DataStreamer : private virtual slsReceiverDefs, public ThreadObject {
|
||||
/** type of thread */
|
||||
static const std::string TypeName;
|
||||
|
||||
/** Total Number of DataStreamer Objects */
|
||||
static int NumberofDataStreamers;
|
||||
|
||||
/** Mask of errors on any object eg.thread creation */
|
||||
static uint64_t ErrorMask;
|
||||
|
||||
/** Mask of all listener objects running */
|
||||
static uint64_t RunningMask;
|
||||
|
||||
/** mutex to update static items among objects (threads)*/
|
||||
static pthread_mutex_t Mutex;
|
||||
/** Object running status */
|
||||
bool runningFlag;
|
||||
|
||||
/** GeneralData (Detector Data) object */
|
||||
const GeneralData* generalData;
|
||||
@ -197,9 +168,6 @@ class DataStreamer : private virtual slsReceiverDefs, public ThreadObject {
|
||||
/** Fifo structure */
|
||||
Fifo* fifo;
|
||||
|
||||
/** Silent Mode */
|
||||
static bool SilentMode;
|
||||
|
||||
|
||||
|
||||
/** ZMQ Socket - Receiver to Client */
|
||||
@ -237,5 +205,8 @@ class DataStreamer : private virtual slsReceiverDefs, public ThreadObject {
|
||||
|
||||
/** additional json header */
|
||||
char* additionJsonHeader;
|
||||
|
||||
/** Silent Mode */
|
||||
bool silentMode;
|
||||
};
|
||||
|
||||
|
@ -20,11 +20,12 @@ class Fifo : private virtual slsReceiverDefs {
|
||||
/**
|
||||
* Constructor
|
||||
* Calls CreateFifos that creates fifos and allocates memory
|
||||
* @param ind self index
|
||||
* @param fifoItemSize size of each fifo item
|
||||
* @param depth fifo depth
|
||||
* @param success true if successful, else false
|
||||
*/
|
||||
Fifo(uint32_t fifoItemSize, uint32_t depth, bool &success);
|
||||
Fifo(int ind, uint32_t fifoItemSize, uint32_t depth, bool &success);
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
@ -88,9 +89,6 @@ class Fifo : private virtual slsReceiverDefs {
|
||||
void DestroyFifos();
|
||||
|
||||
|
||||
/** Total Number of Fifo Class Objects */
|
||||
static int NumberofFifoClassObjects;
|
||||
|
||||
/** Self Index */
|
||||
int index;
|
||||
|
||||
|
@ -51,7 +51,7 @@ public:
|
||||
{
|
||||
ostringstream osfn;
|
||||
osfn << fpath << "/" << fnameprefix;
|
||||
if (dindex >= 0) osfn << "_d" << ((unitindex >= numunits) ? unitindex : (dindex * numunits + unitindex)); //if unit index > numunits, all receivers in one program (userReceiver)
|
||||
if (dindex >= 0) osfn << "_d" << (dindex * numunits + unitindex);
|
||||
if (frindexenable) osfn << "_f" << setfill('0') << setw(12) << fnum;
|
||||
osfn << "_" << findex;
|
||||
osfn << ".h5";
|
||||
|
@ -21,6 +21,8 @@ class Listener : private virtual slsReceiverDefs, public ThreadObject {
|
||||
/**
|
||||
* Constructor
|
||||
* Calls Base Class CreateThread(), sets ErrorMask if error and increments NumberofListerners
|
||||
* @param ret OK or FAIL if thread creation succeeded or failed
|
||||
* @param ind self index
|
||||
* @param dtype detector type
|
||||
* @param f address of Fifo pointer
|
||||
* @param s pointer to receiver status
|
||||
@ -30,7 +32,8 @@ class Listener : private virtual slsReceiverDefs, public ThreadObject {
|
||||
* @param nf pointer to number of images to catch
|
||||
* @param dr pointer to dynamic range
|
||||
*/
|
||||
Listener(detectorType dtype, Fifo*& f, runStatus* s, uint32_t* portno, char* e, int* act, uint64_t* nf, uint32_t* dr);
|
||||
Listener(int& ret, int ind, detectorType dtype, Fifo*& f, runStatus* s,
|
||||
uint32_t* portno, char* e, int* act, uint64_t* nf, uint32_t* dr);
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
@ -39,33 +42,13 @@ class Listener : private virtual slsReceiverDefs, public ThreadObject {
|
||||
~Listener();
|
||||
|
||||
|
||||
//*** static functions ***
|
||||
/**
|
||||
* Get ErrorMask
|
||||
* @return ErrorMask
|
||||
*/
|
||||
static uint64_t GetErrorMask();
|
||||
|
||||
/**
|
||||
* Get RunningMask
|
||||
* @return RunningMask
|
||||
*/
|
||||
static uint64_t GetRunningMask();
|
||||
|
||||
/**
|
||||
* Reset RunningMask
|
||||
*/
|
||||
static void ResetRunningMask();
|
||||
|
||||
/**
|
||||
* Set Silent Mode
|
||||
* @param mode 1 sets 0 unsets
|
||||
*/
|
||||
static void SetSilentMode(bool mode);
|
||||
|
||||
|
||||
//*** non static functions ***
|
||||
//*** getters ***
|
||||
/**
|
||||
* Returns if the thread is currently running
|
||||
* @returns true if thread is running, else false
|
||||
*/
|
||||
bool IsRunning();
|
||||
|
||||
/**
|
||||
* Get acquisition started flag
|
||||
* @return acquisition started flag
|
||||
@ -142,6 +125,12 @@ class Listener : private virtual slsReceiverDefs, public ThreadObject {
|
||||
*/
|
||||
void ShutDownUDPSocket();
|
||||
|
||||
/**
|
||||
* Set Silent Mode
|
||||
* @param mode 1 sets 0 unsets
|
||||
*/
|
||||
void SetSilentMode(bool mode);
|
||||
|
||||
|
||||
|
||||
|
||||
@ -153,12 +142,6 @@ class Listener : private virtual slsReceiverDefs, public ThreadObject {
|
||||
*/
|
||||
std::string GetType();
|
||||
|
||||
/**
|
||||
* Returns if the thread is currently running
|
||||
* @returns true if thread is running, else false
|
||||
*/
|
||||
bool IsRunning();
|
||||
|
||||
/**
|
||||
* Record First Indices (firstAcquisitionIndex, firstMeasurementIndex)
|
||||
* @param fnum frame index to record
|
||||
@ -205,17 +188,8 @@ class Listener : private virtual slsReceiverDefs, public ThreadObject {
|
||||
/** type of thread */
|
||||
static const std::string TypeName;
|
||||
|
||||
/** Total Number of Listener Objects */
|
||||
static int NumberofListeners;
|
||||
|
||||
/** Mask of errors on any object eg.thread creation */
|
||||
static uint64_t ErrorMask;
|
||||
|
||||
/** Mask of all listener objects running */
|
||||
static uint64_t RunningMask;
|
||||
|
||||
/** Mutex to update static items among objects (threads)*/
|
||||
static pthread_mutex_t Mutex;
|
||||
/** Object running status */
|
||||
bool runningFlag;
|
||||
|
||||
/** GeneralData (Detector Data) object */
|
||||
const GeneralData* generalData;
|
||||
@ -223,9 +197,6 @@ class Listener : private virtual slsReceiverDefs, public ThreadObject {
|
||||
/** Fifo structure */
|
||||
Fifo* fifo;
|
||||
|
||||
/** Silent Mode */
|
||||
static bool SilentMode;
|
||||
|
||||
|
||||
// individual members
|
||||
/** Detector Type */
|
||||
@ -303,5 +274,8 @@ class Listener : private virtual slsReceiverDefs, public ThreadObject {
|
||||
|
||||
/** number of images for statistic */
|
||||
uint32_t numFramesStatistic;
|
||||
|
||||
/** Silent Mode */
|
||||
bool silentMode;
|
||||
};
|
||||
|
||||
|
@ -22,18 +22,8 @@ using namespace std;
|
||||
|
||||
const string DataProcessor::TypeName = "DataProcessor";
|
||||
|
||||
int DataProcessor::NumberofDataProcessors(0);
|
||||
|
||||
uint64_t DataProcessor::ErrorMask(0x0);
|
||||
|
||||
uint64_t DataProcessor::RunningMask(0x0);
|
||||
|
||||
pthread_mutex_t DataProcessor::Mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
bool DataProcessor::SilentMode(false);
|
||||
|
||||
|
||||
DataProcessor::DataProcessor(Fifo*& f, fileFormat* ftype, bool fwenable, bool* dsEnable, bool* gpEnable, uint32_t* dr,
|
||||
DataProcessor::DataProcessor(int& ret, int ind, Fifo*& f, fileFormat* ftype, bool fwenable, bool* dsEnable, bool* gpEnable, uint32_t* dr,
|
||||
uint32_t* freq, uint32_t* timer,
|
||||
void (*dataReadycb)(uint64_t, uint32_t, uint32_t, uint64_t, uint64_t,
|
||||
uint16_t, uint16_t, uint16_t, uint16_t, uint32_t, uint16_t, uint8_t, uint8_t,
|
||||
@ -44,7 +34,8 @@ DataProcessor::DataProcessor(Fifo*& f, fileFormat* ftype, bool fwenable, bool* d
|
||||
char*, uint32_t &, void*),
|
||||
void *pDataReadycb) :
|
||||
|
||||
ThreadObject(NumberofDataProcessors),
|
||||
ThreadObject(ind),
|
||||
runningFlag(0),
|
||||
generalData(0),
|
||||
fifo(f),
|
||||
file(0),
|
||||
@ -65,18 +56,16 @@ DataProcessor::DataProcessor(Fifo*& f, fileFormat* ftype, bool fwenable, bool* d
|
||||
numTotalFramesCaught(0),
|
||||
numFramesCaught(0),
|
||||
currentFrameIndex(0),
|
||||
silentMode(false),
|
||||
rawDataReadyCallBack(dataReadycb),
|
||||
rawDataModifyReadyCallBack(dataModifyReadycb),
|
||||
pRawDataReady(pDataReadycb)
|
||||
{
|
||||
if(ThreadObject::CreateThread()){
|
||||
pthread_mutex_lock(&Mutex);
|
||||
ErrorMask ^= (1<<index);
|
||||
pthread_mutex_unlock(&Mutex);
|
||||
}
|
||||
ret = FAIL;
|
||||
if(ThreadObject::CreateThread() == OK)
|
||||
ret = OK;
|
||||
|
||||
NumberofDataProcessors++;
|
||||
FILE_LOG(logDEBUG) << "Number of DataProcessors: " << NumberofDataProcessors;
|
||||
FILE_LOG(logDEBUG) << "DataProcessor " << ind << " created";
|
||||
|
||||
memset((void*)&timerBegin, 0, sizeof(timespec));
|
||||
}
|
||||
@ -86,35 +75,15 @@ DataProcessor::~DataProcessor() {
|
||||
if (file) delete file;
|
||||
if (tempBuffer) delete [] tempBuffer;
|
||||
ThreadObject::DestroyThread();
|
||||
NumberofDataProcessors--;
|
||||
}
|
||||
|
||||
/** static functions */
|
||||
|
||||
uint64_t DataProcessor::GetErrorMask() {
|
||||
return ErrorMask;
|
||||
}
|
||||
|
||||
uint64_t DataProcessor::GetRunningMask() {
|
||||
return RunningMask;
|
||||
}
|
||||
|
||||
void DataProcessor::ResetRunningMask() {
|
||||
RunningMask = 0x0;
|
||||
}
|
||||
|
||||
void DataProcessor::SetSilentMode(bool mode) {
|
||||
SilentMode = mode;
|
||||
}
|
||||
|
||||
/** non static functions */
|
||||
/** getters */
|
||||
string DataProcessor::GetType(){
|
||||
return TypeName;
|
||||
}
|
||||
|
||||
bool DataProcessor::IsRunning() {
|
||||
return ((1 << index) & RunningMask);
|
||||
return runningFlag;
|
||||
}
|
||||
|
||||
bool DataProcessor::GetAcquisitionStartedFlag(){
|
||||
@ -149,16 +118,12 @@ uint64_t DataProcessor::GetProcessedMeasurementIndex() {
|
||||
|
||||
/** setters */
|
||||
void DataProcessor::StartRunning() {
|
||||
pthread_mutex_lock(&Mutex);
|
||||
RunningMask |= (1<<index);
|
||||
pthread_mutex_unlock(&Mutex);
|
||||
runningFlag = true;
|
||||
}
|
||||
|
||||
|
||||
void DataProcessor::StopRunning() {
|
||||
pthread_mutex_lock(&Mutex);
|
||||
RunningMask ^= (1<<index);
|
||||
pthread_mutex_unlock(&Mutex);
|
||||
runningFlag = false;
|
||||
}
|
||||
|
||||
void DataProcessor::SetFifo(Fifo*& f) {
|
||||
@ -173,6 +138,7 @@ void DataProcessor::ResetParametersforNewAcquisition() {
|
||||
}
|
||||
|
||||
void DataProcessor::ResetParametersforNewMeasurement(){
|
||||
runningFlag = false;
|
||||
numFramesCaught = 0;
|
||||
firstMeasurementIndex = 0;
|
||||
measurementStartedFlag = false;
|
||||
@ -253,7 +219,7 @@ void DataProcessor::SetupFileWriter(bool fwe, int* nd, char* fname, char* fpath,
|
||||
if (g)
|
||||
generalData = g;
|
||||
// fix xcoord as detector is not providing it right now
|
||||
xcoordin1D = ((NumberofDataProcessors > (*nunits)) ? index : ((*dindex) * (*nunits)) + index);
|
||||
xcoordin1D = ((*dindex) * (*nunits)) + index;
|
||||
|
||||
|
||||
if (file) {
|
||||
@ -267,13 +233,13 @@ void DataProcessor::SetupFileWriter(bool fwe, int* nd, char* fname, char* fpath,
|
||||
file = new HDF5File(index, generalData->maxFramesPerFile,
|
||||
nd, fname, fpath, findex, owenable,
|
||||
dindex, nunits, nf, dr, portno,
|
||||
generalData->nPixelsX, generalData->nPixelsY, &SilentMode);
|
||||
generalData->nPixelsX, generalData->nPixelsY, &silentMode);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
file = new BinaryFile(index, generalData->maxFramesPerFile,
|
||||
nd, fname, fpath, findex, owenable,
|
||||
dindex, nunits, nf, dr, portno, &SilentMode);
|
||||
dindex, nunits, nf, dr, portno, &silentMode);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -499,6 +465,10 @@ void DataProcessor::SetPixelDimension() {
|
||||
}
|
||||
}
|
||||
|
||||
void DataProcessor::SetSilentMode(bool mode) {
|
||||
silentMode = mode;
|
||||
}
|
||||
|
||||
|
||||
/** eiger specific */
|
||||
void DataProcessor::InsertGapPixels(char* buf, uint32_t dr) {
|
||||
|
@ -15,19 +15,10 @@ using namespace std;
|
||||
|
||||
const string DataStreamer::TypeName = "DataStreamer";
|
||||
|
||||
int DataStreamer::NumberofDataStreamers(0);
|
||||
|
||||
uint64_t DataStreamer::ErrorMask(0x0);
|
||||
|
||||
uint64_t DataStreamer::RunningMask(0x0);
|
||||
|
||||
pthread_mutex_t DataStreamer::Mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
bool DataStreamer::SilentMode(false);
|
||||
|
||||
|
||||
DataStreamer::DataStreamer(Fifo*& f, uint32_t* dr, int* sEnable, uint64_t* fi, int* fd, char* ajh) :
|
||||
ThreadObject(NumberofDataStreamers),
|
||||
DataStreamer::DataStreamer(int& ret, int ind, Fifo*& f, uint32_t* dr, int* sEnable, uint64_t* fi, int* fd, char* ajh) :
|
||||
ThreadObject(ind),
|
||||
runningFlag(0),
|
||||
generalData(0),
|
||||
fifo(f),
|
||||
zmqSocket(0),
|
||||
@ -40,16 +31,14 @@ DataStreamer::DataStreamer(Fifo*& f, uint32_t* dr, int* sEnable, uint64_t* fi, i
|
||||
firstMeasurementIndex(0),
|
||||
completeBuffer(0),
|
||||
flippedData(fd),
|
||||
additionJsonHeader(ajh)
|
||||
additionJsonHeader(ajh),
|
||||
silentMode(false)
|
||||
{
|
||||
if(ThreadObject::CreateThread()){
|
||||
pthread_mutex_lock(&Mutex);
|
||||
ErrorMask ^= (1<<index);
|
||||
pthread_mutex_unlock(&Mutex);
|
||||
}
|
||||
ret = FAIL;
|
||||
if(ThreadObject::CreateThread() == OK)
|
||||
ret = OK;
|
||||
|
||||
NumberofDataStreamers++;
|
||||
FILE_LOG(logDEBUG) << "Number of DataStreamers: " << NumberofDataStreamers;
|
||||
FILE_LOG(logDEBUG) << "DataStreamer " << ind << " created";
|
||||
|
||||
strcpy(fileNametoStream, "");
|
||||
}
|
||||
@ -59,51 +48,26 @@ DataStreamer::~DataStreamer() {
|
||||
CloseZmqSocket();
|
||||
if (completeBuffer) delete [] completeBuffer;
|
||||
ThreadObject::DestroyThread();
|
||||
NumberofDataStreamers--;
|
||||
}
|
||||
|
||||
/** static functions */
|
||||
|
||||
uint64_t DataStreamer::GetErrorMask() {
|
||||
return ErrorMask;
|
||||
}
|
||||
|
||||
uint64_t DataStreamer::GetRunningMask() {
|
||||
return RunningMask;
|
||||
}
|
||||
|
||||
void DataStreamer::ResetRunningMask() {
|
||||
RunningMask = 0x0;
|
||||
}
|
||||
|
||||
void DataStreamer::SetSilentMode(bool mode) {
|
||||
SilentMode = mode;
|
||||
}
|
||||
|
||||
|
||||
/** non static functions */
|
||||
/** getters */
|
||||
string DataStreamer::GetType(){
|
||||
return TypeName;
|
||||
}
|
||||
|
||||
bool DataStreamer::IsRunning() {
|
||||
return ((1 << index) & RunningMask);
|
||||
return runningFlag;
|
||||
}
|
||||
|
||||
|
||||
/** setters */
|
||||
void DataStreamer::StartRunning() {
|
||||
pthread_mutex_lock(&Mutex);
|
||||
RunningMask |= (1<<index);
|
||||
pthread_mutex_unlock(&Mutex);
|
||||
runningFlag = true;
|
||||
}
|
||||
|
||||
|
||||
void DataStreamer::StopRunning() {
|
||||
pthread_mutex_lock(&Mutex);
|
||||
RunningMask ^= (1<<index);
|
||||
pthread_mutex_unlock(&Mutex);
|
||||
runningFlag = false;
|
||||
}
|
||||
|
||||
void DataStreamer::SetFifo(Fifo*& f) {
|
||||
@ -116,6 +80,7 @@ void DataStreamer::ResetParametersforNewAcquisition() {
|
||||
}
|
||||
|
||||
void DataStreamer::ResetParametersforNewMeasurement(char* fname){
|
||||
runningFlag = false;
|
||||
firstMeasurementIndex = 0;
|
||||
measurementStartedFlag = false;
|
||||
strcpy(fileNametoStream, fname);
|
||||
@ -295,7 +260,7 @@ int DataStreamer::SendHeader(sls_detector_header* header, uint32_t size, uint32_
|
||||
|
||||
|
||||
|
||||
int DataStreamer::restreamStop() {
|
||||
int DataStreamer::RestreamStop() {
|
||||
//send dummy header
|
||||
int ret = zmqSocket->SendHeaderData(index, true, SLS_DETECTOR_JSON_HEADER_VERSION);
|
||||
if (!ret) {
|
||||
@ -304,3 +269,9 @@ int DataStreamer::restreamStop() {
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
void DataStreamer::SetSilentMode(bool mode) {
|
||||
silentMode = mode;
|
||||
}
|
||||
|
||||
|
@ -12,10 +12,9 @@
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
|
||||
int Fifo::NumberofFifoClassObjects(0);
|
||||
|
||||
Fifo::Fifo(uint32_t fifoItemSize, uint32_t depth, bool &success):
|
||||
index(NumberofFifoClassObjects),
|
||||
Fifo::Fifo(int ind, uint32_t fifoItemSize, uint32_t depth, bool &success):
|
||||
index(ind),
|
||||
memory(0),
|
||||
fifoBound(0),
|
||||
fifoFree(0),
|
||||
@ -24,7 +23,7 @@ Fifo::Fifo(uint32_t fifoItemSize, uint32_t depth, bool &success):
|
||||
status_fifoBound(0),
|
||||
status_fifoFree(depth){
|
||||
FILE_LOG(logDEBUG) << __AT__ << " called";
|
||||
NumberofFifoClassObjects++;
|
||||
success = true;
|
||||
if(CreateFifos(fifoItemSize) == FAIL)
|
||||
success = false;
|
||||
}
|
||||
@ -34,7 +33,6 @@ Fifo::~Fifo() {
|
||||
FILE_LOG(logDEBUG) << __AT__ << " called";
|
||||
//cprintf(BLUE,"Fifo Object %d: Goodbye\n", index);
|
||||
DestroyFifos();
|
||||
NumberofFifoClassObjects--;
|
||||
}
|
||||
|
||||
|
||||
|
@ -18,19 +18,11 @@ using namespace std;
|
||||
|
||||
const string Listener::TypeName = "Listener";
|
||||
|
||||
int Listener::NumberofListeners(0);
|
||||
|
||||
uint64_t Listener::ErrorMask(0x0);
|
||||
|
||||
uint64_t Listener::RunningMask(0x0);
|
||||
|
||||
pthread_mutex_t Listener::Mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
bool Listener::SilentMode(false);
|
||||
|
||||
|
||||
Listener::Listener(detectorType dtype, Fifo*& f, runStatus* s, uint32_t* portno, char* e, int* act, uint64_t* nf, uint32_t* dr) :
|
||||
ThreadObject(NumberofListeners),
|
||||
Listener::Listener(int& ret, int ind, detectorType dtype, Fifo*& f, runStatus* s,
|
||||
uint32_t* portno, char* e, int* act, uint64_t* nf, uint32_t* dr) :
|
||||
ThreadObject(ind),
|
||||
runningFlag(0),
|
||||
generalData(0),
|
||||
fifo(f),
|
||||
myDetectorType(dtype),
|
||||
@ -51,15 +43,14 @@ Listener::Listener(detectorType dtype, Fifo*& f, runStatus* s, uint32_t* portno,
|
||||
carryOverFlag(0),
|
||||
carryOverPacket(0),
|
||||
listeningPacket(0),
|
||||
udpSocketAlive(0)
|
||||
udpSocketAlive(0),
|
||||
silentMode(false)
|
||||
{
|
||||
if(ThreadObject::CreateThread()){
|
||||
pthread_mutex_lock(&Mutex);
|
||||
ErrorMask ^= (1<<index);
|
||||
pthread_mutex_unlock(&Mutex);
|
||||
}
|
||||
NumberofListeners++;
|
||||
FILE_LOG(logDEBUG) << "Number of Listeners: " << NumberofListeners;
|
||||
ret = FAIL;
|
||||
if(ThreadObject::CreateThread() == OK)
|
||||
ret = OK;
|
||||
|
||||
FILE_LOG(logDEBUG) << "Listener " << ind << " created";
|
||||
}
|
||||
|
||||
|
||||
@ -70,35 +61,15 @@ Listener::~Listener() {
|
||||
if (carryOverPacket) delete [] carryOverPacket;
|
||||
if (listeningPacket) delete [] listeningPacket;
|
||||
ThreadObject::DestroyThread();
|
||||
NumberofListeners--;
|
||||
}
|
||||
|
||||
/** static functions */
|
||||
|
||||
uint64_t Listener::GetErrorMask() {
|
||||
return ErrorMask;
|
||||
}
|
||||
|
||||
uint64_t Listener::GetRunningMask() {
|
||||
return RunningMask;
|
||||
}
|
||||
|
||||
void Listener::ResetRunningMask() {
|
||||
RunningMask = 0x0;
|
||||
}
|
||||
|
||||
void Listener::SetSilentMode(bool mode) {
|
||||
SilentMode = mode;
|
||||
}
|
||||
|
||||
/** non static functions */
|
||||
/** getters */
|
||||
string Listener::GetType(){
|
||||
return TypeName;
|
||||
}
|
||||
|
||||
bool Listener::IsRunning() {
|
||||
return ((1 << index) & RunningMask);
|
||||
return runningFlag;
|
||||
}
|
||||
|
||||
bool Listener::GetAcquisitionStartedFlag(){
|
||||
@ -119,16 +90,12 @@ uint64_t Listener::GetLastFrameIndexCaught() {
|
||||
|
||||
/** setters */
|
||||
void Listener::StartRunning() {
|
||||
pthread_mutex_lock(&Mutex);
|
||||
RunningMask |= (1<<index);
|
||||
pthread_mutex_unlock(&Mutex);
|
||||
runningFlag = true;
|
||||
}
|
||||
|
||||
|
||||
void Listener::StopRunning() {
|
||||
pthread_mutex_lock(&Mutex);
|
||||
RunningMask ^= (1<<index);
|
||||
pthread_mutex_unlock(&Mutex);
|
||||
runningFlag = false;
|
||||
}
|
||||
|
||||
|
||||
@ -146,6 +113,7 @@ void Listener::ResetParametersforNewAcquisition() {
|
||||
|
||||
|
||||
void Listener::ResetParametersforNewMeasurement() {
|
||||
runningFlag = false;
|
||||
measurementStartedFlag = false;
|
||||
numPacketsCaught = 0;
|
||||
firstMeasurementIndex = 0;
|
||||
@ -181,7 +149,7 @@ void Listener::RecordFirstIndices(uint64_t fnum) {
|
||||
firstAcquisitionIndex = fnum;
|
||||
}
|
||||
|
||||
if(!SilentMode) {
|
||||
if(!silentMode) {
|
||||
if (!index) cprintf(BLUE,"%d First Acquisition Index:%lu\n"
|
||||
"%d First Measurement Index:%lu\n",
|
||||
index, firstAcquisitionIndex,
|
||||
@ -252,6 +220,10 @@ void Listener::ShutDownUDPSocket() {
|
||||
}
|
||||
|
||||
|
||||
void Listener::SetSilentMode(bool mode) {
|
||||
silentMode = mode;
|
||||
}
|
||||
|
||||
|
||||
void Listener::ThreadExecution() {
|
||||
char* buffer;
|
||||
@ -304,7 +276,7 @@ void Listener::ThreadExecution() {
|
||||
fifo->PushAddress(buffer);
|
||||
|
||||
//Statistics
|
||||
if(!SilentMode) {
|
||||
if(!silentMode) {
|
||||
numFramesStatistic++;
|
||||
if (numFramesStatistic >= generalData->maxFramesPerFile)
|
||||
PrintFifoStatistics();
|
||||
|
@ -216,26 +216,31 @@ int UDPStandardImplementation::setDataStreamEnable(const bool enable) {
|
||||
dataStreamer.clear();
|
||||
|
||||
if (enable) {
|
||||
bool error = false;
|
||||
for ( int i = 0; i < numThreads; ++i ) {
|
||||
dataStreamer.push_back(new DataStreamer(fifo[i], &dynamicRange, &shortFrameEnable, &fileIndex, flippedData, additionalJsonHeader));
|
||||
dataStreamer[i]->SetGeneralData(generalData);
|
||||
if (dataStreamer[i]->CreateZmqSockets(&numThreads, streamingPort, streamingSrcIP) == FAIL) {
|
||||
error = true;
|
||||
break;
|
||||
|
||||
int ret = FAIL;
|
||||
DataStreamer* s = new DataStreamer(ret, i, fifo[i], &dynamicRange, &shortFrameEnable, &fileIndex, flippedData, additionalJsonHeader);
|
||||
if (ret == FAIL)
|
||||
cprintf(RED,"Error: Could not create data callback threads\n");
|
||||
else {
|
||||
dataStreamer.push_back(s);
|
||||
dataStreamer[i]->SetGeneralData(generalData);
|
||||
if (dataStreamer[i]->CreateZmqSockets(&numThreads, streamingPort, streamingSrcIP) == FAIL) {
|
||||
cprintf(RED,"Error: Could not create zmq sockets\n");
|
||||
ret = FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
// error in creating threads or zmq sockets
|
||||
if (ret == FAIL) {
|
||||
for (vector<DataStreamer*>::const_iterator it = dataStreamer.begin(); it != dataStreamer.end(); ++it)
|
||||
delete(*it);
|
||||
dataStreamer.clear();
|
||||
dataStreamEnable = false;
|
||||
return FAIL;
|
||||
}
|
||||
}
|
||||
if (DataStreamer::GetErrorMask() || error) {
|
||||
if (DataStreamer::GetErrorMask())
|
||||
cprintf(RED,"Error: Could not create data callback threads\n");
|
||||
else
|
||||
cprintf(RED,"Error: Could not create zmq sockets\n");
|
||||
for (vector<DataStreamer*>::const_iterator it = dataStreamer.begin(); it != dataStreamer.end(); ++it)
|
||||
delete(*it);
|
||||
dataStreamer.clear();
|
||||
dataStreamEnable = false;
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
SetThreadPriorities();
|
||||
}
|
||||
}
|
||||
@ -311,9 +316,12 @@ int UDPStandardImplementation::setFifoDepth(const uint32_t i) {
|
||||
void UDPStandardImplementation::setSilentMode(const uint32_t i){
|
||||
silentMode = i;
|
||||
|
||||
Listener::SetSilentMode(i);
|
||||
DataProcessor::SetSilentMode(i);
|
||||
DataStreamer::SetSilentMode(i);
|
||||
for (vector<Listener*>::const_iterator it = listener.begin(); it != listener.end(); ++it)
|
||||
(*it)->SetSilentMode(i);
|
||||
for (vector<DataProcessor*>::const_iterator it = dataProcessor.begin(); it != dataProcessor.end(); ++it)
|
||||
(*it)->SetSilentMode(i);
|
||||
for (vector<DataStreamer*>::const_iterator it = dataStreamer.begin(); it != dataStreamer.end(); ++it)
|
||||
(*it)->SetSilentMode(i);
|
||||
|
||||
FILE_LOG(logINFO) << "Silent Mode: " << i;
|
||||
}
|
||||
@ -363,12 +371,18 @@ int UDPStandardImplementation::setDetectorType(const detectorType d) {
|
||||
}
|
||||
|
||||
//create threads
|
||||
for ( int i=0; i < numThreads; ++i ) {
|
||||
listener.push_back(new Listener(myDetectorType, fifo[i], &status, &udpPortNum[i], eth, &activated, &numberOfFrames, &dynamicRange));
|
||||
dataProcessor.push_back(new DataProcessor(fifo[i], &fileFormatType,
|
||||
fileWriteEnable, &dataStreamEnable, &gapPixelsEnable, &dynamicRange, &frameToGuiFrequency, &frameToGuiTimerinMS,
|
||||
rawDataReadyCallBack, rawDataModifyReadyCallBack, pRawDataReady));
|
||||
if (Listener::GetErrorMask() || DataProcessor::GetErrorMask()) {
|
||||
for ( int i = 0; i < numThreads; ++i ) {
|
||||
|
||||
int ret = FAIL;
|
||||
Listener* l = new Listener(ret, i, myDetectorType, fifo[i], &status, &udpPortNum[i], eth, &activated, &numberOfFrames, &dynamicRange);
|
||||
DataProcessor* p = NULL;
|
||||
if (ret == OK)
|
||||
p = new DataProcessor(ret, i, fifo[i], &fileFormatType,
|
||||
fileWriteEnable, &dataStreamEnable, &gapPixelsEnable, &dynamicRange, &frameToGuiFrequency, &frameToGuiTimerinMS,
|
||||
rawDataReadyCallBack, rawDataModifyReadyCallBack, pRawDataReady);
|
||||
|
||||
// error in creating threads
|
||||
if (ret == FAIL) {
|
||||
FILE_LOG(logERROR) << "Could not create listener/dataprocessor threads (index:" << i << ")";
|
||||
for (vector<Listener*>::const_iterator it = listener.begin(); it != listener.end(); ++it)
|
||||
delete(*it);
|
||||
@ -378,6 +392,9 @@ int UDPStandardImplementation::setDetectorType(const detectorType d) {
|
||||
dataProcessor.clear();
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
listener.push_back(l);
|
||||
dataProcessor.push_back(p);
|
||||
}
|
||||
|
||||
//set up writer and callbacks
|
||||
@ -474,14 +491,20 @@ void UDPStandardImplementation::stopReceiver(){
|
||||
//set status to transmitting
|
||||
startReadout();
|
||||
|
||||
//wait for the processes to be done
|
||||
while(Listener::GetRunningMask()){
|
||||
usleep(5000);
|
||||
}
|
||||
while(DataProcessor::GetRunningMask()){
|
||||
usleep(5000);
|
||||
//wait for the processes (Listener and DataProcessor) to be done
|
||||
bool running = true;
|
||||
while(running) {
|
||||
running = false;
|
||||
for (vector<Listener*>::const_iterator it = listener.begin(); it != listener.end(); ++it)
|
||||
if ((*it)->IsRunning())
|
||||
running = true;
|
||||
for (vector<DataProcessor*>::const_iterator it = dataProcessor.begin(); it != dataProcessor.end(); ++it)
|
||||
if ((*it)->IsRunning())
|
||||
running = true;
|
||||
usleep(5000);
|
||||
}
|
||||
|
||||
|
||||
//create virtual file
|
||||
if (fileWriteEnable && fileFormatType == HDF5) {
|
||||
uint64_t maxIndexCaught = 0;
|
||||
@ -495,9 +518,15 @@ void UDPStandardImplementation::stopReceiver(){
|
||||
dataProcessor[0]->EndofAcquisition(maxIndexCaught); //to create virtual file
|
||||
}
|
||||
|
||||
while(DataStreamer::GetRunningMask()){
|
||||
usleep(5000);
|
||||
}
|
||||
//wait for the processes (DataStreamer) to be done
|
||||
running = true;
|
||||
while(running) {
|
||||
running = false;
|
||||
for (vector<DataStreamer*>::const_iterator it = dataStreamer.begin(); it != dataStreamer.end(); ++it)
|
||||
if ((*it)->IsRunning())
|
||||
running = true;
|
||||
usleep(5000);
|
||||
}
|
||||
|
||||
status = RUN_FINISHED;
|
||||
FILE_LOG(logINFO) << "Status: " << runStatusType(status);
|
||||
@ -603,7 +632,7 @@ void UDPStandardImplementation::closeFiles() {
|
||||
int UDPStandardImplementation::restreamStop() {
|
||||
bool ret = OK;
|
||||
for (vector<DataStreamer*>::const_iterator it = dataStreamer.begin(); it != dataStreamer.end(); ++it) {
|
||||
if ((*it)->restreamStop() == FAIL)
|
||||
if ((*it)->RestreamStop() == FAIL)
|
||||
ret = FAIL;
|
||||
}
|
||||
|
||||
@ -667,11 +696,13 @@ int UDPStandardImplementation::SetupFifoStructure() {
|
||||
delete(*it);
|
||||
fifo.clear();
|
||||
for ( int i = 0; i < numThreads; i++ ) {
|
||||
|
||||
//create fifo structure
|
||||
bool success = true;
|
||||
fifo.push_back( new Fifo (
|
||||
(generalData->imageSize) * numberofJobs + (generalData->fifoBufferHeaderSize),
|
||||
fifoDepth, success));
|
||||
Fifo* f = new Fifo (i,
|
||||
(generalData->imageSize) * numberofJobs + (generalData->fifoBufferHeaderSize),
|
||||
fifoDepth, success);
|
||||
//error
|
||||
if (!success) {
|
||||
cprintf(RED,"Error: Could not allocate memory for fifo structure of index %d\n", i);
|
||||
for (vector<Fifo*>::const_iterator it = fifo.begin(); it != fifo.end(); ++it)
|
||||
@ -679,6 +710,8 @@ int UDPStandardImplementation::SetupFifoStructure() {
|
||||
fifo.clear();
|
||||
return FAIL;
|
||||
}
|
||||
fifo.push_back(f);
|
||||
|
||||
//set the listener & dataprocessor threads to point to the right fifo
|
||||
if(listener.size())listener[i]->SetFifo(fifo[i]);
|
||||
if(dataProcessor.size())dataProcessor[i]->SetFifo(fifo[i]);
|
||||
@ -693,10 +726,6 @@ int UDPStandardImplementation::SetupFifoStructure() {
|
||||
|
||||
|
||||
void UDPStandardImplementation::ResetParametersforNewMeasurement() {
|
||||
Listener::ResetRunningMask();
|
||||
DataProcessor::ResetRunningMask();
|
||||
DataStreamer::ResetRunningMask();
|
||||
|
||||
for (vector<Listener*>::const_iterator it = listener.begin(); it != listener.end(); ++it)
|
||||
(*it)->ResetParametersforNewMeasurement();
|
||||
for (vector<DataProcessor*>::const_iterator it = dataProcessor.begin(); it != dataProcessor.end(); ++it)
|
||||
|
Loading…
x
Reference in New Issue
Block a user