mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-24 23:30:03 +02:00
moving towards c++ api
This commit is contained in:
parent
28b0897dd7
commit
d3200dc76f
@ -58,6 +58,11 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter
|
||||
|
||||
|
||||
//***file parameters***
|
||||
/**
|
||||
* Get File Format
|
||||
* @return file format
|
||||
*/
|
||||
fileFormat getFileFormat() const;
|
||||
/**
|
||||
* Get File Name Prefix (without frame index, file index and extension (_d0_f000000000000_8.raw))
|
||||
* @return NULL or file name prefix (max of 1000 characters)
|
||||
@ -248,6 +253,11 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter
|
||||
|
||||
|
||||
//***file parameters***
|
||||
/**
|
||||
* Set File Format
|
||||
*/
|
||||
void setFileFormat(slsReceiverDefs::fileFormat f);
|
||||
|
||||
/**
|
||||
* Set File Name Prefix (without frame index, file index and extension (_d0_f000000000000_8.raw))
|
||||
* Does not check for file existence since it is created only at startReceiver
|
||||
@ -556,6 +566,8 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter
|
||||
uint32_t udpPortNum[MAX_NUMBER_OF_LISTENING_THREADS];
|
||||
|
||||
//***file parameters***
|
||||
/** File format */
|
||||
fileFormat fileFormatType;
|
||||
/** File Name without frame index, file index and extension (_d0_f000000000000_8.raw)*/
|
||||
char fileName[MAX_STR_LENGTH];
|
||||
/** File Path */
|
||||
|
@ -118,6 +118,12 @@ class UDPInterface {
|
||||
|
||||
|
||||
//***file parameters***
|
||||
/**
|
||||
* Get File Format
|
||||
* @return file format
|
||||
*/
|
||||
virtual slsReceiverDefs::fileFormat getFileFormat() const = 0;
|
||||
|
||||
/**
|
||||
* Get File Name Prefix (without frame index, file index and extension (_d0_f000000000000_8.raw))
|
||||
* @return NULL or pointer to file name prefix, must be released by calling function (max of 1000 characters)
|
||||
@ -306,6 +312,11 @@ class UDPInterface {
|
||||
|
||||
|
||||
//***file parameters***
|
||||
/**
|
||||
* Set File Format
|
||||
*/
|
||||
virtual void setFileFormat(slsReceiverDefs::fileFormat f) = 0;
|
||||
|
||||
/**
|
||||
* Set File Name Prefix (without frame index, file index and extension (_d0_f000000000000_8.raw))
|
||||
* Does not check for file existence since it is created only at startReceiver
|
||||
|
@ -25,6 +25,9 @@
|
||||
#include <stdio.h>
|
||||
#include <semaphore.h>
|
||||
|
||||
#ifdef HDF5C
|
||||
#include "hdf5.h"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @short does all the functions for a receiver, set/get parameters, start/stop etc.
|
||||
@ -635,8 +638,17 @@ private:
|
||||
|
||||
/** File Descriptor */
|
||||
FILE *sfilefd[MAX_NUMBER_OF_WRITER_THREADS];
|
||||
#ifdef HDF5C
|
||||
H5File *hdf5_fileId[MAX_NUMBER_OF_WRITER_THREADS];
|
||||
DataSpace *hdf5_dataspaceId[MAX_NUMBER_OF_WRITER_THREADS];
|
||||
DataSet *hdf5_datasetId[MAX_NUMBER_OF_WRITER_THREADS];
|
||||
hid_t hdf5_datatype;
|
||||
|
||||
|
||||
/*hid_t hdf5fileId[MAX_NUMBER_OF_WRITER_THREADS];
|
||||
hid_t hdf5DatasetId[MAX_NUMBER_OF_WRITER_THREADS];
|
||||
hid_t hdf5DataspaceId[MAX_NUMBER_OF_WRITER_THREADS];
|
||||
hid_t hdf5DataType;*/
|
||||
#endif
|
||||
//***acquisition indices/count parameters***
|
||||
/** Frame Number of First Frame of an entire Acquisition (including all scans) */
|
||||
uint64_t startAcquisitionIndex;
|
||||
@ -801,6 +813,11 @@ private:
|
||||
/** Set to self-terminate writer threads waiting for semaphores */
|
||||
bool killAllWritingThreads;
|
||||
|
||||
//***data shape ***
|
||||
/** Number of pixels in x axis */
|
||||
int NX;
|
||||
/** Number of pixels in y axis */
|
||||
int NY;
|
||||
|
||||
//***filter parameters***
|
||||
/** Common Mode Subtraction Enable FIXME: Always false, only moench uses, Ask Anna */
|
||||
|
@ -147,7 +147,7 @@ typedef struct {
|
||||
#define JFRAU_PACKET_INDEX_MASK 0x0//Not Applicable, use struct
|
||||
|
||||
#define JFRAU_PIXELS_IN_ONE_ROW (256*4)
|
||||
#define JFRAU_PIXELS_IN_ONE_COL (256*2)
|
||||
#define JFRAU_PIXELS_IN_ONE_COL (256)
|
||||
#define JFRAU_BYTES_IN_ONE_ROW (JFRAU_PIXELS_IN_ONE_ROW*2)
|
||||
|
||||
|
||||
|
@ -218,6 +218,10 @@ private:
|
||||
/** enable flipped data */
|
||||
int set_flipped_data();
|
||||
|
||||
/** set file format */
|
||||
int set_file_format();
|
||||
|
||||
|
||||
|
||||
//General Functions
|
||||
/** Locks Receiver */
|
||||
|
@ -116,6 +116,17 @@ public:
|
||||
STOPPED /**< acquisition stopped externally */
|
||||
};
|
||||
|
||||
/**
|
||||
format
|
||||
*/
|
||||
enum fileFormat {
|
||||
GET_FILE_FORMAT=-1,/**< the receiver will return its file format */
|
||||
BINARY, /**< binary format */
|
||||
ASCII, /**< ascii format */
|
||||
HDF5 /**< hdf5 format */
|
||||
};
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
/** returns string from enabled/disabled
|
||||
\param b true or false
|
||||
|
@ -56,8 +56,9 @@ enum {
|
||||
|
||||
F_READ_RECEIVER_TIMER, /** < sets the timer between each data stream in receiver */
|
||||
|
||||
F_SET_FLIPPED_DATA_RECEIVER /** < sets the enable to flip data across x/y axis (bottom/top) */
|
||||
F_SET_FLIPPED_DATA_RECEIVER, /** < sets the enable to flip data across x/y axis (bottom/top) */
|
||||
|
||||
F_SET_RECEIVER_FILE_FORMAT /** < sets the receiver file format */
|
||||
/* Always append functions hereafter!!! */
|
||||
};
|
||||
|
||||
|
@ -60,6 +60,7 @@ void UDPBaseImplementation::initializeMembers(){
|
||||
}
|
||||
|
||||
//***file parameters***
|
||||
fileFormatType = BINARY;
|
||||
strcpy(fileName,"run");
|
||||
strcpy(filePath,"");
|
||||
fileIndex = 0;
|
||||
@ -113,6 +114,9 @@ int UDPBaseImplementation::getFlippedData(int axis) const{
|
||||
|
||||
|
||||
/***file parameters***/
|
||||
slsReceiverDefs::fileFormat UDPBaseImplementation::getFileFormat() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return fileFormatType;}
|
||||
|
||||
|
||||
char *UDPBaseImplementation::getFileName() const{
|
||||
FILE_LOG(logDEBUG) << __AT__ << " starting";
|
||||
|
||||
@ -227,6 +231,20 @@ void UDPBaseImplementation::setFlippedData(int axis, int enable){
|
||||
|
||||
|
||||
/***file parameters***/
|
||||
void UDPBaseImplementation::setFileFormat(const fileFormat f){
|
||||
FILE_LOG(logDEBUG) << __AT__ << " starting";
|
||||
|
||||
if(f!=HDF5)
|
||||
fileFormatType = f;
|
||||
#ifdef HDF5C
|
||||
else if((f==HDF5) && (myDetectorType == EIGER || myDetectorType == JUNGFRAU))
|
||||
fileFormatType = f;
|
||||
#endif
|
||||
|
||||
FILE_LOG(logINFO) << "File Index:" << fileIndex;
|
||||
}
|
||||
|
||||
|
||||
void UDPBaseImplementation::setFileName(const char c[]){
|
||||
FILE_LOG(logDEBUG) << __AT__ << " starting";
|
||||
|
||||
|
@ -21,6 +21,13 @@
|
||||
#include <zmq.h> //zmq
|
||||
#include <sstream>
|
||||
|
||||
#ifdef HDF5C
|
||||
#include "H5Cpp.h"
|
||||
#ifndef H5_NO_NAMESPACE
|
||||
using namespace H5;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define WRITE_HEADERS
|
||||
@ -152,7 +159,15 @@ void UDPStandardImplementation::initializeMembers(){
|
||||
strcpy(fileNamePerThread[i],"");
|
||||
strcpy(fileHeader[i],"");
|
||||
sfilefd[i] = 0;
|
||||
#ifdef HDF5C
|
||||
hdf5_fileId[i] = 0;
|
||||
hdf5_dataspaceId[i] = 0;
|
||||
hdf5_datasetId[i] = 0;
|
||||
#endif
|
||||
}
|
||||
#ifdef HDF5C
|
||||
hdf5DataType = H5T_STD_U16LE;
|
||||
#endif
|
||||
maxFramesPerFile = 0;
|
||||
fileCreateSuccess = false;
|
||||
|
||||
@ -218,6 +233,10 @@ void UDPStandardImplementation::initializeMembers(){
|
||||
createFileMask = 0x0;
|
||||
killAllWritingThreads = false;
|
||||
|
||||
//***data shape ***
|
||||
NX = 0;
|
||||
NY = 0;
|
||||
|
||||
//***filter parameters***
|
||||
commonModeSubtractionEnable = false;
|
||||
moenchCommonModeSubtraction = 0;
|
||||
@ -632,6 +651,15 @@ int UDPStandardImplementation::setDynamicRange(const uint32_t i){
|
||||
|
||||
FILE_LOG(logDEBUG) << "Info: Setting Dynamic Range to " << i;
|
||||
dynamicRange = i;
|
||||
#ifdef HDF5C
|
||||
switch(dynamicRange){
|
||||
case 4:
|
||||
case 8: hdf5DataType = H5T_STD_U8LE; break;
|
||||
case 16: hdf5DataType = H5T_STD_U16LE; break;
|
||||
case 32: hdf5DataType = H5T_STD_U32LE; break;
|
||||
default: cprintf(BG_RED,"unknown dynamic range\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
if(myDetectorType == EIGER){
|
||||
|
||||
@ -828,6 +856,8 @@ int UDPStandardImplementation::setDetectorType(const detectorType d){
|
||||
footerOffset = EIGER_DATA_PACKET_HEADER_SIZE + oneDataSize;
|
||||
fifoBufferHeaderSize= (HEADER_SIZE_NUM_TOT_PACKETS + FILE_FRAME_HEADER_LENGTH);
|
||||
excludeMissingPackets= true;
|
||||
NX = EIGER_PIXELS_IN_ONE_ROW;
|
||||
NY = EIGER_PIXELS_IN_ONE_COL;
|
||||
break;
|
||||
case JUNGFRAUCTB:
|
||||
packetsPerFrame = JCTB_PACKETS_PER_FRAME;
|
||||
@ -857,6 +887,8 @@ int UDPStandardImplementation::setDetectorType(const detectorType d){
|
||||
fifoBufferHeaderSize= (HEADER_SIZE_NUM_TOT_PACKETS + FILE_FRAME_HEADER_LENGTH);
|
||||
//footerOffset = Not applicable;
|
||||
excludeMissingPackets=true;
|
||||
NX = JFRAU_PIXELS_IN_ONE_ROW;
|
||||
NY = JFRAU_PIXELS_IN_ONE_COL;
|
||||
break;
|
||||
default:
|
||||
FILE_LOG(logERROR) << "This is an unknown receiver type " << (int)d;
|
||||
@ -968,6 +1000,35 @@ int UDPStandardImplementation::startReceiver(char *c){
|
||||
fclose(sfilefd[i]);
|
||||
sfilefd[i] = 0;
|
||||
}
|
||||
#ifdef HDF5C
|
||||
pthread_mutex_lock(&writeMutex);
|
||||
|
||||
try{
|
||||
Exception::dontPrint(); //to handle errors
|
||||
if(hdf5_fileId[i]) delete hdf5_fileId[i];
|
||||
if(hdf5_dataspaceId[i]) delete hdf5_dataspaceId[i];
|
||||
if(hdf5_datasetId[i]) delete hdf5_datasetId[i];
|
||||
}// end of try block
|
||||
catch(Exception error){
|
||||
cprintf(RED,"Error in closing HDF5 handles\n");
|
||||
error.printError();
|
||||
return -1;
|
||||
}
|
||||
/*
|
||||
if(hdf5DataspaceId[i]){
|
||||
H5Sclose(hdf5DataspaceId[i]);
|
||||
hdf5DataspaceId[i] = 0;
|
||||
}
|
||||
if(hdf5DatasetId[i]){
|
||||
H5Dclose(hdf5DatasetId[i]);
|
||||
hdf5DatasetId[i] = 0;
|
||||
}
|
||||
if(hdf5fileId[i]){
|
||||
H5Fclose(hdf5fileId[i]);
|
||||
hdf5fileId[i] = 0;
|
||||
}*/
|
||||
pthread_mutex_unlock(&writeMutex);
|
||||
#endif
|
||||
//reset gui variables
|
||||
frametoGuiCounter[i] = 0;
|
||||
guiNumPackets[i] = 0;
|
||||
@ -1201,6 +1262,36 @@ void UDPStandardImplementation::closeFile(int ithread){
|
||||
fclose(sfilefd[ithread]);
|
||||
sfilefd[ithread] = 0;
|
||||
}
|
||||
#ifdef HDF5C
|
||||
pthread_mutex_lock(&writeMutex);
|
||||
|
||||
try{
|
||||
Exception::dontPrint(); //to handle errors
|
||||
if(hdf5_fileId[i]) delete hdf5_fileId[i];
|
||||
if(hdf5_dataspaceId[i]) delete hdf5_dataspaceId[i];
|
||||
if(hdf5_datasetId[i]) delete hdf5_datasetId[i];
|
||||
}// end of try block
|
||||
catch(Exception error){
|
||||
cprintf(RED,"Error in closing HDF5 handles\n");
|
||||
error.printError();
|
||||
return -1;
|
||||
}
|
||||
/*
|
||||
if(hdf5DataspaceId[ithread]){
|
||||
H5Sclose(hdf5DataspaceId[ithread]);
|
||||
hdf5DataspaceId[ithread] = 0;
|
||||
}
|
||||
if(hdf5DatasetId[ithread]){
|
||||
H5Dclose(hdf5DatasetId[ithread]);
|
||||
hdf5DatasetId[ithread] = 0;
|
||||
}
|
||||
if(hdf5fileId[ithread]){
|
||||
H5Fclose(hdf5fileId[ithread]);
|
||||
hdf5fileId[ithread] = 0;
|
||||
}
|
||||
*/
|
||||
pthread_mutex_unlock(&writeMutex);
|
||||
#endif
|
||||
}
|
||||
|
||||
//compression
|
||||
@ -1559,7 +1650,12 @@ int UDPStandardImplementation::setupWriter(){
|
||||
|
||||
if(fileCreateSuccess == OK){
|
||||
FILE_LOG(logDEBUG) << "Successfully created file(s)";
|
||||
#ifdef HDF5C
|
||||
if(fileFormatType == HDF5)
|
||||
cout << "HDF5 Writer Ready ..." << endl;
|
||||
#else
|
||||
cout << "Writer Ready ..." << endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
return fileCreateSuccess;
|
||||
@ -1572,44 +1668,150 @@ int UDPStandardImplementation::createNewFile(int ithread){
|
||||
|
||||
//create file name
|
||||
if(!frameIndexEnable)
|
||||
sprintf(completeFileName[ithread], "%s/%s_%lld.raw", filePath,fileNamePerThread[ithread],(long long int)fileIndex);
|
||||
sprintf(completeFileName[ithread], "%s/%s_%lld", filePath,fileNamePerThread[ithread],(long long int)fileIndex);
|
||||
else
|
||||
sprintf(completeFileName[ithread], "%s/%s_f%012lld_%lld.raw", filePath,fileNamePerThread[ithread],(long long int)lastFrameNumberInFile[ithread]+1,(long long int)fileIndex);
|
||||
sprintf(completeFileName[ithread], "%s/%s_f%012lld_%lld", filePath,fileNamePerThread[ithread],(long long int)lastFrameNumberInFile[ithread]+1,(long long int)fileIndex);
|
||||
|
||||
//file type
|
||||
switch(fileFormatType){
|
||||
#ifdef HDF5C
|
||||
case HDF5:
|
||||
strcat(completeFileName[ithread],".h5");
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
strcat(completeFileName[ithread],".raw");
|
||||
break;
|
||||
}
|
||||
#ifdef DEBUG4
|
||||
FILE_LOG(logINFO) << completefileName;
|
||||
#endif
|
||||
|
||||
|
||||
//filewrite enable & we allowed to create/close files
|
||||
if(fileWriteEnable && cbAction > DO_NOTHING){
|
||||
|
||||
//close file pointers
|
||||
if(sfilefd[ithread]){
|
||||
//all threads need to close file, reset mask and exit loop
|
||||
if(myDetectorType == EIGER && fileWriteEnable && (cbAction > DO_NOTHING)){
|
||||
updateFileHeader(ithread);
|
||||
fseek(sfilefd[ithread],0,0);
|
||||
fwrite((void*)fileHeader[ithread], 1, FILE_HEADER_SIZE, sfilefd[ithread]);
|
||||
}
|
||||
fflush(sfilefd[ithread]);
|
||||
fclose(sfilefd[ithread]);
|
||||
sfilefd[ithread] = 0;
|
||||
}
|
||||
|
||||
//create file
|
||||
if(!overwriteEnable){
|
||||
if (NULL == (sfilefd[ithread] = fopen((const char *) (completeFileName[ithread]), "wx"))){
|
||||
FILE_LOG(logERROR) << "Could not create/overwrite file" << completeFileName[ithread];
|
||||
if(fileFormatType == BINARY){
|
||||
//close file pointers
|
||||
if(sfilefd[ithread]){
|
||||
//all threads need to close file, reset mask and exit loop
|
||||
if(myDetectorType == EIGER && fileWriteEnable && (cbAction > DO_NOTHING)){
|
||||
updateFileHeader(ithread);
|
||||
fseek(sfilefd[ithread],0,0);
|
||||
fwrite((void*)fileHeader[ithread], 1, FILE_HEADER_SIZE, sfilefd[ithread]);
|
||||
}
|
||||
fflush(sfilefd[ithread]);
|
||||
fclose(sfilefd[ithread]);
|
||||
sfilefd[ithread] = 0;
|
||||
}
|
||||
|
||||
|
||||
//create file
|
||||
if(!overwriteEnable){
|
||||
if (NULL == (sfilefd[ithread] = fopen((const char *) (completeFileName[ithread]), "wx"))){
|
||||
FILE_LOG(logERROR) << "Could not create/overwrite file" << completeFileName[ithread];
|
||||
sfilefd[ithread] = 0;
|
||||
return FAIL;
|
||||
}
|
||||
}else if (NULL == (sfilefd[ithread] = fopen((const char *) (completeFileName[ithread]), "w"))){
|
||||
FILE_LOG(logERROR) << "Could not create file" << completeFileName[ithread];
|
||||
sfilefd[ithread] = 0;
|
||||
return FAIL;
|
||||
}
|
||||
}else if (NULL == (sfilefd[ithread] = fopen((const char *) (completeFileName[ithread]), "w"))){
|
||||
FILE_LOG(logERROR) << "Could not create file" << completeFileName[ithread];
|
||||
sfilefd[ithread] = 0;
|
||||
return FAIL;
|
||||
//setting file buffer size to 16mb
|
||||
setvbuf(sfilefd[ithread],NULL,_IOFBF,BUF_SIZE);
|
||||
}
|
||||
//setting file buffer size to 16mb
|
||||
setvbuf(sfilefd[ithread],NULL,_IOFBF,BUF_SIZE);
|
||||
|
||||
|
||||
#ifdef HDF5C
|
||||
else if(fileFormatType == HDF5){
|
||||
pthread_mutex_lock(&writeMutex);
|
||||
|
||||
if(hdf5DataspaceId[ithread]){
|
||||
H5Sclose(hdf5DataspaceId[ithread]);
|
||||
hdf5DataspaceId[ithread] = 0;
|
||||
}
|
||||
if(hdf5DatasetId[ithread]){
|
||||
H5Dclose(hdf5DatasetId[ithread]);
|
||||
hdf5DatasetId[ithread] = 0;
|
||||
}
|
||||
if(hdf5fileId[ithread]){
|
||||
// update attributes
|
||||
bool error = true;
|
||||
hsize_t dims = 1;
|
||||
hid_t hdf5AttributeDataspaceId = H5Screate_simple (1, &dims, NULL);
|
||||
if(hdf5AttributeDataspaceId>=0){
|
||||
hid_t hdf5AttributeId = H5Acreate2(hdf5fileId[ithread],"Dynamic Range",H5T_STD_I32LE,hdf5AttributeDataspaceId,
|
||||
H5P_DEFAULT, H5P_DEFAULT);
|
||||
if(hdf5AttributeId>=0){
|
||||
if(H5Awrite(hdf5AttributeId,H5T_STD_I32LE,&dynamicRange)>=0){
|
||||
if(H5Aclose(hdf5AttributeId)>=0){
|
||||
error = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(error){
|
||||
FILE_LOG(logERROR) << "Could not create attribute for " << completeFileName[ithread] << endl;
|
||||
pthread_mutex_unlock(&writeMutex);
|
||||
return FAIL;
|
||||
}
|
||||
H5Fclose(hdf5fileId[ithread]);
|
||||
hdf5fileId[ithread] = 0;
|
||||
}
|
||||
|
||||
|
||||
//create file
|
||||
if(!overwriteEnable){
|
||||
hdf5fileId[ithread] = H5Fcreate(completeFileName[ithread], H5F_ACC_EXCL, H5P_DEFAULT, H5P_DEFAULT);
|
||||
if(hdf5fileId[ithread]<0){
|
||||
FILE_LOG(logERROR) << "Could not create new file" << completeFileName[ithread] << ". Check if it exists or permissions" << endl;
|
||||
pthread_mutex_unlock(&writeMutex);
|
||||
return FAIL;
|
||||
}
|
||||
}else{
|
||||
hdf5fileId[ithread] = H5Fcreate(completeFileName[ithread], H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
|
||||
if(hdf5fileId[ithread]<0){
|
||||
FILE_LOG(logERROR) << "Could not create/overwrite new file" << completeFileName[ithread] << ". Check permissions" << endl;
|
||||
pthread_mutex_unlock(&writeMutex);
|
||||
return FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
//create dataspace and dataset
|
||||
hsize_t srcdims[3] = {NY,NX,numberOfFrames};
|
||||
if(dynamicRange == 4)
|
||||
srcdims[1] = NX/2;
|
||||
hdf5DataspaceId[ithread] = H5Screate_simple (3, srcdims, NULL);
|
||||
bool error = true;
|
||||
if(hdf5DataspaceId[ithread]>=0){
|
||||
//fillvalues
|
||||
hid_t hdf5Dcpl = H5Pcreate(H5P_DATASET_CREATE);
|
||||
if(hdf5Dcpl>=0){
|
||||
//fill it
|
||||
int fill_value = -1;
|
||||
if(H5Pset_fill_value(hdf5Dcpl, hdf5DataType, &fill_value)>=0){
|
||||
//dataset
|
||||
hdf5DatasetId[ithread] = H5Dcreate2 (hdf5fileId[ithread],"run", hdf5DataType, hdf5DataspaceId[ithread],
|
||||
H5P_DEFAULT, hdf5Dcpl, H5P_DEFAULT);
|
||||
if(hdf5DatasetId[ithread]>=0){
|
||||
error = false;
|
||||
}else cprintf(RED, "error in dataset creation\n");
|
||||
}else cprintf(RED, "error in filling values\n");
|
||||
}else cprintf(RED, "error in fill value id creation\n");
|
||||
}else cprintf(RED, "error in dataspace creation\n");
|
||||
if(error){
|
||||
FILE_LOG(logERROR) << "Could not create dataspace/dataset/attribute for thread " << ithread << endl;
|
||||
pthread_mutex_unlock(&writeMutex);
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&writeMutex);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
//Print packet loss and filenames
|
||||
if(totalWritingPacketCount[ithread]){
|
||||
@ -1648,7 +1850,7 @@ int UDPStandardImplementation::createNewFile(int ithread){
|
||||
printf("Thread:%d File opened:%s\n",ithread, completeFileName[ithread]);
|
||||
|
||||
//write file header
|
||||
if(myDetectorType == EIGER)
|
||||
if(myDetectorType == EIGER && fileFormatType == BINARY)
|
||||
fwrite((void*)fileHeader[ithread], 1, FILE_HEADER_SIZE, sfilefd[ithread]);
|
||||
}
|
||||
|
||||
@ -2667,10 +2869,41 @@ void UDPStandardImplementation::stopWriting(int ithread, char* wbuffer){
|
||||
|
||||
|
||||
//all threads need to close file, reset mask and exit loop
|
||||
if(myDetectorType == EIGER && fileWriteEnable && (cbAction > DO_NOTHING)){
|
||||
updateFileHeader(ithread);
|
||||
fseek(sfilefd[ithread],0,0);
|
||||
fwrite((void*)fileHeader[ithread], 1, FILE_HEADER_SIZE, sfilefd[ithread]);
|
||||
if(fileWriteEnable && (cbAction > DO_NOTHING)){
|
||||
|
||||
#ifdef HDF5C
|
||||
if(fileFormatType == HDF5){
|
||||
|
||||
if(hdf5fileId[ithread]){
|
||||
pthread_mutex_lock(&writeMutex);
|
||||
// update attributes
|
||||
bool error = true;
|
||||
hsize_t dims = 1;
|
||||
hid_t hdf5AttributeDataspaceId = H5Screate_simple (1, &dims, NULL);
|
||||
if(hdf5AttributeDataspaceId>=0){
|
||||
hid_t hdf5AttributeId = H5Acreate2(hdf5fileId[ithread],"Dynamic Range",H5T_STD_I32LE,hdf5AttributeDataspaceId,
|
||||
H5P_DEFAULT, H5P_DEFAULT);
|
||||
if(hdf5AttributeId>=0){
|
||||
if(H5Awrite(hdf5AttributeId,H5T_STD_I32LE,&dynamicRange)>=0){
|
||||
if(H5Aclose(hdf5AttributeId)>=0){
|
||||
error = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(error){
|
||||
FILE_LOG(logERROR) << "Could not create attribute for " << completeFileName[ithread] << endl;
|
||||
}
|
||||
pthread_mutex_unlock(&writeMutex);
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
if(fileFormatType == BINARY && myDetectorType == EIGER){
|
||||
updateFileHeader(ithread);
|
||||
fseek(sfilefd[ithread],0,0);
|
||||
fwrite((void*)fileHeader[ithread], 1, FILE_HEADER_SIZE, sfilefd[ithread]);
|
||||
}
|
||||
}
|
||||
|
||||
//Print packet loss
|
||||
@ -2881,10 +3114,37 @@ void UDPStandardImplementation::handleCompleteFramesOnly(int ithread, char* wbuf
|
||||
|
||||
|
||||
//write to file if enabled and update write parameters
|
||||
if((fileWriteEnable) && (sfilefd[ithread])){
|
||||
if((fileWriteEnable) && (sfilefd[ithread]||hdf5fileId[ithread])){
|
||||
if(tempframenumber && (tempframenumber%maxFramesPerFile) == 0)
|
||||
createNewFile(ithread);
|
||||
fwrite(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS, 1, (bufferSize + FILE_FRAME_HEADER_LENGTH), sfilefd[ithread]);
|
||||
#ifdef HDF5C
|
||||
|
||||
if(fileFormatType == HDF5){
|
||||
pthread_mutex_lock(&writeMutex);
|
||||
hsize_t dims2[2]={NY,NX};
|
||||
hsize_t count[3] = {NY,NX,1};
|
||||
if(dynamicRange == 4){
|
||||
dims2[1] = NX/2;
|
||||
count[1] = NX/2;
|
||||
}
|
||||
hid_t memspace = H5Screate_simple(2,dims2,NULL);
|
||||
hsize_t start[3] = {0, 0, tempframenumber};
|
||||
|
||||
if(H5Sselect_hyperslab(hdf5DataspaceId[ithread], H5S_SELECT_SET, start, NULL, count, NULL)<0){
|
||||
cprintf(RED,"could not create hyperslab %d \n",ithread);
|
||||
}
|
||||
if(H5Dwrite (hdf5DatasetId[ithread], hdf5DataType, memspace, hdf5DataspaceId[ithread],
|
||||
H5P_DEFAULT, wbuffer + fifoBufferHeaderSize)<0){
|
||||
cprintf(RED,"could not write dataset for thread %d \n",ithread);
|
||||
}
|
||||
H5Sclose(memspace);
|
||||
|
||||
pthread_mutex_unlock(&writeMutex);
|
||||
}else
|
||||
#endif
|
||||
|
||||
if(fileFormatType == BINARY)
|
||||
fwrite(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS, 1, (bufferSize + FILE_FRAME_HEADER_LENGTH), sfilefd[ithread]);
|
||||
}
|
||||
|
||||
|
||||
|
@ -265,6 +265,9 @@ int slsReceiverTCPIPInterface::function_table(){
|
||||
flist[F_STREAM_DATA_FROM_RECEIVER] = &slsReceiverTCPIPInterface::set_data_stream_enable;
|
||||
flist[F_READ_RECEIVER_TIMER] = &slsReceiverTCPIPInterface::set_read_receiver_timer;
|
||||
flist[F_SET_FLIPPED_DATA_RECEIVER] = &slsReceiverTCPIPInterface::set_flipped_data;
|
||||
flist[F_SET_RECEIVER_FILE_FORMAT] = &slsReceiverTCPIPInterface::set_file_format;
|
||||
|
||||
|
||||
|
||||
#ifdef VERYVERBOSE
|
||||
for (int i=0;i<numberOfFunctions;i++)
|
||||
@ -3089,8 +3092,76 @@ int slsReceiverTCPIPInterface::set_flipped_data(){
|
||||
|
||||
|
||||
|
||||
int slsReceiverTCPIPInterface::set_file_format() {
|
||||
ret=OK;
|
||||
fileFormat retval = GET_FILE_FORMAT;
|
||||
fileFormat f = GET_FILE_FORMAT;
|
||||
strcpy(mess,"Could not set/get file format\n");
|
||||
|
||||
|
||||
// receive arguments
|
||||
if(mySock->ReceiveDataOnly(&f,sizeof(f)) < 0 ){
|
||||
strcpy(mess,"Error reading from socket\n");
|
||||
cprintf(RED,"%s",mess);
|
||||
ret = FAIL;
|
||||
}
|
||||
|
||||
|
||||
// execute action if the arguments correctly arrived
|
||||
#ifdef SLS_RECEIVER_UDP_FUNCTIONS
|
||||
if (ret==OK) {
|
||||
if (lockStatus==1 && mySock->differentClients==1){
|
||||
sprintf(mess,"Receiver locked by %s\n", mySock->lastClientIP);
|
||||
ret=FAIL;
|
||||
}
|
||||
|
||||
if(ret!=FAIL){
|
||||
if (receiverBase == NULL){
|
||||
strcpy(mess,SET_RECEIVER_ERR_MESSAGE);
|
||||
cprintf(RED,"%s",mess);
|
||||
ret=FAIL;
|
||||
}else if(receiverBase->getStatus()==RUNNING && (f>=0)){
|
||||
strcpy(mess,"Cannot set file format while status is running\n");
|
||||
cprintf(RED,"%s",mess);
|
||||
ret=FAIL;
|
||||
}else{
|
||||
if(f != -1)
|
||||
receiverBase->setFileFormat(f);
|
||||
retval = receiverBase->getFileFormat();
|
||||
if(f >= 0 && retval != f){
|
||||
sprintf(mess,"Tried to set file format to %d, but returned %d\n",f,retval);
|
||||
ret = FAIL;
|
||||
cprintf(RED,"%s",mess);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#ifdef VERYVERBOSE
|
||||
if(ret!=FAIL)
|
||||
cout << "File Format: " << retval << endl;
|
||||
else
|
||||
cout << mess << endl;
|
||||
#endif
|
||||
|
||||
|
||||
if(ret==OK && mySock->differentClients){
|
||||
FILE_LOG(logDEBUG) << "Force update";
|
||||
ret=FORCE_UPDATE;
|
||||
}
|
||||
|
||||
// send answer
|
||||
mySock->SendDataOnly(&ret,sizeof(ret));
|
||||
if(ret==FAIL){
|
||||
cprintf(RED,"%s\n",mess);
|
||||
mySock->SendDataOnly(mess,sizeof(mess));
|
||||
}
|
||||
mySock->SendDataOnly(&retval,sizeof(retval));
|
||||
|
||||
//return ok/fail
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user