From 1fffc70e6da482fabf860aed630a1608fb54ed3e Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Thu, 31 Oct 2024 13:21:06 +0000 Subject: [PATCH 1/5] Rich/Types.h: Add new Array class with specifically typed index check --- Detector/Rich/include/Detector/Rich/Types.h | 42 ++++++++++++++++++++- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/Detector/Rich/include/Detector/Rich/Types.h b/Detector/Rich/include/Detector/Rich/Types.h index 9e32436c33..8a4f1c152a 100644 --- a/Detector/Rich/include/Detector/Rich/Types.h +++ b/Detector/Rich/include/Detector/Rich/Types.h @@ -20,11 +20,12 @@ #include "Math/Point3D.h" #include "Math/Vector3D.h" -// STL files +// STL #include #include #include #include +#include #include // Hack to work around cling issue @@ -52,7 +53,8 @@ namespace Rich { }; /// Detector side enum - enum Side : int32_t { + /// FixMe: Check if underlying type here can be reduced to int8_t ? + enum Side : std::int32_t { InvalidSide = -1, ///< Invalid side // RICH1 top = 0, ///< Upper panel in RICH1 @@ -94,6 +96,42 @@ namespace Rich { template using RadiatorArray = std::array; + /// Array class with enforced index type + template + struct TypedIndexArray : public std::array { + // Only allow the defined index type in access calls + template + T& operator[]( const I index ) { + static_assert( std::is_same_v ); + return this->std::array::operator[]( index ); + } + template + const T& operator[]( const I index ) const { + static_assert( std::is_same_v ); + return this->std::array::operator[]( index ); + } + template + T& at( const I index ) { + static_assert( std::is_same_v ); + return this->std::array::at( index ); + } + template + const T& at( const I index ) const { + static_assert( std::is_same_v ); + return this->std::array::at( index ); + } + }; + + /// Type for enforced index type fixed size arrays for data for each RICH + template + using DetectorEnumArray = TypedIndexArray; + /// Type for enforced index type fixed size arrays with RICH panel information + template + using PanelEnumArray = TypedIndexArray; + /// Type for enforced index type fixed size arrays with radiator information + template + using RadiatorEnumArray = TypedIndexArray; + /// Type for container of detector types using Detectors = boost::container::small_vector; /// Type for container of side types -- GitLab From 512e46dfa7a88d18440d17276844e5a7fd9aac8c Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Mon, 4 Nov 2024 11:31:27 +0000 Subject: [PATCH 2/5] Rich/Types.h: Remove cling/clang workaround --- Detector/Rich/include/Detector/Rich/Types.h | 24 ++++++--------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/Detector/Rich/include/Detector/Rich/Types.h b/Detector/Rich/include/Detector/Rich/Types.h index 8a4f1c152a..5bfb97e1dd 100644 --- a/Detector/Rich/include/Detector/Rich/Types.h +++ b/Detector/Rich/include/Detector/Rich/Types.h @@ -28,21 +28,16 @@ #include #include -// Hack to work around cling issue -#define N_SIDE_TYPES 2 -#define N_DETECTOR_TYPES 2 -#define N_RADIATOR_TYPES 3 - namespace Rich { /// Number of RICH detectors - inline constexpr std::uint16_t NRiches = N_DETECTOR_TYPES; + inline constexpr std::uint16_t NRiches = 2u; /// Number of PD panels per RICH detector - inline constexpr uint16_t NPDPanelsPerRICH = N_SIDE_TYPES; + inline constexpr std::uint16_t NPDPanelsPerRICH = 2u; /// Total number of PD panels - inline constexpr uint16_t NTotalPDPanels = NRiches * NPDPanelsPerRICH; + inline constexpr std::uint16_t NTotalPDPanels = NRiches * NPDPanelsPerRICH; /// Number of RICH radiators - inline constexpr std::uint16_t NRadiatorTypes = N_RADIATOR_TYPES; + inline constexpr std::uint16_t NRadiatorTypes = 3u; /// RICH enum enum DetectorType : std::int8_t { @@ -133,11 +128,11 @@ namespace Rich { using RadiatorEnumArray = TypedIndexArray; /// Type for container of detector types - using Detectors = boost::container::small_vector; + using Detectors = boost::container::small_vector; /// Type for container of side types - using Sides = boost::container::small_vector; + using Sides = boost::container::small_vector; /// Type for container of radiator types - using Radiators = boost::container::small_vector; + using Radiators = boost::container::small_vector; /// Access all valid detector types inline Detectors detectors() noexcept { return {Rich::Rich1, Rich::Rich2}; } @@ -148,11 +143,6 @@ namespace Rich { } // namespace Rich -// remove clang hack -#undef N_SIDE_TYPES -#undef N_DETECTOR_TYPES -#undef N_RADIATOR_TYPES - namespace Rich::Detector { // Geometrical Types -- GitLab From 0f9b07bdb3ebf5160e5fca1f3deaa981261b1c7b Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Mon, 4 Nov 2024 11:33:38 +0000 Subject: [PATCH 3/5] Rich/Types.h: Make Rich::Side an 8 bit int --- Detector/Rich/include/Detector/Rich/Types.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Detector/Rich/include/Detector/Rich/Types.h b/Detector/Rich/include/Detector/Rich/Types.h index 5bfb97e1dd..415120b3f9 100644 --- a/Detector/Rich/include/Detector/Rich/Types.h +++ b/Detector/Rich/include/Detector/Rich/Types.h @@ -48,8 +48,7 @@ namespace Rich { }; /// Detector side enum - /// FixMe: Check if underlying type here can be reduced to int8_t ? - enum Side : std::int32_t { + enum Side : std::int8_t { InvalidSide = -1, ///< Invalid side // RICH1 top = 0, ///< Upper panel in RICH1 -- GitLab From a25c6a3e88b1a33674c52e45d602597612f424db Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Mon, 4 Nov 2024 13:33:13 +0000 Subject: [PATCH 4/5] remove unused boost version header --- Detector/Rich/include/Detector/Rich/Types.h | 1 - 1 file changed, 1 deletion(-) diff --git a/Detector/Rich/include/Detector/Rich/Types.h b/Detector/Rich/include/Detector/Rich/Types.h index 415120b3f9..ab30e8aeb0 100644 --- a/Detector/Rich/include/Detector/Rich/Types.h +++ b/Detector/Rich/include/Detector/Rich/Types.h @@ -13,7 +13,6 @@ // Boost #include -#include // ROOT #include "Math/Plane3D.h" -- GitLab From 9d8e50ffbc3734f427abf447322f7295e0507908 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Thu, 14 Nov 2024 13:41:46 +0000 Subject: [PATCH 5/5] Add detector enum to RICH mirror objects --- Detector/Rich/include/Detector/Rich/DeRichMirror.h | 12 +++++++----- Detector/Rich1/src/Rich1DEA/DeRich1Mirror1.cpp | 3 +++ Detector/Rich1/src/Rich1DEA/DeRich1Mirror2.cpp | 3 +++ Detector/Rich2/src/Rich2DEA/DeRich2SecMirror.cpp | 3 +++ Detector/Rich2/src/Rich2DEA/DeRich2SphMirror.cpp | 3 +++ 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/Detector/Rich/include/Detector/Rich/DeRichMirror.h b/Detector/Rich/include/Detector/Rich/DeRichMirror.h index 25b3e71524..2aaa238c81 100644 --- a/Detector/Rich/include/Detector/Rich/DeRichMirror.h +++ b/Detector/Rich/include/Detector/Rich/DeRichMirror.h @@ -23,11 +23,12 @@ namespace LHCb::Detector { struct DeRichMirrorSegObject : DeIOVObject { public: - int m_mirrorNumber = -1; ///< id number which is same as the copy number. - Rich::Side m_mirrorSide = Rich::InvalidSide; ///< side number 0 for top and 1 for bottom - double m_SegmentROC = 0; ///< Mirror radius of curvature - double m_SegmentXSize = 0; ///< Mirror X size - double m_SegmentYSize = 0; ///< Mirror Y size + int m_mirrorNumber = -1; ///< id number which is same as the copy number. + Rich::DetectorType m_rich = Rich::InvalidDetector; ///< RICH Detector + Rich::Side m_mirrorSide = Rich::InvalidSide; ///< side number 0 for top and 1 for bottom + double m_SegmentROC = 0; ///< Mirror radius of curvature + double m_SegmentXSize = 0; ///< Mirror X size + double m_SegmentYSize = 0; ///< Mirror Y size dd4hep::Position m_SegmentLocalCOC; ///< local COC in the corresponding Rich1Mirro2Master system dd4hep::Position m_SegmentGlobalCOC; ///< COC in the global coordinate system dd4hep::Position m_MirrorSurfCentrePtn; ///< Centre point of mirror segment surface in global frame @@ -93,6 +94,7 @@ namespace LHCb::Detector { auto mirrorNumber() const noexcept { return this->access()->m_mirrorNumber; } auto mirrorSide() const noexcept { return this->access()->m_mirrorSide; } + auto rich() const noexcept { return this->access()->m_rich; } auto SegXSize() const noexcept { return toLHCbLengthUnits( this->access()->m_SegmentXSize ); } auto SegYSize() const noexcept { return toLHCbLengthUnits( this->access()->m_SegmentYSize ); } diff --git a/Detector/Rich1/src/Rich1DEA/DeRich1Mirror1.cpp b/Detector/Rich1/src/Rich1DEA/DeRich1Mirror1.cpp index f5d811a9e6..c38a321b38 100644 --- a/Detector/Rich1/src/Rich1DEA/DeRich1Mirror1.cpp +++ b/Detector/Rich1/src/Rich1DEA/DeRich1Mirror1.cpp @@ -33,6 +33,9 @@ DeRich1Mirror1SegObject::DeRich1Mirror1SegObject( const dd4hep::DetElement& dd4hep::cond::ConditionUpdateContext& ctxt ) : DeRichMirrorSegObject( de, ctxt ) { + // RICH + m_rich = Rich::Rich1; + // mirror number m_mirrorNumber = de.parent().id(); diff --git a/Detector/Rich1/src/Rich1DEA/DeRich1Mirror2.cpp b/Detector/Rich1/src/Rich1DEA/DeRich1Mirror2.cpp index a5b2335da4..c3b7c9942c 100644 --- a/Detector/Rich1/src/Rich1DEA/DeRich1Mirror2.cpp +++ b/Detector/Rich1/src/Rich1DEA/DeRich1Mirror2.cpp @@ -33,6 +33,9 @@ DeRich1Mirror2SegObject::DeRich1Mirror2SegObject( const dd4hep::DetElement& dd4hep::cond::ConditionUpdateContext& ctxt ) : DeRichMirrorSegObject( de, ctxt ) { + // RICH + m_rich = Rich::Rich1; + // mirror number m_mirrorNumber = de.id(); diff --git a/Detector/Rich2/src/Rich2DEA/DeRich2SecMirror.cpp b/Detector/Rich2/src/Rich2DEA/DeRich2SecMirror.cpp index dfa66049ad..509065a022 100644 --- a/Detector/Rich2/src/Rich2DEA/DeRich2SecMirror.cpp +++ b/Detector/Rich2/src/Rich2DEA/DeRich2SecMirror.cpp @@ -34,6 +34,9 @@ DeRich2SecMirrorSegObject::DeRich2SecMirrorSegObject( const dd4hep::DetElement& dd4hep::cond::ConditionUpdateContext& ctxt ) : DeRichMirrorSegObject( de, ctxt ) { + // RICH + m_rich = Rich::Rich2; + // mirror number m_mirrorNumber = de.id(); diff --git a/Detector/Rich2/src/Rich2DEA/DeRich2SphMirror.cpp b/Detector/Rich2/src/Rich2DEA/DeRich2SphMirror.cpp index c782450810..a70c090bbd 100644 --- a/Detector/Rich2/src/Rich2DEA/DeRich2SphMirror.cpp +++ b/Detector/Rich2/src/Rich2DEA/DeRich2SphMirror.cpp @@ -34,6 +34,9 @@ DeRich2SphMirrorSegObject::DeRich2SphMirrorSegObject( const dd4hep::DetElement& dd4hep::cond::ConditionUpdateContext& ctxt ) : DeRichMirrorSegObject( de, ctxt ) { + // RICH + m_rich = Rich::Rich2; + // mirror number m_mirrorNumber = de.id(); -- GitLab