/******************************************************************************** * Copyright (C) 2014-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * * * * This software is distributed under the terms of the * * GNU Lesser General Public Licence (LGPL) version 3, * * copied verbatim in the file "LICENSE" * ********************************************************************************/ #ifndef FAIR_MQ_SPLITTER_H #define FAIR_MQ_SPLITTER_H #include #include namespace fair::mq { class Splitter : public Device { public: Splitter() = default; protected: bool fMultipart = true; int fNumOutputs = 0; int fDirection = 0; std::string fInChannelName; std::string fOutChannelName; void InitTask() override { fMultipart = fConfig->GetProperty("multipart"); fInChannelName = fConfig->GetProperty("in-channel"); fOutChannelName = fConfig->GetProperty("out-channel"); fNumOutputs = fChannels.at(fOutChannelName).size(); fDirection = 0; if (fMultipart) { OnData(fInChannelName, &Splitter::HandleData); } else { OnData(fInChannelName, &Splitter::HandleData); } } template bool HandleData(T& payload, int) { Send(payload, fOutChannelName, fDirection); if (++fDirection >= fNumOutputs) { fDirection = 0; } return true; } }; } // namespace fair::mq #endif /* FAIR_MQ_SPLITTER_H */