52 auto header = o2::header::get<const DataHeader*>(
ref.header);
54 throw runtime_error(
"Attempt to extract a POD from a wrong message kind");
56 if ((payloadSize %
sizeof(T)) != 0) {
57 throw runtime_error(
"Cannot extract POD from message as size do not match");
60 return gsl::span<T>(
reinterpret_cast<T*
>(
const_cast<char*
>(
ref.payload)), payloadSize /
sizeof(T));
64 static_assert(is_type_complete_v<struct RootSerializationSupport>,
"Framework/RootSerializationSupport.h not included");
65 call_if_defined<struct RootSerializationSupport>([&](
auto* p) {
71 using RSS = std::decay_t<
decltype(*p)>;
73 auto header = o2::header::get<const DataHeader*>(
ref.header);
75 throw runtime_error(
"Attempt to extract a TMessage from non-ROOT serialised message");
78 typename RSS::FairInputTBuffer ftm(
const_cast<char*
>(
ref.payload), payloadSize);
79 auto* requestedClass = RSS::TClass::GetClass(
typeid(T));
81 auto* storedClass = ftm.ReadClass();
83 assert(requestedClass !=
nullptr);
85 ftm.SetBufferOffset(0);
87 auto*
object = ftm.ReadObjectAny(storedClass);
88 if (
object ==
nullptr) {
89 throw runtime_error_f(
"Failed to read object with name %s from message using ROOT serialization.",
90 (storedClass !=
nullptr ? storedClass->GetName() :
"<unknown>"));
93 if constexpr (std::is_base_of<typename RSS::TObject, T>::value) {
102 auto*
r =
dynamic_cast<T*
>(
static_cast<typename RSS::TObject*
>(
object));
107 }
else if (storedClass->InheritsFrom(requestedClass)) {
108 result.reset(
static_cast<T*
>(
object));
115 auto* delfunc = storedClass->GetDelete();
120 throw runtime_error_f(
"Attempting to extract a %s but a %s is actually stored which cannot be casted to the requested one.",
121 (requestedClass !=
nullptr ? requestedClass->GetName() :
"<unknown>"),
122 (storedClass !=
nullptr ? storedClass->GetName() :
"<unknown>"));
129 if constexpr (
requires(T t) { t.SetOwner(
true); }) {
135 }
else if constexpr (is_specialization_v<T, ROOTSerialized> ==
true) {
139 static_assert(is_type_complete_v<struct RootSerializationSupport>,
"Framework/RootSerializationSupport.h not included");
140 using wrapped =
typename T::wrapped_type;
142 std::unique_ptr<wrapped>
result;
144 call_if_defined<struct RootSerializationSupport>([&](
auto* p) {
145 using RSS = std::decay_t<
decltype(*p)>;
147 auto header = o2::header::get<const DataHeader*>(
ref.header);
149 throw runtime_error(
"Attempt to extract a TMessage from non-ROOT serialised message");
151 auto* cl = RSS::TClass::GetClass(
typeid(wrapped));
153 throw runtime_error(
"ROOT serialization not supported, dictionary not found for data type");
156 typename RSS::FairInputTBuffer ftm(
const_cast<char*
>(
ref.payload), payloadSize);
158 auto* classInfo = ftm.ReadClass();
159 ftm.SetBufferOffset(0);
161 result.reset(
static_cast<wrapped*
>(ftm.ReadObjectAny(cl)));
162 if (
result.get() ==
nullptr) {
163 throw runtime_error_f(
"Unable to extract class %s", cl ==
nullptr ?
"<name not available>" : cl->GetName());
166 if constexpr (
requires(T t) { t.SetOwner(
true); }) {
171 }
else if constexpr (is_specialization_v<T, CCDBSerialized> ==
true) {
172 using wrapped =
typename T::wrapped_type;
175 if constexpr (std::is_base_of<o2::conf::ConfigurableParam, wrapped>::value) {
176 auto&
param =
const_cast<typename std::remove_const<wrapped&>::type
>(wrapped::Instance());
180 std::unique_ptr<wrapped>
result(
static_cast<wrapped*
>(
ptr));