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