Skip to content

Commit a5aa074

Browse files
committed
fix3
Signed-off-by: Felix Schlepper <felix.schlepper@cern.ch>
1 parent a415760 commit a5aa074

3 files changed

Lines changed: 38 additions & 14 deletions

File tree

Common/Utils/include/CommonUtils/EnumFlags.h

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <string>
2525
#include <sstream>
2626
#include <limits>
27+
#include <bit>
2728
#include <bitset>
2829
#include <initializer_list>
2930
#include <cstdint>
@@ -34,7 +35,15 @@
3435
#include <iostream>
3536
#include <iomanip>
3637

38+
#if !defined(__CUDACC__) && !defined(__HIPCC__)
39+
#define O2_ENUMFLAGS_ENABLE_REFLECTION 1
40+
#else
41+
#define O2_ENUMFLAGS_ENABLE_REFLECTION 0
42+
#endif
43+
44+
#if O2_ENUMFLAGS_ENABLE_REFLECTION
3745
#include "CommonUtils/StringUtils.h"
46+
#endif
3847

3948
namespace o2::utils
4049
{
@@ -55,6 +64,7 @@ concept EnumFlagHelper = requires {
5564
// This is very much inspired by much more extensive libraries like magic_enum.
5665
// Inspiration by its c++20 version (https://github.com/fix8mt/conjure_enum).
5766
// NOTE: Cannot detect if bit values past the underlying type are defined.
67+
#if O2_ENUMFLAGS_ENABLE_REFLECTION
5868
template <EnumFlagHelper E>
5969
struct FlagsHelper final {
6070
using U = std::underlying_type_t<E>;
@@ -317,10 +327,12 @@ struct FlagsHelper final {
317327
return false;
318328
}
319329
};
330+
#endif
320331

321332
} // namespace details::enum_flags
322333

323334
// Require an enum to fullfil what one would except from a bitset.
335+
#if O2_ENUMFLAGS_ENABLE_REFLECTION
324336
template <typename E>
325337
concept EnumFlag = requires {
326338
// range checks
@@ -332,6 +344,10 @@ concept EnumFlag = requires {
332344
requires !details::enum_flags::FlagsHelper<E>::hasNone(); // added automatically
333345
requires !details::enum_flags::FlagsHelper<E>::hasAll(); // added automatically
334346
};
347+
#else
348+
template <typename E>
349+
concept EnumFlag = details::enum_flags::EnumFlagHelper<E>;
350+
#endif
335351

336352
/**
337353
* \brief Class to aggregate and manage enum-based on-off flags.
@@ -358,7 +374,9 @@ template <EnumFlag E>
358374
class EnumFlags
359375
{
360376
static constexpr int DefaultBase{2};
377+
#if O2_ENUMFLAGS_ENABLE_REFLECTION
361378
using H = details::enum_flags::FlagsHelper<E>;
379+
#endif
362380
using U = std::underlying_type_t<E>;
363381
U mBits{0};
364382

@@ -388,18 +406,21 @@ class EnumFlags
388406
// Initialize with a list of flags.
389407
constexpr EnumFlags(std::initializer_list<E> flags) noexcept
390408
{
391-
std::for_each(flags.begin(), flags.end(), [this](const E f) noexcept { mBits |= to_bit(f); });
409+
for (const E f : flags) {
410+
mBits |= to_bit(f);
411+
}
392412
}
413+
#if O2_ENUMFLAGS_ENABLE_REFLECTION
393414
// Init from a string.
394415
//
395416
explicit EnumFlags(const std::string& str, int base = DefaultBase)
396417
{
397418
set(str, base);
398419
}
399-
// Destructor.
400-
constexpr ~EnumFlags() = default;
420+
#endif
401421

402-
static constexpr U None{0}; // Represents no flags set.
422+
static constexpr U None{0}; // Represents no flags set.
423+
#if O2_ENUMFLAGS_ENABLE_REFLECTION
403424
static constexpr U All{H::MaxRep}; // Represents all flags set.
404425

405426
// Return list of all enum values
@@ -432,6 +453,7 @@ class EnumFlags
432453
throw;
433454
}
434455
}
456+
#endif
435457
// Returns the raw bitset value.
436458
[[nodiscard]] constexpr auto value() const noexcept
437459
{
@@ -493,6 +515,7 @@ class EnumFlags
493515
}
494516

495517
// Checks if all flags are set.
518+
#if O2_ENUMFLAGS_ENABLE_REFLECTION
496519
[[nodiscard]] constexpr bool all() const noexcept
497520
{
498521
return mBits == All;
@@ -537,6 +560,7 @@ class EnumFlags
537560
}
538561
return oss.str();
539562
}
563+
#endif
540564

541565
// Checks if any flag is set (Boolean context).
542566
[[nodiscard]] constexpr explicit operator bool() const noexcept
@@ -645,6 +669,7 @@ class EnumFlags
645669
}
646670

647671
// Serializes the flag set to a string.
672+
#if O2_ENUMFLAGS_ENABLE_REFLECTION
648673
[[nodiscard]] std::string serialize() const
649674
{
650675
return std::to_string(mBits);
@@ -659,6 +684,7 @@ class EnumFlags
659684
}
660685
mBits = static_cast<U>(v);
661686
}
687+
#endif
662688

663689
// Counts the number of set bits (active flags).
664690
[[nodiscard]] constexpr size_t count() const noexcept
@@ -686,6 +712,7 @@ class EnumFlags
686712

687713
private:
688714
// Set implementation, bits was zeroed before.
715+
#if O2_ENUMFLAGS_ENABLE_REFLECTION
689716
void setImpl(const std::string& s, int base = 2)
690717
{
691718
// Helper to check if character is valid for given base
@@ -782,15 +809,20 @@ class EnumFlags
782809
throw std::invalid_argument("Cannot parse string!");
783810
}
784811
}
812+
#endif
785813
};
786814

815+
#if O2_ENUMFLAGS_ENABLE_REFLECTION
787816
template <EnumFlag E>
788817
std::ostream& operator<<(std::ostream& os, const EnumFlags<E>& f)
789818
{
790819
os << f.pstring(true);
791820
return os;
792821
}
822+
#endif
793823

794824
} // namespace o2::utils
795825

826+
#undef O2_ENUMFLAGS_ENABLE_REFLECTION
827+
796828
#endif

Detectors/ITSMFT/ITS/tracking/include/ITStracking/Configuration.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@
2323
#include <vector>
2424
#endif
2525

26-
#if !defined(__CUDACC__) && !defined(__HIPCC__)
2726
#include "CommonUtils/EnumFlags.h"
28-
#endif
2927
#include "DetectorsBase/Propagator.h"
3028
#include "ITStracking/Constants.h"
3129

@@ -43,12 +41,7 @@ enum class IterationStep : uint8_t {
4341
MarkVerticesAsUPC,
4442
};
4543

46-
#if !defined(__CUDACC__) && !defined(__HIPCC__)
4744
using IterationSteps = o2::utils::EnumFlags<IterationStep>;
48-
#else
49-
struct IterationSteps {
50-
};
51-
#endif
5245

5346
struct TrackingParameters {
5447
int CellMinimumLevel() const noexcept { return MinTrackLength - constants::ClustersPerCell + 1; }
@@ -57,7 +50,7 @@ struct TrackingParameters {
5750
int TrackletsPerRoad() const noexcept { return NLayers - 1; }
5851
std::string asString() const;
5952

60-
IterationSteps PassFlags;
53+
IterationSteps PassFlags{IterationStep::FirstPass, IterationStep::RebuildClusterLUT};
6154
int NLayers = 7;
6255
std::vector<uint32_t> AddTimeError = {0, 0, 0, 0, 0, 0, 0};
6356
std::vector<float> LayerZ = {16.333f + 1, 16.333f + 1, 16.333f + 1, 42.140f + 1, 42.140f + 1, 73.745f + 1, 73.745f + 1};
@@ -104,7 +97,7 @@ struct TrackingParameters {
10497
struct VertexingParameters {
10598
std::string asString() const;
10699

107-
IterationSteps PassFlags;
100+
IterationSteps PassFlags{IterationStep::FirstPass, IterationStep::ResetVertices};
108101
std::vector<float> LayerZ = {16.333f + 1, 16.333f + 1, 16.333f + 1, 42.140f + 1, 42.140f + 1, 73.745f + 1, 73.745f + 1};
109102
std::vector<float> LayerRadii = {2.33959f, 3.14076f, 3.91924f, 19.6213f, 24.5597f, 34.388f, 39.3329f};
110103
int vertPerRofThreshold = 0; // Maximum number of vertices per ROF to trigger second a round

Detectors/ITSMFT/ITS/tracking/include/ITStracking/TrackerTraits.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
#include <oneapi/tbb.h>
2020

21-
#include "DetectorsBase/Propagator.h"
2221
#include "ITStracking/Configuration.h"
2322
#include "ITStracking/IndexTableUtils.h"
2423
#include "ITStracking/TimeFrame.h"

0 commit comments

Comments
 (0)