diff --git a/include/aare/defs.hpp b/include/aare/defs.hpp index fdb1734..35b9624 100644 --- a/include/aare/defs.hpp +++ b/include/aare/defs.hpp @@ -190,14 +190,27 @@ struct ModuleGeometry{ using dynamic_shape = std::vector; //TODO! Can we uniform enums between the libraries? + +/** + * @brief Enum class to identify different detectors. + * The values are the same as in slsDetectorPackage + * Different spelling to avoid confusion with the slsDetectorPackage + */ enum class DetectorType { - Jungfrau, + //Standard detectors match the enum values from slsDetectorPackage + Generic, Eiger, - Mythen3, - Moench, - Moench03, - Moench03_old, + Gotthard, + Jungfrau, ChipTestBoard, + Moench, + Mythen3, + Gotthard2, + Xilinx_ChipTestBoard, + + //Additional detectors used for defining processing. Variants of the standard ones. + Moench03=100, + Moench03_old, Unknown }; diff --git a/src/defs.cpp b/src/defs.cpp index 16fa3d0..7c7cc45 100644 --- a/src/defs.cpp +++ b/src/defs.cpp @@ -21,23 +21,37 @@ void assert_failed(const std::string &msg) */ template <> std::string ToString(DetectorType arg) { switch (arg) { - case DetectorType::Jungfrau: - return "Jungfrau"; + case DetectorType::Generic: + return "Generic"; case DetectorType::Eiger: return "Eiger"; - case DetectorType::Mythen3: - return "Mythen3"; + case DetectorType::Gotthard: + return "Gotthard"; + case DetectorType::Jungfrau: + return "Jungfrau"; + case DetectorType::ChipTestBoard: + return "ChipTestBoard"; case DetectorType::Moench: return "Moench"; + case DetectorType::Mythen3: + return "Mythen3"; + case DetectorType::Gotthard2: + return "Gotthard2"; + case DetectorType::Xilinx_ChipTestBoard: + return "Xilinx_ChipTestBoard"; + + //Custom ones case DetectorType::Moench03: return "Moench03"; case DetectorType::Moench03_old: return "Moench03_old"; - case DetectorType::ChipTestBoard: - return "ChipTestBoard"; - default: + case DetectorType::Unknown: return "Unknown"; + + //no default case to trigger compiler warning if not all + //enum values are handled } + throw std::runtime_error("Could not decode detector to string"); } /** @@ -47,21 +61,34 @@ template <> std::string ToString(DetectorType arg) { * @throw runtime_error if the string does not match any DetectorType */ template <> DetectorType StringTo(const std::string &arg) { - if (arg == "Jungfrau") - return DetectorType::Jungfrau; + if (arg == "Generic") + return DetectorType::Generic; if (arg == "Eiger") return DetectorType::Eiger; - if (arg == "Mythen3") - return DetectorType::Mythen3; + if (arg == "Gotthard") + return DetectorType::Gotthard; + if (arg == "Jungfrau") + return DetectorType::Jungfrau; + if (arg == "ChipTestBoard") + return DetectorType::ChipTestBoard; if (arg == "Moench") return DetectorType::Moench; + if (arg == "Mythen3") + return DetectorType::Mythen3; + if (arg == "Gotthard2") + return DetectorType::Gotthard2; + if (arg == "Xilinx_ChipTestBoard") + return DetectorType::Xilinx_ChipTestBoard; + + //Custom ones if (arg == "Moench03") return DetectorType::Moench03; if (arg == "Moench03_old") return DetectorType::Moench03_old; - if (arg == "ChipTestBoard") - return DetectorType::ChipTestBoard; - throw std::runtime_error("Could not decode dector from: \"" + arg + "\""); + if (arg == "Unknown") + return DetectorType::Unknown; + + throw std::runtime_error("Could not decode detector from: \"" + arg + "\""); } /** diff --git a/src/defs.test.cpp b/src/defs.test.cpp index b001f62..6ab9394 100644 --- a/src/defs.test.cpp +++ b/src/defs.test.cpp @@ -1,12 +1,59 @@ #include "aare/defs.hpp" -// #include "aare/utils/floats.hpp" #include #include + +using aare::ToString; +using aare::StringTo; + TEST_CASE("Enum to string conversion") { - // By the way I don't think the enum string conversions should be in the defs.hpp file + // TODO! By the way I don't think the enum string conversions should be in the defs.hpp file // but let's use this to show a test + REQUIRE(ToString(aare::DetectorType::Generic) == "Generic"); + REQUIRE(ToString(aare::DetectorType::Eiger) == "Eiger"); + REQUIRE(ToString(aare::DetectorType::Gotthard) == "Gotthard"); REQUIRE(ToString(aare::DetectorType::Jungfrau) == "Jungfrau"); + REQUIRE(ToString(aare::DetectorType::ChipTestBoard) == "ChipTestBoard"); + REQUIRE(ToString(aare::DetectorType::Moench) == "Moench"); + REQUIRE(ToString(aare::DetectorType::Mythen3) == "Mythen3"); + REQUIRE(ToString(aare::DetectorType::Gotthard2) == "Gotthard2"); + REQUIRE(ToString(aare::DetectorType::Xilinx_ChipTestBoard) == "Xilinx_ChipTestBoard"); + REQUIRE(ToString(aare::DetectorType::Moench03) == "Moench03"); + REQUIRE(ToString(aare::DetectorType::Moench03_old) == "Moench03_old"); + REQUIRE(ToString(aare::DetectorType::Unknown) == "Unknown"); +} + +TEST_CASE("String to enum"){ + REQUIRE(StringTo("Generic") == aare::DetectorType::Generic); + REQUIRE(StringTo("Eiger") == aare::DetectorType::Eiger); + REQUIRE(StringTo("Gotthard") == aare::DetectorType::Gotthard); + REQUIRE(StringTo("Jungfrau") == aare::DetectorType::Jungfrau); + REQUIRE(StringTo("ChipTestBoard") == aare::DetectorType::ChipTestBoard); + REQUIRE(StringTo("Moench") == aare::DetectorType::Moench); + REQUIRE(StringTo("Mythen3") == aare::DetectorType::Mythen3); + REQUIRE(StringTo("Gotthard2") == aare::DetectorType::Gotthard2); + REQUIRE(StringTo("Xilinx_ChipTestBoard") == aare::DetectorType::Xilinx_ChipTestBoard); + REQUIRE(StringTo("Moench03") == aare::DetectorType::Moench03); + REQUIRE(StringTo("Moench03_old") == aare::DetectorType::Moench03_old); + REQUIRE(StringTo("Unknown") == aare::DetectorType::Unknown); +} + +TEST_CASE("Enum values"){ + //Since some of the enums are written to file we need to make sure + //they match the value in the slsDetectorPackage + + REQUIRE(static_cast(aare::DetectorType::Generic) == 0); + REQUIRE(static_cast(aare::DetectorType::Eiger) == 1); + REQUIRE(static_cast(aare::DetectorType::Gotthard) == 2); + REQUIRE(static_cast(aare::DetectorType::Jungfrau) == 3); + REQUIRE(static_cast(aare::DetectorType::ChipTestBoard) == 4); + REQUIRE(static_cast(aare::DetectorType::Moench) == 5); + REQUIRE(static_cast(aare::DetectorType::Mythen3) == 6); + REQUIRE(static_cast(aare::DetectorType::Gotthard2) == 7); + REQUIRE(static_cast(aare::DetectorType::Xilinx_ChipTestBoard) == 8); + + //Not included + REQUIRE(static_cast(aare::DetectorType::Moench03) == 100); } TEST_CASE("DynamicCluster creation") {