diff --git a/core/base/utils/CbmEnumArray.h b/core/base/utils/CbmEnumArray.h new file mode 100644 index 0000000000000000000000000000000000000000..03404d0cba1ba1f39cf221522f9cbe92abcbd981 --- /dev/null +++ b/core/base/utils/CbmEnumArray.h @@ -0,0 +1,58 @@ +/* Copyright (C) 2024 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt + SPDX-License-Identifier: GPL-3.0-only + Authors: Sergei Zharko [committer] */ + +/// @file CaEnumArray.h +/// @brief Array indexed by a generic enum class +/// @since 22.05.2024 +/// @author Sergei Zharko <s.zharko@gsi.de> + +#pragma once // include this header only once per compilation unit + +#include <boost/serialization/array.hpp> +#include <boost/serialization/base_object.hpp> + +#include <array> + +namespace cbm::core +{ + /// \class cbm::algo::ca::EnumArray + /// \brief Class of arrays, which can be accessed by an enum class entry as an index + /// \note The enum-array must contain an entry kEND, which represents the number of the enumeration entries and + /// is used, as an array size + /// \tparam E The enum class type + /// \tparam T Type of data in the underlying array + template<class E, class T> + class EnumArray : public std::array<T, static_cast<std::size_t>(E::END)> { + using U = typename std::underlying_type<E>::type; ///< Underlying type of enumeration + using Arr = std::array<T, static_cast<std::size_t>(E::END)>; + + public: + /// \brief Mutable access operator, indexed by enum entry + /// \param entry Enum entry for the element + T& operator[](const E& entry) { return Arr::operator[](static_cast<U>(entry)); } + + /// \brief Mutable access operator, indexed by underlying index type + /// \param index Index of the element + T& operator[](U index) { return Arr::operator[](index); } + + /// \brief Constant access operator, indexed by enum entry + /// \param entry Enum entry for the element + const T& operator[](const E& entry) const { return Arr::operator[](static_cast<U>(entry)); } + + /// \brief Constant access operator, indexed by underlying index type + /// \param index Index of the element + const T& operator[](U index) const { return Arr::operator[](index); } + + /// \brief Convertion operator to the base array class + operator Arr&() const { return *this; } + + private: + friend class boost::serialization::access; + template<typename Archive> + void serialize(Archive& ar, const unsigned int /*version*/) + { + ar& boost::serialization::base_object<Arr>(*this); + } + }; +} // namespace cbm::core diff --git a/reco/kfnew/CbmKfTrackingSetupBuilder.cxx b/reco/kfnew/CbmKfTrackingSetupBuilder.cxx index a231d54e9de72985b202c4fb86aec629ca818c26..25a491084b544541f103d36f82c616f960da36a1 100644 --- a/reco/kfnew/CbmKfTrackingSetupBuilder.cxx +++ b/reco/kfnew/CbmKfTrackingSetupBuilder.cxx @@ -73,13 +73,11 @@ try { } for (int iSt = 0; iSt < pIfs->GetNtrackingStations(); ++iSt) { fBuilder.AddLayer( - GeoLayer<ETrackingDetID>{.fDetID = detID, // ca::Tracking detector id scheme - .fLocID = iSt, // ca::Tracking station indexing - .fZref = pIfs->GetZref(iSt), - .fZmin = pIfs->GetZmin(iSt), - .fZmax = pIfs->GetZmax(iSt), - .fXmax = std::max(std::fabs(pIfs->GetXmin(iSt)), std::fabs(pIfs->GetXmax(iSt))), - .fYmax = std::max(std::fabs(pIfs->GetYmin(iSt)), std::fabs(pIfs->GetYmax(iSt)))}); + GeoLayer<ETrackingDetID>{detID, // ca::Tracking detector id scheme + iSt, // ca::Tracking station indexing + pIfs->GetZref(iSt), pIfs->GetZmin(iSt), pIfs->GetZmax(iSt), + std::max(std::fabs(pIfs->GetXmin(iSt)), std::fabs(pIfs->GetXmax(iSt))), + std::max(std::fabs(pIfs->GetYmin(iSt)), std::fabs(pIfs->GetYmax(iSt)))}); } }; CollectStations(fbUseMvd ? CbmMvdTrackingInterface::Instance() : nullptr, ETrackingDetID::Mvd);