Project
Loading...
Searching...
No Matches
DataRelayer.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_DATARELAYER_H_
12#define O2_FRAMEWORK_DATARELAYER_H_
13
19#include <fairmq/Message.h>
21#include "Framework/Tracing.h"
24
25#include <cstddef>
26#include <mutex>
27#include <span>
28#include <vector>
29#include <functional>
30
31#include <fairmq/FwdDecls.h>
32
33namespace o2::monitoring
34{
35class Monitoring;
36}
37
38namespace o2::framework
39{
40
41enum struct CacheEntryStatus : int {
42 EMPTY,
43 PENDING,
44 RUNNING,
45 DONE
46};
47
49{
50 public:
57 struct RelayChoice {
58 enum struct Type {
59 WillRelay,
60 Invalid,
62 Dropped
63 };
66 // The timeslice affected by the given operation.
68 };
69
71 int newSlots = 0;
72 int expiredSlots = 0;
73 };
74
75 struct PruneOp {
77 };
78
84
85 enum struct InputType : int {
86 Invalid = 0,
87 Data = 1,
88 SourceInfo = 2,
89 DomainInfo = 3
90 };
91
92 struct InputInfo {
93 InputInfo(size_t p, size_t s, InputType t, ChannelIndex i)
94 : position(p), size(s), type(t), index(i)
95 {
96 }
97 size_t position;
98 size_t size;
101 };
102
104 std::vector<InputRoute> const& routes,
107 int);
108
114 ActivityStats processDanglingInputs(std::vector<ExpirationHandler> const&,
115 ServiceRegistryRef context, bool createNew);
116
117 using OnDropCallback = std::function<void(TimesliceSlot, std::vector<std::span<fair::mq::MessagePtr>>&, TimesliceIndex::OldestOutputInfo info)>;
118
119 // Callback for when some messages are about to be owned by the the DataRelayer
120 using OnInsertionCallback = std::function<void(ServiceRegistryRef&, std::span<fair::mq::MessagePtr>&)>;
121
125 void pruneCache(TimesliceSlot slot, OnDropCallback onDrop = nullptr);
126
138 RelayChoice relay(void const* rawHeader,
139 std::unique_ptr<fair::mq::Message>* messages,
140 InputInfo const& info,
141 size_t nMessages,
142 size_t nPayloads = 1,
143 OnInsertionCallback onInsertion = nullptr,
144 OnDropCallback onDrop = nullptr);
145
148 void setOldestPossibleInput(TimesliceId timeslice, ChannelIndex channel);
149
153
155 void getReadyToProcess(std::vector<RecordAction>& completed);
156
160 std::vector<std::vector<fair::mq::MessagePtr>> consumeAllInputsForTimeslice(TimesliceSlot id);
161 std::vector<std::vector<fair::mq::MessagePtr>> consumeExistingInputsForTimeslice(TimesliceSlot id);
162
164 [[nodiscard]] size_t getParallelTimeslices() const;
165
167 void setPipelineLength(size_t s);
168
170 void sendContextState();
171 void publishMetrics();
172
177
180 void updateCacheStatus(TimesliceSlot slot, CacheEntryStatus oldStatus, CacheEntryStatus newStatus);
190 void clear();
191
194 void rescan() { mTimesliceIndex.rescan(); };
195
196 [[nodiscard]] size_t getCacheSize() const { return mCache.size(); }
197 [[nodiscard]] size_t getNumberOfTimeslices() const { return mTimesliceIndex.size(); }
198 [[nodiscard]] size_t getNumberOfUniqueInputs() const { return mDistinctRoutesIndex.size(); }
199
200 private:
201 ServiceRegistryRef mContext;
202
207 std::vector<std::vector<fair::mq::MessagePtr>> mCache;
208
211 TimesliceIndex& mTimesliceIndex;
212
213 CompletionPolicy mCompletionPolicy;
214 std::vector<size_t> mDistinctRoutesIndex;
215 std::vector<InputSpec> mInputs;
216 std::vector<data_matcher::DataDescriptorMatcher> mInputMatchers;
217 std::vector<data_matcher::VariableContext> mVariableContextes;
218 std::vector<CacheEntryStatus> mCachedStateMetrics;
219 std::vector<PruneOp> mPruneOps;
220 size_t mMaxLanes;
221
222 O2_LOCKABLE_NAMED(std::recursive_mutex, mMutex, "data relayer mutex");
223};
224
225} // namespace o2::framework
226
227#endif // O2_FRAMEWORK_DATARELAYER_H_
std::vector< OutputRoute > routes
int32_t i
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error s
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char Directory with events to Events directory is and not inside events Show standalone event Run event generator maximum time bin of continuous for triggered for automatic continuous for automatic continuous triggered uint64_t
#define O2_LOCKABLE_NAMED(T, V, N)
Definition Tracing.h:19
o2::monitoring::Monitoring Monitoring
uint32_t getFirstTFOrbitForSlot(TimesliceSlot slot)
Get the firstTForbit associate to a given slot.
void updateCacheStatus(TimesliceSlot slot, CacheEntryStatus oldStatus, CacheEntryStatus newStatus)
uint32_t getRunNumberForSlot(TimesliceSlot slot)
Get the runNumber associated to a given slot.
void prunePending(OnDropCallback)
Prune all the pending entries in the cache.
std::function< void(TimesliceSlot, std::vector< std::span< fair::mq::MessagePtr > > &, TimesliceIndex::OldestOutputInfo info)> OnDropCallback
size_t getCacheSize() const
void getReadyToProcess(std::vector< RecordAction > &completed)
void setPipelineLength(size_t s)
Tune the maximum number of in flight timeslices this can handle.
std::vector< std::vector< fair::mq::MessagePtr > > consumeAllInputsForTimeslice(TimesliceSlot id)
size_t getParallelTimeslices() const
Returns how many timeslices we can handle in parallel.
RelayChoice relay(void const *rawHeader, std::unique_ptr< fair::mq::Message > *messages, InputInfo const &info, size_t nMessages, size_t nPayloads=1, OnInsertionCallback onInsertion=nullptr, OnDropCallback onDrop=nullptr)
void pruneCache(TimesliceSlot slot, OnDropCallback onDrop=nullptr)
Prune the cache for a given slot.
std::function< void(ServiceRegistryRef &, std::span< fair::mq::MessagePtr > &)> OnInsertionCallback
std::vector< std::vector< fair::mq::MessagePtr > > consumeExistingInputsForTimeslice(TimesliceSlot id)
void setOldestPossibleInput(TimesliceId timeslice, ChannelIndex channel)
uint64_t getCreationTimeForSlot(TimesliceSlot slot)
Get the creation time associated to a given slot.
static constexpr ServiceKind service_kind
Definition DataRelayer.h:54
void sendContextState()
Send metrics with the VariableContext information.
TimesliceId getTimesliceForSlot(TimesliceSlot slot)
size_t getNumberOfTimeslices() const
ActivityStats processDanglingInputs(std::vector< ExpirationHandler > const &, ServiceRegistryRef context, bool createNew)
size_t getNumberOfUniqueInputs() const
TimesliceIndex::OldestOutputInfo getOldestPossibleOutput() const
uint32_t getFirstTFCounterForSlot(TimesliceSlot slot)
Get the firstTFCounter associate to a given slot.
void clear()
Remove all pending messages.
void rescan()
Mark all the cachelines as invalid, e.g. due to an out of band event.
GLsizeiptr size
Definition glcorearb.h:659
GLint GLint GLsizei GLint GLenum GLenum type
Definition glcorearb.h:275
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
ServiceKind
The kind of service we are asking for.
CompletionOp
Action to take with the InputRecord:
InputInfo(size_t p, size_t s, InputType t, ChannelIndex i)
Definition DataRelayer.h:93
CompletionPolicy::CompletionOp op
Definition DataRelayer.h:82
Type type
What was the outcome of the relay operation.
Definition DataRelayer.h:65
@ Invalid
Ownership of the data has been taken.
@ Backpressured
The incoming data was not valid and has been dropped.
@ Dropped
The incoming data was not relayed, because we are backpressured.