somewhere

This commit is contained in:
Dhanya Maliakal 2017-02-10 10:08:00 +01:00
parent c89f6e649c
commit b260d08225
18 changed files with 1076 additions and 356 deletions

View File

@ -18,17 +18,91 @@ class BinaryFileWriter : private virtual slsReceiverDefs, public FileWriter {
/** /**
* Constructor * Constructor
* creates the File Writer * creates the File Writer
* @fname pointer to file name prefix * @param ind self index
* @param fname pointer to file name prefix
* @param fpath pointer to file path
* @param findex pointer to file index
* @param frindexenable pointer to frame index enable
* @param owenable pointer to over write enable
* @param dindex pointer to detector index
* @param nunits pointer to number of theads/ units per detector
* @param maxf pointer to max frames per file
*/ */
BinaryFileWriter(char* fname); BinaryFileWriter(int ind, char* fname, char* fpath, uint64_t* findex,
bool* frindexenable, bool* owenable, int* dindex, int* nunits, uint32_t maxf);
/** /**
* Destructor * Destructor
*/ */
~BinaryFileWriter(); ~BinaryFileWriter();
/**
* Print all member values
*/
void PrintMembers();
/**
* Set Max frames per file
* @param maxf maximum frames per file
*/
void SetMaxFramesPerFile(uint32_t maxf);
/**
* Create file
* @param fnum current frame index to include in file name
* @returns OK or FAIL
*/
int CreateFile(uint64_t fnum);
/**
* Close File
*/
void CloseFile();
/**
* Create File Name in format fpath/fnameprefix_fx_dy_z.raw,
* where x is fnum, y is (dindex * numunits + unitindex) and z is findex
* @param fpath file path
* @param fnameprefix file name prefix (includes scan and position variables)
* @param findex file index
* @param frindexenable frame index enable
* @param fnum frame number index
* @param dindex readout index
* @param numunits number of units per readout. eg. eiger has 2 udp units per readout
* @param unitindex unit index
* @returns complete file name created
*/
static std::string CreateFileName(char* fpath, char* fnameprefix, uint64_t findex, bool frindexenable,
uint64_t fnum = 0, int dindex = -1, int numunits = 1, int unitindex = 0);
/**
* Create File
* @param owenable overwrite enable
* @param fname complete file name
* @returns OK or FAIL
*/
static int CreateDataFile(bool owenable, char* fname);
/**
* Close File
*/
static void CloseDataFile();
private: private:
/**
* Get Type
* @return type
*/
fileFormat GetType();
/** Maximum frames per file */
uint32_t maxFramesPerFile;
}; };
#endif #endif

View File

@ -27,8 +27,16 @@ class DataProcessor : private virtual slsReceiverDefs, public ThreadObject {
* @param f address of Fifo pointer * @param f address of Fifo pointer
* @param s pointer to receiver status * @param s pointer to receiver status
* @param m pointer to mutex for status * @param m pointer to mutex for status
* @param ftype pointer to file format type
* @param fwenable pointer to file writer 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); DataProcessor(Fifo*& f, runStatus* s, pthread_mutex_t* m, fileFormat* ftype, bool* fwenable,
int* cbaction,
void (*dataReadycb)(int, char*, int, FILE*, char*, void*),
void *pDataReadycb);
/** /**
* Destructor * Destructor
@ -37,23 +45,18 @@ class DataProcessor : private virtual slsReceiverDefs, public ThreadObject {
~DataProcessor(); ~DataProcessor();
//*** static functions ***
/** /**
* Get RunningMask * Get ErrorMask
* @return RunningMask * @return ErrorMask
*/ */
static uint64_t GetErrorMask(); static uint64_t GetErrorMask();
/** /**
* Get acquisition started flag * Get RunningMask
* @return acquisition started flag * @return RunningMask
*/ */
static bool GetAcquisitionStartedFlag(); static uint64_t GetRunningMask();
/**
* Get measurement started flag
* @return measurement started flag
*/
static bool GetMeasurementStartedFlag();
/** /**
* Set GeneralData pointer to the one given * Set GeneralData pointer to the one given
@ -61,6 +64,22 @@ class DataProcessor : private virtual slsReceiverDefs, public ThreadObject {
*/ */
static void SetGeneralData(GeneralData*& g); static void SetGeneralData(GeneralData*& g);
//*** non static functions ***
//*** getters ***
/**
* Get acquisition started flag
* @return acquisition started flag
*/
bool GetAcquisitionStartedFlag();
/**
* Get measurement started flag
* @return measurement started flag
*/
bool GetMeasurementStartedFlag();
/** /**
* Get Total Complete Frames Caught for an entire acquisition (including all scans) * Get Total Complete Frames Caught for an entire acquisition (including all scans)
* @return total number of frames caught for entire acquisition * @return total number of frames caught for entire acquisition
@ -79,6 +98,8 @@ class DataProcessor : private virtual slsReceiverDefs, public ThreadObject {
*/ */
uint64_t GetProcessedAcquisitionIndex(); uint64_t GetProcessedAcquisitionIndex();
//*** setters ***
/** /**
* Set bit in RunningMask to allow thread to run * Set bit in RunningMask to allow thread to run
*/ */
@ -105,6 +126,31 @@ class DataProcessor : private virtual slsReceiverDefs, public ThreadObject {
*/ */
void ResetParametersforNewMeasurement(); void ResetParametersforNewMeasurement();
/**
* Set Max frames per file
*/
void SetMaxFramesPerFile();
/**
* Set File Format
* @param f file format
*/
void SetFileFormat(const fileFormat fs);
/**
* Set up file writer object and call backs
* @param fname pointer to file name prefix
* @param fpath pointer to file path
* @param findex pointer to file index
* @param frindexenable pointer to frame index enable
* @param owenable pointer to over write enable
* @param dindex pointer to detector index
* @param nunits pointer to number of theads/ units per detector
*/
void SetupFileWriter(char* fname, char* fpath, uint64_t* findex,
bool* frindexenable, bool* owenable, int* dindex, int* nunits);
/** /**
* Create New File * Create New File
*/ */
@ -129,6 +175,18 @@ class DataProcessor : private virtual slsReceiverDefs, public ThreadObject {
*/ */
bool IsRunning(); bool IsRunning();
/**
* Record First Indices (firstAcquisitionIndex, firstMeasurementIndex)
* @param fnum frame index to record
*/
void RecordFirstIndices(uint64_t fnum);
/**
* Destroy file writer object
* @return OK or FAIL
*/
void DestroyFileWriter();
/** /**
* Thread Exeution for DataProcessor Class * Thread Exeution for DataProcessor Class
* Pop bound addresses, process them, * Pop bound addresses, process them,
@ -143,6 +201,13 @@ class DataProcessor : private virtual slsReceiverDefs, public ThreadObject {
*/ */
void StopProcessing(char* buf); void StopProcessing(char* buf);
/**
* Process an image popped from fifo,
* write to file if fw enabled & update parameters
* @param buffer
*/
void ProcessAnImage(char* buf);
/** type of thread */ /** type of thread */
@ -169,10 +234,10 @@ class DataProcessor : private virtual slsReceiverDefs, public ThreadObject {
// individual members // individual members
/** Aquisition Started flag */ /** Aquisition Started flag */
static bool acquisitionStartedFlag; bool acquisitionStartedFlag;
/** Measurement Started flag */ /** Measurement Started flag */
static bool measurementStartedFlag; bool measurementStartedFlag;
/** Receiver Status */ /** Receiver Status */
runStatus* status; runStatus* status;
@ -196,7 +261,37 @@ class DataProcessor : private virtual slsReceiverDefs, public ThreadObject {
uint64_t currentFrameIndex; uint64_t currentFrameIndex;
/** File writer implemented as binary or hdf5 filewriter */ /** File writer implemented as binary or hdf5 filewriter */
std::vector <FileWriter*> fileWriter; FileWriter* fileWriter;
/** File Format Type */
fileFormat* fileFormatType;
/** File Write Enable */
bool* fileWriteEnable;
//***callback parameters***
/** Pointer to the action which decides what the user and default responsibilities to save data are
* 0 raw data ready callback takes care of open,close,write file
* 1 callback writes file, we have to open, close it
* 2 we open, close, write file, callback does not do anything */
int* callbackAction;
/**
* function being called back for raw data
* args to raw data ready callback are
* framenum
* datapointer
* datasize in bytes
* file descriptor
* guidatapointer (NULL, no data required)
*/
void (*rawDataReadyCallBack)(int, char*, int, FILE*, char*, void*);
void *pRawDataReady;
}; };
#endif #endif

View File

@ -13,33 +13,121 @@
#include "logger.h" #include "logger.h"
#include <string>
class FileWriter : private virtual slsReceiverDefs { class FileWriter : private virtual slsReceiverDefs {
public: public:
/** /**
* Constructor * Constructor
* creates the File Writer * creates the File Writer
* @fname pointer to file name prefix * @param ind self index
* @param fname pointer to file name prefix
* @param fpath pointer to file path
* @param findex pointer to file index
* @param frindexenable pointer to frame index enable
* @param owenable pointer to over write enable
* @param dindex pointer to detector index
* @param nunits pointer to number of theads/ units per detector
*/ */
FileWriter(char* fname); FileWriter(int ind, char* fname, char* fpath, uint64_t* findex,
bool* frindexenable, bool* owenable, int* dindex, int* nunits);
/** /**
* Destructor * Destructor
*/ */
~FileWriter(); virtual ~FileWriter();
/** /**
* Get File Name prefix * Get Current File Name
* @returns file name prefix * @returns current file name
*/ */
char* GetFileName(); std::string GetCurrentFileName();
/**
* Print all member values
*/
virtual void PrintMembers();
/**
* Get Type
* @return type
*/
virtual fileFormat GetType() = 0;
/**
* Get Member Pointer Values before the object is destroyed
* @param fname pointer to file name prefix
* @param fpath pointer to file path
* @param findex pointer to file index
* @param frindexenable pointer to frame index enable
* @param owenable pointer to over write enable
* @param dindex pointer to detector index
* @param nunits pointer to number of theads/ units per detector
*/
void GetMemberPointerValues(char* fname, char* fpath, uint64_t* findex,
bool* frindexenable, bool* owenable, int* dindex, int* nunits);
/**
* Create file
* @param fnum current frame index to include in file name
* @returns OK or FAIL
*/
virtual int CreateFile(uint64_t fnum){
cprintf(RED,"This is a generic function that should be overloaded by a derived class\n");
return OK;
}
/**
* Close File
*/
virtual void CloseFile() {
cprintf(RED,"This is a generic function that should be overloaded by a derived class\n");
}
// Binary specific
/**
* Set Max frames per file
* @param maxf maximum frames per file
*/
virtual void SetMaxFramesPerFile(uint32_t maxf) {
cprintf(RED,"This is a generic function that should be overloaded by a derived class\n");
}
protected: protected:
char* fileName; /** Self Index */
int index;
/** File Name Prefix */
char* fileNamePrefix;
/** File Path */
char* filePath;
/** File Index */
uint64_t* fileIndex;
/** Frame Index */
bool* frameIndexEnable;
/** File Write Enable */
bool* fileWriteEnable;
/** Over write enable */
bool* overWriteEnable;
/** Detector Index */
int* detIndex;
/** Number of units per detector. Eg. Eiger has 2, others 1 */
int* numUnitsPerDetector;
/** Current File Name */
std::string currentFileName;
}; };
#endif #endif

View File

@ -73,6 +73,20 @@ public:
/** Destructor */ /** Destructor */
virtual ~GeneralData(){}; virtual ~GeneralData(){};
/**
* Get Header Infomation (frame number, packet number)
* @param index thread index for debugging purposes
* @param packetData pointer to data
* @param frameNumber frame number
* @param packetNumber packet number
*/
virtual void GetHeaderInfo(int index, char* packetData, uint64_t& frameNumber, uint32_t& packetNumber) const {
frameNumber = ((uint32_t)(*((uint32_t*)(packetData))));
frameNumber++;
packetNumber = frameNumber&packetIndexMask;
frameNumber = (frameNumber & frameIndexMask) >> frameIndexOffset;
}
/** /**
* Get Header Infomation (frame number, packet number) * Get Header Infomation (frame number, packet number)
* @param index thread index for debugging purposes * @param index thread index for debugging purposes
@ -83,14 +97,9 @@ public:
* @param subFrameNumber sub frame number if applicable * @param subFrameNumber sub frame number if applicable
* @param bunchId bunch id * @param bunchId bunch id
*/ */
void GetHeaderInfo(int index, char* packetData, uint32_t dynamicRange, virtual void GetHeaderInfo(int index, char* packetData, uint32_t dynamicRange,
uint64_t& frameNumber, uint32_t& packetNumber, uint32_t& subFrameNumber, uint64_t bunchId) const { uint64_t& frameNumber, uint32_t& packetNumber, uint32_t& subFrameNumber, uint64_t bunchId) const {
subFrameNumber = 0; cprintf(RED,"This is a generic function that should be overloaded by a derived class\n");
bunchId = 0;
frameNumber = ((uint32_t)(*((uint32_t*)(packetData))));
frameNumber++;
packetNumber = frameNumber&packetIndexMask;
frameNumber = (frameNumber & frameIndexMask) >> frameIndexOffset;
} }
/** /**
@ -99,7 +108,7 @@ public:
* @param tgEnable true if 10GbE is enabled, else false * @param tgEnable true if 10GbE is enabled, else false
*/ */
virtual void SetDynamicRange(int dr, bool tgEnable) { virtual void SetDynamicRange(int dr, bool tgEnable) {
//This is a generic function that is overloaded by a dervied class cprintf(RED,"This is a generic function that should be overloaded by a derived class\n");
}; };
/** /**
@ -108,13 +117,13 @@ public:
* @param dr dynamic range * @param dr dynamic range
*/ */
virtual void SetTenGigaEnable(bool tgEnable, int dr) { virtual void SetTenGigaEnable(bool tgEnable, int dr) {
//This is a generic function that is overloaded by a dervied class cprintf(RED,"This is a generic function that should be overloaded by a derived class\n");
}; };
/** /**
* Print all variables * Print all variables
*/ */
void Print() const { virtual void Print() const {
printf("\n\nDetector Data Variables:\n"); printf("\n\nDetector Data Variables:\n");
printf( "Pixels X: %d\n" printf( "Pixels X: %d\n"
"Pixels Y: %d\n" "Pixels Y: %d\n"
@ -169,7 +178,7 @@ class GotthardData : public GeneralData {
packetIndexMask = 1; packetIndexMask = 1;
maxFramesPerFile = MAX_FRAMES_PER_FILE; maxFramesPerFile = MAX_FRAMES_PER_FILE;
fifoBufferSize = packetSize*packetsPerFrame; fifoBufferSize = packetSize*packetsPerFrame;
fifoBufferHeaderSize= FIFO_BUFFER_HEADER_SIZE; fifoBufferHeaderSize= FIFO_HEADER_NUMBYTES;
defaultFifoDepth = 25000; defaultFifoDepth = 25000;
}; };
}; };
@ -190,7 +199,7 @@ class ShortGotthardData : public GeneralData {
frameIndexMask = 0xFFFFFFFF; frameIndexMask = 0xFFFFFFFF;
maxFramesPerFile = SHORT_MAX_FRAMES_PER_FILE; maxFramesPerFile = SHORT_MAX_FRAMES_PER_FILE;
fifoBufferSize = packetSize*packetsPerFrame; fifoBufferSize = packetSize*packetsPerFrame;
fifoBufferHeaderSize= FIFO_BUFFER_HEADER_SIZE; fifoBufferHeaderSize= FIFO_HEADER_NUMBYTES;
defaultFifoDepth = 25000; defaultFifoDepth = 25000;
}; };
}; };
@ -218,7 +227,7 @@ class PropixData : public GeneralData {
packetIndexMask = 1; packetIndexMask = 1;
maxFramesPerFile = MAX_FRAMES_PER_FILE; maxFramesPerFile = MAX_FRAMES_PER_FILE;
fifoBufferSize = packetSize*packetsPerFrame; fifoBufferSize = packetSize*packetsPerFrame;
fifoBufferHeaderSize= FIFO_BUFFER_HEADER_SIZE; fifoBufferHeaderSize= FIFO_HEADER_NUMBYTES;
defaultFifoDepth = 25000; defaultFifoDepth = 25000;
}; };
}; };
@ -244,7 +253,7 @@ class Moench02Data : public GeneralData {
packetIndexMask = 0xFF; packetIndexMask = 0xFF;
maxFramesPerFile = MOENCH_MAX_FRAMES_PER_FILE; maxFramesPerFile = MOENCH_MAX_FRAMES_PER_FILE;
fifoBufferSize = packetSize*packetsPerFrame; fifoBufferSize = packetSize*packetsPerFrame;
fifoBufferHeaderSize= FIFO_BUFFER_HEADER_SIZE + FILE_FRAME_HEADER_SIZE; fifoBufferHeaderSize= FIFO_HEADER_NUMBYTES + FILE_FRAME_HEADER_SIZE;
defaultFifoDepth = 2500; defaultFifoDepth = 2500;
}; };
@ -278,7 +287,7 @@ class Moench03Data : public GeneralData {
packetIndexMask = 0xFFFFFFFF; packetIndexMask = 0xFFFFFFFF;
maxFramesPerFile = JFRAU_MAX_FRAMES_PER_FILE; maxFramesPerFile = JFRAU_MAX_FRAMES_PER_FILE;
fifoBufferSize = packetSize*packetsPerFrame; fifoBufferSize = packetSize*packetsPerFrame;
fifoBufferHeaderSize= FIFO_BUFFER_HEADER_SIZE + FILE_FRAME_HEADER_SIZE; fifoBufferHeaderSize= FIFO_HEADER_NUMBYTES + FILE_FRAME_HEADER_SIZE;
defaultFifoDepth = 2500; defaultFifoDepth = 2500;
}; };
@ -309,7 +318,7 @@ class JCTBData : public GeneralData {
imageSize = dataSize*packetsPerFrame; imageSize = dataSize*packetsPerFrame;
maxFramesPerFile = JFCTB_MAX_FRAMES_PER_FILE; maxFramesPerFile = JFCTB_MAX_FRAMES_PER_FILE;
fifoBufferSize = packetSize*packetsPerFrame; fifoBufferSize = packetSize*packetsPerFrame;
fifoBufferHeaderSize= FIFO_BUFFER_HEADER_SIZE + FILE_FRAME_HEADER_SIZE; fifoBufferHeaderSize= FIFO_HEADER_NUMBYTES + FILE_FRAME_HEADER_SIZE;
defaultFifoDepth = 2500; defaultFifoDepth = 2500;
}; };
@ -351,7 +360,7 @@ private:
imageSize = dataSize*packetsPerFrame; imageSize = dataSize*packetsPerFrame;
maxFramesPerFile = JFRAU_MAX_FRAMES_PER_FILE; maxFramesPerFile = JFRAU_MAX_FRAMES_PER_FILE;
fifoBufferSize = packetSize*packetsPerFrame; fifoBufferSize = packetSize*packetsPerFrame;
fifoBufferHeaderSize= FIFO_BUFFER_HEADER_SIZE + FILE_FRAME_HEADER_SIZE; fifoBufferHeaderSize= FIFO_HEADER_NUMBYTES + FILE_FRAME_HEADER_SIZE;
defaultFifoDepth = 2500; defaultFifoDepth = 2500;
}; };
@ -420,13 +429,26 @@ private:
frameIndexMask = 0xffffff; frameIndexMask = 0xffffff;
maxFramesPerFile = EIGER_MAX_FRAMES_PER_FILE; maxFramesPerFile = EIGER_MAX_FRAMES_PER_FILE;
fifoBufferSize = packetSize*packetsPerFrame; fifoBufferSize = packetSize*packetsPerFrame;
fifoBufferHeaderSize= FIFO_BUFFER_HEADER_SIZE + FILE_FRAME_HEADER_SIZE; fifoBufferHeaderSize= FIFO_HEADER_NUMBYTES + FILE_FRAME_HEADER_SIZE;
defaultFifoDepth = 100; defaultFifoDepth = 100;
footerOffset = packetHeaderSize+dataSize; footerOffset = packetHeaderSize+dataSize;
threadsPerReceiver = 2; threadsPerReceiver = 2;
headerPacketSize = 48; headerPacketSize = 48;
}; };
/**
* Get Header Infomation (frame number, packet number)
* @param index thread index for debugging purposes
* @param packetData pointer to data
* @param frameNumber frame number
* @param packetNumber packet number
*/
void GetHeaderInfo(int index, char* packetData, uint64_t& frameNumber, uint32_t& packetNumber) const {
eiger_packet_footer_t* footer = (eiger_packet_footer_t*)(packetData + footerOffset);
frameNumber = (uint64_t)((*( (uint64_t*) footer)) & frameIndexMask);
packetNumber = (uint32_t)(*( (uint16_t*) footer->packetNumber))-1;
}
/** /**
* Get Header Infomation (frame number, packet number) * Get Header Infomation (frame number, packet number)
* @param index thread index for debugging purposes * @param index thread index for debugging purposes
@ -480,7 +502,7 @@ private:
*/ */
void Print() const { void Print() const {
GeneralData::Print(); GeneralData::Print();
printf( "Packet Header Size: %d" printf( "Packet Header Size: %d\n"
"Footer Offset : %d\n", "Footer Offset : %d\n",
packetHeaderSize, packetHeaderSize,
footerOffset); footerOffset);

View File

@ -18,17 +18,76 @@ class HDF5FileWriter : private virtual slsReceiverDefs, public FileWriter {
/** /**
* Constructor * Constructor
* creates the File Writer * creates the File Writer
* @fname pointer to file name prefix * @param fname pointer to file name prefix
* @param fpath pointer to file path
* @param findex pointer to file index
* @param frindexenable pointer to frame index enable
* @param owenable pointer to over write enable
* @param dindex pointer to detector index
* @param nunits pointer to number of theads/ units per detector
*/ */
HDF5FileWriter(char* fname); HDF5FileWriter(int ind, char* fname, char* fpath, uint64_t* findex,
bool* frindexenable, bool* owenable, int* dindex, int* nunits);
/** /**
* Destructor * Destructor
*/ */
~HDF5FileWriter(); ~HDF5FileWriter();
/**
* Print all member values
*/
void PrintMembers();
/**
* Create file
* @param fnum current frame index to include in file name
* @returns OK or FAIL
*/
int CreateFile(uint64_t fnum);
/**
* Close File
*/
void CloseFile();
/**
* Create File Name in format fpath/fnameprefix_fx_dy_z.raw,
* where x is fnum, y is (dindex * numunits + unitindex) and z is findex
* @param fpath file path
* @param fnameprefix file name prefix (includes scan and position variables)
* @param findex file index
* @param frindexenable frame index enable
* @param fnum frame number index
* @param dindex readout index
* @param numunits number of units per readout. eg. eiger has 2 udp units per readout
* @param unitindex unit index
* @returns complete file name created
*/
static std::string CreateFileName(char* fpath, char* fnameprefix, uint64_t findex, bool frindexenable,
uint64_t fnum = 0, int dindex = -1, int numunits = 1, int unitindex = 0);
/**
* Create File
* @param owenable overwrite enable
* @param fname complete file name
* @returns OK or FAIL
*/
static int CreateDataFile(bool owenable, char* fname);
/**
* Close File
*/
static void CloseDataFile();
private: private:
/**
* Get Type
* @return type
*/
fileFormat GetType();
}; };
#endif #endif

View File

@ -25,8 +25,9 @@ class Listener : private virtual slsReceiverDefs, public ThreadObject {
* @param f address of Fifo pointer * @param f address of Fifo pointer
* @param s pointer to receiver status * @param s pointer to receiver status
* @param portno pointer to udp port number * @param portno pointer to udp port number
* @param e ethernet interface
*/ */
Listener(Fifo*& f, runStatus* s, uint32_t* portno); Listener(Fifo*& f, runStatus* s, uint32_t* portno, char* e);
/** /**
* Destructor * Destructor
@ -35,23 +36,18 @@ class Listener : private virtual slsReceiverDefs, public ThreadObject {
~Listener(); ~Listener();
//*** static functions ***
/** /**
* Get RunningMask * Get ErrorMask
* @return RunningMask * @return ErrorMask
*/ */
static uint64_t GetErrorMask(); static uint64_t GetErrorMask();
/** /**
* Get acquisition started flag * Get RunningMask
* @return acquisition started flag * @return RunningMask
*/ */
static bool GetAcquisitionStartedFlag(); static uint64_t GetRunningMask();
/**
* Get measurement started flag
* @return measurement started flag
*/
static bool GetMeasurementStartedFlag();
/** /**
* Set GeneralData pointer to the one given * Set GeneralData pointer to the one given
@ -59,6 +55,22 @@ class Listener : private virtual slsReceiverDefs, public ThreadObject {
*/ */
static void SetGeneralData(GeneralData*& g); static void SetGeneralData(GeneralData*& g);
//*** non static functions ***
//*** getters ***
/**
* Get acquisition started flag
* @return acquisition started flag
*/
bool GetAcquisitionStartedFlag();
/**
* Get measurement started flag
* @return measurement started flag
*/
bool GetMeasurementStartedFlag();
/** /**
* Get Total Packets caught in an acquisition * Get Total Packets caught in an acquisition
* @return Total Packets caught in an acquisition * @return Total Packets caught in an acquisition
@ -66,10 +78,13 @@ class Listener : private virtual slsReceiverDefs, public ThreadObject {
uint64_t GetTotalPacketsCaught(); uint64_t GetTotalPacketsCaught();
/** /**
* Get number of bytes currently received in udp buffer * Get Last Frame index caught
* @return last frame index caught
*/ */
uint64_t GetNumReceivedinUDPBuffer(); uint64_t GetLastFrameIndexCaught();
//*** setters ***
/** /**
* Set bit in RunningMask to allow thread to run * Set bit in RunningMask to allow thread to run
*/ */
@ -99,10 +114,9 @@ class Listener : private virtual slsReceiverDefs, public ThreadObject {
/** /**
* Creates UDP Sockets * Creates UDP Sockets
* @param eth ethernet interface or null
* @return OK or FAIL * @return OK or FAIL
*/ */
int CreateUDPSockets(const char* eth); int CreateUDPSockets();
/** /**
* Shuts down and deletes UDP Sockets * Shuts down and deletes UDP Sockets
@ -126,6 +140,12 @@ class Listener : private virtual slsReceiverDefs, public ThreadObject {
*/ */
bool IsRunning(); bool IsRunning();
/**
* Record First Indices (firstAcquisitionIndex, firstMeasurementIndex)
* @param fnum frame index to record
*/
void RecordFirstIndices(uint64_t fnum);
/** /**
* Thread Exeution for Listener Class * Thread Exeution for Listener Class
* Pop free addresses, listen to udp socket, * Pop free addresses, listen to udp socket,
@ -141,6 +161,15 @@ class Listener : private virtual slsReceiverDefs, public ThreadObject {
*/ */
void StopListening(char* buf); void StopListening(char* buf);
/**
* Listen to the UDP Socket for an image,
* place them in the right order
* @param buffer
* @returns number of bytes of relevant data, can be image size or 0
*/
uint32_t ListenToAnImage(char* buf);
/** type of thread */ /** type of thread */
static const std::string TypeName; static const std::string TypeName;
@ -166,10 +195,10 @@ class Listener : private virtual slsReceiverDefs, public ThreadObject {
// individual members // individual members
/** Aquisition Started flag */ /** Aquisition Started flag */
static bool acquisitionStartedFlag; bool acquisitionStartedFlag;
/** Measurement Started flag */ /** Measurement Started flag */
static bool measurementStartedFlag; bool measurementStartedFlag;
/** Receiver Status */ /** Receiver Status */
runStatus* status; runStatus* status;
@ -180,6 +209,9 @@ class Listener : private virtual slsReceiverDefs, public ThreadObject {
/** UDP Port Number */ /** UDP Port Number */
uint32_t* udpPortNumber; uint32_t* udpPortNumber;
/** ethernet interface */
char* eth;
/**Number of complete Packets caught for an entire acquisition (including all scans) */ /**Number of complete Packets caught for an entire acquisition (including all scans) */
uint64_t numTotalPacketsCaught; uint64_t numTotalPacketsCaught;
@ -192,6 +224,20 @@ class Listener : private virtual slsReceiverDefs, public ThreadObject {
/** Frame Number of First Frame for each real time acquisition (eg. for each scan) */ /** Frame Number of First Frame for each real time acquisition (eg. for each scan) */
uint64_t firstMeasurementIndex; uint64_t firstMeasurementIndex;
/** Current Frame Index, default value is 0
* ( always check acquisitionStartedFlag for validity first)
*/
uint64_t currentFrameIndex;
/** Last Frame Index caught from udp network */
uint64_t lastCaughtFrameIndex;
/** True if there is a packet carry over from previous Image */
bool carryOverFlag;
/** Carry over packet buffer */
char* carryOverPacket;
}; };
#endif #endif

View File

@ -55,6 +55,12 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase
*/ */
int64_t getAcquisitionIndex() const; int64_t getAcquisitionIndex() const;
/**
* Set File Format
* @param f fileformat binary or hdf5
*/
void setFileFormat(slsReceiverDefs::fileFormat f);
/** /**
* Set File Name Prefix (without frame index, file index and extension (_f000000000000_8.raw)) * Set File Name Prefix (without frame index, file index and extension (_f000000000000_8.raw))
* Does not check for file existence since it is created only at startReceiver * Does not check for file existence since it is created only at startReceiver
@ -243,6 +249,12 @@ private:
/** Number of Jobs */ /** Number of Jobs */
int numberofJobs; int numberofJobs;
/** Pointer to the action which decides what the user and default responsibilities to save data are
* 0 raw data ready callback takes care of open,close,write file
* 1 callback writes file, we have to open, close it
* 2 we open, close, write file, callback does not do anything */
int callbackAction;
//*** mutex *** //*** mutex ***
/** Status mutex */ /** Status mutex */
pthread_mutex_t statusMutex; pthread_mutex_t statusMutex;

View File

@ -83,12 +83,6 @@ using namespace std;
#define DEFAULT_GUI_PORTNO 65000 #define DEFAULT_GUI_PORTNO 65000
#define DEFAULT_ZMQ_PORTNO 70001 #define DEFAULT_ZMQ_PORTNO 70001
/** Structure of an eiger packet footer */
typedef struct {
unsigned char frameNumber[6];
unsigned char packetNumber[2];
} eiger_packet_footer_t;
class genericSocket{ class genericSocket{
public: public:
@ -617,25 +611,16 @@ enum communicationProtocol{
if (socketDescriptor<0) return -1; if (socketDescriptor<0) return -1;
//if length given, listens to length, else listens for packetsize till length is reached //if length given, listens to length, else listens for packetsize till length is reached
if(length){ if(length){
/*int k = 0;*/
while(length>0){ while(length>0){
nsending = (length>packet_size) ? packet_size:length; nsending = (length>packet_size) ? packet_size:length;
nsent = recvfrom(socketDescriptor,(char*)buf+total_sent,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length); nsent = recvfrom(socketDescriptor,(char*)buf+total_sent,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length);
cprintf(CYAN,"nsent:%d\n",nsent);
if(nsent == header_packet_size) if(nsent == header_packet_size)
continue; continue;
if(nsent != nsending){ //if((nsent != nsending)){ && (nsent < packet_size)){ if(nsent != nsending){
if(nsent && (nsent != -1)) if(nsent && (nsent != -1))
cprintf(RED,"Incomplete Packet size %d\n",nsent); cprintf(RED,"Incomplete Packet size %d\n",nsent);
break; break;
} }
eiger_packet_footer_t* footer = (eiger_packet_footer_t*)(buf + 1024+8);
cprintf(MAGENTA,"generic fnum:%lld, pnum:%d \n",
(long long int)(uint64_t)((*( (uint64_t*) footer)) ),
(uint32_t)(*( (uint16_t*) footer->packetNumber)));
length-=nsent; length-=nsent;
total_sent+=nsent; total_sent+=nsent;
} }
@ -646,8 +631,10 @@ enum communicationProtocol{
nsending=packet_size; nsending=packet_size;
while(1){ while(1){
nsent = recvfrom(socketDescriptor,(char*)buf+total_sent,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length); nsent = recvfrom(socketDescriptor,(char*)buf+total_sent,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length);
if(nsent<=0 || nsent == packet_size) //break out of loop only if read one packets size or read didnt work (cuz of shutdown)
if(nsent<=0 || nsent == packet_size)
break; break;
//incomplete packets or header packets ignored and read buffer again
if(nsent != packet_size && nsent != header_packet_size) if(nsent != packet_size && nsent != header_packet_size)
cprintf(RED,"Incomplete Packet size %d\n",nsent); cprintf(RED,"Incomplete Packet size %d\n",nsent);
} }

View File

@ -18,7 +18,7 @@
#define FILE_FRAME_HEADER_SIZE 16 #define FILE_FRAME_HEADER_SIZE 16
//fifo //fifo
#define FIFO_BUFFER_HEADER_SIZE 4 #define FIFO_HEADER_NUMBYTES 4
//parameters to calculate fifo depth //parameters to calculate fifo depth
#define SAMPLE_TIME_IN_NS 100000000//100ms #define SAMPLE_TIME_IN_NS 100000000//100ms

View File

@ -188,6 +188,19 @@ public:
default: return std::string("idle"); \ default: return std::string("idle"); \
}}; }};
/** returns string from file format index
\param s can be BINARY, ASCII, HDF5
\returns string binary, ascii, hdf5
*/
static std::string getFileFormatType(fileFormat f){\
switch (f) { \
case ASCII: return std::string("ascii"); \
case HDF5: return std::string("hdf5"); \
case BINARY: return std::string("binary"); \
default: return std::string("unknown"); \
}};
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -7,16 +7,64 @@
#include "BinaryFileWriter.h" #include "BinaryFileWriter.h"
#include <iostream> #include <iostream>
#include <iomanip>
using namespace std; using namespace std;
BinaryFileWriter::BinaryFileWriter(char* fname): BinaryFileWriter::BinaryFileWriter(int ind, char* fname, char* fpath, uint64_t* findex,
FileWriter(fname) { bool* frindexenable, bool* owenable, int* dindex, int* nunits, uint32_t maxf):
FileWriter(ind, fname, fpath, findex, frindexenable, owenable, dindex, nunits),
maxFramesPerFile(maxf)
{
printf("%d BinaryFileWriter constructor\n",index);
PrintMembers();
} }
BinaryFileWriter::~BinaryFileWriter() { BinaryFileWriter::~BinaryFileWriter() {
printf("%d BinaryFileWriter destructor\n",index);
} }
void BinaryFileWriter::PrintMembers() {
FileWriter::PrintMembers();
printf("Max Frames Per File: %d\n",maxFramesPerFile);
}
slsReceiverDefs::fileFormat BinaryFileWriter::GetType() {
return BINARY;
}
void BinaryFileWriter::SetMaxFramesPerFile(uint32_t maxf) {
maxFramesPerFile = maxf;
}
int BinaryFileWriter::CreateFile(uint64_t fnum) {
currentFileName = CreateFileName(filePath, fileNamePrefix, *fileIndex,
*frameIndexEnable, fnum, *detIndex, *numUnitsPerDetector, index);
printf("%d Binary File: %s\n", index, currentFileName.c_str());
return OK;
}
void BinaryFileWriter::CloseFile() {
printf("%d Closing File: %s\n", index, currentFileName.c_str());
}
string BinaryFileWriter::CreateFileName(char* fpath, char* fnameprefix, uint64_t findex,
bool frindexenable, uint64_t fnum, int dindex, int numunits, int unitindex) {
ostringstream osfn;
osfn << fpath << "/" << fnameprefix;
if (dindex >= 0) osfn << "_d" << (dindex * numunits + unitindex);
if (frindexenable) osfn << "_f" << setfill('0') << setw(12) << fnum;
osfn << "_" << findex;
osfn << ".raw";
return osfn.str();
}
int BinaryFileWriter::CreateDataFile(bool owenable, char* fname) {
return OK;
}
void BinaryFileWriter::CloseDataFile() {
}

View File

@ -30,24 +30,29 @@ pthread_mutex_t DataProcessor::Mutex = PTHREAD_MUTEX_INITIALIZER;
const GeneralData* DataProcessor::generalData(0); const GeneralData* DataProcessor::generalData(0);
bool DataProcessor::acquisitionStartedFlag(false);
bool DataProcessor::measurementStartedFlag(false); DataProcessor::DataProcessor(Fifo*& f, runStatus* s, pthread_mutex_t* m, fileFormat* ftype, bool* fwenable,
int* cbaction,
void (*dataReadycb)(int, char*, int, FILE*, char*, void*),
DataProcessor::DataProcessor(Fifo*& f, runStatus* s, pthread_mutex_t* m) : void *pDataReadycb) :
ThreadObject(NumberofDataProcessors), ThreadObject(NumberofDataProcessors),
fifo(f), fifo(f),
acquisitionStartedFlag(false),
measurementStartedFlag(false),
status(s), status(s),
statusMutex(m), statusMutex(m),
numTotalFramesCaught(0), numTotalFramesCaught(0),
numFramesCaught(0), numFramesCaught(0),
firstAcquisitionIndex(0), firstAcquisitionIndex(0),
firstMeasurementIndex(0), firstMeasurementIndex(0),
currentFrameIndex(0) currentFrameIndex(0),
fileWriter(0),
fileFormatType(ftype),
fileWriteEnable(fwenable),
callbackAction(cbaction),
rawDataReadyCallBack(dataReadycb),
pRawDataReady(pDataReadycb)
{ {
FILE_LOG (logDEBUG) << __AT__ << " called";
if(ThreadObject::CreateThread()){ if(ThreadObject::CreateThread()){
pthread_mutex_lock(&Mutex); pthread_mutex_lock(&Mutex);
ErrorMask ^= (1<<index); ErrorMask ^= (1<<index);
@ -59,40 +64,22 @@ DataProcessor::DataProcessor(Fifo*& f, runStatus* s, pthread_mutex_t* m) :
DataProcessor::~DataProcessor() { DataProcessor::~DataProcessor() {
FILE_LOG (logDEBUG) << __AT__ << " called"; if (fileWriter) delete fileWriter;
for (vector<FileWriter*>::const_iterator it = fileWriter.begin(); it != fileWriter.end(); ++it)
delete(*it);
fileWriter.clear();
ThreadObject::DestroyThread(); ThreadObject::DestroyThread();
NumberofDataProcessors--; NumberofDataProcessors--;
} }
/** static functions */ /** static functions */
uint64_t DataProcessor::GetErrorMask() { uint64_t DataProcessor::GetErrorMask() {
FILE_LOG (logDEBUG) << __AT__ << " called";
return ErrorMask; return ErrorMask;
} }
uint64_t DataProcessor::GetRunningMask() {
bool DataProcessor::GetAcquisitionStartedFlag(){ return RunningMask;
FILE_LOG (logDEBUG) << __AT__ << " called";
return acquisitionStartedFlag;
} }
bool DataProcessor::GetMeasurementStartedFlag(){
FILE_LOG (logDEBUG) << __AT__ << " called";
return measurementStartedFlag;
}
void DataProcessor::SetGeneralData(GeneralData*& g) { void DataProcessor::SetGeneralData(GeneralData*& g) {
FILE_LOG (logDEBUG) << __AT__ << " called";
generalData = g; generalData = g;
#ifdef VERY_VERBOSE #ifdef VERY_VERBOSE
generalData->Print(); generalData->Print();
@ -101,37 +88,40 @@ void DataProcessor::SetGeneralData(GeneralData*& g) {
/** non static functions */ /** non static functions */
/** getters */
string DataProcessor::GetType(){ string DataProcessor::GetType(){
return TypeName; return TypeName;
} }
bool DataProcessor::IsRunning() {
return ((1 << index) & RunningMask);
}
bool DataProcessor::GetAcquisitionStartedFlag(){
return acquisitionStartedFlag;
}
bool DataProcessor::GetMeasurementStartedFlag(){
return measurementStartedFlag;
}
uint64_t DataProcessor::GetNumTotalFramesCaught() { uint64_t DataProcessor::GetNumTotalFramesCaught() {
FILE_LOG (logDEBUG) << __AT__ << " called";
return numTotalFramesCaught; return numTotalFramesCaught;
} }
uint64_t DataProcessor::GetNumFramesCaught() { uint64_t DataProcessor::GetNumFramesCaught() {
FILE_LOG (logDEBUG) << __AT__ << " called";
return numFramesCaught; return numFramesCaught;
} }
uint64_t DataProcessor::GetProcessedAcquisitionIndex() { uint64_t DataProcessor::GetProcessedAcquisitionIndex() {
FILE_LOG (logDEBUG) << __AT__ << " called";
return currentFrameIndex - firstAcquisitionIndex; return currentFrameIndex - firstAcquisitionIndex;
} }
bool DataProcessor::IsRunning() {
FILE_LOG (logDEBUG) << __AT__ << " called";
return ((1 << index) & RunningMask);
}
/** setters */
void DataProcessor::StartRunning() { void DataProcessor::StartRunning() {
FILE_LOG (logDEBUG) << __AT__ << " called";
pthread_mutex_lock(&Mutex); pthread_mutex_lock(&Mutex);
RunningMask |= (1<<index); RunningMask |= (1<<index);
pthread_mutex_unlock(&Mutex); pthread_mutex_unlock(&Mutex);
@ -139,7 +129,6 @@ void DataProcessor::StartRunning() {
void DataProcessor::StopRunning() { void DataProcessor::StopRunning() {
FILE_LOG (logDEBUG) << __AT__ << " called";
pthread_mutex_lock(&Mutex); pthread_mutex_lock(&Mutex);
RunningMask ^= (1<<index); RunningMask ^= (1<<index);
pthread_mutex_unlock(&Mutex); pthread_mutex_unlock(&Mutex);
@ -147,32 +136,22 @@ void DataProcessor::StopRunning() {
void DataProcessor::SetFifo(Fifo*& f) { void DataProcessor::SetFifo(Fifo*& f) {
FILE_LOG (logDEBUG) << __AT__ << " called";
fifo = f; fifo = f;
} }
void DataProcessor::ResetParametersforNewAcquisition() { void DataProcessor::ResetParametersforNewAcquisition() {
FILE_LOG (logDEBUG) << __AT__ << " called";
numTotalFramesCaught = 0; numTotalFramesCaught = 0;
firstAcquisitionIndex = 0; firstAcquisitionIndex = 0;
currentFrameIndex = 0; currentFrameIndex = 0;
if(acquisitionStartedFlag){ acquisitionStartedFlag = false;
pthread_mutex_lock(&Mutex);
acquisitionStartedFlag = false;
pthread_mutex_unlock(&Mutex);
}
} }
void DataProcessor::ResetParametersforNewMeasurement(){ void DataProcessor::ResetParametersforNewMeasurement(){
FILE_LOG (logDEBUG) << __AT__ << " called";
numFramesCaught = 0; numFramesCaught = 0;
firstMeasurementIndex = 0; firstMeasurementIndex = 0;
if(measurementStartedFlag){ measurementStartedFlag = false;
pthread_mutex_lock(&Mutex);
measurementStartedFlag = false;
pthread_mutex_unlock(&Mutex);
}
if(RunningMask){ if(RunningMask){
pthread_mutex_lock(&Mutex); pthread_mutex_lock(&Mutex);
RunningMask = 0x0; RunningMask = 0x0;
@ -181,57 +160,133 @@ void DataProcessor::ResetParametersforNewMeasurement(){
} }
void DataProcessor::ThreadExecution() { void DataProcessor::RecordFirstIndices(uint64_t fnum) {
FILE_LOG (logDEBUG) << __AT__ << " called"; //listen to this fnum, later +1
currentFrameIndex = fnum;
char* buffer=0; measurementStartedFlag = true;
fifo->PopAddress(buffer); firstMeasurementIndex = fnum;
#ifdef FIFODEBUG
if (!index) cprintf(BLUE,"DataProcessor %d, pop 0x%p buffer:%s\n", index,(void*)(buffer),buffer); //start of entire acquisition
#endif if (!acquisitionStartedFlag) {
uint32_t numPackets = (uint32_t)(*((uint32_t*)buffer)); acquisitionStartedFlag = true;
if (numPackets == DUMMY_PACKET_VALUE) { firstAcquisitionIndex = fnum;
StopProcessing(buffer);
return;
} }
uint64_t fnum; uint32_t pnum; uint32_t snum; uint64_t bcid; #ifdef VERBOSE
generalData->GetHeaderInfo(index,buffer+generalData->fifoBufferHeaderSize,16,fnum,pnum,snum,bcid); cprintf(BLUE,"%d First Acquisition Index:%lld\tFirst Measurement Index:%lld\n",
if (!index) cprintf(BLUE,"DataProcessing %d: fnum:%lld, pnum:%d\n", index, (long long int)fnum, pnum); index, (long long int)firstAcquisitionIndex, (long long int)firstMeasurementIndex);
#endif
}
fifo->FreeAddress(buffer);
void DataProcessor::SetMaxFramesPerFile() {
if (fileWriter->GetType() == BINARY)
fileWriter->SetMaxFramesPerFile(generalData->maxFramesPerFile);
}
void DataProcessor::SetFileFormat(const fileFormat f) {
if (*fileFormatType != f) {
switch(f){
#ifdef HDF5C
case HDF5:
*fileFormatType = f;
#endif
default:
*fileFormatType = f;
break;
}
//remember the pointer values before they are destroyed
char* fname=0; char* fpath=0; uint64_t* findex=0; bool* frindexenable=0;
bool* fwenable=0; bool* owenable=0; int* dindex=0; int* nunits=0;
fileWriter->GetMemberPointerValues(fname, fpath, findex, frindexenable, owenable, dindex, nunits);
SetupFileWriter(fname, fpath, findex, frindexenable, owenable, dindex, nunits);
}
} }
void DataProcessor::StopProcessing(char* buf) { void DataProcessor::SetupFileWriter(char* fname, char* fpath, uint64_t* findex,
FILE_LOG (logDEBUG) << __AT__ << " called"; bool* frindexenable, bool* owenable, int* dindex, int* nunits)
{
cprintf(BLUE,"%d: End of Processing\n", index); if (fileWriter)
delete fileWriter;
fifo->FreeAddress(buf); switch(*fileFormatType){
StopRunning(); #ifdef HDF5C
case HDF5:
if (!index) { fileWriter = new HDF5FileWriter(index, fname, fpath, findex,
while (RunningMask) frindexenable, owenable, dindex, nunits);
usleep(5000); break;
pthread_mutex_lock(statusMutex); #endif
*status = RUN_FINISHED; default:
pthread_mutex_unlock((statusMutex)); fileWriter = new BinaryFileWriter(index, fname, fpath, findex,
FILE_LOG(logINFO) << "Status: " << runStatusType(*status); frindexenable, owenable, dindex, nunits, generalData->maxFramesPerFile);
break;
} }
} }
int DataProcessor::CreateNewFile() { int DataProcessor::CreateNewFile() {
FILE_LOG (logDEBUG) << __AT__ << " called"; if (!fileWriter)
//create file fileWriter.push_back(new BinaryFileWriter(fileName)) return FAIL;
if (fileWriter->CreateFile(currentFrameIndex) == FAIL)
return FAIL;
return OK; return OK;
} }
void DataProcessor::CloseFile() { void DataProcessor::CloseFile() {
FILE_LOG (logDEBUG) << __AT__ << " called"; if (fileWriter)
fileWriter->CloseFile();
} }
void DataProcessor::ThreadExecution() {
char* buffer=0;
fifo->PopAddress(buffer);
#ifdef FIFODEBUG
if (!index) cprintf(BLUE,"DataProcessor %d, pop 0x%p buffer:%s\n", index,(void*)(buffer),buffer);
#endif
//check dummy
uint32_t numBytes = (uint32_t)(*((uint32_t*)buffer));
if (numBytes == DUMMY_PACKET_VALUE) {
StopProcessing(buffer);
return;
}
ProcessAnImage(buffer + FIFO_HEADER_NUMBYTES);
//free
fifo->FreeAddress(buffer);
}
void DataProcessor::StopProcessing(char* buf) {
fifo->FreeAddress(buf);
CloseFile();
StopRunning();
cprintf(BLUE,"%d: Processing Completed\n", index);
}
void DataProcessor::ProcessAnImage(char* buf) {
numFramesCaught++;
numTotalFramesCaught++;
uint64_t fnum = (*((uint64_t*)buf));
//#ifdef VERBOSE
if (!index) cprintf(BLUE,"DataProcessing %d: fnum:%lld\n", index, (long long int)fnum);
//#endif
if (!measurementStartedFlag)
RecordFirstIndices(fnum);
}

View File

@ -10,15 +10,57 @@
using namespace std; using namespace std;
FileWriter::FileWriter(char* fname): FileWriter::FileWriter(int ind, char* fname, char* fpath, uint64_t* findex,
fileName(fname) { bool* frindexenable, bool* owenable, int* dindex, int* nunits):
cout<<"fileName:"<<fileName<<endl; index(ind),
fileNamePrefix(fname),
filePath(fpath),
fileIndex(findex),
frameIndexEnable(frindexenable),
overWriteEnable(owenable),
detIndex(dindex),
numUnitsPerDetector(nunits)
{
printf("%d FileWriter constructor\n",index);
} }
FileWriter::~FileWriter() { FileWriter::~FileWriter() {
printf("%d FileWriter Destructor\n", index);
} }
char* FileWriter::GetFileName() { string FileWriter::GetCurrentFileName() {
return fileName; return currentFileName;
}
void FileWriter::PrintMembers() {
printf("\nGeneral Writer Variables:"
"Index: %d\n"
"File Name Prefix: %s\n"
"File Path: %s\n"
"File Index: %lld\n"
"Frame Index Enable: %d\n"
"Over Write Enable: %d\n"
"Detector Index: %d\n"
"Number of Units Per Detector: %d\n",
index,
fileNamePrefix,
filePath,
(long long int)*fileIndex,
*frameIndexEnable,
*overWriteEnable,
*detIndex,
*numUnitsPerDetector);
}
void FileWriter::GetMemberPointerValues(char* fname, char* fpath, uint64_t* findex,
bool* frindexenable, bool* owenable, int* dindex, int* nunits)
{
fname = fileNamePrefix;
fpath = filePath;
findex = fileIndex;
frindexenable = frameIndexEnable;
owenable = overWriteEnable;
dindex = detIndex;
nunits = numUnitsPerDetector;
} }

View File

@ -7,17 +7,59 @@
#include "HDF5FileWriter.h" #include "HDF5FileWriter.h"
#include <iostream> #include <iostream>
#include <iomanip>
using namespace std; using namespace std;
HDF5FileWriter::HDF5FileWriter(char* fname): HDF5FileWriter::HDF5FileWriter(int ind, char* fname, char* fpath, uint64_t* findex,
FileWriter(fname) { bool* frindexenable, bool* owenable, int* dindex, int* nunits):
FileWriter(ind, fname, fpath, findex, frindexenable, owenable, dindex, nunits)
{
printf("%d HDF5FileWriter constructor\n",index);
PrintMembers();
} }
HDF5FileWriter::~HDF5FileWriter() { HDF5FileWriter::~HDF5FileWriter() {
printf("%d HDF5FileWriter destructor\n",index);
}
void HDF5FileWriter::PrintMembers() {
FileWriter::PrintMembers();
printf("\nHDF5 Print Members \n");
} }
slsReceiverDefs::fileFormat HDF5FileWriter::GetType() {
return HDF5;
}
int HDF5FileWriter::CreateFile(uint64_t fnum) {
currentFileName = CreateFileName(filePath, fileNamePrefix, *fileIndex,
*frameIndexEnable, fnum, *detIndex, *numUnitsPerDetector, index);
printf("%d HDF5 File: %s\n", index, currentFileName.c_str());
return OK;
}
void HDF5FileWriter::CloseFile() {
}
string HDF5FileWriter::CreateFileName(char* fpath, char* fnameprefix, uint64_t findex,
bool frindexenable, uint64_t fnum, int dindex, int numunits, int unitindex) {
ostringstream osfn;
osfn << fpath << "/" << fnameprefix;
if (dindex >= 0) osfn << "_d" << (dindex * numunits + unitindex);
if (frindexenable) osfn << "_f" << setfill('0') << setw(12) << fnum;
osfn << "_" << findex;
osfn << ".h5";
return osfn.str();
}
int HDF5FileWriter::CreateDataFile(bool owenable, char* fname) {
return OK;
}
void HDF5FileWriter::CloseDataFile() {
}

View File

@ -27,23 +27,25 @@ pthread_mutex_t Listener::Mutex = PTHREAD_MUTEX_INITIALIZER;
const GeneralData* Listener::generalData(0); const GeneralData* Listener::generalData(0);
bool Listener::acquisitionStartedFlag(false);
bool Listener::measurementStartedFlag(false); Listener::Listener(Fifo*& f, runStatus* s, uint32_t* portno, char* e) :
Listener::Listener(Fifo*& f, runStatus* s, uint32_t* portno) :
ThreadObject(NumberofListeners), ThreadObject(NumberofListeners),
fifo(f), fifo(f),
acquisitionStartedFlag(false),
measurementStartedFlag(false),
status(s), status(s),
udpSocket(0), udpSocket(0),
udpPortNumber(portno), udpPortNumber(portno),
eth(e),
numTotalPacketsCaught(0), numTotalPacketsCaught(0),
numPacketsCaught(0), numPacketsCaught(0),
firstAcquisitionIndex(0), firstAcquisitionIndex(0),
firstMeasurementIndex(0) firstMeasurementIndex(0),
currentFrameIndex(0),
lastCaughtFrameIndex(0),
carryOverFlag(0),
carryOverPacket(0)
{ {
FILE_LOG (logDEBUG) << __AT__ << " called";
if(ThreadObject::CreateThread()){ if(ThreadObject::CreateThread()){
pthread_mutex_lock(&Mutex); pthread_mutex_lock(&Mutex);
ErrorMask ^= (1<<index); ErrorMask ^= (1<<index);
@ -55,67 +57,59 @@ Listener::Listener(Fifo*& f, runStatus* s, uint32_t* portno) :
Listener::~Listener() { Listener::~Listener() {
FILE_LOG (logDEBUG) << __AT__ << " called"; if (carryOverPacket) delete carryOverPacket;
ThreadObject::DestroyThread(); ThreadObject::DestroyThread();
NumberofListeners--; NumberofListeners--;
} }
/** static functions */ /** static functions */
uint64_t Listener::GetErrorMask() { uint64_t Listener::GetErrorMask() {
FILE_LOG (logDEBUG) << __AT__ << " called";
return ErrorMask; return ErrorMask;
} }
uint64_t Listener::GetRunningMask() {
bool Listener::GetAcquisitionStartedFlag(){ return RunningMask;
FILE_LOG (logDEBUG) << __AT__ << " called";
return acquisitionStartedFlag;
}
bool Listener::GetMeasurementStartedFlag(){
FILE_LOG (logDEBUG) << __AT__ << " called";
return measurementStartedFlag;
} }
void Listener::SetGeneralData(GeneralData*& g) { void Listener::SetGeneralData(GeneralData*& g) {
FILE_LOG (logDEBUG) << __AT__ << " called"; FILE_LOG (logDEBUG) << __AT__ << " called";
generalData = g; generalData = g;
//#ifdef VERY_VERBOSE #ifdef VERY_VERBOSE
generalData->Print(); generalData->Print();
//#endif #endif
} }
/** non static functions */
/** non static functions */
/** getters */
string Listener::GetType(){ string Listener::GetType(){
return TypeName; return TypeName;
} }
uint64_t Listener::GetTotalPacketsCaught() {
FILE_LOG (logDEBUG) << __AT__ << " called";
return numTotalPacketsCaught;
}
uint64_t Listener::GetNumReceivedinUDPBuffer() {
FILE_LOG (logDEBUG) << __AT__ << " called";
if(!udpSocket)
return 0;
return udpSocket->getCurrentTotalReceived();
}
bool Listener::IsRunning() { bool Listener::IsRunning() {
FILE_LOG (logDEBUG) << __AT__ << " called";
return ((1 << index) & RunningMask); return ((1 << index) & RunningMask);
} }
bool Listener::GetAcquisitionStartedFlag(){
return acquisitionStartedFlag;
}
bool Listener::GetMeasurementStartedFlag(){
return measurementStartedFlag;
}
uint64_t Listener::GetTotalPacketsCaught() {
return numTotalPacketsCaught;
}
uint64_t Listener::GetLastFrameIndexCaught() {
return lastCaughtFrameIndex;
}
/** setters */
void Listener::StartRunning() { void Listener::StartRunning() {
FILE_LOG (logDEBUG) << __AT__ << " called";
pthread_mutex_lock(&Mutex); pthread_mutex_lock(&Mutex);
RunningMask |= (1<<index); RunningMask |= (1<<index);
pthread_mutex_unlock(&Mutex); pthread_mutex_unlock(&Mutex);
@ -123,7 +117,6 @@ void Listener::StartRunning() {
void Listener::StopRunning() { void Listener::StopRunning() {
FILE_LOG (logDEBUG) << __AT__ << " called";
pthread_mutex_lock(&Mutex); pthread_mutex_lock(&Mutex);
RunningMask ^= (1<<index); RunningMask ^= (1<<index);
pthread_mutex_unlock(&Mutex); pthread_mutex_unlock(&Mutex);
@ -131,32 +124,28 @@ void Listener::StopRunning() {
void Listener::SetFifo(Fifo*& f) { void Listener::SetFifo(Fifo*& f) {
FILE_LOG (logDEBUG) << __AT__ << " called";
fifo = f; fifo = f;
} }
void Listener::ResetParametersforNewAcquisition() { void Listener::ResetParametersforNewAcquisition() {
FILE_LOG (logDEBUG) << __AT__ << " called"; acquisitionStartedFlag = false;
numTotalPacketsCaught = 0; numTotalPacketsCaught = 0;
firstAcquisitionIndex = 0; firstAcquisitionIndex = 0;
if(acquisitionStartedFlag){ currentFrameIndex = 0;
pthread_mutex_lock(&Mutex); lastCaughtFrameIndex = 0;
acquisitionStartedFlag = false;
pthread_mutex_unlock(&Mutex);
}
} }
void Listener::ResetParametersforNewMeasurement(){ void Listener::ResetParametersforNewMeasurement(){
FILE_LOG (logDEBUG) << __AT__ << " called"; measurementStartedFlag = false;
numPacketsCaught = 0; numPacketsCaught = 0;
firstMeasurementIndex = 0; firstMeasurementIndex = 0;
if(measurementStartedFlag){ carryOverFlag = false;
pthread_mutex_lock(&Mutex); if (carryOverPacket)
measurementStartedFlag = false; delete carryOverPacket;
pthread_mutex_unlock(&Mutex); carryOverPacket = new char[generalData->packetSize];
}
if(RunningMask){ if(RunningMask){
pthread_mutex_lock(&Mutex); pthread_mutex_lock(&Mutex);
RunningMask = 0x0; RunningMask = 0x0;
@ -165,84 +154,40 @@ void Listener::ResetParametersforNewMeasurement(){
} }
void Listener::ThreadExecution() {
FILE_LOG (logDEBUG) << __AT__ << " called";
char* buffer; void Listener::RecordFirstIndices(uint64_t fnum) {
fifo->GetNewAddress(buffer); //listen to this fnum, later +1
#ifdef FIFODEBUG currentFrameIndex = fnum;
if (!index) cprintf(GREEN,"Listener %d, pop 0x%p buffer:%s\n", index,(void*)(buffer),buffer);
#endif
int rc = 0; measurementStartedFlag = true;
firstMeasurementIndex = fnum;
//udpsocket doesnt exist //start of entire acquisition
if (!udpSocket) { if (!acquisitionStartedFlag) {
FILE_LOG(logERROR) << "Listening_Thread " << index << ": UDP Socket not created or shut down earlier"; acquisitionStartedFlag = true;
(*((uint32_t*)buffer)) = 0; firstAcquisitionIndex = fnum;
StopListening(buffer);
return;
} }
if (!index) cprintf(GREEN,"%d First Acquisition Index:%lld\n"
//get data "%d First Measurement Index:%lld\n",
if (*status != TRANSMITTING) { index, (long long int)firstAcquisitionIndex,
rc = udpSocket->ReceiveDataOnly(buffer + generalData->fifoBufferHeaderSize,generalData->fifoBufferSize); index, (long long int)firstMeasurementIndex);
if (!index) cprintf(GREEN,"Listening %d: rc: %d\n",index,rc);
(*((uint32_t*)buffer)) = ((rc <= 0) ? 0 : rc);
}
//done acquiring
if (*status == TRANSMITTING) {
StopListening(buffer);
return;
}
uint64_t fnum; uint32_t pnum; uint32_t snum; uint64_t bcid=0;
generalData->GetHeaderInfo(index,buffer + generalData->fifoBufferHeaderSize,16,fnum,pnum,snum,bcid);
if (!index) cprintf(GREEN,"Listening %d: fnum:%lld, pnum:%d\n", index, (long long int)fnum, pnum);
//push into fifo
fifo->PushAddress(buffer);
} }
void Listener::StopListening(char* buf) { int Listener::CreateUDPSockets() {
FILE_LOG (logDEBUG) << __AT__ << " called"; ShutDownUDPSocket();
cprintf(BLUE,"%d: End of Listening\n", index); //if eth is mistaken with ip address
if (strchr(eth,'.') != NULL){
uint32_t numPackets = (uint32_t)(*((uint32_t*)buf)); strcpy(eth,"");
}
//incomplete packets if(!strlen(eth)){
if (numPackets > 0) { FILE_LOG(logWARNING) << "eth is empty. Listening to all";
fifo->PushAddress(buf);
fifo->GetNewAddress(buf);
#ifdef FIFODEBUG
if (!index) cprintf(GREEN,"Listener %d, Got incomplete, for dummy: pop 0x%p buffer:%s\n", index,(void*)(buf),buf);
#endif
} }
//dummy
(*((uint32_t*)buf)) = DUMMY_PACKET_VALUE;
fifo->PushAddress(buf);
StopRunning();
//#ifdef DEBUG4
if (!index) FILE_LOG(logINFO) << "Listening Thread (" << *udpPortNumber << ")"
" Packets caught: " << numPacketsCaught;
//#endif
}
int Listener::CreateUDPSockets(const char* eth) {
FILE_LOG (logDEBUG) << __AT__ << " called";
udpSocket = new genericSocket(*udpPortNumber, genericSocket::UDP, udpSocket = new genericSocket(*udpPortNumber, genericSocket::UDP,
generalData->packetSize, eth, generalData->headerPacketSize); generalData->packetSize, (strlen(eth)?eth:NULL), generalData->headerPacketSize);
int iret = udpSocket->getErrorStatus(); int iret = udpSocket->getErrorStatus();
if(!iret){ if(!iret){
cout << "UDP port opened at port " << *udpPortNumber << endl; cout << "UDP port opened at port " << *udpPortNumber << endl;
@ -256,8 +201,6 @@ int Listener::CreateUDPSockets(const char* eth) {
void Listener::ShutDownUDPSocket() { void Listener::ShutDownUDPSocket() {
FILE_LOG (logDEBUG) << __AT__ << " called";
if(udpSocket){ if(udpSocket){
udpSocket->ShutDownSocket(); udpSocket->ShutDownSocket();
FILE_LOG(logINFO) << "Shut down UDP Socket " << index; FILE_LOG(logINFO) << "Shut down UDP Socket " << index;
@ -266,3 +209,123 @@ void Listener::ShutDownUDPSocket() {
} }
} }
void Listener::ThreadExecution() {
char* buffer;
int rc = 0;
fifo->GetNewAddress(buffer);
#ifdef FIFODEBUG
if (!index) cprintf(GREEN,"Listener %d, pop 0x%p buffer:%s\n", index,(void*)(buffer),buffer);
#endif
//udpsocket doesnt exist
if (!udpSocket) {
FILE_LOG(logERROR) << "Listening_Thread " << index << ": UDP Socket not created or shut down earlier";
(*((uint32_t*)buffer)) = 0;
StopListening(buffer);
return;
}
//get data
if (*status != TRANSMITTING)
rc = ListenToAnImage(buffer + generalData->fifoBufferHeaderSize);
//done acquiring
if (*status == TRANSMITTING) {
StopListening(buffer);
return;
}
//error check
if (rc <= 0) cprintf(BG_RED,"Error:(Weird), UDP Sockets not shut down, but received nothing\n");
(*((uint32_t*)buffer)) = rc;
(*((uint64_t*)(buffer + FIFO_HEADER_NUMBYTES ))) = currentFrameIndex;
currentFrameIndex++;
//push into fifo
fifo->PushAddress(buffer);
}
void Listener::StopListening(char* buf) {
(*((uint32_t*)buf)) = DUMMY_PACKET_VALUE;
fifo->PushAddress(buf);
StopRunning();
#ifdef VERBOSE
cprintf(GREEN,"%d: Listening Packets (%d) : %d\n", index, *udpPortNumber, numPacketsCaught);
#endif
cprintf(GREEN,"%d: Listening Completed\n", index);
}
uint32_t Listener::ListenToAnImage(char* buf) {
uint32_t rc = 0;
uint64_t fnum = 0; uint32_t pnum = 0;
uint32_t offset = 0;
uint32_t currentpnum = 0;
int psize = generalData->packetSize;
//reset to -1
memset(buf,0xFF,psize);
//look for carry over
if (carryOverFlag) {
//check if its the current image packet
generalData->GetHeaderInfo(index,carryOverPacket,fnum,pnum);
if (fnum != currentFrameIndex) {
return generalData->imageSize;
}
carryOverFlag = false;
memcpy(buf,carryOverPacket, psize);
offset += psize;
}
while (offset < generalData->fifoBufferSize) {
//listen to new packet
rc += udpSocket->ReceiveDataOnly(buf + offset);
if (rc <= 0) return 0;
//update parameters
numPacketsCaught++; //record immediately to get more time before socket shutdown
numTotalPacketsCaught++;
generalData->GetHeaderInfo(index,buf + offset,fnum,pnum);
lastCaughtFrameIndex = fnum;
//#ifdef VERBOSE
if (!index && !pnum) cprintf(BLUE,"Listening %d: fnum:%lld, pnum:%d\n", index, (long long int)fnum, pnum);
//#endif
if (!measurementStartedFlag)
RecordFirstIndices(fnum);
//future packet
if(fnum != currentFrameIndex) {
carryOverFlag = true;
memcpy(carryOverPacket,buf + offset, psize);
return generalData->imageSize;
}
(*((uint64_t*)(buf - FILE_FRAME_HEADER_SIZE))) = fnum;
//future packet of same frame
if(pnum != currentpnum) {
memcpy(buf + (pnum * psize), buf + offset, psize);
memset(buf + offset, 0xFF, psize);
}
//update offset & current frame index
offset = (pnum + 1) * psize;
}
return generalData->imageSize;
}

View File

@ -16,20 +16,18 @@ ThreadObject::ThreadObject(int ind):
index(ind), index(ind),
alive(false), alive(false),
killThread(false), killThread(false),
thread(0) { thread(0)
FILE_LOG (logDEBUG) << __AT__ << " called"; {
PrintMembers(); PrintMembers();
} }
ThreadObject::~ThreadObject() { ThreadObject::~ThreadObject() {
FILE_LOG (logDEBUG) << __AT__ << " called";
DestroyThread(); DestroyThread();
} }
void ThreadObject::PrintMembers() { void ThreadObject::PrintMembers() {
FILE_LOG (logDEBUG) << __AT__ << " called";
FILE_LOG (logDEBUG) << "Index : " << index FILE_LOG (logDEBUG) << "Index : " << index
<< "\nalive: " << alive << "\nalive: " << alive
<< "\nkillThread: " << killThread << "\nkillThread: " << killThread
@ -38,7 +36,6 @@ void ThreadObject::PrintMembers() {
void ThreadObject::DestroyThread() { void ThreadObject::DestroyThread() {
FILE_LOG (logDEBUG) << __AT__ << " called";
if(alive){ if(alive){
killThread = true; killThread = true;
sem_post(&semaphore); sem_post(&semaphore);
@ -52,7 +49,6 @@ void ThreadObject::DestroyThread() {
int ThreadObject::CreateThread() { int ThreadObject::CreateThread() {
FILE_LOG (logDEBUG) << __AT__ << " called";
if(alive){ if(alive){
FILE_LOG (logERROR) << "Cannot create thread " << index << ". Already alive"; FILE_LOG (logERROR) << "Cannot create thread " << index << ". Already alive";
return FAIL; return FAIL;
@ -72,16 +68,12 @@ int ThreadObject::CreateThread() {
void* ThreadObject::StartThread(void* thisPointer) { void* ThreadObject::StartThread(void* thisPointer) {
FILE_LOG (logDEBUG) << __AT__ << " called"; ((ThreadObject*)thisPointer)->RunningThread();
((ThreadObject*)thisPointer)->RunningThread(); return thisPointer;
return thisPointer;
} }
void ThreadObject::RunningThread() { void ThreadObject::RunningThread() {
FILE_LOG (logDEBUG) << __AT__ << " called";
while(true) { while(true) {
while(IsRunning()) { while(IsRunning()) {

View File

@ -220,14 +220,17 @@ void UDPBaseImplementation::setFlippedData(int axis, int enable){
void UDPBaseImplementation::setFileFormat(const fileFormat f){ void UDPBaseImplementation::setFileFormat(const fileFormat f){
FILE_LOG(logDEBUG) << __AT__ << " starting"; FILE_LOG(logDEBUG) << __AT__ << " starting";
if(f!=HDF5) switch(f){
fileFormatType = f;
#ifdef HDF5C #ifdef HDF5C
else if((f==HDF5) && (myDetectorType == EIGER || myDetectorType == JUNGFRAU)) case HDF5:
fileFormatType = f; fileFormatType = f;
#endif #endif
default:
fileFormatType = f;
break;
}
FILE_LOG(logINFO) << "File Index:" << fileIndex; FILE_LOG(logINFO) << "File Format:" << getFileFormatType(fileFormatType);
} }

View File

@ -62,6 +62,7 @@ void UDPStandardImplementation::InitializeMembers() {
//*** receiver parameters *** //*** receiver parameters ***
numThreads = 1; numThreads = 1;
numberofJobs = 1; numberofJobs = 1;
callbackAction = DO_EVERYTHING;
//*** mutex *** //*** mutex ***
pthread_mutex_init(&statusMutex,NULL); pthread_mutex_init(&statusMutex,NULL);
@ -76,33 +77,69 @@ void UDPStandardImplementation::InitializeMembers() {
uint64_t UDPStandardImplementation::getTotalFramesCaught() const { uint64_t UDPStandardImplementation::getTotalFramesCaught() const {
FILE_LOG (logDEBUG) << __AT__ << " starting"; FILE_LOG (logDEBUG) << __AT__ << " starting";
uint64_t sum = 0; uint64_t sum = 0;
uint32_t flagsum = 0;
vector<DataProcessor*>::const_iterator it; vector<DataProcessor*>::const_iterator it;
for (vector<DataProcessor*>::const_iterator it = dataProcessor.begin(); it != dataProcessor.end(); ++it) for (vector<DataProcessor*>::const_iterator it = dataProcessor.begin(); it != dataProcessor.end(); ++it) {
flagsum += ((*it)->GetMeasurementStartedFlag() ? 1 : 0);
sum += (*it)->GetNumTotalFramesCaught(); sum += (*it)->GetNumTotalFramesCaught();
}
//no data processed
if (flagsum != dataProcessor.size()) return 0;
return (sum/dataProcessor.size()); return (sum/dataProcessor.size());
} }
uint64_t UDPStandardImplementation::getFramesCaught() const { uint64_t UDPStandardImplementation::getFramesCaught() const {
FILE_LOG (logDEBUG) << __AT__ << " starting"; FILE_LOG (logDEBUG) << __AT__ << " starting";
uint64_t sum = 0; uint64_t sum = 0;
for (vector<DataProcessor*>::const_iterator it = dataProcessor.begin(); it != dataProcessor.end(); ++it) uint32_t flagsum = 0;
for (vector<DataProcessor*>::const_iterator it = dataProcessor.begin(); it != dataProcessor.end(); ++it) {
flagsum += ((*it)->GetAcquisitionStartedFlag() ? 1 : 0);
sum += (*it)->GetNumFramesCaught(); sum += (*it)->GetNumFramesCaught();
}
//no data processed
if (flagsum != dataProcessor.size()) return 0;
return (sum/dataProcessor.size()); return (sum/dataProcessor.size());
} }
int64_t UDPStandardImplementation::getAcquisitionIndex() const { int64_t UDPStandardImplementation::getAcquisitionIndex() const {
FILE_LOG (logDEBUG) << __AT__ << " starting"; FILE_LOG (logDEBUG) << __AT__ << " starting";
//no data processed
if(!DataProcessor::GetAcquisitionStartedFlag())
return -1;
uint64_t sum = 0; uint64_t sum = 0;
for (vector<DataProcessor*>::const_iterator it = dataProcessor.begin(); it != dataProcessor.end(); ++it) uint32_t flagsum = 0;
for (vector<DataProcessor*>::const_iterator it = dataProcessor.begin(); it != dataProcessor.end(); ++it){
flagsum += ((*it)->GetAcquisitionStartedFlag() ? 1 : 0);
sum += (*it)->GetProcessedAcquisitionIndex(); sum += (*it)->GetProcessedAcquisitionIndex();
}
//no data processed
if (flagsum != dataProcessor.size()) return -1;
return (sum/dataProcessor.size()); return (sum/dataProcessor.size());
} }
void UDPStandardImplementation::setFileFormat(const fileFormat f){
FILE_LOG(logDEBUG) << __AT__ << " starting";
//destroy file writer, set file format and create file writer
for (vector<DataProcessor*>::const_iterator it = dataProcessor.begin(); it != dataProcessor.end(); ++it)
(*it)->SetFileFormat(f);
FILE_LOG(logINFO) << "File Format:" << getFileFormatType(fileFormatType);
}
void UDPStandardImplementation::setFileName(const char c[]) { void UDPStandardImplementation::setFileName(const char c[]) {
FILE_LOG (logDEBUG) << __AT__ << " starting"; FILE_LOG (logDEBUG) << __AT__ << " starting";
@ -114,6 +151,8 @@ void UDPStandardImplementation::setFileName(const char c[]) {
if (uscore!=string::npos) { if (uscore!=string::npos) {
if (sscanf(tempname.substr(uscore+1, tempname.size()-uscore-1).c_str(), "d%d", &detindex)) { if (sscanf(tempname.substr(uscore+1, tempname.size()-uscore-1).c_str(), "d%d", &detindex)) {
detID = detindex; detID = detindex;
tempname=tempname.substr(0,uscore);
strcpy(fileName, tempname.c_str());
} }
} }
if (detindex == -1) if (detindex == -1)
@ -146,6 +185,10 @@ int UDPStandardImplementation::setShortFrameEnable(const int i) {
Listener::SetGeneralData(generalData); Listener::SetGeneralData(generalData);
DataProcessor::SetGeneralData(generalData); DataProcessor::SetGeneralData(generalData);
for (vector<DataProcessor*>::const_iterator it = dataProcessor.begin(); it != dataProcessor.end(); ++it) {
(*it)->SetMaxFramesPerFile();
}
} }
FILE_LOG (logINFO) << "Short Frame Enable: " << shortFrameEnable; FILE_LOG (logINFO) << "Short Frame Enable: " << shortFrameEnable;
return OK; return OK;
@ -324,7 +367,7 @@ int UDPStandardImplementation::setDetectorType(const detectorType d) {
FILE_LOG (logDEBUG) << "Setting receiver type"; FILE_LOG (logDEBUG) << "Setting receiver type";
DeleteMembers();cout<<"size of fifo:"<<fifo.size()<<endl; DeleteMembers();
InitializeMembers(); InitializeMembers();
myDetectorType = d; myDetectorType = d;
switch(myDetectorType) { switch(myDetectorType) {
@ -357,6 +400,9 @@ int UDPStandardImplementation::setDetectorType(const detectorType d) {
numThreads = generalData->threadsPerReceiver; numThreads = generalData->threadsPerReceiver;
fifoDepth = generalData->defaultFifoDepth; fifoDepth = generalData->defaultFifoDepth;
//local network parameters
SetLocalNetworkParameters();
//create fifo structure //create fifo structure
numberofJobs = -1; numberofJobs = -1;
if (SetupFifoStructure() == FAIL) { if (SetupFifoStructure() == FAIL) {
@ -366,8 +412,9 @@ int UDPStandardImplementation::setDetectorType(const detectorType d) {
//create threads //create threads
for ( int i=0; i < numThreads; ++i ) { for ( int i=0; i < numThreads; ++i ) {
listener.push_back(new Listener(fifo[i], &status, &udpPortNum[i])); listener.push_back(new Listener(fifo[i], &status, &udpPortNum[i], eth));
dataProcessor.push_back(new DataProcessor(fifo[i], &status, &statusMutex)); dataProcessor.push_back(new DataProcessor(fifo[i], &status, &statusMutex, &fileFormatType, &fileWriteEnable,
&callbackAction, rawDataReadyCallBack,pRawDataReady));
if (Listener::GetErrorMask() || DataProcessor::GetErrorMask()) { if (Listener::GetErrorMask() || DataProcessor::GetErrorMask()) {
FILE_LOG (logERROR) << "Error: Could not creates listener/dataprocessor threads (index:" << i << ")"; FILE_LOG (logERROR) << "Error: Could not creates listener/dataprocessor threads (index:" << i << ")";
for (vector<Listener*>::const_iterator it = listener.begin(); it != listener.end(); ++it) for (vector<Listener*>::const_iterator it = listener.begin(); it != listener.end(); ++it)
@ -380,8 +427,11 @@ int UDPStandardImplementation::setDetectorType(const detectorType d) {
} }
} }
//local network parameters //set up writer and callbacks
SetLocalNetworkParameters(); for (vector<DataProcessor*>::const_iterator it = dataProcessor.begin(); it != dataProcessor.end(); ++it)
(*it)->SetupFileWriter(fileName, filePath, &fileIndex, &frameIndexEnable,
&overwriteEnable, &detID, &numThreads);
FILE_LOG (logDEBUG) << " Detector type set to " << getDetectorType(d); FILE_LOG (logDEBUG) << " Detector type set to " << getDetectorType(d);
return OK; return OK;
@ -413,6 +463,7 @@ int UDPStandardImplementation::startReceiver(char *c) {
FILE_LOG(logERROR) << c; FILE_LOG(logERROR) << c;
return FAIL; return FAIL;
} }
cout << "Listener Ready ..." << endl;
if(fileWriteEnable){ if(fileWriteEnable){
if (SetupWriter() == FAIL) { if (SetupWriter() == FAIL) {
@ -421,6 +472,24 @@ int UDPStandardImplementation::startReceiver(char *c) {
return FAIL; return FAIL;
} }
} }
cout << "Processor Ready ..." << endl;
//callbacks
callbackAction = DO_EVERYTHING;
if (startAcquisitionCallBack) /** file path and file index not required?? or need to include detector index? do they need the datasize? its given for write data anyway */
callbackAction=startAcquisitionCallBack(filePath, fileName, fileIndex,
(generalData->fifoBufferSize) * numberofJobs + (generalData->fifoBufferHeaderSize), pStartAcquisition);
if (callbackAction < DO_EVERYTHING) {
FILE_LOG(logINFO) << "Call back activated. Data saving must be taken care of by user in call back.";
if (rawDataReadyCallBack) {
FILE_LOG(logINFO) << "Data Write has been defined externally";
}
} else if(!fileWriteEnable) {
FILE_LOG(logINFO) << "Data will not be saved";
}
//change status //change status
pthread_mutex_lock(&statusMutex); pthread_mutex_lock(&statusMutex);
@ -432,6 +501,7 @@ int UDPStandardImplementation::startReceiver(char *c) {
FILE_LOG(logINFO) << "Receiver Started"; FILE_LOG(logINFO) << "Receiver Started";
FILE_LOG(logINFO) << "Status: " << runStatusType(status); FILE_LOG(logINFO) << "Status: " << runStatusType(status);
return OK;
} }
@ -443,10 +513,41 @@ void UDPStandardImplementation::stopReceiver(){
//set status to transmitting //set status to transmitting
startReadout(); startReadout();
//wait until status is run_finished //wait for the processes to be done
while(status == TRANSMITTING){ while(Listener::GetRunningMask()){
usleep(5000); usleep(5000);
} }
while(DataProcessor::GetRunningMask()){
usleep(5000);
}
pthread_mutex_lock(&statusMutex);
status = RUN_FINISHED;
pthread_mutex_unlock(&(statusMutex));
FILE_LOG(logINFO) << "Status: " << runStatusType(status);
{ //statistics
int tot = 0;
for (int i = 0; i < numThreads; i++) {
tot += dataProcessor[i]->GetNumFramesCaught();
if (dataProcessor[i]->GetNumFramesCaught() < numberOfFrames) {
cprintf(RED, "\nPort %d\n",udpPortNum[i]);
cprintf(RED, "Missing Packets \t: %lld\n",(long long int)numberOfFrames*generalData->packetsPerFrame-listener[i]->GetTotalPacketsCaught());
cprintf(RED, "Frames Caught \t\t: %lld\n",(long long int)dataProcessor[i]->GetNumFramesCaught());
cprintf(RED, "Last Frame Number Caught :%lld\n",(long long int)listener[i]->GetLastFrameIndexCaught());
}else{
cprintf(GREEN, "\nPort %d\n",udpPortNum[i]);
cprintf(GREEN, "Missing Packets \t: %lld\n",(long long int)numberOfFrames*generalData->packetsPerFrame-listener[i]->GetTotalPacketsCaught());
cprintf(GREEN, "Frames Caught \t\t: %lld\n",(long long int)dataProcessor[i]->GetNumFramesCaught());
cprintf(GREEN, "Last Frame Number Caught :%lld\n",(long long int)listener[i]->GetLastFrameIndexCaught());
}
}
//callback
if (acquisitionFinishedCallBack)
acquisitionFinishedCallBack((int)(tot/numThreads), pAcquisitionFinished);
}
//change status //change status
pthread_mutex_lock(&statusMutex); pthread_mutex_lock(&statusMutex);
@ -473,18 +574,11 @@ void UDPStandardImplementation::startReadout(){
for (vector<Listener*>::const_iterator it = listener.begin(); it != listener.end(); ++it) for (vector<Listener*>::const_iterator it = listener.begin(); it != listener.end(); ++it)
totalP += (*it)->GetTotalPacketsCaught(); totalP += (*it)->GetTotalPacketsCaught();
//current udp buffer received
int currentReceivedInBuffer=0,prevReceivedInBuffer=-1;
for (vector<Listener*>::const_iterator it = listener.begin(); it != listener.end(); ++it)
currentReceivedInBuffer += (*it)->GetNumReceivedinUDPBuffer();
//wait for all packets //wait for all packets
if((unsigned long long int)totalP!=numberOfFrames*generalData->packetsPerFrame*listener.size()){ if((unsigned long long int)totalP!=numberOfFrames*generalData->packetsPerFrame*listener.size()){
//wait as long as there is change from prev totalP, //wait as long as there is change from prev totalP,
//and also change from received in buffer to previous value while(prev != totalP){
//(as one listens to many at a time, shouldnt cut off in between)
while((prev != totalP) || (prevReceivedInBuffer!= currentReceivedInBuffer)){
#ifdef VERY_VERBOSE #ifdef VERY_VERBOSE
cprintf(MAGENTA,"waiting for all packets prevP:%d totalP:%d PrevBuffer:%d currentBuffer:%d\n",prev,totalP,prevReceivedInBuffer,currentReceivedInBuffer); cprintf(MAGENTA,"waiting for all packets prevP:%d totalP:%d PrevBuffer:%d currentBuffer:%d\n",prev,totalP,prevReceivedInBuffer,currentReceivedInBuffer);
@ -494,16 +588,11 @@ void UDPStandardImplementation::startReadout(){
prev = totalP; prev = totalP;
totalP = 0; totalP = 0;
prevReceivedInBuffer = currentReceivedInBuffer;
currentReceivedInBuffer = 0;
for (vector<Listener*>::const_iterator it = listener.begin(); it != listener.end(); ++it) { for (vector<Listener*>::const_iterator it = listener.begin(); it != listener.end(); ++it)
totalP += (*it)->GetTotalPacketsCaught(); totalP += (*it)->GetTotalPacketsCaught();
currentReceivedInBuffer += (*it)->GetNumReceivedinUDPBuffer();
}
#ifdef VERY_VERBOSE #ifdef VERY_VERBOSE
cprintf(MAGENTA,"\tupdated: totalP:%d currently in buffer:%d\n",totalP,currentReceivedInBuffer); cprintf(MAGENTA,"\tupdated: totalP:%d\n",totalP);
#endif #endif
} }
} }
@ -644,18 +733,9 @@ void UDPStandardImplementation::ResetParametersforNewMeasurement() {
int UDPStandardImplementation::CreateUDPSockets() { int UDPStandardImplementation::CreateUDPSockets() {
FILE_LOG (logDEBUG) << __AT__ << " called"; FILE_LOG (logDEBUG) << __AT__ << " called";
shutDownUDPSockets();
//if eth is mistaken with ip address
if (strchr(eth,'.') != NULL){
strcpy(eth,"");
}
if(!strlen(eth)){
FILE_LOG(logWARNING) << "eth is empty. Listening to all";
}
bool error = false; bool error = false;
for (unsigned int i = 0; i < listener.size(); ++i) for (unsigned int i = 0; i < listener.size(); ++i)
if (listener[i]->CreateUDPSockets((strlen(eth)?eth:NULL)) == FAIL) { if (listener[i]->CreateUDPSockets() == FAIL) {
error = true; error = true;
break; break;
} }
@ -665,7 +745,6 @@ int UDPStandardImplementation::CreateUDPSockets() {
} }
FILE_LOG(logDEBUG) << "UDP socket(s) created successfully."; FILE_LOG(logDEBUG) << "UDP socket(s) created successfully.";
cout << "Listener Ready ..." << endl;
return OK; return OK;
} }