Project
Loading...
Searching...
No Matches
FairMQDeviceProxy.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_FAIRMQDEVICEPROXY_H_
12#define O2_FRAMEWORK_FAIRMQDEVICEPROXY_H_
13
14#include <memory>
15
22#include <fairmq/FwdDecls.h>
23#include <fairmq/Version.h>
24#if (FAIRMQ_VERSION_DEC >= 111000)
25#include <fairmq/shmem/Common.h>
26#endif
27#include <vector>
28
29namespace o2::header
30{
31struct DataHeader;
32};
33
34namespace o2::framework
35{
36#if (FAIRMQ_VERSION_DEC >= 111000)
37using PointerReconstructor = std::function<std::byte*(fair::mq::shmem::MetaHeader&&)>;
38#endif
43{
44 public:
45 FairMQDeviceProxy() = default;
47 void bind(std::vector<OutputRoute> const& outputs, std::vector<InputRoute> const& inputs,
48 std::vector<ForwardRoute> const& forwards,
49 std::function<fair::mq::Channel&(std::string const&)> bindChannelByName,
50 std::function<bool(void)> newStateRequestedCallback);
51
53 [[nodiscard]] OutputRoute const& getOutputRoute(RouteIndex routeIndex) const { return mOutputs.at(routeIndex.value); }
55 [[nodiscard]] fair::mq::TransportFactory* getOutputTransport(RouteIndex routeIndex) const;
57 [[nodiscard]] fair::mq::TransportFactory* getInputTransport(RouteIndex routeIndex) const;
59 [[nodiscard]] fair::mq::TransportFactory* getForwardTransport(RouteIndex routeIndex) const;
61 [[nodiscard]] ChannelIndex getOutputChannelIndexByName(std::string const& channelName) const;
63 [[nodiscard]] ChannelIndex getInputChannelIndexByName(std::string const& channelName) const;
65 [[nodiscard]] ChannelIndex getForwardChannelIndexByName(std::string const& channelName) const;
67 [[nodiscard]] ChannelIndex getOutputChannelIndex(OutputSpec const& spec, size_t timeslice) const;
68#if (FAIRMQ_VERSION_DEC >= 111000)
70 [[nodiscard]] PointerReconstructor getShmPointerReconstructor(InputSpec const& spec, size_t timeslice);
71#endif
73 void getMatchingForwardChannelIndexes(std::vector<ChannelIndex>& result, header::DataHeader const& header, size_t timeslice) const;
75 [[nodiscard]] ChannelIndex getOutputChannelIndex(RouteIndex routeIndex) const;
76 [[nodiscard]] ChannelIndex getInputChannelIndex(RouteIndex routeIndex) const;
77 [[nodiscard]] ChannelIndex getForwardChannelIndex(RouteIndex routeIndex) const;
79 [[nodiscard]] fair::mq::Channel* getInputChannel(ChannelIndex channelIndex) const;
80 [[nodiscard]] fair::mq::Channel* getOutputChannel(ChannelIndex channelIndex) const;
81 [[nodiscard]] fair::mq::Channel* getForwardChannel(ChannelIndex channelIndex) const;
82
84 [[nodiscard]] OutputChannelInfo const& getOutputChannelInfo(ChannelIndex channelIndex) const;
86 [[nodiscard]] ForwardChannelInfo const& getForwardChannelInfo(ChannelIndex channelIndex) const;
87
92
93 [[nodiscard]] std::unique_ptr<fair::mq::Message> createOutputMessage(RouteIndex routeIndex) const;
94 [[nodiscard]] std::unique_ptr<fair::mq::Message> createOutputMessage(RouteIndex routeIndex, const size_t size) const;
95
96 [[nodiscard]] std::unique_ptr<fair::mq::Message> createInputMessage(RouteIndex routeIndex) const;
97 [[nodiscard]] std::unique_ptr<fair::mq::Message> createInputMessage(RouteIndex routeIndex, const size_t size) const;
98
99 [[nodiscard]] std::unique_ptr<fair::mq::Message> createForwardMessage(RouteIndex routeIndex) const;
100
101 [[nodiscard]] size_t getNumOutputChannels() const { return mOutputChannelInfos.size(); }
102 [[nodiscard]] size_t getNumInputChannels() const { return mInputChannels.size(); }
103 [[nodiscard]] size_t getNumForwardChannels() const { return mForwardChannelInfos.size(); }
104 [[nodiscard]] size_t getNumForwards() const { return mForwards.size(); }
105
106 [[nodiscard]] bool newStateRequested() const { return mStateChangeCallback(); }
107
108 private:
109 std::vector<OutputRoute> mOutputs;
110 std::vector<RouteState> mOutputRoutes;
111 std::vector<OutputChannelInfo> mOutputChannelInfos;
112 std::vector<OutputChannelState> mOutputChannelStates;
113
114 std::vector<InputRoute> mInputs;
115 std::vector<RouteState> mInputRoutes;
116 std::vector<fair::mq::Channel*> mInputChannels;
117 std::vector<std::string> mInputChannelNames;
118
119 std::vector<ForwardRoute> mForwards;
120 std::vector<RouteState> mForwardRoutes;
121 std::vector<ForwardChannelInfo> mForwardChannelInfos;
122 std::vector<ForwardChannelState> mForwardChannelStates;
123
124 std::function<bool()> mStateChangeCallback;
125};
126
127} // namespace o2::framework
128
129#endif // O2_FRAMEWORK_FAIRMQDEVICEPROXY_H_
std::unique_ptr< fair::mq::Message > createOutputMessage(RouteIndex routeIndex) const
void bind(std::vector< OutputRoute > const &outputs, std::vector< InputRoute > const &inputs, std::vector< ForwardRoute > const &forwards, std::function< fair::mq::Channel &(std::string const &)> bindChannelByName, std::function< bool(void)> newStateRequestedCallback)
ForwardChannelState & getForwardChannelState(ChannelIndex channelIndex)
Retrieve information associated to a given forward by ChannelIndex.
fair::mq::TransportFactory * getForwardTransport(RouteIndex routeIndex) const
Retrieve the transport associated to a given route.
OutputChannelState & getOutputChannelState(ChannelIndex channelIndex)
Retrieve information associated to a given forward by ChannelIndex.
OutputRoute const & getOutputRoute(RouteIndex routeIndex) const
Retrieve the transport associated to a given route.
ChannelIndex getInputChannelIndexByName(std::string const &channelName) const
ChannelIndex from a given channel name.
ChannelIndex getForwardChannelIndexByName(std::string const &channelName) const
ChannelIndex from a given channel name.
ChannelIndex getForwardChannelIndex(RouteIndex routeIndex) const
void getMatchingForwardChannelIndexes(std::vector< ChannelIndex > &result, header::DataHeader const &header, size_t timeslice) const
Retrieve the channel index from a given OutputSpec and the associated timeslice.
ForwardChannelInfo const & getForwardChannelInfo(ChannelIndex channelIndex) const
Retrieve information associated to a given forward by ChannelIndex.
ChannelIndex getOutputChannelIndexByName(std::string const &channelName) const
ChannelIndex from a given channel name.
fair::mq::Channel * getForwardChannel(ChannelIndex channelIndex) const
fair::mq::TransportFactory * getOutputTransport(RouteIndex routeIndex) const
Retrieve the transport associated to a given route.
ChannelIndex getOutputChannelIndex(OutputSpec const &spec, size_t timeslice) const
Retrieve the channel index from a given OutputSpec and the associated timeslice.
fair::mq::Channel * getOutputChannel(ChannelIndex channelIndex) const
std::unique_ptr< fair::mq::Message > createForwardMessage(RouteIndex routeIndex) const
fair::mq::Channel * getInputChannel(ChannelIndex channelIndex) const
Retrieve the channel associated to a given output route.
ChannelIndex getInputChannelIndex(RouteIndex routeIndex) const
OutputChannelInfo const & getOutputChannelInfo(ChannelIndex channelIndex) const
Retrieve information associated to a given forward by ChannelIndex.
fair::mq::TransportFactory * getInputTransport(RouteIndex routeIndex) const
Retrieve the transport associated to a given route.
std::unique_ptr< fair::mq::Message > createInputMessage(RouteIndex routeIndex) const
FairMQDeviceProxy(FairMQDeviceProxy const &)=delete
GLuint64EXT * result
Definition glcorearb.h:5662
GLsizeiptr size
Definition glcorearb.h:659
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
O2 data header classes and API, v0.1.
Definition DetID.h:49
Forward channel information.
Definition ChannelInfo.h:88
Output channel information.
Definition ChannelInfo.h:73
the main header struct
Definition DataHeader.h:620