48 auto header = o2::header::get<const DataHeader*>(
ref.header);
50 throw runtime_error(
"Attempt to extract a POD from a wrong message kind");
52 if ((payloadSize %
sizeof(T)) != 0) {
53 throw runtime_error(
"Cannot extract POD from message as size do not match");
56 return gsl::span<T>(
reinterpret_cast<T*
>(
const_cast<char*
>(
ref.payload)), payloadSize /
sizeof(T));
60 static_assert(is_type_complete_v<struct RootSerializationSupport>,
"Framework/RootSerializationSupport.h not included");
61 call_if_defined<struct RootSerializationSupport>([&](
auto* p) {
67 using RSS = std::decay_t<
decltype(*p)>;
69 auto header = o2::header::get<const DataHeader*>(
ref.header);
71 throw runtime_error(
"Attempt to extract a TMessage from non-ROOT serialised message");
74 typename RSS::FairInputTBuffer ftm(
const_cast<char*
>(
ref.payload), payloadSize);
75 auto* requestedClass = RSS::TClass::GetClass(
typeid(T));
77 auto* storedClass = ftm.ReadClass();
79 assert(requestedClass !=
nullptr);
81 ftm.SetBufferOffset(0);
83 auto*
object = ftm.ReadObjectAny(storedClass);
84 if (
object ==
nullptr) {
85 throw runtime_error_f(
"Failed to read object with name %s from message using ROOT serialization.",
86 (storedClass !=
nullptr ? storedClass->GetName() :
"<unknown>"));
89 if constexpr (std::is_base_of<typename RSS::TObject, T>::value) {
98 auto*
r =
dynamic_cast<T*
>(
static_cast<typename RSS::TObject*
>(
object));
103 }
else if (storedClass->InheritsFrom(requestedClass)) {
104 result.reset(
static_cast<T*
>(
object));
111 auto* delfunc = storedClass->GetDelete();
116 throw runtime_error_f(
"Attempting to extract a %s but a %s is actually stored which cannot be casted to the requested one.",
117 (requestedClass !=
nullptr ? requestedClass->GetName() :
"<unknown>"),
118 (storedClass !=
nullptr ? storedClass->GetName() :
"<unknown>"));
125 if constexpr (
requires(T t) { t.SetOwner(
true); }) {
131 }
else if constexpr (is_specialization_v<T, ROOTSerialized> ==
true) {
135 static_assert(is_type_complete_v<struct RootSerializationSupport>,
"Framework/RootSerializationSupport.h not included");
136 using wrapped =
typename T::wrapped_type;
138 std::unique_ptr<wrapped>
result;
140 call_if_defined<struct RootSerializationSupport>([&](
auto* p) {
141 using RSS = std::decay_t<
decltype(*p)>;
143 auto header = o2::header::get<const DataHeader*>(
ref.header);
145 throw runtime_error(
"Attempt to extract a TMessage from non-ROOT serialised message");
147 auto* cl = RSS::TClass::GetClass(
typeid(wrapped));
149 throw runtime_error(
"ROOT serialization not supported, dictionary not found for data type");
152 typename RSS::FairInputTBuffer ftm(
const_cast<char*
>(
ref.payload), payloadSize);
154 auto* classInfo = ftm.ReadClass();
155 ftm.SetBufferOffset(0);
157 result.reset(
static_cast<wrapped*
>(ftm.ReadObjectAny(cl)));
158 if (
result.get() ==
nullptr) {
159 throw runtime_error_f(
"Unable to extract class %s", cl ==
nullptr ?
"<name not available>" : cl->GetName());
162 if constexpr (
requires(T t) { t.SetOwner(
true); }) {
167 }
else if constexpr (is_specialization_v<T, CCDBSerialized> ==
true) {
168 using wrapped =
typename T::wrapped_type;
171 if constexpr (std::is_base_of<o2::conf::ConfigurableParam, wrapped>::value) {
172 auto&
param =
const_cast<typename std::remove_const<wrapped&>::type
>(wrapped::Instance());
176 std::unique_ptr<wrapped>
result(
static_cast<wrapped*
>(
ptr));