Skip to content

Commit 053adc6

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

1 file changed

Lines changed: 70 additions & 48 deletions

File tree

  • Framework/Core/include/Framework

Framework/Core/include/Framework/ASoA.h

Lines changed: 70 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2370,59 +2370,81 @@ 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+
if (!streamed) { \
2419+
LOGP(fatal, "Could not deserialise a {} from the CCDB payload for {} ({} bytes). Check the configured " \
2420+
"path (option \"ccdb:{}\") and that the object exists for this timestamp.", \
2421+
#_ConcreteType_, _CCDBQuery_, span.size(), _Label_); \
2422+
} \
2423+
deserialised = finalise(streamed); \
2424+
} \
2425+
return *deserialised; \
2426+
} \
2427+
} \
2428+
\
2429+
decltype(auto) \
2430+
get() const \
2431+
{ \
2432+
return _Getter_(); \
2433+
} \
24212434
};
24222435

2436+
#define DECLARE_SOA_CCDB_COLUMN_FULL(_Name_, _Label_, _Getter_, _ConcreteType_, _CCDBQuery_) \
2437+
DECLARE_SOA_CCDB_COLUMN_FULL_FINALISED(_Name_, _Label_, _Getter_, _ConcreteType_, _CCDBQuery_, \
2438+
[](_ConcreteType_* ccdbObject) { return ccdbObject; })
2439+
24232440
#define DECLARE_SOA_CCDB_COLUMN(_Name_, _Getter_, _ConcreteType_, _CCDBQuery_) \
24242441
DECLARE_SOA_CCDB_COLUMN_FULL(_Name_, "f" #_Name_, _Getter_, _ConcreteType_, _CCDBQuery_)
24252442

2443+
/* As DECLARE_SOA_CCDB_COLUMN, plus a finalisation function run on the freshly deserialised
2444+
object. The finaliser must be the last argument so that commas in a lambda body are absorbed. */
2445+
#define DECLARE_SOA_CCDB_COLUMN_FINALISED(_Name_, _Getter_, _ConcreteType_, _CCDBQuery_, ...) \
2446+
DECLARE_SOA_CCDB_COLUMN_FULL_FINALISED(_Name_, "f" #_Name_, _Getter_, _ConcreteType_, _CCDBQuery_, __VA_ARGS__)
2447+
24262448
#define DECLARE_SOA_COLUMN(_Name_, _Getter_, _Type_) \
24272449
DECLARE_SOA_COLUMN_FULL(_Name_, _Getter_, _Type_, "f" #_Name_)
24282450

0 commit comments

Comments
 (0)