mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2026-02-19 22:38:43 +01:00
added ReadingMode member to RawMasterFile adapted error in Matterhorntransformer
This commit is contained in:
@@ -71,7 +71,7 @@ ScanParameters::ScanParameters(const bool enabled, const DACIndex dac,
|
||||
const int start, const int stop, const int step,
|
||||
const int64_t settleTime)
|
||||
: m_enabled(enabled), m_dac(dac), m_start(start), m_stop(stop),
|
||||
m_step(step), m_settleTime(settleTime) {};
|
||||
m_step(step), m_settleTime(settleTime){};
|
||||
|
||||
// "[enabled\ndac dac 4\nstart 500\nstop 2200\nstep 5\nsettleTime 100us\n]"
|
||||
ScanParameters::ScanParameters(const std::string &par) {
|
||||
@@ -195,6 +195,30 @@ ScanParameters RawMasterFile::scan_parameters() const {
|
||||
|
||||
std::optional<ROI> RawMasterFile::roi() const { return m_roi; }
|
||||
|
||||
ReadingMode RawMasterFile::get_reading_mode() const {
|
||||
|
||||
if (m_type != DetectorType::ChipTestBoard &&
|
||||
m_type != DetectorType::Xilinx_ChipTestBoard) {
|
||||
LOG(TLogLevel::logINFO)
|
||||
<< "reading mode is only available for CTB detectors.";
|
||||
return ReadingMode::Unknown;
|
||||
}
|
||||
|
||||
if (m_analog_flag && m_digital_flag) {
|
||||
return ReadingMode::AnalogAndDigital;
|
||||
} else if (m_analog_flag) {
|
||||
return ReadingMode::Analog;
|
||||
} else if (m_digital_flag && m_transceiver_flag) {
|
||||
return ReadingMode::DigitalAndTransceiver;
|
||||
} else if (m_digital_flag) {
|
||||
return ReadingMode::Digital;
|
||||
} else if (m_transceiver_flag) {
|
||||
return ReadingMode::Transceiver;
|
||||
} else {
|
||||
return ReadingMode::Unknown;
|
||||
}
|
||||
}
|
||||
|
||||
void RawMasterFile::parse_json(std::istream &is) {
|
||||
json j;
|
||||
is >> j;
|
||||
@@ -205,10 +229,10 @@ void RawMasterFile::parse_json(std::istream &is) {
|
||||
m_type = string_to<DetectorType>(j["Detector Type"].get<std::string>());
|
||||
m_timing_mode = string_to<TimingMode>(j["Timing Mode"].get<std::string>());
|
||||
|
||||
m_geometry = {
|
||||
j["Geometry"]["y"],
|
||||
j["Geometry"]["x"]}; // TODO: isnt it only available for version > 7.1?
|
||||
// - try block default should be 1x1
|
||||
m_geometry = {j["Geometry"]["y"],
|
||||
j["Geometry"]["x"]}; // TODO: isnt it only available for
|
||||
// version > 7.1?
|
||||
// - try block default should be 1x1
|
||||
|
||||
m_image_size_in_bytes =
|
||||
v < 8.0 ? j["Image Size in bytes"] : j["Image Size"];
|
||||
@@ -244,7 +268,7 @@ void RawMasterFile::parse_json(std::istream &is) {
|
||||
// TODO! Not valid for CTB but not changing api right now!
|
||||
// Not all detectors write the bitdepth but in case
|
||||
// its not there it is 16
|
||||
if(j.contains("Dynamic Range") && j["Dynamic Range"].is_number()){
|
||||
if (j.contains("Dynamic Range") && j["Dynamic Range"].is_number()) {
|
||||
m_bitdepth = j["Dynamic Range"];
|
||||
} else {
|
||||
m_bitdepth = 16;
|
||||
@@ -255,18 +279,18 @@ void RawMasterFile::parse_json(std::istream &is) {
|
||||
m_frame_discard_policy = string_to<FrameDiscardPolicy>(
|
||||
j["Frame Discard Policy"].get<std::string>());
|
||||
|
||||
if(j.contains("Number of rows") && j["Number of rows"].is_number()){
|
||||
if (j.contains("Number of rows") && j["Number of rows"].is_number()) {
|
||||
m_number_of_rows = j["Number of rows"];
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// Special treatment of analog flag because of Moench03
|
||||
try {
|
||||
m_analog_flag = j.at("Analog Flag");
|
||||
m_analog_flag = static_cast<bool>(j.at("Analog Flag").get<int>());
|
||||
} catch (const json::out_of_range &e) {
|
||||
// if it doesn't work still set it to one
|
||||
// to try to decode analog samples (Old Moench03)
|
||||
m_analog_flag = 1;
|
||||
m_analog_flag = true;
|
||||
}
|
||||
try {
|
||||
if (m_analog_flag) {
|
||||
@@ -276,7 +300,7 @@ void RawMasterFile::parse_json(std::istream &is) {
|
||||
} catch (const json::out_of_range &e) {
|
||||
// keep the optional empty
|
||||
// and set analog flag to 0
|
||||
m_analog_flag = 0;
|
||||
m_analog_flag = false;
|
||||
}
|
||||
//-----------------------------------------------------------------
|
||||
try {
|
||||
@@ -291,7 +315,7 @@ void RawMasterFile::parse_json(std::istream &is) {
|
||||
// m_adc_mask = 0;
|
||||
// }
|
||||
try {
|
||||
int digital_flag = j.at("Digital Flag");
|
||||
bool digital_flag = static_cast<bool>(j.at("Digital Flag").get<int>());
|
||||
if (digital_flag) {
|
||||
m_digital_samples = j.at("Digital Samples");
|
||||
}
|
||||
@@ -299,7 +323,8 @@ void RawMasterFile::parse_json(std::istream &is) {
|
||||
// keep the optional empty
|
||||
}
|
||||
try {
|
||||
m_transceiver_flag = j.at("Transceiver Flag");
|
||||
m_transceiver_flag =
|
||||
static_cast<bool>(j.at("Transceiver Flag").get<int>());
|
||||
if (m_transceiver_flag) {
|
||||
m_transceiver_samples = j.at("Transceiver Samples");
|
||||
}
|
||||
@@ -379,7 +404,6 @@ void RawMasterFile::parse_json(std::istream &is) {
|
||||
m_counter_mask =
|
||||
std::stoi(j["Counter Mask"].get<std::string>(), nullptr, 16);
|
||||
}
|
||||
|
||||
|
||||
// Update detector type for Moench
|
||||
// TODO! How does this work with old .raw master files?
|
||||
@@ -433,9 +457,9 @@ void RawMasterFile::parse_raw(std::istream &is) {
|
||||
// } else if (key == "Number of rows"){
|
||||
// m_number_of_rows = std::stoi(value);
|
||||
} else if (key == "Analog Flag") {
|
||||
m_analog_flag = std::stoi(value);
|
||||
m_analog_flag = static_cast<bool>(std::stoi(value));
|
||||
} else if (key == "Digital Flag") {
|
||||
m_digital_flag = std::stoi(value);
|
||||
m_digital_flag = static_cast<bool>(std::stoi(value));
|
||||
|
||||
} else if (key == "Analog Samples") {
|
||||
if (m_analog_flag == 1) {
|
||||
|
||||
@@ -146,6 +146,8 @@ TEST_CASE("Parse a master file in .json format", "[.integration]") {
|
||||
|
||||
REQUIRE_FALSE(f.analog_samples());
|
||||
REQUIRE_FALSE(f.digital_samples());
|
||||
|
||||
REQUIRE(f.get_reading_mode() == ReadingMode::Unknown);
|
||||
}
|
||||
|
||||
TEST_CASE("Parse a master file in old .raw format",
|
||||
@@ -211,6 +213,8 @@ TEST_CASE("Parse a master file in .raw format", "[.integration]") {
|
||||
// Frames in File : 100
|
||||
REQUIRE(f.frames_in_file() == 100);
|
||||
|
||||
REQUIRE(f.get_reading_mode() == ReadingMode::Unknown);
|
||||
|
||||
// #Frame Header
|
||||
// Frame Number : 8 bytes
|
||||
// SubFrame Number/ExpLength : 4 bytes
|
||||
@@ -398,7 +402,7 @@ TEST_CASE("Parse EIGER 7.2 master from string stream") {
|
||||
REQUIRE(f.timing_mode() == TimingMode::Auto);
|
||||
REQUIRE(f.geometry().col == 2);
|
||||
REQUIRE(f.geometry().row == 2);
|
||||
|
||||
|
||||
REQUIRE(f.image_size_in_bytes() == 524288);
|
||||
REQUIRE(f.pixels_x() == 512);
|
||||
REQUIRE(f.pixels_y() == 256);
|
||||
@@ -560,6 +564,7 @@ TEST_CASE("Parse a CTB file from stream") {
|
||||
REQUIRE(f.digital_samples() == std::nullopt); // Digital Flag is 0
|
||||
REQUIRE(f.transceiver_samples() == 1152);
|
||||
REQUIRE(f.frames_in_file() == 40);
|
||||
REQUIRE(f.get_reading_mode() == ReadingMode::Transceiver);
|
||||
}
|
||||
|
||||
TEST_CASE("Parse v8.0 MYTHEN3 from stream") {
|
||||
|
||||
@@ -75,35 +75,32 @@ TEST_CASE("test_apply_custom_weights") {
|
||||
CHECK_THAT(output, WithinAbs(6.34, 0.001));
|
||||
}
|
||||
|
||||
TEST_CASE("Mask 32 bit unsigned integer to 24 bit"){
|
||||
//any number less than 2**24 (16777216) should be the same
|
||||
CHECK(aare::mask32to24bits(0)==0);
|
||||
CHECK(aare::mask32to24bits(19)==19);
|
||||
CHECK(aare::mask32to24bits(29875)==29875);
|
||||
CHECK(aare::mask32to24bits(1092177)==1092177);
|
||||
CHECK(aare::mask32to24bits(0xFFFF)==0xFFFF);
|
||||
CHECK(aare::mask32to24bits(0xFFFFFFFF)==0xFFFFFF);
|
||||
TEST_CASE("Mask 32 bit unsigned integer to 24 bit") {
|
||||
// any number less than 2**24 (16777216) should be the same
|
||||
CHECK(aare::mask32to24bits(0) == 0);
|
||||
CHECK(aare::mask32to24bits(19) == 19);
|
||||
CHECK(aare::mask32to24bits(29875) == 29875);
|
||||
CHECK(aare::mask32to24bits(1092177) == 1092177);
|
||||
CHECK(aare::mask32to24bits(0xFFFF) == 0xFFFF);
|
||||
CHECK(aare::mask32to24bits(0xFFFFFFFF) == 0xFFFFFF);
|
||||
|
||||
// Offset specifies that the should ignore 0-7 bits
|
||||
// at the start
|
||||
CHECK(aare::mask32to24bits(0xFFFF, BitOffset(4))==0xFFF);
|
||||
CHECK(aare::mask32to24bits(0xFF0000d9)==0xd9);
|
||||
CHECK(aare::mask32to24bits(0xFF000d9F, BitOffset(4))==0xF000d9);
|
||||
CHECK(aare::mask32to24bits(16777217)==1);
|
||||
CHECK(aare::mask32to24bits(15,BitOffset(7))==0);
|
||||
|
||||
//Highest bit set to 1 should just be excluded
|
||||
//lowest 4 bits set to 1
|
||||
CHECK(aare::mask32to24bits(0x8000000f,BitOffset(7))==0);
|
||||
|
||||
CHECK(aare::mask32to24bits(0xFFFF, BitOffset(4)) == 0xFFF);
|
||||
CHECK(aare::mask32to24bits(0xFF0000d9) == 0xd9);
|
||||
CHECK(aare::mask32to24bits(0xFF000d9F, BitOffset(4)) == 0xF000d9);
|
||||
CHECK(aare::mask32to24bits(16777217) == 1);
|
||||
CHECK(aare::mask32to24bits(15, BitOffset(7)) == 0);
|
||||
|
||||
// Highest bit set to 1 should just be excluded
|
||||
// lowest 4 bits set to 1
|
||||
CHECK(aare::mask32to24bits(0x8000000f, BitOffset(7)) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("Expand container with 24 bit data to 32"){
|
||||
TEST_CASE("Expand container with 24 bit data to 32") {
|
||||
{
|
||||
uint8_t buffer[] = {
|
||||
0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
};
|
||||
|
||||
aare::NDView<uint8_t, 1> input(&buffer[0], {9});
|
||||
@@ -116,9 +113,7 @@ TEST_CASE("Expand container with 24 bit data to 32"){
|
||||
}
|
||||
{
|
||||
uint8_t buffer[] = {
|
||||
0x0F, 0x00, 0x00,
|
||||
0xFF, 0x00, 0x00,
|
||||
0xFF, 0xFF, 0xFF,
|
||||
0x0F, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF,
|
||||
};
|
||||
|
||||
aare::NDView<uint8_t, 1> input(&buffer[0], {9});
|
||||
@@ -131,9 +126,7 @@ TEST_CASE("Expand container with 24 bit data to 32"){
|
||||
}
|
||||
{
|
||||
uint8_t buffer[] = {
|
||||
0x00, 0x00, 0xFF,
|
||||
0xFF, 0xFF, 0x00,
|
||||
0x00, 0xFF, 0x00,
|
||||
0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0x00,
|
||||
};
|
||||
|
||||
aare::NDView<uint8_t, 1> input(&buffer[0], {9});
|
||||
@@ -147,20 +140,36 @@ TEST_CASE("Expand container with 24 bit data to 32"){
|
||||
REQUIRE_THROWS(aare::expand24to32bit(input, out.view(), BitOffset(4)));
|
||||
}
|
||||
{
|
||||
//For use with offset we need an extra byte
|
||||
uint8_t buffer[] = {
|
||||
0x00, 0x00, 0xFF,
|
||||
0xFF, 0xFF, 0x00,
|
||||
0x00, 0xFF, 0x00, 0x00
|
||||
};
|
||||
// For use with offset we need an extra byte
|
||||
uint8_t buffer[] = {0x00, 0x00, 0xFF, 0xFF, 0xFF,
|
||||
0x00, 0x00, 0xFF, 0x00, 0x00};
|
||||
|
||||
aare::NDView<uint8_t, 1> input(&buffer[0], {10});
|
||||
aare::NDArray<uint32_t, 1> out({3}); //still output.size == 3
|
||||
aare::NDArray<uint32_t, 1> out({3}); // still output.size == 3
|
||||
aare::expand24to32bit(input, out.view(), BitOffset(4));
|
||||
|
||||
CHECK(out(0) == 0xFFF000);
|
||||
CHECK(out(1) == 0xFFF);
|
||||
CHECK(out(2) == 0xFF0);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Expand 4 bit values packed into 8 bit to 8 bit values") {
|
||||
{
|
||||
uint8_t buffer[] = {
|
||||
0x00, 0xF0, 0xFF, 0x00, 0xF0, 0xFF,
|
||||
};
|
||||
|
||||
aare::NDView<uint8_t, 1> input(&buffer[0], {6});
|
||||
aare::NDArray<uint8_t, 1> out({12});
|
||||
aare::expand4to8bit(input, out.view());
|
||||
|
||||
uint8_t expected_output[] = {
|
||||
0x0, 0x0, 0x0, 0xF, 0xF, 0xF,
|
||||
0x0, 0x0, 0x0, 0xF, 0xF, 0xF}; // is it first little or big endian?
|
||||
|
||||
for (size_t i = 0; i < 12; ++i) {
|
||||
CHECK(out(i) == expected_output[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user