28namespace object_store_helpers
31constexpr static std::string_view errorPrefix =
"Could not extract object to be merged: ";
33template <
typename... Args>
36 std::ostringstream ss;
38 return std::move(ss.str());
43 using namespace std::string_view_literals;
44 auto*
object = ftm.ReadObjectAny(
type);
46 if (
object ==
nullptr) {
47 throw std::runtime_error(concat(errorPrefix,
"Failed to read object with name '"sv,
type->GetName(),
"' from message using ROOT serialization."sv));
54 using namespace std::string_view_literals;
56 if (objectAsMergeInterface ==
nullptr) {
57 throw std::runtime_error(concat(errorPrefix,
"Could not cast '"sv, storedClass->GetName(),
"' to MergeInterface"sv));
60 return objectAsMergeInterface;
70 auto result = std::vector<TObjectPtr>{};
71 result.reserve(extractedVector->size());
72 std::transform(extractedVector->begin(), extractedVector->end(), std::back_inserter(
result), [](
const auto& rawTObject) { return TObjectPtr(rawTObject, algorithm::deleteTCollections); });
85 using namespace std::string_view_literals;
88 throw std::runtime_error(concat(errorPrefix,
"It is not ROOT-serialized"sv));
93 auto* storedClass = ftm.ReadClass();
94 if (storedClass ==
nullptr) {
95 throw std::runtime_error(concat(errorPrefix,
"Unknown stored class"sv));
97 ftm.SetBufferOffset(0);
100 if (
const auto extractedVector =
extractVector(ftm, storedClass)) {
101 return extractedVector.value();
104 const bool inheritsFromMergeInterface = storedClass->InheritsFrom(TClass::GetClass(
typeid(
MergeInterface)));
105 const bool inheritsFromTObject = storedClass->InheritsFrom(TClass::GetClass(
typeid(
TObject)));
107 if (!inheritsFromMergeInterface && !inheritsFromTObject) {
108 throw std::runtime_error(concat(errorPrefix,
"Class '"sv, storedClass->GetName(),
"'does not inherit from MergeInterface nor TObject"sv));
113 if (inheritsFromMergeInterface) {
115 objectAsMergeInterface->postDeserialization();
126 result.reserve(vector.size());
127 std::transform(vector.begin(), vector.end(), std::back_inserter(
result), [](
const auto&
ptr) { return ptr.get(); });
131template <
typename TypeToSnapshot>
135 if (!std::holds_alternative<TypeToSnapshot>(
object)) {
149 if (!std::holds_alternative<VectorOfTObjectPtrs>(
object)) {
154 const auto& mergedVector = std::get<VectorOfTObjectPtrs>(
object);
Definition of O2 Mergers merging interface, v0.1.
Algorithms for merging objects.
Definition of ObjectStore for Mergers, v0.1.
void snapshot(const Output &spec, T const &object)
An interface which allows to merge custom objects.
static std::string mergerIntegralOutputBinding()
GLint GLint GLsizei GLint GLenum GLenum type
bpo::variables_map arguments
void deleteTCollections(TObject *obj)
MergeInterface * castToMergeInterface(bool inheritsFromTObject, void *object, TClass *storedClass)
void * readObject(const TClass *type, o2::framework::FairInputTBuffer &ftm)
std::optional< ObjectStore > extractVector(o2::framework::FairInputTBuffer &ftm, const TClass *storedClass)
ObjectStore extractObjectFrom(const framework::DataRef &ref)
Takes a DataRef, deserializes it (if type is supported) and puts into an ObjectStore.
VectorOfRawTObjects toRawObserverPointers(const VectorOfTObjectPtrs &)
Helper function that converts vector of smart pointers to the vector of raw pointers that is serializ...
bool snapshot(framework::DataAllocator &allocator, const header::DataHeader::SubSpecificationType subSpec, const ObjectStore &mergedObject)
Used in FullHistorMerger's and IntegratingMerger's publish function. Checks mergedObject for every st...
std::vector< TObjectPtr > VectorOfTObjectPtrs
std::vector< TObject * > VectorOfRawTObjects
std::shared_ptr< TObject > TObjectPtr
std::shared_ptr< MergeInterface > MergeInterfacePtr
std::variant< std::monostate, TObjectPtr, VectorOfTObjectPtrs, MergeInterfacePtr > ObjectStore
constexpr auto concat(Ts const &... t)
static o2::header::DataHeader::PayloadSizeType getPayloadSize(const DataRef &ref)
static bool snapshot(framework::DataAllocator &allocator, const header::DataHeader::SubSpecificationType subSpec, const ObjectStore &object)
static bool snapshot(framework::DataAllocator &allocator, const header::DataHeader::SubSpecificationType subSpec, const ObjectStore &object)