in the process of streamer

This commit is contained in:
Dhanya Maliakal
2017-02-27 15:38:46 +01:00
parent 936dfea8a7
commit 3b07afe3fc
16 changed files with 654 additions and 171 deletions

View File

@ -14,6 +14,7 @@
class GeneralData;
class Fifo;
class File;
class DataStreamer;
#include <vector>
@ -24,15 +25,14 @@ class DataProcessor : private virtual slsReceiverDefs, public ThreadObject {
* Constructor
* Calls Base Class CreateThread(), sets ErrorMask if error and increments NumberofDataProcessors
* @param f address of Fifo pointer
* @param s pointer to receiver status
* @param m pointer to mutex for status
* @param ftype pointer to file format type
* @param fwenable pointer to file writer enable
* @param dsEnable pointer to data stream enable
* @param cbaction pointer to call back action
* @param dataReadycb pointer to data ready call back function
* @param pDataReadycb pointer to arguments of data ready call back function
*/
DataProcessor(Fifo*& f, runStatus* s, pthread_mutex_t* m, fileFormat* ftype, bool* fwenable,
DataProcessor(Fifo*& f, fileFormat* ftype, bool* fwenable, bool* dsEnable,
int* cbaction,
void (*dataReadycb)(int, char*, int, FILE*, char*, void*),
void *pDataReadycb);
@ -57,6 +57,10 @@ class DataProcessor : private virtual slsReceiverDefs, public ThreadObject {
*/
static uint64_t GetRunningMask();
/**
* Reset RunningMask
*/
static void ResetRunningMask();
//*** non static functions ***
//*** getters ***
@ -124,6 +128,13 @@ class DataProcessor : private virtual slsReceiverDefs, public ThreadObject {
*/
void SetGeneralData(GeneralData* g);
/**
* Set thread priority
* @priority priority
* @returns OK or FAIL
*/
int SetThreadPriority(int priority);
/**
* Set File Format
* @param f file format
@ -235,8 +246,8 @@ class DataProcessor : private virtual slsReceiverDefs, public ThreadObject {
/** Fifo structure */
Fifo* fifo;
// individual members
/** Data Stream Enable */
bool* dataStreamEnable;
/** Aquisition Started flag */
bool acquisitionStartedFlag;
@ -244,12 +255,6 @@ class DataProcessor : private virtual slsReceiverDefs, public ThreadObject {
/** Measurement Started flag */
bool measurementStartedFlag;
/** Receiver Status */
runStatus* status;
/** Status mutex */
pthread_mutex_t* statusMutex;
/**Number of complete frames caught for an entire acquisition (including all scans) */
uint64_t numTotalFramesCaught;

View File

@ -9,14 +9,23 @@
#include "ThreadObject.h"
class GeneralData;
class Fifo;
class DataStreamer;
class ZmqSocket;
class DataStreamer : private virtual slsReceiverDefs, public ThreadObject {
public:
/**
* Constructor
* Calls Base Class CreateThread(), sets ErrorMask if error and increments NumberofDataStreamers
* @param f address of Fifo pointer
* @param dr pointer to dynamic range
* @param freq poiner to streaming frequency
* @param timer poiner to timer if streaming frequency is random
*/
DataStreamer();
DataStreamer(Fifo*& f, uint32_t* dr, uint32_t* freq, uint32_t* timer);
/**
* Destructor
@ -25,18 +34,30 @@ 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();
//*** non static functions ***
//*** getters ***
//*** setters ***
/**
* Set bit in RunningMask to allow thread to run
*/
@ -47,6 +68,52 @@ class DataStreamer : private virtual slsReceiverDefs, public ThreadObject {
*/
void StopRunning();
/**
* Set Fifo pointer to the one given
* @param f address of Fifo pointer
*/
void SetFifo(Fifo*& f);
/**
* Reset parameters for new acquisition (including all scans)
*/
void ResetParametersforNewAcquisition();
/**
* Reset parameters for new measurement (eg. for each scan)
*/
void ResetParametersforNewMeasurement();
/**
* Create Part1 of Json Header which includes common attributes in an acquisition
*/
void CreateHeaderPart1();
/**
* Set GeneralData pointer to the one given
* @param g address of GeneralData (Detector Data) pointer
*/
void SetGeneralData(GeneralData* g);
/**
* Set thread priority
* @priority priority
* @returns OK or FAIL
*/
int SetThreadPriority(int priority);
/**
* Creates Zmq Sockets
* @param dindex pointer to detector index
* @param nunits pointer to number of theads/ units per detector
* @return OK or FAIL
*/
int CreateZmqSockets(int* dindex, int* nunits);
/**
* Shuts down and deletes Zmq Sockets
*/
void CloseZmqSocket();
private:
@ -62,13 +129,52 @@ class DataStreamer : private virtual slsReceiverDefs, public ThreadObject {
*/
bool IsRunning();
/**
* Record First Indices (firstAcquisitionIndex, firstMeasurementIndex)
* @param fnum frame index to record
*/
void RecordFirstIndices(uint64_t fnum);
/**
* Thread Exeution for DataStreamer Class
* Stream an image via zmq
*/
void ThreadExecution();
/**
* Frees dummy buffer,
* reset running mask by calling StopRunning()
* @param buf address of pointer
*/
void StopProcessing(char* buf);
/**
* Process an image popped from fifo,
* write to file if fw enabled & update parameters
* @param buffer
*/
void ProcessAnImage(char* buf);
/**
* This function should be called only in random frequency mode
* Checks if timer is done and ready to send data
* @returns true if ready to send data, else false
*/
bool CheckTimer();
/**
* This function should be called only in non random frequency mode
* Checks if count is done and ready to send data
* @returns true if ready to send data, else false
*/
bool CheckCount();
/**
* Create and send Json Header
* @param fnum frame number
* @returns 0 if error, else 1
*/
int SendHeader(uint64_t fnum);
/** type of thread */
static const std::string TypeName;
@ -84,5 +190,50 @@ class DataStreamer : private virtual slsReceiverDefs, public ThreadObject {
/** mutex to update static items among objects (threads)*/
static pthread_mutex_t Mutex;
/** Json Header Format for each measurement part */
static const char *jsonHeaderFormat_part1;
/** Json Header Format */
static const char *jsonHeaderFormat;
/** GeneralData (Detector Data) object */
const GeneralData* generalData;
/** Fifo structure */
Fifo* fifo;
/** ZMQ Socket - Receiver to Client */
ZmqSocket* zmqSocket;
/** Pointer to dynamic range */
uint32_t* dynamicRange;
/** Pointer to Streaming frequency, if 0, sending random images with a timer */
uint32_t* streamingFrequency;
/** Pointer to the timer if Streaming frequency is random */
uint32_t* streamingTimerInMs;
/** Current frequency count */
uint32_t currentFreqCount;
/** timer beginning stamp for random streaming */
struct timespec timerBegin;
/** Current Json Header prefix*/
char* currentHeader;
/** Aquisition Started flag */
bool acquisitionStartedFlag;
/** Measurement Started flag */
bool measurementStartedFlag;
/** Frame Number of First Frame of an entire Acquisition (including all scans) */
uint64_t firstAcquisitionIndex;
/** Frame Number of First Frame for each real time acquisition (eg. for each scan) */
uint64_t firstMeasurementIndex;
};

View File

@ -31,16 +31,16 @@ class Fifo : private virtual slsReceiverDefs {
*/
~Fifo();
/**
* Pops free address from fifoFree
*/
void GetNewAddress(char*& address);
/**
* Frees the bound address by pushing into fifoFree
*/
void FreeAddress(char*& address);
/**
* Pops free address from fifoFree
*/
void GetNewAddress(char*& address);
/**
* Pushes bound address into fifoBound
*/
@ -51,6 +51,16 @@ class Fifo : private virtual slsReceiverDefs {
*/
void PopAddress(char*& address);
/**
* Pushes bound address into fifoStream
*/
void PushAddressToStream(char*& address);
/**
* Pops bound address from fifoStream to stream data
*/
void PopAddressToStream(char*& address);
private:
/**
@ -82,4 +92,6 @@ class Fifo : private virtual slsReceiverDefs {
/** Circular Fifo pointing to addresses of freed data in memory */
CircularFifo<char>* fifoFree;
/** Circular Fifo pointing to addresses of to be streamed data in memory */
CircularFifo<char>* fifoStream;
};

View File

@ -428,7 +428,7 @@ private:
packetsPerFrame = 256;
imageSize = dataSize*packetsPerFrame;
frameIndexMask = 0xffffff;
maxFramesPerFile = 5;//EIGER_MAX_FRAMES_PER_FILE;
maxFramesPerFile = EIGER_MAX_FRAMES_PER_FILE;
fifoBufferSize = imageSize;
fifoBufferHeaderSize= FIFO_HEADER_NUMBYTES + FILE_FRAME_HEADER_SIZE;
defaultFifoDepth = 100;

View File

@ -447,10 +447,10 @@ public:
hid_t vdsdataset = H5Dcreate2 (fd, virtualDatasetname.c_str(), dtype, vdsDataspace, H5P_DEFAULT, dcpl, H5P_DEFAULT);
if (vdsdataset >= 0){
H5Sclose(vdsDataspace);
H5Sclose(srcDataspace);
H5Dclose(vdsdataset);
H5Fclose(fd);
H5Sclose(vdsDataspace);vdsDataspace = 0;
H5Sclose(srcDataspace);srcDataspace = 0;
H5Dclose(vdsdataset);vdsdataset = 0;
H5Fclose(fd);fd = 0;
return 0;
} else cprintf(RED, "could not create virtual dataset in virtual file %s\n", virtualfname.c_str());
@ -468,6 +468,7 @@ public:
} else cprintf(RED, "could not create dfal for virtual file %s\n", virtualfname.c_str());
H5Fclose(fd);
fd = 0;
return 1;
}

View File

@ -25,8 +25,10 @@ class Listener : private virtual slsReceiverDefs, public ThreadObject {
* @param s pointer to receiver status
* @param portno pointer to udp port number
* @param e ethernet interface
* @param act pointer to activated
* @param nf pointer to number of images to catch
*/
Listener(Fifo*& f, runStatus* s, uint32_t* portno, char* e);
Listener(Fifo*& f, runStatus* s, uint32_t* portno, char* e, int* act, uint64_t* nf);
/**
* Destructor
@ -49,11 +51,9 @@ class Listener : private virtual slsReceiverDefs, public ThreadObject {
static uint64_t GetRunningMask();
/**
* Set GeneralData pointer to the one given
* @param g address of GeneralData (Detector Data) pointer
* Reset RunningMask
*/
static void SetGeneralData(GeneralData*& g);
static void ResetRunningMask();
//*** non static functions ***
@ -94,7 +94,6 @@ class Listener : private virtual slsReceiverDefs, public ThreadObject {
*/
void StopRunning();
/**
* Set Fifo pointer to the one given
* @param f address of Fifo pointer
@ -111,6 +110,19 @@ class Listener : private virtual slsReceiverDefs, public ThreadObject {
*/
void ResetParametersforNewMeasurement();
/**
* Set GeneralData pointer to the one given
* @param g address of GeneralData (Detector Data) pointer
*/
void SetGeneralData(GeneralData*& g);
/**
* Set thread priority
* @priority priority
* @returns OK or FAIL
*/
int SetThreadPriority(int priority);
/**
* Creates UDP Sockets
* @return OK or FAIL
@ -168,6 +180,13 @@ class Listener : private virtual slsReceiverDefs, public ThreadObject {
*/
uint32_t ListenToAnImage(char* buf);
/**
* Create an image (for deactivated detectors),
* @param buffer
* @returns image size or 0
*/
uint32_t CreateAnImage(char* buf);
/** type of thread */
@ -202,7 +221,7 @@ class Listener : private virtual slsReceiverDefs, public ThreadObject {
/** Receiver Status */
runStatus* status;
/** UDP Sockets - Detector to Receiver */
/** UDP Socket - Detector to Receiver */
genericSocket* udpSocket;
/** UDP Port Number */
@ -211,6 +230,12 @@ class Listener : private virtual slsReceiverDefs, public ThreadObject {
/** ethernet interface */
char* eth;
/** if the detector is activated */
int* activated;
/** Number of Images to catch */
uint64_t* numImages;
/**Number of complete Packets caught for an entire acquisition (including all scans) */
uint64_t numTotalPacketsCaught;

View File

@ -206,6 +206,11 @@ private:
*/
void SetLocalNetworkParameters();
/**
* Set Thread Priorities
*/
void SetThreadPriorities();
/**
* Set up the Fifo Structure for processing buffers
* between listening and dataprocessor threads

View File

@ -62,7 +62,6 @@ class sockaddr_in;
#include <stdio.h>
using namespace std;
#define DEFAULT_PACKET_SIZE 1286
@ -72,7 +71,7 @@ using namespace std;
#define DEFAULT_BACKLOG 5
#define DEFAULT_UDP_PORTNO 50001
#define DEFAULT_GUI_PORTNO 65000
#define DEFAULT_ZMQ_PORTNO 70001
//#define DEFAULT_ZMQ_PORTNO 70001
class genericSocket{
@ -102,13 +101,10 @@ enum communicationProtocol{
{
memset(&serverAddress, 0, sizeof(serverAddress));
memset(&clientAddress, 0, sizeof(clientAddress));
// strcpy(hostname,host_ip_or_name);
strcpy(lastClientIP,"none");
strcpy(thisClientIP,"none1");
strcpy(dummyClientIP,"dummy");
differentClients = 0;
struct hostent *hostInfo = gethostbyname(host_ip_or_name);
if (hostInfo == NULL){
cerr << "Exiting: Problem interpreting host: " << host_ip_or_name << "\n";
@ -170,13 +166,13 @@ enum communicationProtocol{
/* // you can specify an IP address: */
/* // or you can let it automatically select one: */
/* myaddr.sin_addr.s_addr = INADDR_ANY; */
strcpy(lastClientIP,"none");
strcpy(thisClientIP,"none1");
strcpy(dummyClientIP,"dummy");
differentClients = 0;
if(serverAddress.sin_port == htons(port_number)){
socketDescriptor = -10;
return;
@ -209,8 +205,7 @@ enum communicationProtocol{
if (string(ip)!=string("0.0.0.0")) {
if (inet_pton(AF_INET, ip, &(serverAddress.sin_addr)))
;
if (inet_pton(AF_INET, ip, &(serverAddress.sin_addr)));
else
serverAddress.sin_addr.s_addr = htonl(INADDR_ANY);
}
@ -718,7 +713,6 @@ enum communicationProtocol{
int nsent;
int total_sent;
int header_packet_size;
// pthread_mutex_t mp;
};

View File

@ -35,3 +35,7 @@
#define DUMMY_PACKET_VALUE 0xFFFFFFFF
#define LISTENER_PRIORITY 99
#define PROCESSOR_PRIORITY 90
#define STREAMER_PRIORITY 80
#define TCP_PRIORITY 50