Skip to content

Commit 20d95ab

Browse files
committed
DPL Analysis: allow finalising callback also for CCDB columns
Allows having the LUT as a CCDB column.
1 parent a63c2a2 commit 20d95ab

1 file changed

Lines changed: 65 additions & 48 deletions

File tree

  • Framework/Core/include/Framework

Framework/Core/include/Framework/ASoA.h

Lines changed: 65 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2370,59 +2370,76 @@ consteval static std::string_view namespace_prefix()
23702370
}; \
23712371
[[maybe_unused]] static constexpr o2::framework::expressions::BindingNode _Getter_ { _Label_, _Name_::hash, o2::framework::expressions::selectArrowType<_Type_>() }
23722372

2373-
#define DECLARE_SOA_CCDB_COLUMN_FULL(_Name_, _Label_, _Getter_, _ConcreteType_, _CCDBQuery_) \
2374-
struct _Name_ : o2::soa::Column<int64_t[3], _Name_> { \
2375-
static constexpr const char* mLabel = _Label_; \
2376-
static constexpr const char* query = _CCDBQuery_; \
2377-
static constexpr const uint32_t hash = crc32(namespace_prefix<_Name_>(), std::string_view{#_Getter_}); \
2378-
static constexpr bool needs_ptr_rec = true; \
2379-
std::function<std::byte*(fair::mq::shmem::MetaHeader&&)> const* ptrRec = nullptr; \
2380-
using base = o2::soa::Column<int64_t[3], _Name_>; \
2381-
using type = int64_t[3]; \
2382-
using column_t = _Name_; \
2383-
_Name_(arrow::ChunkedArray const* column) \
2384-
: o2::soa::Column<int64_t[3], _Name_>(o2::soa::ColumnIterator<int64_t[3]>(column)) \
2385-
{ \
2386-
} \
2387-
\
2388-
_Name_() = default; \
2389-
_Name_(_Name_ const& other) = default; \
2390-
_Name_& operator=(_Name_ const& other) = default; \
2391-
\
2392-
decltype(auto) _Getter_() const \
2393-
{ \
2394-
auto& [handle, segment, size] = *mColumnIterator; \
2395-
auto span = std::span<std::byte>{(*ptrRec)(fair::mq::shmem::MetaHeader{ \
2396-
static_cast<size_t>(size), \
2397-
0, handle, 0, 0, \
2398-
static_cast<uint16_t>(segment), true}), \
2399-
static_cast<size_t>(size)}; \
2400-
if constexpr (std::same_as<_ConcreteType_, std::span<std::byte>>) { \
2401-
return span; \
2402-
} else { \
2403-
static std::byte* payload = nullptr; \
2404-
static _ConcreteType_* deserialised = nullptr; \
2405-
static TClass* c = TClass::GetClass(#_ConcreteType_); \
2406-
if (payload != (std::byte*)span.data()) { \
2407-
payload = (std::byte*)span.data(); \
2408-
delete deserialised; \
2409-
TBufferFile f(TBufferFile::EMode::kRead, span.size(), (char*)span.data(), kFALSE); \
2410-
deserialised = (_ConcreteType_*)soa::extractCCDBPayload((char*)payload, span.size(), c, "ccdb_object"); \
2411-
} \
2412-
return *deserialised; \
2413-
} \
2414-
} \
2415-
\
2416-
decltype(auto) \
2417-
get() const \
2418-
{ \
2419-
return _Getter_(); \
2420-
} \
2373+
#define DECLARE_SOA_CCDB_COLUMN_FULL_FINALISED(_Name_, _Label_, _Getter_, _ConcreteType_, _CCDBQuery_, ...) \
2374+
struct _Name_ : o2::soa::Column<int64_t[3], _Name_> { \
2375+
static constexpr const char* mLabel = _Label_; \
2376+
static constexpr const char* query = _CCDBQuery_; \
2377+
static constexpr const uint32_t hash = crc32(namespace_prefix<_Name_>(), std::string_view{#_Getter_}); \
2378+
static constexpr bool needs_ptr_rec = true; \
2379+
/* Post-deserialisation fixup for objects which are not usable straight out of the ROOT */ \
2380+
/* streamer, e.g. FlatObjects whose internal pointers must be rectified first. Runs on */ \
2381+
/* the receiving device, once per (re)deserialisation, before the object is ever handed */ \
2382+
/* out. Returns the object to cache: a finaliser returning a different instance owns */ \
2383+
/* disposing of the one it was given. */ \
2384+
using finaliser_t = _ConcreteType_* (*)(_ConcreteType_*); \
2385+
static constexpr finaliser_t finalise = __VA_ARGS__; \
2386+
std::function<std::byte*(fair::mq::shmem::MetaHeader&&)> const* ptrRec = nullptr; \
2387+
using base = o2::soa::Column<int64_t[3], _Name_>; \
2388+
using type = int64_t[3]; \
2389+
using column_t = _Name_; \
2390+
_Name_(arrow::ChunkedArray const* column) \
2391+
: o2::soa::Column<int64_t[3], _Name_>(o2::soa::ColumnIterator<int64_t[3]>(column)) \
2392+
{ \
2393+
} \
2394+
\
2395+
_Name_() = default; \
2396+
_Name_(_Name_ const& other) = default; \
2397+
_Name_& operator=(_Name_ const& other) = default; \
2398+
\
2399+
decltype(auto) _Getter_() const \
2400+
{ \
2401+
auto& [handle, segment, size] = *mColumnIterator; \
2402+
auto span = std::span<std::byte>{(*ptrRec)(fair::mq::shmem::MetaHeader{ \
2403+
static_cast<size_t>(size), \
2404+
0, handle, 0, 0, \
2405+
static_cast<uint16_t>(segment), true}), \
2406+
static_cast<size_t>(size)}; \
2407+
if constexpr (std::same_as<_ConcreteType_, std::span<std::byte>>) { \
2408+
return span; \
2409+
} else { \
2410+
static std::byte* payload = nullptr; \
2411+
static _ConcreteType_* deserialised = nullptr; \
2412+
static TClass* c = TClass::GetClass(#_ConcreteType_); \
2413+
if (payload != (std::byte*)span.data()) { \
2414+
payload = (std::byte*)span.data(); \
2415+
delete deserialised; \
2416+
TBufferFile f(TBufferFile::EMode::kRead, span.size(), (char*)span.data(), kFALSE); \
2417+
auto* streamed = (_ConcreteType_*)soa::extractCCDBPayload((char*)payload, span.size(), c, "ccdb_object"); \
2418+
deserialised = streamed ? finalise(streamed) : nullptr; \
2419+
} \
2420+
return *deserialised; \
2421+
} \
2422+
} \
2423+
\
2424+
decltype(auto) \
2425+
get() const \
2426+
{ \
2427+
return _Getter_(); \
2428+
} \
24212429
};
24222430

2431+
#define DECLARE_SOA_CCDB_COLUMN_FULL(_Name_, _Label_, _Getter_, _ConcreteType_, _CCDBQuery_) \
2432+
DECLARE_SOA_CCDB_COLUMN_FULL_FINALISED(_Name_, _Label_, _Getter_, _ConcreteType_, _CCDBQuery_, \
2433+
[](_ConcreteType_* ccdbObject) { return ccdbObject; })
2434+
24232435
#define DECLARE_SOA_CCDB_COLUMN(_Name_, _Getter_, _ConcreteType_, _CCDBQuery_) \
24242436
DECLARE_SOA_CCDB_COLUMN_FULL(_Name_, "f" #_Name_, _Getter_, _ConcreteType_, _CCDBQuery_)
24252437

2438+
/* As DECLARE_SOA_CCDB_COLUMN, plus a finalisation function run on the freshly deserialised
2439+
object. The finaliser must be the last argument so that commas in a lambda body are absorbed. */
2440+
#define DECLARE_SOA_CCDB_COLUMN_FINALISED(_Name_, _Getter_, _ConcreteType_, _CCDBQuery_, ...) \
2441+
DECLARE_SOA_CCDB_COLUMN_FULL_FINALISED(_Name_, "f" #_Name_, _Getter_, _ConcreteType_, _CCDBQuery_, __VA_ARGS__)
2442+
24262443
#define DECLARE_SOA_COLUMN(_Name_, _Getter_, _Type_) \
24272444
DECLARE_SOA_COLUMN_FULL(_Name_, _Getter_, _Type_, "f" #_Name_)
24282445

0 commit comments

Comments
 (0)