hdf5 doestn work yet, wip

This commit is contained in:
maliakal_d 2022-02-18 15:51:54 +01:00
parent fb631187fa
commit 83ff4ab112
4 changed files with 39 additions and 24 deletions

View File

@ -1065,6 +1065,7 @@ void qDrawPlot::toDoublePixelData(double *dest, char *source, int size,
int discardBits = numDiscardBits; int discardBits = numDiscardBits;
uint16_t temp = 0; uint16_t temp = 0;
uint8_t *src = (uint8_t *)source;
switch (dr) { switch (dr) {
case 4: case 4:
@ -1086,22 +1087,13 @@ void qDrawPlot::toDoublePixelData(double *dest, char *source, int size,
case 12: case 12:
for (ichan = 0; ichan < size; ++ichan) { for (ichan = 0; ichan < size; ++ichan) {
// first 12 bit pixel temp = (*src++ & 0xFF);
// lsb (8 bytes) temp |= ((*src & 0xF) << 8u);
temp = (*((u_int8_t *)source)) & 0xFF;
++source;
// msb (4 bytes)
temp |= (((*((u_int8_t *)source)) & 0xF) << 8);
dest[ichan] = (double)temp; dest[ichan] = (double)temp;
// second 12bit pixel
++ichan; ++ichan;
// lsb (4 bytes)
temp = (((*((u_int8_t *)source)) & 0xF0) >> 4); temp = ((*src++ & 0xF0) >> 4u);
++source; temp |= ((*src++ & 0xFF) << 4u);
// msb (8 bytes)
temp |= (((*((u_int8_t *)source)) & 0xFF) << 4);
++source;
dest[ichan] = (double)temp; dest[ichan] = (double)temp;
} }
break; break;

View File

@ -2377,14 +2377,12 @@ void *start_timer(void *arg) {
case 12: case 12:
// first 12 bit pixel // first 12 bit pixel
// first 8 byte // first 8 byte
*source = *source = eiger_virtual_test_mode ? 0xFE : (uint8_t)(i & 0xFF);
eiger_virtual_test_mode ? 0xFE : (uint8_t)(pixelVal & 0xFF);
++source; ++source;
// second 8 byte (first nibble) // second 8 byte (first nibble)
temp = eiger_virtual_test_mode temp =
? 0xF eiger_virtual_test_mode ? 0xF : (uint8_t)((i >> 8) & 0xF);
: (uint8_t)((pixelVal >> 8) & 0xF);
// second 12bit pixel // second 12bit pixel
++i; ++i;
@ -2392,13 +2390,12 @@ void *start_timer(void *arg) {
// second 8 byte (second nibble) // second 8 byte (second nibble)
*source = eiger_virtual_test_mode *source = eiger_virtual_test_mode
? 0xE ? 0xE
: temp | ((uint8_t)(pixelVal & 0xF) << 4); : temp | ((uint8_t)(i & 0xF) << 4);
++source; ++source;
// third byte // third byte
*source = eiger_virtual_test_mode *source =
? 0xFF eiger_virtual_test_mode ? 0xFF : (uint8_t)((i >> 4) & 0xFF);
: (uint8_t)((pixelVal >> 4) & 0xFF);
++source; ++source;
break; break;

View File

@ -249,8 +249,30 @@ void HDF5DataFile::WriteToFile(char *buffer, const int buffersize,
WriteParameterDatasets(currentFrameNumber, (sls_receiver_header *)(buffer)); WriteParameterDatasets(currentFrameNumber, (sls_receiver_header *)(buffer));
} }
void HDF5DataFile::Convert12to16Bit(uint16_t *dst, uint8_t *src) {
for (int i = 0; i < EIGER_NUM_PIXELS; ++i) {
*dst = (*src++ & 0xFF);
*dst++ |= ((*src & 0xF) << 8);
++i;
*dst = ((*src++ & 0xF0) >> 4);
*dst++ |= ((*src++ & 0xFF) << 4);
}
}
void HDF5DataFile::WriteDataFile(const uint64_t currentFrameNumber, void HDF5DataFile::WriteDataFile(const uint64_t currentFrameNumber,
char *buffer) { char *buffer) {
char *revBuffer = buffer;
if (dynamicRange_ == 12) {
revBuffer = (char *)malloc(EIGER_16_BIT_IMAGE_SIZE);
if (revBuffer == nullptr) {
throw sls::RuntimeError("Could not allocate memory for 12 bit to "
"16 bit conversion in object " +
std::to_string(index_));
}
Convert12to16Bit((uint16_t *)revBuffer, (uint8_t *)buffer);
free(revBuffer);
}
std::lock_guard<std::mutex> lock(*hdf5Lib_); std::lock_guard<std::mutex> lock(*hdf5Lib_);
uint64_t nDimx = uint64_t nDimx =
@ -267,7 +289,7 @@ void HDF5DataFile::WriteDataFile(const uint64_t currentFrameNumber,
dataSpace_->selectHyperslab(H5S_SELECT_SET, count, start); dataSpace_->selectHyperslab(H5S_SELECT_SET, count, start);
DataSpace memspace(2, dims2); DataSpace memspace(2, dims2);
dataSet_->write(buffer, dataType_, memspace, *dataSpace_); dataSet_->write(revBuffer, dataType_, memspace, *dataSpace_);
memspace.close(); memspace.close();
} catch (const Exception &error) { } catch (const Exception &error) {
LOG(logERROR) << "Could not write to file in object " << index_; LOG(logERROR) << "Could not write to file in object " << index_;

View File

@ -35,6 +35,7 @@ class HDF5DataFile : private virtual slsDetectorDefs, public File {
private: private:
void CreateFile(); void CreateFile();
void Convert12to16Bit(uint16_t *dst, uint8_t *src);
void WriteDataFile(const uint64_t currentFrameNumber, char *buffer); void WriteDataFile(const uint64_t currentFrameNumber, char *buffer);
void WriteParameterDatasets(const uint64_t currentFrameNumber, void WriteParameterDatasets(const uint64_t currentFrameNumber,
sls_receiver_header *rheader); sls_receiver_header *rheader);
@ -72,4 +73,7 @@ class HDF5DataFile : private virtual slsDetectorDefs, public File {
int detIndex_{0}; int detIndex_{0};
int numUnitsPerReadout_{0}; int numUnitsPerReadout_{0};
uint32_t udpPortNumber_{0}; uint32_t udpPortNumber_{0};
static const int EIGER_NUM_PIXELS{256 * 2 * 256};
static const int EIGER_16_BIT_IMAGE_SIZE{EIGER_NUM_PIXELS * 2};
}; };