From dbdf17c661225c4d3edd9f07b6f4fb5b40ff254c Mon Sep 17 00:00:00 2001 From: Alexey Rybalchenko Date: Wed, 3 Nov 2021 12:33:11 +0100 Subject: [PATCH] Avoid accessing Device.fChannels directly, use getters --- examples/copypush/sampler.cxx | 2 +- examples/n-m/sender.cxx | 2 +- examples/readout/receiver.cxx | 2 +- examples/region/sampler.cxx | 4 ++-- examples/region/sink.cxx | 6 +++--- fairmq/devices/BenchmarkSampler.h | 2 +- fairmq/devices/Merger.h | 2 +- fairmq/devices/Multiplier.h | 10 +++++----- fairmq/devices/Sink.h | 2 +- fairmq/devices/Splitter.h | 2 +- test/helper/devices/TestPollIn.h | 4 ++-- 11 files changed, 19 insertions(+), 19 deletions(-) diff --git a/examples/copypush/sampler.cxx b/examples/copypush/sampler.cxx index 345b98aeb..2e38a692c 100644 --- a/examples/copypush/sampler.cxx +++ b/examples/copypush/sampler.cxx @@ -19,7 +19,7 @@ struct Sampler : fair::mq::Device { void InitTask() override { - fNumDataChannels = fChannels.at("data").size(); + fNumDataChannels = GetNumSubChannels("data"); fMaxIterations = fConfig->GetProperty("max-iterations"); } diff --git a/examples/n-m/sender.cxx b/examples/n-m/sender.cxx index 9320a8483..9c1dd0e56 100644 --- a/examples/n-m/sender.cxx +++ b/examples/n-m/sender.cxx @@ -28,7 +28,7 @@ struct Sender : fair::mq::Device void Run() override { - FairMQChannel& dataInChannel = fChannels.at("sync").at(0); + FairMQChannel& dataInChannel = GetChannel("sync", 0); while (!NewStatePending()) { Header h; diff --git a/examples/readout/receiver.cxx b/examples/readout/receiver.cxx index 59df99baf..e58f99062 100644 --- a/examples/readout/receiver.cxx +++ b/examples/readout/receiver.cxx @@ -26,7 +26,7 @@ struct Receiver : Device void Run() override { - Channel& dataInChannel = fChannels.at("sr").at(0); + Channel& dataInChannel = GetChannel("sr", 0); while (!NewStatePending()) { auto msg(dataInChannel.NewMessage()); diff --git a/examples/region/sampler.cxx b/examples/region/sampler.cxx index 98e9fbaba..42f982c39 100644 --- a/examples/region/sampler.cxx +++ b/examples/region/sampler.cxx @@ -23,7 +23,7 @@ struct Sampler : fair::mq::Device fLinger = fConfig->GetProperty("region-linger"); fMaxIterations = fConfig->GetProperty("max-iterations"); - fChannels.at("data").at(0).Transport()->SubscribeToRegionEvents([](FairMQRegionInfo info) { + GetChannel("data", 0).Transport()->SubscribeToRegionEvents([](FairMQRegionInfo info) { LOG(info) << "Region event: " << info.event << ": " << (info.managed ? "managed" : "unmanaged") << ", id: " << info.id @@ -87,7 +87,7 @@ struct Sampler : fair::mq::Device LOG(info) << "All acknowledgements received."; } } - fChannels.at("data").at(0).Transport()->UnsubscribeFromRegionEvents(); + GetChannel("data", 0).Transport()->UnsubscribeFromRegionEvents(); } private: diff --git a/examples/region/sink.cxx b/examples/region/sink.cxx index c271dc74a..a8af6ed0e 100644 --- a/examples/region/sink.cxx +++ b/examples/region/sink.cxx @@ -22,7 +22,7 @@ struct Sink : Device { // Get the fMaxIterations value from the command line options (via fConfig) fMaxIterations = fConfig->GetProperty("max-iterations"); - fChannels.at("data").at(0).Transport()->SubscribeToRegionEvents([](RegionInfo info) { + GetChannel("data", 0).Transport()->SubscribeToRegionEvents([](RegionInfo info) { LOG(info) << "Region event: " << info.event << ": " << (info.managed ? "managed" : "unmanaged") << ", id: " << info.id << ", ptr: " << info.ptr << ", size: " << info.size @@ -32,7 +32,7 @@ struct Sink : Device void Run() override { - Channel& dataInChannel = fChannels.at("data").at(0); + Channel& dataInChannel = GetChannel("data", 0); while (!NewStatePending()) { auto msg(dataInChannel.Transport()->CreateMessage()); @@ -51,7 +51,7 @@ struct Sink : Device void ResetTask() override { - fChannels.at("data").at(0).Transport()->UnsubscribeFromRegionEvents(); + GetChannel("data", 0).Transport()->UnsubscribeFromRegionEvents(); } private: diff --git a/fairmq/devices/BenchmarkSampler.h b/fairmq/devices/BenchmarkSampler.h index a25209ec1..013aef919 100644 --- a/fairmq/devices/BenchmarkSampler.h +++ b/fairmq/devices/BenchmarkSampler.h @@ -44,7 +44,7 @@ class BenchmarkSampler : public Device void Run() override { // store the channel reference to avoid traversing the map on every loop iteration - FairMQChannel& dataOutChannel = fChannels.at(fOutChannelName).at(0); + FairMQChannel& dataOutChannel = GetChannel(fOutChannelName, 0); LOG(info) << "Starting the benchmark with message size of " << fMsgSize << " and " << fMaxIterations << " iterations."; auto tStart = std::chrono::high_resolution_clock::now(); diff --git a/fairmq/devices/Merger.h b/fairmq/devices/Merger.h index 53ab43132..e08eba171 100644 --- a/fairmq/devices/Merger.h +++ b/fairmq/devices/Merger.h @@ -43,7 +43,7 @@ class Merger : public Device void Run() override { - int numInputs = fChannels.at(fInChannelName).size(); + int numInputs = GetNumSubChannels(fInChannelName); std::vector chans; diff --git a/fairmq/devices/Multiplier.h b/fairmq/devices/Multiplier.h index e4013287c..5b48bf7ad 100644 --- a/fairmq/devices/Multiplier.h +++ b/fairmq/devices/Multiplier.h @@ -30,7 +30,7 @@ class Multiplier : public Device fMultipart = fConfig->GetProperty("multipart"); fInChannelName = fConfig->GetProperty("in-channel"); fOutChannelNames = fConfig->GetProperty>("out-channel"); - fNumOutputs = fChannels.at(fOutChannelNames.at(0)).size(); + fNumOutputs = GetNumSubChannels(fOutChannelNames.at(0)); if (fMultipart) { OnData(fInChannelName, &Multiplier::HandleMultipartData); @@ -43,7 +43,7 @@ class Multiplier : public Device bool HandleSingleData(std::unique_ptr& payload, int) { for (unsigned int i = 0; i < fOutChannelNames.size() - 1; ++i) { // all except last channel - for (unsigned int j = 0; j < fChannels.at(fOutChannelNames.at(i)).size(); ++j) { // all subChannels in a channel + for (unsigned int j = 0; j < GetNumSubChannels(fOutChannelNames.at(i)); ++j) { // all subChannels in a channel FairMQMessagePtr msgCopy(fTransportFactory->CreateMessage()); msgCopy->Copy(*payload); @@ -51,7 +51,7 @@ class Multiplier : public Device } } - unsigned int lastChannelSize = fChannels.at(fOutChannelNames.back()).size(); + unsigned int lastChannelSize = GetNumSubChannels(fOutChannelNames.back()); for (unsigned int i = 0; i < lastChannelSize - 1; ++i) { // iterate over all except last subChannels of the last channel FairMQMessagePtr msgCopy(fTransportFactory->CreateMessage()); @@ -68,7 +68,7 @@ class Multiplier : public Device bool HandleMultipartData(FairMQParts& payload, int) { for (unsigned int i = 0; i < fOutChannelNames.size() - 1; ++i) { // all except last channel - for (unsigned int j = 0; j < fChannels.at(fOutChannelNames.at(i)).size(); ++j) { // all subChannels in a channel + for (unsigned int j = 0; j < GetNumSubChannels(fOutChannelNames.at(i)); ++j) { // all subChannels in a channel FairMQParts parts; for (int k = 0; k < payload.Size(); ++k) { @@ -81,7 +81,7 @@ class Multiplier : public Device } } - unsigned int lastChannelSize = fChannels.at(fOutChannelNames.back()).size(); + unsigned int lastChannelSize = GetNumSubChannels(fOutChannelNames.back()); for (unsigned int i = 0; i < lastChannelSize - 1; ++i) { // iterate over all except last subChannels of the last channel FairMQParts parts; diff --git a/fairmq/devices/Sink.h b/fairmq/devices/Sink.h index 0b6a6b36d..32d618542 100644 --- a/fairmq/devices/Sink.h +++ b/fairmq/devices/Sink.h @@ -48,7 +48,7 @@ class Sink : public Device void Run() override { // store the channel reference to avoid traversing the map on every loop iteration - FairMQChannel& dataInChannel = fChannels.at(fInChannelName).at(0); + FairMQChannel& dataInChannel = GetChannel(fInChannelName, 0); LOG(info) << "Starting sink and expecting to receive " << fMaxIterations << " messages."; auto tStart = std::chrono::high_resolution_clock::now(); diff --git a/fairmq/devices/Splitter.h b/fairmq/devices/Splitter.h index 2bc4f7c8f..addc31e1f 100644 --- a/fairmq/devices/Splitter.h +++ b/fairmq/devices/Splitter.h @@ -30,7 +30,7 @@ class Splitter : public Device fMultipart = fConfig->GetProperty("multipart"); fInChannelName = fConfig->GetProperty("in-channel"); fOutChannelName = fConfig->GetProperty("out-channel"); - fNumOutputs = fChannels.at(fOutChannelName).size(); + fNumOutputs = GetNumSubChannels(fOutChannelName); fDirection = 0; if (fMultipart) { diff --git a/test/helper/devices/TestPollIn.h b/test/helper/devices/TestPollIn.h index 9c1d2354b..f86c73289 100644 --- a/test/helper/devices/TestPollIn.h +++ b/test/helper/devices/TestPollIn.h @@ -37,8 +37,8 @@ class PollIn : public FairMQDevice { vector chans; - chans.push_back(&fChannels.at("data1").at(0)); - chans.push_back(&fChannels.at("data2").at(0)); + chans.push_back(&GetChannel("data1", 0)); + chans.push_back(&GetChannel("data2", 0)); FairMQPollerPtr poller = nullptr;