55 if constexpr (is_messageable<T>::value ==
true) {
57 auto header = o2::header::get<const DataHeader*>(
ref.header);
59 throw runtime_error(
"Attempt to extract a POD from a wrong message kind");
61 if ((payloadSize %
sizeof(T)) != 0) {
62 throw runtime_error(
"Cannot extract POD from message as size do not match");
65 return gsl::span<T>(
reinterpret_cast<T*
>(
const_cast<char*
>(
ref.payload)), payloadSize /
sizeof(T));
67 is_messageable<T>::value ==
false) {
69 static_assert(is_type_complete_v<struct RootSerializationSupport>,
"Framework/RootSerializationSupport.h not included");
70 call_if_defined<struct RootSerializationSupport>([&](
auto* p) {
76 using RSS = std::decay_t<
decltype(*p)>;
78 auto header = o2::header::get<const DataHeader*>(
ref.header);
80 throw runtime_error(
"Attempt to extract a TMessage from non-ROOT serialised message");
83 typename RSS::FairInputTBuffer ftm(
const_cast<char*
>(
ref.payload), payloadSize);
84 auto* requestedClass = RSS::TClass::GetClass(
typeid(T));
86 auto* storedClass = ftm.ReadClass();
88 assert(requestedClass !=
nullptr);
90 ftm.SetBufferOffset(0);
92 auto*
object = ftm.ReadObjectAny(storedClass);
93 if (
object ==
nullptr) {
94 throw runtime_error_f(
"Failed to read object with name %s from message using ROOT serialization.",
95 (storedClass !=
nullptr ? storedClass->GetName() :
"<unknown>"));
98 if constexpr (std::is_base_of<typename RSS::TObject, T>::value) {
107 auto*
r =
dynamic_cast<T*
>(
static_cast<typename RSS::TObject*
>(
object));
112 }
else if (storedClass->InheritsFrom(requestedClass)) {
113 result.reset(
static_cast<T*
>(
object));
120 auto* delfunc = storedClass->GetDelete();
125 throw runtime_error_f(
"Attempting to extract a %s but a %s is actually stored which cannot be casted to the requested one.",
126 (requestedClass !=
nullptr ? requestedClass->GetName() :
"<unknown>"),
127 (storedClass !=
nullptr ? storedClass->GetName() :
"<unknown>"));
134 if constexpr (
requires(T t) { t.SetOwner(
true); }) {
140 }
else if constexpr (is_specialization_v<T, ROOTSerialized> ==
true) {
144 static_assert(is_type_complete_v<struct RootSerializationSupport>,
"Framework/RootSerializationSupport.h not included");
145 using wrapped =
typename T::wrapped_type;
147 std::unique_ptr<wrapped>
result;
149 call_if_defined<struct RootSerializationSupport>([&](
auto* p) {
150 using RSS = std::decay_t<
decltype(*p)>;
152 auto header = o2::header::get<const DataHeader*>(
ref.header);
154 throw runtime_error(
"Attempt to extract a TMessage from non-ROOT serialised message");
156 auto* cl = RSS::TClass::GetClass(
typeid(wrapped));
158 throw runtime_error(
"ROOT serialization not supported, dictionary not found for data type");
161 typename RSS::FairInputTBuffer ftm(
const_cast<char*
>(
ref.payload), payloadSize);
163 auto* classInfo = ftm.ReadClass();
164 ftm.SetBufferOffset(0);
166 result.reset(
static_cast<wrapped*
>(ftm.ReadObjectAny(cl)));
167 if (
result.get() ==
nullptr) {
168 throw runtime_error_f(
"Unable to extract class %s", cl ==
nullptr ?
"<name not available>" : cl->GetName());
171 if constexpr (
requires(T t) { t.SetOwner(
true); }) {
176 }
else if constexpr (is_specialization_v<T, CCDBSerialized> ==
true) {
177 using wrapped =
typename T::wrapped_type;
180 if constexpr (std::is_base_of<o2::conf::ConfigurableParam, wrapped>::value) {
181 auto&
param =
const_cast<typename std::remove_const<wrapped&>::type
>(wrapped::Instance());
185 std::unique_ptr<wrapped>
result(
static_cast<wrapped*
>(
ptr));