Skip to content

Commit

Permalink
Merge e1ff2ab into sapling-pr-archive-ktf
Browse files Browse the repository at this point in the history
  • Loading branch information
ktf authored Dec 2, 2024
2 parents 30ad269 + e1ff2ab commit 140e172
Show file tree
Hide file tree
Showing 82 changed files with 2,437 additions and 768 deletions.
3 changes: 2 additions & 1 deletion Common/Constants/include/CommonConstants/MathConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ namespace constants
{
namespace math
{
constexpr float Almost0 = 1.175494351e-38f;
constexpr float Almost0 = 0x1.0p-126f; // smallest non-denormal float
constexpr float Epsilon = 0x0.000002p0f; // smallest float such that 1 != 1 + Epsilon
constexpr float Almost1 = 1.f - 1.0e-6f;
constexpr float VeryBig = 1.f / Almost0;

Expand Down
24 changes: 13 additions & 11 deletions Common/Utils/include/CommonUtils/ConfigurableParam.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,17 +321,19 @@ class ConfigurableParam
} // end namespace o2

// a helper macro for boilerplate code in parameter classes
#define O2ParamDef(classname, key) \
public: \
classname(TRootIOCtor*) {} \
classname(classname const&) = delete; \
\
private: \
static constexpr char const* const sKey = key; \
static classname sInstance; \
classname() = default; \
template <typename T> \
friend class o2::conf::ConfigurableParamHelper;
#define O2ParamDef(classname, key) \
public: \
classname(TRootIOCtor*) {} \
classname(classname const&) = delete; \
\
private: \
static constexpr char const* const sKey = key; \
static classname sInstance; \
classname() = default; \
template <typename T> \
friend class o2::conf::ConfigurableParamHelper; \
template <typename T, typename P> \
friend class o2::conf::ConfigurableParamPromoter;

// a helper macro to implement necessary symbols in source
#define O2ParamImpl(classname) classname classname::sInstance;
Expand Down
158 changes: 150 additions & 8 deletions Common/Utils/include/CommonUtils/ConfigurableParamHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,18 @@ class _ParamHelper
{
private:
static std::vector<ParamDataMember>* getDataMembersImpl(std::string const& mainkey, TClass* cl, void*,
std::map<std::string, ConfigurableParam::EParamProvenance> const* provmap);
std::map<std::string, ConfigurableParam::EParamProvenance> const* provmap, size_t virtualoffset);

static void fillKeyValuesImpl(std::string const& mainkey, TClass* cl, void*, boost::property_tree::ptree*,
std::map<std::string, std::pair<std::type_info const&, void*>>*,
EnumRegistry*);
EnumRegistry*, size_t offset);

static void printWarning(std::type_info const&);

static void assignmentImpl(std::string const& mainkey, TClass* cl, void* to, void* from,
std::map<std::string, ConfigurableParam::EParamProvenance>* provmap);
std::map<std::string, ConfigurableParam::EParamProvenance>* provmap, size_t offset);
static void syncCCDBandRegistry(std::string const& mainkey, TClass* cl, void* to, void* from,
std::map<std::string, ConfigurableParam::EParamProvenance>* provmap);
std::map<std::string, ConfigurableParam::EParamProvenance>* provmap, size_t offset);

static void outputMembersImpl(std::ostream& out, std::string const& mainkey, std::vector<ParamDataMember> const* members, bool showProv, bool useLogger);
static void printMembersImpl(std::string const& mainkey, std::vector<ParamDataMember> const* members, bool showProv, bool useLogger);
Expand All @@ -65,6 +65,9 @@ class _ParamHelper

template <typename P>
friend class ConfigurableParamHelper;

template <typename Base, typename P>
friend class ConfigurableParamPromoter;
};

// ----------------------------------------------------------------
Expand Down Expand Up @@ -140,7 +143,7 @@ class ConfigurableParamHelper : virtual public ConfigurableParam
return nullptr;
}

return _ParamHelper::getDataMembersImpl(getName(), cl, (void*)this, sValueProvenanceMap);
return _ParamHelper::getDataMembersImpl(getName(), cl, (void*)this, sValueProvenanceMap, 0);
}

// ----------------------------------------------------------------
Expand All @@ -153,7 +156,7 @@ class ConfigurableParamHelper : virtual public ConfigurableParam
_ParamHelper::printWarning(typeid(P));
return;
}
_ParamHelper::fillKeyValuesImpl(getName(), cl, (void*)this, tree, sKeyToStorageMap, sEnumRegistry);
_ParamHelper::fillKeyValuesImpl(getName(), cl, (void*)this, tree, sKeyToStorageMap, sEnumRegistry, 0);
}

// ----------------------------------------------------------------
Expand All @@ -167,7 +170,7 @@ class ConfigurableParamHelper : virtual public ConfigurableParam
file->GetObject(getName().c_str(), readback);
if (readback != nullptr) {
_ParamHelper::assignmentImpl(getName(), TClass::GetClass(typeid(P)), (void*)this, (void*)readback,
sValueProvenanceMap);
sValueProvenanceMap, 0);
delete readback;
}
setRegisterMode(true);
Expand All @@ -185,7 +188,146 @@ class ConfigurableParamHelper : virtual public ConfigurableParam
//
setRegisterMode(false);
_ParamHelper::syncCCDBandRegistry(getName(), TClass::GetClass(typeid(P)), (void*)this, (void*)externalobj,
sValueProvenanceMap);
sValueProvenanceMap, 0);
setRegisterMode(true);
}

// ----------------------------------------------------------------

void serializeTo(TFile* file) const final
{
file->WriteObjectAny((void*)this, TClass::GetClass(typeid(P)), getName().c_str());
}
};

// Promotes a simple struct Base to a configurable parameter class
// Aka implements all interfaces for a ConfigurableParam P, which shares or
// takes the fields from a Base struct
template <typename P, typename Base>
class ConfigurableParamPromoter : public Base, virtual public ConfigurableParam
{
public:
using ConfigurableParam::ConfigurableParam;

static const P& Instance()
{
return P::sInstance;
}

// extracts a copy of the underlying data struct
Base detach() const
{
static_assert(std::copyable<Base>, "Base type must be copyable.");
return static_cast<Base>(*this);
}

// ----------------------------------------------------------------
std::string getName() const final
{
return P::sKey;
}

// ----------------------------------------------------------------
// get the provenace of the member with given key
EParamProvenance getMemberProvenance(const std::string& key) const final
{
return getProvenance(getName() + '.' + key);
}

// ----------------------------------------------------------------

// one of the key methods, using introspection to print itself
void printKeyValues(bool showProv = true, bool useLogger = false) const final
{
if (!isInitialized()) {
initialize();
}
auto members = getDataMembers();
_ParamHelper::printMembersImpl(getName(), members, showProv, useLogger);
}

//
size_t getHash() const final
{
return _ParamHelper::getHashImpl(getName(), getDataMembers());
}

// ----------------------------------------------------------------

void output(std::ostream& out) const final
{
auto members = getDataMembers();
_ParamHelper::outputMembersImpl(out, getName(), members, true, false);
}

// ----------------------------------------------------------------

// Grab the list of ConfigurableParam data members
// Returns a nullptr if the TClass of the P template class cannot be created.
std::vector<ParamDataMember>* getDataMembers() const
{
// just a helper line to make sure P::sInstance is looked-up
// and that compiler complains about missing static sInstance of type P
// volatile void* ptr = (void*)&P::sInstance;
// static assert on type of sInstance:
static_assert(std::is_same<decltype(P::sInstance), P>::value,
"static instance must of same type as class");

// obtain the TClass for the Base type and delegate further
auto cl = TClass::GetClass(typeid(Base));
if (!cl) {
_ParamHelper::printWarning(typeid(Base));
return nullptr;
}

// we need to put an offset of 8 bytes since internally this is using data members of the Base class
// which doesn't account for the virtual table of P
return _ParamHelper::getDataMembersImpl(getName(), cl, (void*)this, sValueProvenanceMap, 8);
}

// ----------------------------------------------------------------

// fills the data structures with the initial default values
void putKeyValues(boost::property_tree::ptree* tree) final
{
auto cl = TClass::GetClass(typeid(Base));
if (!cl) {
_ParamHelper::printWarning(typeid(Base));
return;
}
_ParamHelper::fillKeyValuesImpl(getName(), cl, (void*)this, tree, sKeyToStorageMap, sEnumRegistry, 8);
}

// ----------------------------------------------------------------

void initFrom(TFile* file) final
{
// switch off auto registering since the readback object is
// only a "temporary" singleton
setRegisterMode(false);
P* readback = nullptr;
file->GetObject(getName().c_str(), readback);
if (readback != nullptr) {
_ParamHelper::assignmentImpl(getName(), TClass::GetClass(typeid(Base)), (void*)this, (void*)readback,
sValueProvenanceMap, 8);
delete readback;
}
setRegisterMode(true);
}

// ----------------------------------------------------------------

void syncCCDBandRegistry(void* externalobj) final
{
// We may be getting an external copy from CCDB which is passed as externalobj.
// The task of this function is to
// a) update the internal registry with fields coming from CCDB
// but only if keys have not been modified via RT == command line / ini file
// b) update the external object with with fields having RT provenance
//
setRegisterMode(false);
_ParamHelper::syncCCDBandRegistry(getName(), TClass::GetClass(typeid(Base)), (void*)this, (void*)externalobj,
sValueProvenanceMap, 8);
setRegisterMode(true);
}

Expand Down
66 changes: 66 additions & 0 deletions Common/Utils/include/CommonUtils/EnumBitOperators.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
#ifndef O2_FRAMEWORK_ENUM_BIT_OPERATORS_H_
#define O2_FRAMEWORK_ENUM_BIT_OPERATORS_H_

#include <type_traits>

#define O2_DEFINE_ENUM_BIT_OPERATORS(enum_t) \
constexpr auto operator|(enum_t lhs, enum_t rhs) \
{ \
return static_cast<enum_t>( \
static_cast<std::underlying_type_t<enum_t>>(lhs) | \
static_cast<std::underlying_type_t<enum_t>>(rhs)); \
} \
\
constexpr auto operator&(enum_t lhs, enum_t rhs) \
{ \
return static_cast<enum_t>( \
static_cast<std::underlying_type_t<enum_t>>(lhs) & \
static_cast<std::underlying_type_t<enum_t>>(rhs)); \
} \
\
constexpr auto operator^(enum_t lhs, enum_t rhs) \
{ \
return static_cast<enum_t>( \
static_cast<std::underlying_type_t<enum_t>>(lhs) ^ \
static_cast<std::underlying_type_t<enum_t>>(rhs)); \
} \
\
constexpr auto operator~(enum_t op) \
{ \
return static_cast<enum_t>( \
~static_cast<std::underlying_type_t<enum_t>>(op)); \
} \
\
constexpr auto& operator|=(enum_t& lhs, enum_t rhs) \
{ \
lhs = lhs | rhs; \
return lhs; \
} \
\
constexpr auto& operator&=(enum_t& lhs, enum_t rhs) \
{ \
lhs = lhs & rhs; \
return lhs; \
} \
\
constexpr enum_t& operator^=(enum_t& lhs, enum_t rhs) \
{ \
lhs = lhs ^ rhs; \
return lhs; \
}

#define O2_ENUM_TEST_BIT(mask, value) ((mask & value) == value)
#define O2_ENUM_SET_BIT(bit) ((1 << bit))
#define O2_ENUM_ANY_BIT(enum) ((static_cast<std::underlying_type_t<decltype(enum)>>(enum) != 0))

#endif
7 changes: 7 additions & 0 deletions Common/Utils/include/CommonUtils/TreeStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class TreeStream
const char* getName() const { return mTree.GetName(); }
void setID(int id) { mID = id; }
int getID() const { return mID; }

TreeStream& operator<<(const Bool_t& b)
{
CheckIn('B', &b);
Expand All @@ -75,6 +76,12 @@ class TreeStream
return *this;
}

TreeStream& operator<<(const int8_t& i)
{
CheckIn('B', &i);
return *this;
}

TreeStream& operator<<(const UChar_t& c)
{
CheckIn('b', &c);
Expand Down
Loading

0 comments on commit 140e172

Please sign in to comment.