Skip to content
Snippets Groups Projects
Commit ab6d88c0 authored by Sergey Gorbunov's avatar Sergey Gorbunov
Browse files

Ca: move ObjectInitController class to /algo

parent bfdb61fd
No related branches found
No related tags found
1 merge request!1357Ca: move ObjectInitController class to /algo
Pipeline #24454 passed
......@@ -50,6 +50,7 @@ install(
utils/CaSimdPseudo.h
utils/CaVector.h
utils/CaUtils.h
utils/CaObjectInitController.h
DESTINATION
include/
)
......
/* 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
......@@ -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
......@@ -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
......
......@@ -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
......
......@@ -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
......
/* 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment