mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-13 00:31:14 +00:00
73 lines
2.4 KiB
C++
73 lines
2.4 KiB
C++
/********************************************************************************
|
|
* Copyright (C) 2020 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" *
|
|
********************************************************************************/
|
|
|
|
#include "Header.h"
|
|
|
|
#include <fairmq/Device.h>
|
|
#include <fairmq/runDevice.h>
|
|
|
|
#include <string>
|
|
|
|
using namespace std;
|
|
using namespace example_n_m;
|
|
namespace bpo = boost::program_options;
|
|
|
|
struct Sender : fair::mq::Device
|
|
{
|
|
void InitTask() override
|
|
{
|
|
fIndex = GetConfig()->GetProperty<int>("sender-index");
|
|
fSubtimeframeSize = GetConfig()->GetProperty<int>("subtimeframe-size");
|
|
fNumReceivers = GetConfig()->GetProperty<int>("num-receivers");
|
|
}
|
|
|
|
void Run() override
|
|
{
|
|
fair::mq::Channel& dataInChannel = GetChannel("sync", 0);
|
|
|
|
while (!NewStatePending()) {
|
|
Header h;
|
|
fair::mq::MessagePtr id(NewMessage());
|
|
if (dataInChannel.Receive(id) > 0) {
|
|
h.id = *(static_cast<uint16_t*>(id->GetData()));
|
|
h.senderIndex = fIndex;
|
|
} else {
|
|
continue;
|
|
}
|
|
|
|
fair::mq::Parts parts;
|
|
parts.AddPart(NewSimpleMessage(h));
|
|
parts.AddPart(NewMessage(fSubtimeframeSize));
|
|
|
|
uint64_t currentDataId = h.id;
|
|
int direction = currentDataId % fNumReceivers;
|
|
|
|
if (Send(parts, "data", direction, 0) < 0) {
|
|
LOG(debug) << "Failed to queue Subtimeframe #" << currentDataId << " to Receiver[" << direction << "]";
|
|
}
|
|
}
|
|
}
|
|
|
|
private:
|
|
int fNumReceivers = 0;
|
|
unsigned int fIndex = 0;
|
|
int fSubtimeframeSize = 10000;
|
|
};
|
|
|
|
void addCustomOptions(bpo::options_description& options)
|
|
{
|
|
options.add_options()
|
|
("sender-index", bpo::value<int>()->default_value(0), "Sender Index")
|
|
("subtimeframe-size", bpo::value<int>()->default_value(1000), "Subtimeframe size in bytes")
|
|
("num-receivers", bpo::value<int>()->required(), "Number of EPNs");
|
|
}
|
|
std::unique_ptr<fair::mq::Device> getDevice(fair::mq::ProgOptions& /* config */)
|
|
{
|
|
return std::make_unique<Sender>();
|
|
}
|