51 if constexpr (is_messageable<T>::value ==
true) {
53 auto header = o2::header::get<const DataHeader*>(
ref.header);
55 throw runtime_error(
"Attempt to extract a POD from a wrong message kind");
57 if ((payloadSize %
sizeof(T)) != 0) {
58 throw runtime_error(
"Cannot extract POD from message as size do not match");
61 return gsl::span<T>(
reinterpret_cast<T*
>(
const_cast<char*
>(
ref.payload)), payloadSize /
sizeof(T));
63 is_messageable<T>::value ==
false) {
65 static_assert(is_type_complete_v<struct RootSerializationSupport>,
"Framework/RootSerializationSupport.h not included");
66 call_if_defined<struct RootSerializationSupport>([&](
auto* p) {
72 using RSS = std::decay_t<
decltype(*p)>;
74 auto header = o2::header::get<const DataHeader*>(
ref.header);
76 throw runtime_error(
"Attempt to extract a TMessage from non-ROOT serialised message");
79 typename RSS::FairInputTBuffer ftm(
const_cast<char*
>(
ref.payload), payloadSize);
80 auto* requestedClass = RSS::TClass::GetClass(
typeid(T));
82 auto* storedClass = ftm.ReadClass();
84 assert(requestedClass !=
nullptr);
86 ftm.SetBufferOffset(0);
88 auto*
object = ftm.ReadObjectAny(storedClass);
89 if (
object ==
nullptr) {
90 throw runtime_error_f(
"Failed to read object with name %s from message using ROOT serialization.",
91 (storedClass !=
nullptr ? storedClass->GetName() :
"<unknown>"));
94 if constexpr (std::is_base_of<typename RSS::TObject, T>::value) {
103 auto*
r =
dynamic_cast<T*
>(
static_cast<typename RSS::TObject*
>(
object));
108 }
else if (storedClass->InheritsFrom(requestedClass)) {
109 result.reset(
static_cast<T*
>(
object));
116 auto* delfunc = storedClass->GetDelete();
121 throw runtime_error_f(
"Attempting to extract a %s but a %s is actually stored which cannot be casted to the requested one.",
122 (requestedClass !=
nullptr ? requestedClass->GetName() :
"<unknown>"),
123 (storedClass !=
nullptr ? storedClass->GetName() :
"<unknown>"));
130 if constexpr (
requires(T t) { t.SetOwner(
true); }) {
136 }
else if constexpr (is_specialization_v<T, ROOTSerialized> ==
true) {
140 static_assert(is_type_complete_v<struct RootSerializationSupport>,
"Framework/RootSerializationSupport.h not included");
141 using wrapped =
typename T::wrapped_type;
143 std::unique_ptr<wrapped>
result;
145 call_if_defined<struct RootSerializationSupport>([&](
auto* p) {
146 using RSS = std::decay_t<
decltype(*p)>;
148 auto header = o2::header::get<const DataHeader*>(
ref.header);
150 throw runtime_error(
"Attempt to extract a TMessage from non-ROOT serialised message");
152 auto* cl = RSS::TClass::GetClass(
typeid(wrapped));
154 throw runtime_error(
"ROOT serialization not supported, dictionary not found for data type");
157 typename RSS::FairInputTBuffer ftm(
const_cast<char*
>(
ref.payload), payloadSize);
159 auto* classInfo = ftm.ReadClass();
160 ftm.SetBufferOffset(0);
162 result.reset(
static_cast<wrapped*
>(ftm.ReadObjectAny(cl)));
163 if (
result.get() ==
nullptr) {
164 throw runtime_error_f(
"Unable to extract class %s", cl ==
nullptr ?
"<name not available>" : cl->GetName());
167 if constexpr (
requires(T t) { t.SetOwner(
true); }) {
172 }
else if constexpr (is_specialization_v<T, CCDBSerialized> ==
true) {
173 using wrapped =
typename T::wrapped_type;
176 if constexpr (std::is_base_of<o2::conf::ConfigurableParam, wrapped>::value) {
177 auto&
param =
const_cast<typename std::remove_const<wrapped&>::type
>(wrapped::Instance());
181 std::unique_ptr<wrapped>
result(
static_cast<wrapped*
>(
ptr));