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

@ -1,24 +1,4 @@
# include_directories(
# ${PROJECT_SOURCE_DIR}/catch
# )
# 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)
target_sources(tests PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/test-GeneralData.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test-FileNames.cpp
)

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