added missing enums (#111)

- Missing enums
- Matching values to slsDetectorPackage
- tests
This commit is contained in:
Erik Fröjdh 2024-11-29 15:28:19 +01:00 committed by GitHub
commit 6fd52f6b8d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 108 additions and 21 deletions

View File

@ -190,14 +190,27 @@ struct ModuleGeometry{
using dynamic_shape = std::vector<int64_t>; using dynamic_shape = std::vector<int64_t>;
//TODO! Can we uniform enums between the libraries? //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 { enum class DetectorType {
Jungfrau, //Standard detectors match the enum values from slsDetectorPackage
Generic,
Eiger, Eiger,
Mythen3, Gotthard,
Moench, Jungfrau,
Moench03,
Moench03_old,
ChipTestBoard, ChipTestBoard,
Moench,
Mythen3,
Gotthard2,
Xilinx_ChipTestBoard,
//Additional detectors used for defining processing. Variants of the standard ones.
Moench03=100,
Moench03_old,
Unknown Unknown
}; };

View File

@ -21,23 +21,37 @@ void assert_failed(const std::string &msg)
*/ */
template <> std::string ToString(DetectorType arg) { template <> std::string ToString(DetectorType arg) {
switch (arg) { switch (arg) {
case DetectorType::Jungfrau: case DetectorType::Generic:
return "Jungfrau"; return "Generic";
case DetectorType::Eiger: case DetectorType::Eiger:
return "Eiger"; return "Eiger";
case DetectorType::Mythen3: case DetectorType::Gotthard:
return "Mythen3"; return "Gotthard";
case DetectorType::Jungfrau:
return "Jungfrau";
case DetectorType::ChipTestBoard:
return "ChipTestBoard";
case DetectorType::Moench: case DetectorType::Moench:
return "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: case DetectorType::Moench03:
return "Moench03"; return "Moench03";
case DetectorType::Moench03_old: case DetectorType::Moench03_old:
return "Moench03_old"; return "Moench03_old";
case DetectorType::ChipTestBoard: case DetectorType::Unknown:
return "ChipTestBoard";
default:
return "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 * @throw runtime_error if the string does not match any DetectorType
*/ */
template <> DetectorType StringTo(const std::string &arg) { template <> DetectorType StringTo(const std::string &arg) {
if (arg == "Jungfrau") if (arg == "Generic")
return DetectorType::Jungfrau; return DetectorType::Generic;
if (arg == "Eiger") if (arg == "Eiger")
return DetectorType::Eiger; return DetectorType::Eiger;
if (arg == "Mythen3") if (arg == "Gotthard")
return DetectorType::Mythen3; return DetectorType::Gotthard;
if (arg == "Jungfrau")
return DetectorType::Jungfrau;
if (arg == "ChipTestBoard")
return DetectorType::ChipTestBoard;
if (arg == "Moench") if (arg == "Moench")
return DetectorType::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") if (arg == "Moench03")
return DetectorType::Moench03; return DetectorType::Moench03;
if (arg == "Moench03_old") if (arg == "Moench03_old")
return DetectorType::Moench03_old; return DetectorType::Moench03_old;
if (arg == "ChipTestBoard") if (arg == "Unknown")
return DetectorType::ChipTestBoard; return DetectorType::Unknown;
throw std::runtime_error("Could not decode dector from: \"" + arg + "\"");
throw std::runtime_error("Could not decode detector from: \"" + arg + "\"");
} }
/** /**

View File

@ -1,12 +1,59 @@
#include "aare/defs.hpp" #include "aare/defs.hpp"
// #include "aare/utils/floats.hpp"
#include <catch2/catch_test_macros.hpp> #include <catch2/catch_test_macros.hpp>
#include <string> #include <string>
using aare::ToString;
using aare::StringTo;
TEST_CASE("Enum to string conversion") { 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 // 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::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<aare::DetectorType>("Generic") == aare::DetectorType::Generic);
REQUIRE(StringTo<aare::DetectorType>("Eiger") == aare::DetectorType::Eiger);
REQUIRE(StringTo<aare::DetectorType>("Gotthard") == aare::DetectorType::Gotthard);
REQUIRE(StringTo<aare::DetectorType>("Jungfrau") == aare::DetectorType::Jungfrau);
REQUIRE(StringTo<aare::DetectorType>("ChipTestBoard") == aare::DetectorType::ChipTestBoard);
REQUIRE(StringTo<aare::DetectorType>("Moench") == aare::DetectorType::Moench);
REQUIRE(StringTo<aare::DetectorType>("Mythen3") == aare::DetectorType::Mythen3);
REQUIRE(StringTo<aare::DetectorType>("Gotthard2") == aare::DetectorType::Gotthard2);
REQUIRE(StringTo<aare::DetectorType>("Xilinx_ChipTestBoard") == aare::DetectorType::Xilinx_ChipTestBoard);
REQUIRE(StringTo<aare::DetectorType>("Moench03") == aare::DetectorType::Moench03);
REQUIRE(StringTo<aare::DetectorType>("Moench03_old") == aare::DetectorType::Moench03_old);
REQUIRE(StringTo<aare::DetectorType>("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<int>(aare::DetectorType::Generic) == 0);
REQUIRE(static_cast<int>(aare::DetectorType::Eiger) == 1);
REQUIRE(static_cast<int>(aare::DetectorType::Gotthard) == 2);
REQUIRE(static_cast<int>(aare::DetectorType::Jungfrau) == 3);
REQUIRE(static_cast<int>(aare::DetectorType::ChipTestBoard) == 4);
REQUIRE(static_cast<int>(aare::DetectorType::Moench) == 5);
REQUIRE(static_cast<int>(aare::DetectorType::Mythen3) == 6);
REQUIRE(static_cast<int>(aare::DetectorType::Gotthard2) == 7);
REQUIRE(static_cast<int>(aare::DetectorType::Xilinx_ChipTestBoard) == 8);
//Not included
REQUIRE(static_cast<int>(aare::DetectorType::Moench03) == 100);
} }
TEST_CASE("DynamicCluster creation") { TEST_CASE("DynamicCluster creation") {