@@ -2370,58 +2370,77 @@ 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(_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+ if (!streamed) { \
2419+ LOGP(fatal, \
2420+ "Could not deserialise a {} from the CCDB payload for {} ({} bytes). Check the configured " \
2421+ "path (option \"ccdb:{}\") and that the object exists for this timestamp.", \
2422+ #_ConcreteType_, _CCDBQuery_, span.size(), _Label_); \
2423+ } \
2424+ deserialised = finalise(streamed); \
2425+ } \
2426+ return *deserialised; \
2427+ } \
2428+ } \
2429+ \
2430+ decltype(auto) \
2431+ get() const \
2432+ { \
2433+ return _Getter_(); \
2434+ } \
24212435 };
24222436
2423- #define DECLARE_SOA_CCDB_COLUMN(_Name_, _Getter_, _ConcreteType_, _CCDBQuery_) \
2424- DECLARE_SOA_CCDB_COLUMN_FULL(_Name_, "f" #_Name_, _Getter_, _ConcreteType_, _CCDBQuery_)
2437+ /* Conventional label, and the object used exactly as the ROOT streamer produced it. Reach
2438+ for DECLARE_SOA_CCDB_COLUMN_FULL when it needs finalising first — a FlatObject whose
2439+ pointers must be rectified, say. Its finaliser is the trailing argument, so commas in a
2440+ lambda body are absorbed by __VA_ARGS__. */
2441+ #define DECLARE_SOA_CCDB_COLUMN(_Name_, _Getter_, _ConcreteType_, _CCDBQuery_) \
2442+ DECLARE_SOA_CCDB_COLUMN_FULL(_Name_, "f" #_Name_, _Getter_, _ConcreteType_, _CCDBQuery_, \
2443+ [](_ConcreteType_* ccdbObject) { return ccdbObject; })
24252444
24262445#define DECLARE_SOA_COLUMN(_Name_, _Getter_, _Type_) \
24272446 DECLARE_SOA_COLUMN_FULL(_Name_, _Getter_, _Type_, "f" #_Name_)
0 commit comments