From ab6d88c06225f73c212de26ce52cba1cf6e85f94 Mon Sep 17 00:00:00 2001 From: "se.gorbunov" <se.gorbunov@gsi.de> Date: Sat, 7 Oct 2023 21:54:03 +0000 Subject: [PATCH] Ca: move ObjectInitController class to /algo --- algo/ca/core/CMakeLists.txt | 1 + algo/ca/core/utils/CaObjectInitController.h | 101 ++++++++++++++++++++ algo/log/AlgoFairloggerCompat.h | 7 +- reco/L1/CMakeLists.txt | 2 - reco/L1/L1Algo/L1BaseStationInfo.h | 6 +- reco/L1/L1Algo/L1InitManager.h | 6 +- reco/L1/L1Algo/L1ObjectInitController.h | 98 ------------------- 7 files changed, 113 insertions(+), 108 deletions(-) create mode 100644 algo/ca/core/utils/CaObjectInitController.h delete mode 100644 reco/L1/L1Algo/L1ObjectInitController.h diff --git a/algo/ca/core/CMakeLists.txt b/algo/ca/core/CMakeLists.txt index 91e88e555c..8e43241bac 100644 --- a/algo/ca/core/CMakeLists.txt +++ b/algo/ca/core/CMakeLists.txt @@ -50,6 +50,7 @@ install( utils/CaSimdPseudo.h utils/CaVector.h utils/CaUtils.h + utils/CaObjectInitController.h DESTINATION include/ ) diff --git a/algo/ca/core/utils/CaObjectInitController.h b/algo/ca/core/utils/CaObjectInitController.h new file mode 100644 index 0000000000..31a88feb1b --- /dev/null +++ b/algo/ca/core/utils/CaObjectInitController.h @@ -0,0 +1,101 @@ +/* Copyright (C) 2022 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt + SPDX-License-Identifier: GPL-3.0-only + Authors: Sergey Gorbunov, Sergei Zharko [committer] */ + +#ifndef CaObjectInitController_h +#define CaObjectInitController_h 1 + +/// @file CaObjectInitController.h +/// @author Sergei Zharko +/// @date 22.02.2022 + +#include <bitset> +#include <cassert> +#include <iomanip> +#include <iostream> +#include <sstream> +#include <string> + +#include "AlgoFairloggerCompat.h" + +namespace cbm::algo::ca +{ + /// ObjectInitController is a class, which provides flags system + /// and functionality needed for L1 algorithm objects initialization + /// + /// ObjectInitController is a class, which provides flags system + /// and functionality needed for L1 algorithm objects initialization + /// + // TODO: Possible improvement: introduce another template parameter, which represents a local enum class... + template<int NumberOfFlags, class InitKeyEnum> + class ObjectInitController { + public: + /// Gets an initialization status of the flag placed at bitIndex + /// \param bitIndex index of bit + bool GetFlag(InitKeyEnum bitKey) const; + /// Checks, if the object is finalized, i.e. all its fields were set up + bool IsFinalized() const { return fInitFlags.size() == fInitFlags.count(); } + /// Sets an initialization status of the flag placed at bitIndex + /// \param bitIndex index of bit + /// \param newStatus flag value (true is default) + void SetFlag(InitKeyEnum bitKey, bool newStatus = true); + /// String representation of initialization flags contents + /// \param indentLevel number of indent charachets int output + std::string ToString(int indentLevel = 0) const; + + private: + std::bitset<NumberOfFlags> fInitFlags {}; ///< object of flags sets + }; + + // + //------------------------------------------------------------------------------------------------------------------------ + // + template<int NumberOfFlags, class InitKeyEnum> + bool ObjectInitController<NumberOfFlags, InitKeyEnum>::GetFlag(InitKeyEnum bitKey) const + { + int bitIndex = static_cast<int>(bitKey); + if (bitIndex >= NumberOfFlags || bitIndex < 0) { + LOG(fatal) << "L1OnjectInitController::GetFlagStatus: attempt of flag access with index = " << bitIndex + << " outside the range [0, " << NumberOfFlags << ']'; + //assert((!(bitIndex >= NumberOfFlags || bitIndex < 0))); + } + return fInitFlags[static_cast<int>(bitKey)]; + } + // + //------------------------------------------------------------------------------------------------------------------------ + // + template<int NumberOfFlags, class InitKeyEnum> + void ObjectInitController<NumberOfFlags, InitKeyEnum>::SetFlag(InitKeyEnum bitKey, bool newStatus) + { + int bitIndex = static_cast<int>(bitKey); + if (bitIndex >= NumberOfFlags || bitIndex < 0) { + LOG(fatal) << "L1OnjectInitController::GetFlagStatus: attempt of flag access with index = " << bitIndex + << " outside the range [0, " << NumberOfFlags << ']'; + //assert((!(bitIndex >= NumberOfFlags || bitIndex < 0))); + } + fInitFlags[static_cast<int>(bitKey)] = newStatus; + } + // + //------------------------------------------------------------------------------------------------------------------------ + // + template<int NumberOfFlags, class InitKeyEnum> + std::string ObjectInitController<NumberOfFlags, InitKeyEnum>::ToString(int indentLevel) const + { + std::stringstream aStream {}; + constexpr char indentChar = '\t'; + std::string indent(indentLevel, indentChar); + aStream << indent << "CaObjectInitController: flag values"; + aStream << '\n' << indent << "index: "; + for (int idx = 0; idx < NumberOfFlags; ++idx) { + aStream << std::setw(3) << std::setfill(' ') << idx << ' '; + } + aStream << '\n' << indent << "value: "; + for (int idx = 0; idx < NumberOfFlags; ++idx) { + aStream << " " << static_cast<int>(fInitFlags[idx]) << ' '; + } + return aStream.str(); + } + +} // namespace cbm::algo::ca + +#endif // CaObjectInitController_h diff --git a/algo/log/AlgoFairloggerCompat.h b/algo/log/AlgoFairloggerCompat.h index 67deb7fed5..6075890ed7 100644 --- a/algo/log/AlgoFairloggerCompat.h +++ b/algo/log/AlgoFairloggerCompat.h @@ -10,11 +10,14 @@ #else // defined NO_ROOT -#include <log.hpp> +#ifndef LOG +#include <log.hpp> static constexpr severity_level warn = severity_level::warning; #define LOG(level) L_(level) -#endif +#endif // LOG + +#endif // NO_ROOT #endif // CBM_ALGO_BASE_COMPAT_ONLINEDATALOG_H diff --git a/reco/L1/CMakeLists.txt b/reco/L1/CMakeLists.txt index 5b0c1bdcb0..3f4b0e5104 100644 --- a/reco/L1/CMakeLists.txt +++ b/reco/L1/CMakeLists.txt @@ -202,8 +202,6 @@ install(FILES CbmL1Counters.h L1Algo/L1Triplet.h L1Algo/L1Event.h L1Algo/L1EventMatch.h - L1Algo/L1ObjectInitController.h - #L1Algo/L1Constants.h L1Algo/L1Utils.h utils/CbmCaIdealHitProducer.h utils/CbmCaIdealHitProducerDet.h diff --git a/reco/L1/L1Algo/L1BaseStationInfo.h b/reco/L1/L1Algo/L1BaseStationInfo.h index b7b0863548..4d1e7eb5c6 100644 --- a/reco/L1/L1Algo/L1BaseStationInfo.h +++ b/reco/L1/L1Algo/L1BaseStationInfo.h @@ -17,9 +17,9 @@ // L1 Core #include "CaMaterialMap.h" +#include "CaObjectInitController.h" #include "CaSimd.h" #include "CaStation.h" -#include "L1ObjectInitController.h" // C++ std #include <bitset> @@ -64,7 +64,7 @@ public: kEnd }; - using InitController_t = L1ObjectInitController<static_cast<int>(EInitKey::kEnd), EInitKey>; + using InitController_t = ca::ObjectInitController<static_cast<int>(EInitKey::kEnd), EInitKey>; // // CONSTRUCTORS AND DESTRUCTORS @@ -109,7 +109,7 @@ public: /// Gets field status: 0 - station is outside the field, 1 - station is inside the field int GetFieldStatus() const { return fL1Station.fieldStatus; } - /// Gets a const reference to the L1ObjectInitController object + /// Gets a const reference to the ca::ObjectInitController object const InitController_t& GetInitController() const { return fInitController; } /// Gets a reference to ca::Station info field of the L1BaseStation info diff --git a/reco/L1/L1Algo/L1InitManager.h b/reco/L1/L1Algo/L1InitManager.h index 6c5240d654..a95e175cf8 100644 --- a/reco/L1/L1Algo/L1InitManager.h +++ b/reco/L1/L1Algo/L1InitManager.h @@ -19,11 +19,11 @@ #include "CaConstants.h" #include "CaField.h" +#include "CaObjectInitController.h" #include "CaSimd.h" #include "L1BaseStationInfo.h" #include "L1CAIteration.h" #include "L1EArray.h" -#include "L1ObjectInitController.h" #include "L1Parameters.h" #include "L1Utils.h" @@ -97,7 +97,7 @@ private: using L1DetectorIDIntMap_t = std::unordered_map<L1DetectorID, int, L1Utils::EnumClassHash>; using L1DetectorIDSet_t = std::set<L1DetectorID>; using L1FieldFunction_t = std::function<void(const double (&xyz)[3], double (&B)[3])>; - using InitController_t = L1ObjectInitController<static_cast<int>(EInitKey::kEnd), EInitKey>; + using InitController_t = ca::ObjectInitController<static_cast<int>(EInitKey::kEnd), EInitKey>; template<typename T> using L1DetectorIDArr_t = std::array<T, constants::size::MaxNdetectors>; @@ -156,7 +156,7 @@ public: /// @brief Gets a name of the user input configuration file const std::string& GetInputConfigUser() const { return fsConfigInputMain; } - /// Gets a const reference to L1ObjectInitController + /// Gets a const reference to ca::ObjectInitController const InitController_t& GetInitController() const { return fInitController; } /// Gets total number of active stations diff --git a/reco/L1/L1Algo/L1ObjectInitController.h b/reco/L1/L1Algo/L1ObjectInitController.h deleted file mode 100644 index ac9a141849..0000000000 --- a/reco/L1/L1Algo/L1ObjectInitController.h +++ /dev/null @@ -1,98 +0,0 @@ -/* Copyright (C) 2022 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt - SPDX-License-Identifier: GPL-3.0-only - Authors: Sergey Gorbunov, Sergei Zharko [committer] */ - -#ifndef L1ObjectInitController_h -#define L1ObjectInitController_h 1 - -/// @file L1ObjectInitController.h -/// @author Sergei Zharko -/// @date 22.02.2022 - -#include "Logger.h" - -#include <bitset> -#include <cassert> -#include <iomanip> -#include <iostream> -#include <sstream> -#include <string> - -/// L1ObjectInitController is a class, which provides flags system -/// and functionality needed for L1 algorithm objects initialization -/// -// TODO: Possible improvement: introduce another template parameter, which represents a local enum class... -template<int NumberOfFlags, class InitKeyEnum> -class L1ObjectInitController { -public: - /// Gets an initialization status of the flag placed at bitIndex - /// \param bitIndex index of bit - bool GetFlag(InitKeyEnum bitKey) const; - /// Checks, if the object is finalized, i.e. all its fields were set up - bool IsFinalized() const { return fInitFlags.size() == fInitFlags.count(); } - /// Sets an initialization status of the flag placed at bitIndex - /// \param bitIndex index of bit - /// \param newStatus flag value (true is default) - void SetFlag(InitKeyEnum bitKey, bool newStatus = true); - /// String representation of initialization flags contents - /// \param indentLevel number of indent charachets int output - std::string ToString(int indentLevel = 0) const; - -private: - std::bitset<NumberOfFlags> fInitFlags {}; ///< object of flags sets -}; - -// -//------------------------------------------------------------------------------------------------------------------------ -// -template<int NumberOfFlags, class InitKeyEnum> -bool L1ObjectInitController<NumberOfFlags, InitKeyEnum>::GetFlag(InitKeyEnum bitKey) const -{ -#ifndef FAST_CODE - int bitIndex = static_cast<int>(bitKey); - if (bitIndex >= NumberOfFlags || bitIndex < 0) { - LOG(fatal) << "L1OnjectInitController::GetFlagStatus: attempt of flag access with index = " << bitIndex - << " outside the range [0, " << NumberOfFlags << ']'; - //assert((!(bitIndex >= NumberOfFlags || bitIndex < 0))); - } -#endif // FAST_CODE - return fInitFlags[static_cast<int>(bitKey)]; -} -// -//------------------------------------------------------------------------------------------------------------------------ -// -template<int NumberOfFlags, class InitKeyEnum> -void L1ObjectInitController<NumberOfFlags, InitKeyEnum>::SetFlag(InitKeyEnum bitKey, bool newStatus) -{ -#ifndef FAST_CODE - int bitIndex = static_cast<int>(bitKey); - if (bitIndex >= NumberOfFlags || bitIndex < 0) { - LOG(fatal) << "L1OnjectInitController::GetFlagStatus: attempt of flag access with index = " << bitIndex - << " outside the range [0, " << NumberOfFlags << ']'; - //assert((!(bitIndex >= NumberOfFlags || bitIndex < 0))); - } -#endif // FAST_CODE - fInitFlags[static_cast<int>(bitKey)] = newStatus; -} -// -//------------------------------------------------------------------------------------------------------------------------ -// -template<int NumberOfFlags, class InitKeyEnum> -std::string L1ObjectInitController<NumberOfFlags, InitKeyEnum>::ToString(int indentLevel) const -{ - std::stringstream aStream {}; - constexpr char indentChar = '\t'; - std::string indent(indentLevel, indentChar); - aStream << indent << "L1ObjectInitController: flag values"; - aStream << '\n' << indent << "index: "; - for (int idx = 0; idx < NumberOfFlags; ++idx) { - aStream << std::setw(3) << std::setfill(' ') << idx << ' '; - } - aStream << '\n' << indent << "value: "; - for (int idx = 0; idx < NumberOfFlags; ++idx) { - aStream << " " << static_cast<int>(fInitFlags[idx]) << ' '; - } - return aStream.str(); -} - -#endif // L1ObjectInitController_h -- GitLab