mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-05-06 04:40:02 +02:00
converted to c++
This commit is contained in:
parent
d3200dc76f
commit
f8b34a16dd
@ -26,7 +26,11 @@
|
|||||||
#include <semaphore.h>
|
#include <semaphore.h>
|
||||||
|
|
||||||
#ifdef HDF5C
|
#ifdef HDF5C
|
||||||
#include "hdf5.h"
|
#include "H5Cpp.h"
|
||||||
|
//#ifndef H5_NO_NAMESPACE
|
||||||
|
using namespace H5;
|
||||||
|
//#endif
|
||||||
|
//#include "hdf5.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -639,9 +643,9 @@ private:
|
|||||||
/** File Descriptor */
|
/** File Descriptor */
|
||||||
FILE *sfilefd[MAX_NUMBER_OF_WRITER_THREADS];
|
FILE *sfilefd[MAX_NUMBER_OF_WRITER_THREADS];
|
||||||
#ifdef HDF5C
|
#ifdef HDF5C
|
||||||
H5File *hdf5_fileId[MAX_NUMBER_OF_WRITER_THREADS];
|
|
||||||
DataSpace *hdf5_dataspaceId[MAX_NUMBER_OF_WRITER_THREADS];
|
DataSpace *hdf5_dataspaceId[MAX_NUMBER_OF_WRITER_THREADS];
|
||||||
DataSet *hdf5_datasetId[MAX_NUMBER_OF_WRITER_THREADS];
|
DataSet *hdf5_datasetId[MAX_NUMBER_OF_WRITER_THREADS];
|
||||||
|
H5File *hdf5_fileId[MAX_NUMBER_OF_WRITER_THREADS];
|
||||||
hid_t hdf5_datatype;
|
hid_t hdf5_datatype;
|
||||||
|
|
||||||
/*hid_t hdf5fileId[MAX_NUMBER_OF_WRITER_THREADS];
|
/*hid_t hdf5fileId[MAX_NUMBER_OF_WRITER_THREADS];
|
||||||
|
@ -21,12 +21,6 @@
|
|||||||
#include <zmq.h> //zmq
|
#include <zmq.h> //zmq
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#ifdef HDF5C
|
|
||||||
#include "H5Cpp.h"
|
|
||||||
#ifndef H5_NO_NAMESPACE
|
|
||||||
using namespace H5;
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@ -160,13 +154,13 @@ void UDPStandardImplementation::initializeMembers(){
|
|||||||
strcpy(fileHeader[i],"");
|
strcpy(fileHeader[i],"");
|
||||||
sfilefd[i] = 0;
|
sfilefd[i] = 0;
|
||||||
#ifdef HDF5C
|
#ifdef HDF5C
|
||||||
hdf5_fileId[i] = 0;
|
|
||||||
hdf5_dataspaceId[i] = 0;
|
hdf5_dataspaceId[i] = 0;
|
||||||
hdf5_datasetId[i] = 0;
|
hdf5_datasetId[i] = 0;
|
||||||
|
hdf5_fileId[i] = 0;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#ifdef HDF5C
|
#ifdef HDF5C
|
||||||
hdf5DataType = H5T_STD_U16LE;
|
hdf5_datatype = H5T_STD_U16LE;
|
||||||
#endif
|
#endif
|
||||||
maxFramesPerFile = 0;
|
maxFramesPerFile = 0;
|
||||||
fileCreateSuccess = false;
|
fileCreateSuccess = false;
|
||||||
@ -654,9 +648,9 @@ int UDPStandardImplementation::setDynamicRange(const uint32_t i){
|
|||||||
#ifdef HDF5C
|
#ifdef HDF5C
|
||||||
switch(dynamicRange){
|
switch(dynamicRange){
|
||||||
case 4:
|
case 4:
|
||||||
case 8: hdf5DataType = H5T_STD_U8LE; break;
|
case 8: hdf5_datatype = H5T_STD_U8LE; break;
|
||||||
case 16: hdf5DataType = H5T_STD_U16LE; break;
|
case 16: hdf5_datatype = H5T_STD_U16LE; break;
|
||||||
case 32: hdf5DataType = H5T_STD_U32LE; break;
|
case 32: hdf5_datatype = H5T_STD_U32LE; break;
|
||||||
default: cprintf(BG_RED,"unknown dynamic range\n");
|
default: cprintf(BG_RED,"unknown dynamic range\n");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -1005,14 +999,15 @@ int UDPStandardImplementation::startReceiver(char *c){
|
|||||||
|
|
||||||
try{
|
try{
|
||||||
Exception::dontPrint(); //to handle errors
|
Exception::dontPrint(); //to handle errors
|
||||||
if(hdf5_fileId[i]) delete hdf5_fileId[i];
|
if(hdf5_dataspaceId[i]) {delete hdf5_dataspaceId[i]; hdf5_dataspaceId[i] = 0;}
|
||||||
if(hdf5_dataspaceId[i]) delete hdf5_dataspaceId[i];
|
if(hdf5_datasetId[i]) {delete hdf5_datasetId[i]; hdf5_datasetId[i] = 0;}
|
||||||
if(hdf5_datasetId[i]) delete hdf5_datasetId[i];
|
if(hdf5_fileId[i]) {delete hdf5_fileId[i]; hdf5_fileId[i] = 0;}
|
||||||
}// end of try block
|
}
|
||||||
catch(Exception error){
|
catch(Exception error){
|
||||||
cprintf(RED,"Error in closing HDF5 handles\n");
|
cprintf(RED,"Error in closing HDF5 handles\n");
|
||||||
error.printError();
|
error.printError();
|
||||||
return -1;
|
pthread_mutex_unlock(&writeMutex);
|
||||||
|
return FAIL;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
if(hdf5DataspaceId[i]){
|
if(hdf5DataspaceId[i]){
|
||||||
@ -1267,14 +1262,13 @@ void UDPStandardImplementation::closeFile(int ithread){
|
|||||||
|
|
||||||
try{
|
try{
|
||||||
Exception::dontPrint(); //to handle errors
|
Exception::dontPrint(); //to handle errors
|
||||||
if(hdf5_fileId[i]) delete hdf5_fileId[i];
|
if(hdf5_dataspaceId[ithread]) {delete hdf5_dataspaceId[ithread]; hdf5_dataspaceId[ithread] = 0;}
|
||||||
if(hdf5_dataspaceId[i]) delete hdf5_dataspaceId[i];
|
if(hdf5_datasetId[ithread]) {delete hdf5_datasetId[ithread]; hdf5_datasetId[ithread] = 0;}
|
||||||
if(hdf5_datasetId[i]) delete hdf5_datasetId[i];
|
if(hdf5_fileId[ithread]) {delete hdf5_fileId[ithread]; hdf5_fileId[ithread] = 0;}
|
||||||
}// end of try block
|
}
|
||||||
catch(Exception error){
|
catch(Exception error){
|
||||||
cprintf(RED,"Error in closing HDF5 handles\n");
|
cprintf(RED,"Error in closing HDF5 handles\n");
|
||||||
error.printError();
|
error.printError();
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
if(hdf5DataspaceId[ithread]){
|
if(hdf5DataspaceId[ithread]){
|
||||||
@ -1299,7 +1293,7 @@ void UDPStandardImplementation::closeFile(int ithread){
|
|||||||
#if (defined(MYROOT1) && defined(ALLFILE_DEBUG)) || !defined(MYROOT1)
|
#if (defined(MYROOT1) && defined(ALLFILE_DEBUG)) || !defined(MYROOT1)
|
||||||
if(sfilefd[0]){
|
if(sfilefd[0]){
|
||||||
#ifdef DEBUG4
|
#ifdef DEBUG4
|
||||||
FILE_LOG(logDEBUG4) << "sfilefd: " << (int)sfilefd[i];
|
FILE_LOG(logDEBUG4) << "sfilefd: " << (int)sfilefd[0];
|
||||||
#endif
|
#endif
|
||||||
fclose(sfilefd[0]);
|
fclose(sfilefd[0]);
|
||||||
sfilefd[0] = 0;
|
sfilefd[0] = 0;
|
||||||
@ -1728,6 +1722,67 @@ int UDPStandardImplementation::createNewFile(int ithread){
|
|||||||
else if(fileFormatType == HDF5){
|
else if(fileFormatType == HDF5){
|
||||||
pthread_mutex_lock(&writeMutex);
|
pthread_mutex_lock(&writeMutex);
|
||||||
|
|
||||||
|
//closing file
|
||||||
|
try{
|
||||||
|
Exception::dontPrint(); //to handle errors
|
||||||
|
if(hdf5_dataspaceId[ithread]) {delete hdf5_dataspaceId[ithread]; hdf5_dataspaceId[ithread] = 0;}
|
||||||
|
if(hdf5_datasetId[ithread]) {delete hdf5_datasetId[ithread]; hdf5_datasetId[ithread] = 0;}
|
||||||
|
if(hdf5_fileId[ithread]) {delete hdf5_fileId[ithread]; hdf5_fileId[ithread] = 0; }
|
||||||
|
}
|
||||||
|
catch(AttributeIException error){
|
||||||
|
cprintf(RED,"Error in creating attributes in thread %d\n",ithread);
|
||||||
|
error.printError();
|
||||||
|
pthread_mutex_unlock(&writeMutex);
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
catch(Exception error){
|
||||||
|
cprintf(RED,"Error in closing HDF5 handles in thread %d\n",ithread);
|
||||||
|
error.printError();
|
||||||
|
pthread_mutex_unlock(&writeMutex);
|
||||||
|
return FAIL;
|
||||||
|
}//end of closing file
|
||||||
|
|
||||||
|
//creating file
|
||||||
|
try{
|
||||||
|
Exception::dontPrint(); //to handle errors
|
||||||
|
//creating file
|
||||||
|
if(!overwriteEnable)
|
||||||
|
hdf5_fileId[ithread] = new H5File( completeFileName[ithread], H5F_ACC_EXCL );
|
||||||
|
else
|
||||||
|
hdf5_fileId[ithread] = new H5File( completeFileName[ithread], H5F_ACC_TRUNC );
|
||||||
|
//create property list for a dataset and set up fill values
|
||||||
|
int fillvalue = -1;
|
||||||
|
DSetCreatPropList plist;
|
||||||
|
plist.setFillValue(hdf5_datatype, &fillvalue);
|
||||||
|
//create dataspace for the dataset in the file
|
||||||
|
hsize_t srcdims[3] = {NY,NX,numberOfFrames};
|
||||||
|
if(dynamicRange == 4)
|
||||||
|
srcdims[1] = NX/2;
|
||||||
|
hdf5_dataspaceId[ithread] = new DataSpace (3,srcdims);
|
||||||
|
//Create dataset and write it into the file
|
||||||
|
hdf5_datasetId[ithread] = new DataSet (hdf5_fileId[ithread]->createDataSet(
|
||||||
|
"Data", hdf5_datatype, *hdf5_dataspaceId[ithread], plist));
|
||||||
|
|
||||||
|
//create the data space for the attribute
|
||||||
|
hsize_t dims = 1;
|
||||||
|
DataSpace attr_dataspace = DataSpace (1, &dims);
|
||||||
|
//create file attribute
|
||||||
|
Attribute attribute = hdf5_datasetId[ithread]->createAttribute("Dynamic Range",
|
||||||
|
PredType::STD_I32LE, attr_dataspace);
|
||||||
|
//write the attribute data
|
||||||
|
attribute.write(PredType::STD_I32LE, &dynamicRange);
|
||||||
|
|
||||||
|
}
|
||||||
|
catch(Exception error){
|
||||||
|
cprintf(RED,"Error in creating HDF5 handles in thread %d\n",ithread);
|
||||||
|
error.printError();
|
||||||
|
pthread_mutex_unlock(&writeMutex);
|
||||||
|
return FAIL;
|
||||||
|
}//end of creating file
|
||||||
|
|
||||||
|
pthread_mutex_unlock(&writeMutex);
|
||||||
|
|
||||||
|
/*
|
||||||
if(hdf5DataspaceId[ithread]){
|
if(hdf5DataspaceId[ithread]){
|
||||||
H5Sclose(hdf5DataspaceId[ithread]);
|
H5Sclose(hdf5DataspaceId[ithread]);
|
||||||
hdf5DataspaceId[ithread] = 0;
|
hdf5DataspaceId[ithread] = 0;
|
||||||
@ -1761,7 +1816,6 @@ int UDPStandardImplementation::createNewFile(int ithread){
|
|||||||
hdf5fileId[ithread] = 0;
|
hdf5fileId[ithread] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//create file
|
//create file
|
||||||
if(!overwriteEnable){
|
if(!overwriteEnable){
|
||||||
hdf5fileId[ithread] = H5Fcreate(completeFileName[ithread], H5F_ACC_EXCL, H5P_DEFAULT, H5P_DEFAULT);
|
hdf5fileId[ithread] = H5Fcreate(completeFileName[ithread], H5F_ACC_EXCL, H5P_DEFAULT, H5P_DEFAULT);
|
||||||
@ -1779,6 +1833,8 @@ int UDPStandardImplementation::createNewFile(int ithread){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//create dataspace and dataset
|
//create dataspace and dataset
|
||||||
hsize_t srcdims[3] = {NY,NX,numberOfFrames};
|
hsize_t srcdims[3] = {NY,NX,numberOfFrames};
|
||||||
if(dynamicRange == 4)
|
if(dynamicRange == 4)
|
||||||
@ -1808,6 +1864,7 @@ int UDPStandardImplementation::createNewFile(int ithread){
|
|||||||
}
|
}
|
||||||
|
|
||||||
pthread_mutex_unlock(&writeMutex);
|
pthread_mutex_unlock(&writeMutex);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -2872,11 +2929,29 @@ void UDPStandardImplementation::stopWriting(int ithread, char* wbuffer){
|
|||||||
if(fileWriteEnable && (cbAction > DO_NOTHING)){
|
if(fileWriteEnable && (cbAction > DO_NOTHING)){
|
||||||
|
|
||||||
#ifdef HDF5C
|
#ifdef HDF5C
|
||||||
if(fileFormatType == HDF5){
|
if(fileFormatType == HDF5){;
|
||||||
|
/*
|
||||||
if(hdf5fileId[ithread]){
|
if(hdf5_datasetId[ithread]){
|
||||||
pthread_mutex_lock(&writeMutex);
|
pthread_mutex_lock(&writeMutex);
|
||||||
// update attributes
|
try{
|
||||||
|
Exception::dontPrint(); //to handle errors
|
||||||
|
hsize_t dims = 1;
|
||||||
|
//create the data space for the attribute
|
||||||
|
DataSpace attr_dataspace = DataSpace (1, &dims);
|
||||||
|
//create file attribute
|
||||||
|
Attribute attribute = hdf5_datasetId[ithread]->createAttribute( "Dynamic Range",
|
||||||
|
PredType::STD_I32LE, attr_dataspace);
|
||||||
|
//write the attribute data
|
||||||
|
attribute.write( PredType::STD_I32LE, &dynamicRange);
|
||||||
|
delete hdf5_datasetId[ithread];
|
||||||
|
hdf5_datasetId[ithread] = 0;
|
||||||
|
}
|
||||||
|
catch(Exception error){
|
||||||
|
cprintf(RED,"Error in creating attributes in thread %d\n",ithread);
|
||||||
|
error.printError();
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
/*
|
||||||
bool error = true;
|
bool error = true;
|
||||||
hsize_t dims = 1;
|
hsize_t dims = 1;
|
||||||
hid_t hdf5AttributeDataspaceId = H5Screate_simple (1, &dims, NULL);
|
hid_t hdf5AttributeDataspaceId = H5Screate_simple (1, &dims, NULL);
|
||||||
@ -2894,8 +2969,11 @@ void UDPStandardImplementation::stopWriting(int ithread, char* wbuffer){
|
|||||||
if(error){
|
if(error){
|
||||||
FILE_LOG(logERROR) << "Could not create attribute for " << completeFileName[ithread] << endl;
|
FILE_LOG(logERROR) << "Could not create attribute for " << completeFileName[ithread] << endl;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
/*
|
||||||
pthread_mutex_unlock(&writeMutex);
|
pthread_mutex_unlock(&writeMutex);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
@ -3114,30 +3192,39 @@ void UDPStandardImplementation::handleCompleteFramesOnly(int ithread, char* wbuf
|
|||||||
|
|
||||||
|
|
||||||
//write to file if enabled and update write parameters
|
//write to file if enabled and update write parameters
|
||||||
if((fileWriteEnable) && (sfilefd[ithread]||hdf5fileId[ithread])){
|
if((fileWriteEnable) && (sfilefd[ithread]
|
||||||
|
#ifdef HDF5C
|
||||||
|
||hdf5_fileId[ithread])){
|
||||||
|
#else
|
||||||
|
)){
|
||||||
|
#endif
|
||||||
|
|
||||||
if(tempframenumber && (tempframenumber%maxFramesPerFile) == 0)
|
if(tempframenumber && (tempframenumber%maxFramesPerFile) == 0)
|
||||||
createNewFile(ithread);
|
createNewFile(ithread);
|
||||||
#ifdef HDF5C
|
#ifdef HDF5C
|
||||||
|
|
||||||
if(fileFormatType == HDF5){
|
if(fileFormatType == HDF5){
|
||||||
pthread_mutex_lock(&writeMutex);
|
pthread_mutex_lock(&writeMutex);
|
||||||
hsize_t dims2[2]={NY,NX};
|
|
||||||
|
|
||||||
hsize_t count[3] = {NY,NX,1};
|
hsize_t count[3] = {NY,NX,1};
|
||||||
|
hsize_t start[3] = {0, 0, tempframenumber};
|
||||||
|
hsize_t dims2[2]={NY,NX};
|
||||||
if(dynamicRange == 4){
|
if(dynamicRange == 4){
|
||||||
dims2[1] = NX/2;
|
dims2[1] = NX/2;
|
||||||
count[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){
|
try{
|
||||||
cprintf(RED,"could not create hyperslab %d \n",ithread);
|
Exception::dontPrint(); //to handle errors
|
||||||
|
hdf5_dataspaceId[ithread]->selectHyperslab( H5S_SELECT_SET, count, start);
|
||||||
|
DataSpace memspace(2,dims2);
|
||||||
|
hdf5_datasetId[ithread]->write(wbuffer + fifoBufferHeaderSize, hdf5_datatype, memspace, *hdf5_dataspaceId[ithread]);
|
||||||
}
|
}
|
||||||
if(H5Dwrite (hdf5DatasetId[ithread], hdf5DataType, memspace, hdf5DataspaceId[ithread],
|
catch(Exception error){
|
||||||
H5P_DEFAULT, wbuffer + fifoBufferHeaderSize)<0){
|
cprintf(RED,"Error in writing to file in thread %d\n",ithread);
|
||||||
cprintf(RED,"could not write dataset for thread %d \n",ithread);
|
error.printError();
|
||||||
}
|
}
|
||||||
H5Sclose(memspace);
|
|
||||||
|
|
||||||
pthread_mutex_unlock(&writeMutex);
|
pthread_mutex_unlock(&writeMutex);
|
||||||
}else
|
}else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user