Project
Loading...
Searching...
No Matches
RootMessageContext.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11#ifndef O2_FRAMEWORK_ROOTMESSAGECONTEXT_H_
12#define O2_FRAMEWORK_ROOTMESSAGECONTEXT_H_
13
25
26#include "Headers/DataHeader.h"
27#include "Headers/Stack.h"
29
30#include <fairmq/Message.h>
31#include <fairmq/Parts.h>
32
33#include <cassert>
34#include <functional>
35#include <string>
36#include <type_traits>
37#include <vector>
38
39#include <fairmq/FwdDecls.h>
40
41namespace o2::framework
42{
43
44struct Output;
45
49template <typename T>
51{
52 public:
53 // Note: we strictly require the type to implement the ROOT ClassDef interface in order to be
54 // able to check for the existence of the dirctionary for this type. Could be dropped if any
55 // use case for a type having the dictionary at runtime pops up
56 static_assert(has_root_dictionary<T>::value == true, "unconsistent type: needs to implement ROOT ClassDef interface");
57 using value_type = T;
61 template <typename ContextType, typename... Args>
62 RootSerializedObject(ContextType* context, fair::mq::MessagePtr&& headerMsg, RouteIndex routeIndex, Args&&... args)
63 : ContextObject(std::forward<fair::mq::MessagePtr>(headerMsg), routeIndex)
64 {
65 mObject = std::make_unique<value_type>(std::forward<Args>(args)...);
66 mPayloadMsg = context->proxy().createOutputMessage(routeIndex);
67 }
68 ~RootSerializedObject() override = default;
69
72 fair::mq::Parts finalize() final
73 {
74 assert(mParts.Size() == 1);
75 if (mPayloadMsg->GetSize() < sizeof(char*)) {
76 mPayloadMsg->Rebuild(4096, {64});
77 }
78 TMessageSerializer::Serialize(*mPayloadMsg, mObject.get(), nullptr);
79 mParts.AddPart(std::move(mPayloadMsg));
80 return ContextObject::finalize();
81 }
82
83 operator value_type&()
84 {
85 return *mObject;
86 }
87
89 {
90 return *mObject;
91 }
92
93 private:
94 std::unique_ptr<value_type> mObject;
95 fair::mq::MessagePtr mPayloadMsg;
96};
97
98template <typename T>
99struct enable_root_serialization<T, std::enable_if_t<has_root_dictionary<T>::value && is_messageable<T>::value == false>> : std::true_type {
101};
102
103template <typename T>
104struct root_serializer<T, std::enable_if_t<has_root_dictionary<T>::value || is_specialization<T, ROOTSerialized>::value == true>> : std::true_type {
106};
107
108} // namespace o2::framework
109#endif // O2_FRAMEWORK_MESSAGECONTEXT_H_
Type wrappers for enfording a specific serialization method.
~RootSerializedObject() override=default
RootSerializedObject()=delete
default constructor forbidden, object alwasy has to control messages
RootSerializedObject(ContextType *context, fair::mq::MessagePtr &&headerMsg, RouteIndex routeIndex, Args &&... args)
constructor taking header message by move and creating the object from variadic argument list
fair::mq::Parts finalize() final
Finalize object and return parts by move This retrieves the actual message from the vector object and...
Defining PrimaryVertex explicitly as messageable.
Defining DataPointCompositeObject explicitly as copiable.
static void Serialize(fair::mq::Message &msg, const TObject *input)