Source · fairmq/devices/
Splitter.hheader
Described in builtin-devices: a topology of built-in devices, Design a topology, Built-in devices.
1/********************************************************************************2 * Copyright (C) 2014-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *3 * *4 * This software is distributed under the terms of the *5 * GNU Lesser General Public Licence (LGPL) version 3, *6 * copied verbatim in the file "LICENSE" *7 ********************************************************************************/8 9#ifndef FAIR_MQ_SPLITTER_H10#define FAIR_MQ_SPLITTER_H11 12#include <fairmq/Device.h>13 14#include <string>15 16namespace fair::mq17{18 19class Splitter : public Device20{21 protected:22 bool fMultipart = true;23 int fNumOutputs = 0;24 int fDirection = 0;25 std::string fInChannelName;26 std::string fOutChannelName;27 28 void InitTask() override29 {30 fMultipart = fConfig->GetProperty<bool>("multipart");31 fInChannelName = fConfig->GetProperty<std::string>("in-channel");32 fOutChannelName = fConfig->GetProperty<std::string>("out-channel");33 fNumOutputs = GetNumSubChannels(fOutChannelName);34 fDirection = 0;35 36 if (fMultipart) {37 OnData(fInChannelName, &Splitter::HandleData<Parts>);38 } else {39 OnData(fInChannelName, &Splitter::HandleData<MessagePtr>);40 }41 }42 43 template<typename T>44 bool HandleData(T& payload, int)45 {46 Send(payload, fOutChannelName, fDirection);47 48 if (++fDirection >= fNumOutputs) {49 fDirection = 0;50 }51 52 return true;53 }54};55 56} // namespace fair::mq57 58#endif /* FAIR_MQ_SPLITTER_H */