New filename structure (#38)

* WIP

* WIP

* linking names

* define for hdf5

* minor

* addressed comments
This commit is contained in:
Erik Fröjdh 2019-07-22 16:52:21 +03:00 committed by Dhanya Thattil
parent 6b7d9445aa
commit 1a9755ad0b
15 changed files with 276 additions and 161 deletions

View File

@ -5,8 +5,7 @@ set(PROJECT_VERSION 5.0.0)
include(CheckIPOSupported) include(CheckIPOSupported)
cmake_policy(SET CMP0074 NEW)
include(cmake/project_version.cmake) include(cmake/project_version.cmake)
# Include additional modules that are used unconditionally # Include additional modules that are used unconditionally

View File

@ -47,14 +47,13 @@ class BinaryFile : private virtual slsDetectorDefs, public File, public BinaryFi
/** /**
* Print all member values * Print all member values
*/ */
void PrintMembers(TLogLevel level = logDEBUG1); void PrintMembers(TLogLevel level = logDEBUG1) override;
/** /**
* Create file * Create file
* @param fnum current frame index to include in file name
* @returns OK or FAIL * @returns OK or FAIL
*/ */
int CreateFile(uint64_t fnum); int CreateFile() override;
/** /**
* Create master file * Create master file
@ -71,17 +70,17 @@ class BinaryFile : private virtual slsDetectorDefs, public File, public BinaryFi
*/ */
int CreateMasterFile(bool mfwenable, bool en, uint32_t size, int CreateMasterFile(bool mfwenable, bool en, uint32_t size,
uint32_t nx, uint32_t ny, uint64_t at, uint64_t st, uint64_t sp, uint32_t nx, uint32_t ny, uint64_t at, uint64_t st, uint64_t sp,
uint64_t ap); uint64_t ap) override;
/** /**
* Close Current File * Close Current File
*/ */
void CloseCurrentFile(); void CloseCurrentFile() override;
/** /**
* Close all Files * Close all Files
*/ */
void CloseAllFiles(); void CloseAllFiles() override;
/** /**
* Write data to file * Write data to file
@ -91,7 +90,7 @@ class BinaryFile : private virtual slsDetectorDefs, public File, public BinaryFi
* @param nump number of packets caught * @param nump number of packets caught
* @returns OK or FAIL * @returns OK or FAIL
*/ */
int WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32_t nump); int WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32_t nump) override;
@ -101,7 +100,7 @@ class BinaryFile : private virtual slsDetectorDefs, public File, public BinaryFi
* Get Type * Get Type
* @return type * @return type
*/ */
fileFormat GetFileType(); fileFormat GetFileType() override;

View File

@ -10,6 +10,7 @@
#include "ansi.h" #include "ansi.h"
#include "logger.h"
#include <string> #include <string>
#include <iomanip> #include <iomanip>
@ -33,43 +34,39 @@ class BinaryFileStatic {
* @param fpath file path * @param fpath file path
* @param fnameprefix file name prefix (includes scan and position variables) * @param fnameprefix file name prefix (includes scan and position variables)
* @param findex file index * @param findex file index
* @param frindexenable frame index enable * @param subfindex sub file index
* @param fnum frame number index
* @param dindex readout index * @param dindex readout index
* @param numunits number of units per readout. eg. eiger has 2 udp units per readout * @param numunits number of units per readout. eg. eiger has 2 udp units per readout
* @param unitindex unit index * @param unitindex unit index
* @returns complete file name created * @returns complete file name created
*/ */
static std::string CreateFileName(char* fpath, char* fnameprefix, uint64_t findex, bool frindexenable, static std::string CreateFileName(char *fpath, char *fprefix,
uint64_t fnum = 0, int dindex = -1, int numunits = 1, int unitindex = 0) uint64_t findex, uint64_t subfindex,
{ int dindex, int numunits = 1,
std::ostringstream osfn; int unitindex = 0) {
osfn << fpath << "/" << fnameprefix; std::ostringstream os;
if (dindex >= 0) osfn << "_d" << (dindex * numunits + unitindex); os << fpath << "/" << fprefix << "_d"
if (frindexenable) osfn << "_f" << std::setfill('0') << std::setw(12) << fnum; << (dindex * numunits + unitindex) << "_f" << subfindex << '_'
osfn << "_" << findex; << findex << ".raw";
osfn << ".raw"; return os.str();
return osfn.str();
} }
/** /**
* Create file names for master file * Create file names for master file
* @param fpath file path * @param fpath file path
* @param fnameprefix file name prefix (includes scan and position variables) * @param fnameprefix file name prefix (includes scan and position variables)
* @param findex file index * @param findex file index
* @returns master file name * @returns master file name
*/ */
std::string CreateMasterFileName(char* fpath, char* fnameprefix, uint64_t findex) static std::string CreateMasterFileName(char *fpath, char *fnameprefix,
{ uint64_t findex) {
std::ostringstream osfn; std::ostringstream os;
osfn << fpath << "/" << fnameprefix; os << fpath << "/" << fnameprefix << "_master"
osfn << "_master"; << "_" << findex << ".raw";
osfn << "_" << findex; return os.str();
osfn << ".raw";
return osfn.str();
} }
/** /**
* Close File * Close File
* @param fd file pointer * @param fd file pointer
*/ */

View File

@ -50,6 +50,8 @@ class File : private virtual slsDetectorDefs {
*/ */
std::string GetCurrentFileName(); std::string GetCurrentFileName();
void resetSubFileIndex();
/** /**
* Print all member values * Print all member values
*/ */
@ -81,30 +83,19 @@ class File : private virtual slsDetectorDefs {
/** /**
* Create file * Create file
* @param fnum current frame index to include in file name
* @returns OK or FAIL * @returns OK or FAIL
*/ */
virtual int CreateFile(uint64_t fnum){ virtual int CreateFile() = 0;
FILE_LOG(logERROR) << "This is a generic function CreateFile that should be "
"overloaded by a derived class";
return OK;
}
/** /**
* Close Current File * Close Current File
*/ */
virtual void CloseCurrentFile() { virtual void CloseCurrentFile() = 0;
FILE_LOG(logERROR) << "This is a generic function CloseCurrentFile that should be "
"overloaded by a derived class";
}
/** /**
* Close Files * Close Files
*/ */
virtual void CloseAllFiles() { virtual void CloseAllFiles() = 0;
FILE_LOG(logERROR) << "This is a generic function that should be overloaded "
"by a derived class";
}
/** /**
* Write data to file * Write data to file
@ -113,11 +104,7 @@ class File : private virtual slsDetectorDefs {
* @param nump number of packets caught * @param nump number of packets caught
* @param OK or FAIL * @param OK or FAIL
*/ */
virtual int WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32_t nump) { virtual int WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32_t nump) = 0;
FILE_LOG(logERROR) << "This is a generic function WriteToFile that "
"should be overloaded by a derived class";
return FAIL;
}
/** /**
* Create master file * Create master file
@ -134,11 +121,7 @@ class File : private virtual slsDetectorDefs {
*/ */
virtual int CreateMasterFile(bool mfwenable, bool en, uint32_t size, virtual int CreateMasterFile(bool mfwenable, bool en, uint32_t size,
uint32_t nx, uint32_t ny, uint64_t at, uint64_t st, uint32_t nx, uint32_t ny, uint64_t at, uint64_t st,
uint64_t sp, uint64_t ap) { uint64_t sp, uint64_t ap) = 0;
FILE_LOG(logERROR) << "This is a generic function CreateMasterFile that "
"should be overloaded by a derived class";
return OK;
}
// HDf5 specific // HDf5 specific
/** /**
@ -151,6 +134,7 @@ class File : private virtual slsDetectorDefs {
"should be overloaded by a derived class"; "should be overloaded by a derived class";
} }
/** /**
* End of Acquisition * End of Acquisition
* @param anyPacketsCaught true if any packets are caught, else false * @param anyPacketsCaught true if any packets are caught, else false
@ -193,6 +177,9 @@ class File : private virtual slsDetectorDefs {
/** File Index */ /** File Index */
uint64_t* fileIndex; uint64_t* fileIndex;
/** Sub file index */
uint64_t subFileIndex{0};
/** Over write enable */ /** Over write enable */
bool* overWriteEnable; bool* overWriteEnable;

View File

@ -69,7 +69,7 @@ class HDF5File : private virtual slsDetectorDefs, public File, public HDF5FileSt
* @param fnum current frame index to include in file name * @param fnum current frame index to include in file name
* @returns OK or FAIL * @returns OK or FAIL
*/ */
int CreateFile(uint64_t fnum); int CreateFile();
/** /**
* Close Current File * Close Current File

View File

@ -40,26 +40,24 @@ public:
* @param fpath file path * @param fpath file path
* @param fnameprefix file name prefix (includes scan and position variables) * @param fnameprefix file name prefix (includes scan and position variables)
* @param findex file index * @param findex file index
* @param frindexenable frame index enable * @param subfindex sub file index
* @param fnum frame number index
* @param dindex readout index * @param dindex readout index
* @param numunits number of units per readout. eg. eiger has 2 udp units per readout * @param numunits number of units per readout. eg. eiger has 2 udp units per readout
* @param unitindex unit index * @param unitindex unit index
* @returns complete file name created * @returns complete file name created
*/ */
static std::string CreateFileName(char* fpath, char* fnameprefix, uint64_t findex, bool frindexenable, static std::string CreateFileName(char *fpath, char *fprefix,
uint64_t fnum = 0, int dindex = -1, int numunits = 1, int unitindex = 0) uint64_t findex, uint64_t subfindex,
{ int dindex, int numunits = 1,
std::ostringstream osfn; int unitindex = 0) {
osfn << fpath << "/" << fnameprefix; std::ostringstream os;
if (dindex >= 0) osfn << "_d" << (dindex * numunits + unitindex); os << fpath << "/" << fprefix << "_d"
if (frindexenable) osfn << "_f" << std::setfill('0') << std::setw(12) << fnum; << (dindex * numunits + unitindex) << "_f" << subfindex << '_'
osfn << "_" << findex; << findex << ".h5";
osfn << ".h5"; return os.str();
return osfn.str();
} }
/** /**
* Create master file name * Create master file name
* @param fpath file path * @param fpath file path
* @param fnameprefix file name prefix (includes scan and position variables) * @param fnameprefix file name prefix (includes scan and position variables)
@ -68,12 +66,10 @@ public:
*/ */
static std::string CreateMasterFileName(char* fpath, char* fnameprefix, uint64_t findex) static std::string CreateMasterFileName(char* fpath, char* fnameprefix, uint64_t findex)
{ {
std::ostringstream osfn; std::ostringstream os;
osfn << fpath << "/" << fnameprefix; os << fpath << "/" << fnameprefix << "_master"
osfn << "_master"; << "_" << findex << ".h5";
osfn << "_" << findex; return os.str();
osfn << ".h5";
return osfn.str();
} }
/** /**
@ -111,7 +107,7 @@ public:
delete fd; delete fd;
fd = 0; fd = 0;
} }
} catch(Exception error) { } catch(const Exception& error) {
FILE_LOG(logERROR) << "Could not close HDF5 handles of index " << ind; FILE_LOG(logERROR) << "Could not close HDF5 handles of index " << ind;
error.printErrorStack(); error.printErrorStack();
} }
@ -129,7 +125,7 @@ public:
delete fd; delete fd;
fd = 0; fd = 0;
} }
} catch(Exception error) { } catch(const Exception& error) {
FILE_LOG(logERROR) << "Could not close master HDF5 handles"; FILE_LOG(logERROR) << "Could not close master HDF5 handles";
error.printErrorStack(); error.printErrorStack();
} }
@ -177,7 +173,7 @@ public:
dset->write(buf, dtype, memspace, *dspace); dset->write(buf, dtype, memspace, *dspace);
memspace.close(); memspace.close();
} }
catch(Exception error){ catch(const Exception& error){
FILE_LOG(logERROR) << "Could not write to file in object " << ind; FILE_LOG(logERROR) << "Could not write to file in object " << ind;
error.printErrorStack(); error.printErrorStack();
return 1; return 1;
@ -239,7 +235,7 @@ public:
dset_para[13]->write((char*)storage, parameterDataTypes[13], memspace, *dspace_para); dset_para[13]->write((char*)storage, parameterDataTypes[13], memspace, *dspace_para);
}i=14; }i=14;
} }
catch(Exception error){ catch(const Exception& error){
FILE_LOG(logERROR) << "Could not write parameters (index:" << i << ") to file in object " << ind; FILE_LOG(logERROR) << "Could not write parameters (index:" << i << ") to file in object " << ind;
error.printErrorStack(); error.printErrorStack();
return 1; return 1;
@ -282,7 +278,7 @@ public:
dspace_para = new DataSpace(dset_para[0]->getSpace()); dspace_para = new DataSpace(dset_para[0]->getSpace());
} }
catch(Exception error){ catch(const Exception& error){
FILE_LOG(logERROR) << "Could not extend dataset in object " << ind; FILE_LOG(logERROR) << "Could not extend dataset in object " << ind;
error.printErrorStack(); error.printErrorStack();
return 1; return 1;
@ -417,7 +413,7 @@ public:
fd->close(); fd->close();
} catch(Exception error) { } catch(const Exception& error) {
FILE_LOG(logERROR) << "Could not create master HDF5 handles"; FILE_LOG(logERROR) << "Could not create master HDF5 handles";
error.printErrorStack(); error.printErrorStack();
if (fd) fd->close(); if (fd) fd->close();
@ -521,7 +517,7 @@ public:
dset_para.push_back(ds); dset_para.push_back(ds);
} }
} }
catch(Exception error){ catch(const Exception& error){
FILE_LOG(logERROR) << "Could not create HDF5 handles in object " << ind; FILE_LOG(logERROR) << "Could not create HDF5 handles in object " << ind;
error.printErrorStack(); error.printErrorStack();
if (fd) fd->close(); if (fd) fd->close();
@ -675,8 +671,9 @@ public:
//source file name //source file name
std::string srcFileName = HDF5FileStatic::CreateFileName(fpath, fnameprefix, findex, std::string srcFileName = HDF5FileStatic::CreateFileName(fpath, fnameprefix, findex,
frindexenable, framesSaved, dindex, numunits, i); j, dindex, numunits, i);
FILE_LOG(logERROR) << srcFileName;
// find relative path // find relative path
std::string relative_srcFileName = srcFileName; std::string relative_srcFileName = srcFileName;
{ {
@ -688,7 +685,7 @@ public:
//source dataset name //source dataset name
std::ostringstream osfn; std::ostringstream osfn;
osfn << "/data"; osfn << "/data";
if (frindexenable) osfn << "_f" << std::setfill('0') << std::setw(12) << framesSaved; if (frindexenable) osfn << "_f" << std::setfill('0') << std::setw(12) << j;
std::string srcDatasetName = osfn.str(); std::string srcDatasetName = osfn.str();
//source dataspace //source dataspace
@ -861,7 +858,7 @@ public:
newDataset->write(data_out,datatype); newDataset->write(data_out,datatype);
newfd->close(); newfd->close();
oldfd->close(); oldfd->close();
} catch(Exception error){ } catch(const Exception& error){
FILE_LOG(logERROR) << "Could not copy virtual files"; FILE_LOG(logERROR) << "Could not copy virtual files";
error.printErrorStack(); error.printErrorStack();
free(data_out); free(data_out);

View File

@ -42,12 +42,12 @@ slsDetectorDefs::fileFormat BinaryFile::GetFileType() {
} }
int BinaryFile::CreateFile(uint64_t fnum) { int BinaryFile::CreateFile() {
numFramesInFile = 0; numFramesInFile = 0;
numActualPacketsInFile = 0; numActualPacketsInFile = 0;
currentFileName = BinaryFileStatic::CreateFileName(filePath, fileNamePrefix, *fileIndex, currentFileName = BinaryFileStatic::CreateFileName(filePath, fileNamePrefix, *fileIndex,
(*numImages > 1), fnum, *detIndex, *numUnitsPerDetector, index); subFileIndex, *detIndex, *numUnitsPerDetector, index);
if (BinaryFileStatic::CreateDataFile(filefd, *overWriteEnable, currentFileName, FILE_BUFFER_SIZE) == FAIL) if (BinaryFileStatic::CreateDataFile(filefd, *overWriteEnable, currentFileName, FILE_BUFFER_SIZE) == FAIL)
return FAIL; return FAIL;
@ -72,7 +72,8 @@ int BinaryFile::WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32_
// check if maxframesperfile = 0 for infinite // check if maxframesperfile = 0 for infinite
if ((*maxFramesPerFile) && (numFramesInFile >= (*maxFramesPerFile))) { if ((*maxFramesPerFile) && (numFramesInFile >= (*maxFramesPerFile))) {
CloseCurrentFile(); CloseCurrentFile();
CreateFile(fnum); ++subFileIndex;
CreateFile();
} }
numFramesInFile++; numFramesInFile++;
numActualPacketsInFile += nump; numActualPacketsInFile += nump;

View File

@ -252,11 +252,12 @@ int DataProcessor::CreateNewFile(bool en, uint64_t nf, uint64_t at, uint64_t st,
if (file == nullptr) if (file == nullptr)
return FAIL; return FAIL;
file->CloseAllFiles(); file->CloseAllFiles();
file->resetSubFileIndex();
if (file->CreateMasterFile(*masterFileWriteEnable, en, generalData->imageSize, if (file->CreateMasterFile(*masterFileWriteEnable, en, generalData->imageSize,
generalData->nPixelsX, generalData->nPixelsY, generalData->nPixelsX, generalData->nPixelsY,
at, st, sp, ap) == FAIL) at, st, sp, ap) == FAIL)
return FAIL; return FAIL;
if (file->CreateFile(currentFrameIndex) == FAIL) if (file->CreateFile() == FAIL)
return FAIL; return FAIL;
return OK; return OK;
} }

View File

@ -38,6 +38,10 @@ std::string File::GetCurrentFileName() {
return currentFileName; return currentFileName;
} }
void File::resetSubFileIndex(){
subFileIndex = 0u;
}
void File::PrintMembers(TLogLevel level) { void File::PrintMembers(TLogLevel level) {
FILE_LOG(level) << "\nGeneral Writer Variables:" << std::endl FILE_LOG(level) << "\nGeneral Writer Variables:" << std::endl
<< "Index: " << index << std::endl << "Index: " << index << std::endl

View File

@ -128,22 +128,23 @@ void HDF5File::UpdateDataType() {
} }
int HDF5File::CreateFile(uint64_t fnum) { int HDF5File::CreateFile() {
numFilesinAcquisition++; numFilesinAcquisition++;
numFramesInFile = 0; numFramesInFile = 0;
numActualPacketsInFile = 0; numActualPacketsInFile = 0;
currentFileName = HDF5FileStatic::CreateFileName(filePath, fileNamePrefix, *fileIndex, currentFileName = HDF5FileStatic::CreateFileName(filePath, fileNamePrefix, *fileIndex,
(*numImages > 1), fnum, *detIndex, *numUnitsPerDetector, index); subFileIndex, *detIndex, *numUnitsPerDetector, index);
//first time //first time
if(!fnum) UpdateDataType(); if(subFileIndex == 0u)
UpdateDataType();
uint64_t framestosave = ((*maxFramesPerFile == 0) ? *numImages : // infinite images uint64_t framestosave = ((*maxFramesPerFile == 0) ? *numImages : // infinite images
(((extNumImages - fnum) > (*maxFramesPerFile)) ? // save up to maximum at a time (((extNumImages - subFileIndex) > (*maxFramesPerFile)) ? // save up to maximum at a time
(*maxFramesPerFile) : (extNumImages-fnum))); (*maxFramesPerFile) : (extNumImages-subFileIndex)));
pthread_mutex_lock(&Mutex); pthread_mutex_lock(&Mutex);
if (HDF5FileStatic::CreateDataFile(index, *overWriteEnable, currentFileName, (*numImages > 1), if (HDF5FileStatic::CreateDataFile(index, *overWriteEnable, currentFileName, (*numImages > 1),
fnum, framestosave, nPixelsY, ((*dynamicRange==4) ? (nPixelsX/2) : nPixelsX), subFileIndex, framestosave, nPixelsY, ((*dynamicRange==4) ? (nPixelsX/2) : nPixelsX),
datatype, filefd, dataspace, dataset, datatype, filefd, dataspace, dataset,
HDF5_WRITER_VERSION, MAX_CHUNKED_IMAGES, HDF5_WRITER_VERSION, MAX_CHUNKED_IMAGES,
dataspace_para, dataset_para, dataspace_para, dataset_para,
@ -199,7 +200,8 @@ int HDF5File::WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32_t
// check if maxframesperfile = 0 for infinite // check if maxframesperfile = 0 for infinite
if ((*maxFramesPerFile) && (numFramesInFile >= (*maxFramesPerFile))) { if ((*maxFramesPerFile) && (numFramesInFile >= (*maxFramesPerFile))) {
CloseCurrentFile(); CloseCurrentFile();
CreateFile(fnum); ++subFileIndex;
CreateFile();
} }
numFramesInFile++; numFramesInFile++;
numActualPacketsInFile += nump; numActualPacketsInFile += nump;

View File

@ -1,24 +1,4 @@
# include_directories( target_sources(tests PRIVATE
# ${PROJECT_SOURCE_DIR}/catch ${CMAKE_CURRENT_SOURCE_DIR}/test-GeneralData.cpp
# ) ${CMAKE_CURRENT_SOURCE_DIR}/test-FileNames.cpp
)
# set(SOURCES
# test.cpp
# test-GeneralData.cpp
# )
#target_sources(tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/test-GeneralData.cpp)
# add_executable(testSlsReceiver ${SOURCES})
# target_link_libraries(testSlsReceiver
# slsSupportLib
# slsDetectorShared
# slsReceiverShared
# pthread
# rt
# )
# set_target_properties(testSlsReceiver PROPERTIES
# RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
# )
# #TODO! Move to automatic test discovery
# add_test(test-testSlsReceiver ${CMAKE_BINARY_DIR}/bin/testSlsReceiver)

View File

@ -0,0 +1,147 @@
#include "BinaryFile.h"
#include "BinaryFileStatic.h"
#ifdef HDF5C
#include "HDF5FileStatic.h"
#endif
#include "catch.hpp"
SCENARIO("File name creation raw files", "[receiver]") {
GIVEN("These parameters and a binary file") {
std::string fpath = "/home/test";
std::string fnameprefix = "hej";
uint64_t findex{0};
uint64_t fnum{0};
int dindex{0};
int numunits{1};
int unitindex{0};
WHEN("called with default arguments and true") {
auto fname = BinaryFileStatic::CreateFileName(
&fpath[0], &fnameprefix[0], findex, fnum, dindex);
THEN("filename contains frame index") {
REQUIRE(fname == "/home/test/hej_d0_f0_0.raw");
}
}
WHEN("the file index is set") {
fnum = 123456;
auto fname = BinaryFileStatic::CreateFileName(
&fpath[0], &fnameprefix[0], findex, fnum, dindex);
THEN("The frame number is in the file name") {
REQUIRE(fname == "/home/test/hej_d0_f123456_0.raw");
}
}
WHEN("setting numunits ") {
dindex = 2;
numunits = 2;
unitindex = 0;
auto fname = BinaryFileStatic::CreateFileName(
&fpath[0], &fnameprefix[0], findex, fnum, dindex, numunits,
unitindex);
unitindex = 1;
auto fname2 = BinaryFileStatic::CreateFileName(
&fpath[0], &fnameprefix[0], findex, fnum, dindex, numunits,
unitindex);
THEN("this gets reflected in d number") {
REQUIRE(fname == "/home/test/hej_d4_f0_0.raw");
REQUIRE(fname2 == "/home/test/hej_d5_f0_0.raw");
}
}
WHEN("measurements index is set") {
findex = 96;
dindex = 0;
auto fname = BinaryFileStatic::CreateFileName(
&fpath[0], &fnameprefix[0], findex, fnum, dindex);
THEN("this is printed in the file name") {
REQUIRE(fname == "/home/test/hej_d0_f0_96.raw");
}
}
}
}
SCENARIO("Creating master file name", "[receiver]") {
GIVEN("these parameters") {
std::string fpath = "/home/test";
std::string fnameprefix = "hej";
uint64_t findex{0};
WHEN("the master file name is created") {
THEN("all parameters are found") {
BinaryFileStatic b;
auto fname =
b.CreateMasterFileName(&fpath[0], &fnameprefix[0], findex);
REQUIRE(fname == "/home/test/hej_master_0.raw");
}
}
WHEN("flie index is changed") {
THEN("its visible in the file name") {
findex = 398;
BinaryFileStatic b;
auto fname =
b.CreateMasterFileName(&fpath[0], &fnameprefix[0], findex);
REQUIRE(fname == "/home/test/hej_master_398.raw");
}
}
}
}
#ifdef HDF5C
SCENARIO("File name creation hdf5 files", "[receiver]") {
GIVEN("Some paramters") {
std::string fpath = "/home/test";
std::string fnameprefix = "hej";
uint64_t findex{0};
uint64_t fnum{0};
int dindex{0};
int numunits{1};
int unitindex{0};
WHEN("called with default arguments and true for frindexenable") {
auto fname = HDF5FileStatic::CreateFileName(
&fpath[0], &fnameprefix[0], findex, fnum, dindex);
THEN("filename contains frame index") {
REQUIRE(fname == "/home/test/hej_d0_f0_0.h5");
}
}
WHEN("the frame number is set") {
fnum = 123456;
auto fname = HDF5FileStatic::CreateFileName(
&fpath[0], &fnameprefix[0], findex, fnum, dindex);
THEN("The frame number is in the file name") {
REQUIRE(fname == "/home/test/hej_d0_f123456_0.h5");
}
}
WHEN("setting numunits ") {
dindex = 2;
numunits = 2;
unitindex = 0;
auto fname = HDF5FileStatic::CreateFileName(
&fpath[0], &fnameprefix[0], findex, fnum, dindex, numunits,
unitindex);
unitindex = 1;
auto fname2 = HDF5FileStatic::CreateFileName(
&fpath[0], &fnameprefix[0], findex, fnum, dindex, numunits,
unitindex);
THEN("this gets reflected in d number") {
REQUIRE(fname == "/home/test/hej_d4_f0_0.h5");
REQUIRE(fname2 == "/home/test/hej_d5_f0_0.h5");
}
}
WHEN("set findex") {
findex = 96;
dindex = 0;
auto fname = HDF5FileStatic::CreateFileName(
&fpath[0], &fnameprefix[0], findex, fnum, dindex);
THEN("this is printed in the file name") {
REQUIRE(fname == "/home/test/hej_d0_f0_96.h5");
}
}
}
}
#endif

View File

@ -9,51 +9,51 @@
// using namespace sls; // using namespace sls;
TEST_CASE("Parse jungfrauctb header", "[receiver]") { // TEST_CASE("Parse jungfrauctb header", "[receiver]") {
struct packet { // struct packet {
unsigned char emptyHeader[6]; // unsigned char emptyHeader[6];
unsigned char reserved[4]; // unsigned char reserved[4];
unsigned char packetNumber[1]; // unsigned char packetNumber[1];
unsigned char frameNumber[3]; // unsigned char frameNumber[3];
unsigned char bunchid[8]; // unsigned char bunchid[8];
unsigned char data[UDP_PACKET_DATA_BYTES]; // unsigned char data[UDP_PACKET_DATA_BYTES];
} __attribute__((packed)); // } __attribute__((packed));
MoenchData data; // MoenchData data;
packet test_packet; // packet test_packet;
test_packet.packetNumber[0] = 53u; // test_packet.packetNumber[0] = 53u;
test_packet.frameNumber[0] = 32u; // test_packet.frameNumber[0] = 32u;
test_packet.frameNumber[1] = 15u; // test_packet.frameNumber[1] = 15u;
test_packet.frameNumber[2] = 91u; // test_packet.frameNumber[2] = 91u;
test_packet.bunchid[0] = 91u; // test_packet.bunchid[0] = 91u;
test_packet.bunchid[1] = 25u; // test_packet.bunchid[1] = 25u;
test_packet.bunchid[2] = 15u; // test_packet.bunchid[2] = 15u;
test_packet.bunchid[3] = 1u; // test_packet.bunchid[3] = 1u;
test_packet.bunchid[4] = 32u; // test_packet.bunchid[4] = 32u;
test_packet.bunchid[5] = 251u; // test_packet.bunchid[5] = 251u;
test_packet.bunchid[6] = 18u; // test_packet.bunchid[6] = 18u;
test_packet.bunchid[7] = 240u; // test_packet.bunchid[7] = 240u;
int index = 0; // int index = 0;
char *packetData = reinterpret_cast<char *>(&test_packet); // char *packetData = reinterpret_cast<char *>(&test_packet);
uint32_t dynamicRange{0}; // uint32_t dynamicRange{0};
bool oddStartingPacket{0}; // bool oddStartingPacket{0};
uint64_t frameNumber{0}; // uint64_t frameNumber{0};
uint32_t packetNumber{0}; // uint32_t packetNumber{0};
uint32_t subFrameNumber{0}; // uint32_t subFrameNumber{0};
uint64_t bunchId{0}; // uint64_t bunchId{0};
data.GetHeaderInfo(index, packetData, dynamicRange, oddStartingPacket, // data.GetHeaderInfo(index, packetData, dynamicRange, oddStartingPacket,
frameNumber, packetNumber, subFrameNumber, bunchId); // frameNumber, packetNumber, subFrameNumber, bunchId);
CHECK(packetNumber == 53); // CHECK(packetNumber == 53);
CHECK(frameNumber == 0x5b0f20); // CHECK(frameNumber == 0x5b0f20);
CHECK(bunchId == 0xf012fb20010f195b); // CHECK(bunchId == 0xf012fb20010f195b);
CHECK(subFrameNumber == -1); // CHECK(subFrameNumber == -1);
} // }
TEST_CASE("Parse header gotthard data", "[receiver]") { TEST_CASE("Parse header gotthard data", "[receiver]") {
GotthardData data; GotthardData data;

View File

@ -2,6 +2,8 @@
#include "catch.hpp" #include "catch.hpp"
#include <exception> #include <exception>
#include <string> #include <string>
// tests to add // tests to add
// help for all docs // help for all docs
// command for all depreciated commands // command for all depreciated commands

View File

@ -38,12 +38,11 @@ if (SLS_USE_RECEIVER)
) )
endif (SLS_USE_RECEIVER) endif (SLS_USE_RECEIVER)
set_target_properties(tests PROPERTIES set_target_properties(tests PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
) )
include(CTest) include(CTest)
include(Catch) include(Catch)
catch_discover_tests(tests) catch_discover_tests(tests)