CbmRoot
Loading...
Searching...
No Matches
CbmMQChannels.cxx
Go to the documentation of this file.
1/* Copyright (C) 2019 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Florian Uhlig [committer] */
4
5#include "CbmMQChannels.h"
6
7#include "FairMQDevice.h"
8
9CbmMQChannels::CbmMQChannels(std::vector<std::string> allowedChannels) : fAllowedChannels {allowedChannels}
10{
11 fChannelsToSend.resize(fAllowedChannels.size());
12 for (auto& entry : fChannelsToSend) {
13 entry.push_back("");
14 }
16}
17
18bool CbmMQChannels::IsChannelNameAllowed(std::string channelName)
19{
20 for (auto const& entry : fAllowedChannels) {
21 std::size_t pos1 = channelName.find(entry);
22 if (pos1 != std::string::npos) {
23 const std::vector<std::string>::const_iterator pos =
24 std::find(fAllowedChannels.begin(), fAllowedChannels.end(), entry);
25 const std::vector<std::string>::size_type idx = pos - fAllowedChannels.begin();
26 LOG(info) << "Found " << entry << " in " << channelName;
27 LOG(info) << "Channel name " << channelName << " found in list of allowed channel names at position " << idx;
28 fComponentsToSend[idx]++;
29 // The array is initialized with one empty string. If the string has still teh value from initialization
30 // exchnge the value by the new channel name. In any other case add one more entry to the vector
31 if (fChannelsToSend[idx].size() == 1 && fChannelsToSend[idx].at(0).empty()) {
32 fChannelsToSend[idx].at(0) = channelName;
33 }
34 else {
35 fChannelsToSend[idx].push_back(channelName);
36 }
37 return true;
38 }
39 }
40 LOG(info) << "Channel name " << channelName << " not found in list of allowed channel names.";
41 LOG(info) << "The allowed channels are: ";
42 for (auto const& entry : fAllowedChannels) {
43 LOG(info) << entry;
44 }
45 LOG(error) << "Stop device.";
46 return false;
47}
48
49bool CbmMQChannels::CheckChannels(FairMQDevice* device)
50{
51 // Get the information about created channels from the device
52 // Check if the defined channels from the topology (by name)
53 // are in the list of channels which are possible/allowed
54 // for the device
55 // The idea is to check at initilization if the devices are
56 // properly connected. For the time beeing this is done with a
57 // nameing convention. It is not avoided that someone sends other
58 // data on this channel.
59 int noChannel = device->fChannels.size();
60 LOG(info) << "Number of defined output channels: " << noChannel;
61 for (auto const& entry : device->fChannels) {
62 LOG(info) << "Channel name: " << entry.first;
63 if (!IsChannelNameAllowed(entry.first)) return false;
64 }
65 return true;
66}
static constexpr size_t size()
Definition KfSimdPseudo.h:2
bool CheckChannels(FairMQDevice *device)
std::vector< std::string > fAllowedChannels
std::vector< std::vector< std::string > > fChannelsToSend
bool IsChannelNameAllowed(std::string channelName)
std::vector< int > fComponentsToSend
CbmMQChannels(std::vector< std::string >)