CbmRoot
Loading...
Searching...
No Matches
CbmTsaComponentSink.cxx
Go to the documentation of this file.
1/* Copyright (C) 2018-2019 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Florian Uhlig [committer] */
4
12#include "CbmTsaComponentSink.h"
13
14#include "CbmMQDefs.h"
15
16#include "StorableTimeslice.hpp"
17
18#include "FairMQLogger.h"
19#include "FairMQProgOptions.h" // device->fConfig
20
21#include <boost/archive/binary_iarchive.hpp>
22
23#include <stdexcept>
24#include <string>
25struct InitTaskError : std::runtime_error {
26 using std::runtime_error::runtime_error;
27};
28
29using namespace std;
30
32
34try {
35 // Get the information about created channels from the device
36 // Check if the defined channels from the topology (by name)
37 // are in the list of channels which are possible/allowed
38 // for the device
39 // The idea is to check at initilization if the devices are
40 // properly connected. For the time beeing this is done with a
41 // nameing convention. It is not avoided that someone sends other
42 // data on this channel.
43 int noChannel = fChannels.size();
44 LOG(info) << "Number of defined input channels: " << noChannel;
45 for (auto const& entry : fChannels) {
46 LOG(info) << "Channel name: " << entry.first;
47 if (!IsChannelNameAllowed(entry.first)) throw InitTaskError("Channel name does not match.");
48 OnData(entry.first, &CbmTsaComponentSink::HandleData);
49 }
50}
51catch (InitTaskError& e) {
52 LOG(error) << e.what();
53 // Wrapper defined in CbmMQDefs.h to support different FairMQ versions
55}
56
57bool CbmTsaComponentSink::IsChannelNameAllowed(std::string channelName)
58{
59
60 for (auto const& entry : fAllowedChannels) {
61 std::size_t pos1 = channelName.find(entry);
62 if (pos1 != std::string::npos) {
63 const vector<std::string>::const_iterator pos =
64 std::find(fAllowedChannels.begin(), fAllowedChannels.end(), entry);
65 const vector<std::string>::size_type idx = pos - fAllowedChannels.begin();
66 LOG(info) << "Found " << entry << " in " << channelName;
67 LOG(info) << "Channel name " << channelName << " found in list of allowed channel names at position " << idx;
68 return true;
69 }
70 }
71 LOG(info) << "Channel name " << channelName << " not found in list of allowed channel names.";
72 LOG(error) << "Stop device.";
73 return false;
74}
75
76
77// handler is called whenever a message arrives on "data", with a reference to the message and a sub-channel index (here 0)
78bool CbmTsaComponentSink::HandleData(FairMQMessagePtr& msg, int /*index*/)
79{
80 // Don't do anything with the data
81 // Maybe add an message counter which counts the incomming messages and add
82 // an output
84 LOG(info) << "Received message number " << fNumMessages << " with size " << msg->GetSize();
85
86 std::string msgStr(static_cast<char*>(msg->GetData()), msg->GetSize());
87 std::istringstream iss(msgStr);
88 boost::archive::binary_iarchive inputArchive(iss);
89
90 fles::StorableTimeslice component {0};
91 inputArchive >> component;
92
93 CheckTimeslice(component);
94
95 return true;
96}
97
99
100void CbmTsaComponentSink::PrintMicroSliceDescriptor(const fles::MicrosliceDescriptor& mdsc)
101{
102 LOG(info) << "Header ID: Ox" << std::hex << static_cast<int>(mdsc.hdr_id) << std::dec;
103 LOG(info) << "Header version: Ox" << std::hex << static_cast<int>(mdsc.hdr_ver) << std::dec;
104 LOG(info) << "Equipement ID: " << mdsc.eq_id;
105 LOG(info) << "Flags: " << mdsc.flags;
106 LOG(info) << "Sys ID: Ox" << std::hex << static_cast<int>(mdsc.sys_id) << std::dec;
107 LOG(info) << "Sys version: Ox" << std::hex << static_cast<int>(mdsc.sys_ver) << std::dec;
108 LOG(info) << "Microslice Idx: " << mdsc.idx;
109 LOG(info) << "Checksum: " << mdsc.crc;
110 LOG(info) << "Size: " << mdsc.size;
111 LOG(info) << "Offset: " << mdsc.offset;
112}
113
114bool CbmTsaComponentSink::CheckTimeslice(const fles::Timeslice& ts)
115{
116 if (0 == ts.num_components()) {
117 LOG(error) << "No Component in TS " << ts.index();
118 return 1;
119 }
120 LOG(info) << "Found " << ts.num_components() << " different components in timeslice";
121
122 for (size_t c = 0; c < ts.num_components(); ++c) {
123 LOG(info) << "Found " << ts.num_microslices(c) << " microslices in component " << c;
124 LOG(info) << "Component " << c << " has a size of " << ts.size_component(c) << " bytes";
125 LOG(info) << "Sys ID: Ox" << std::hex << static_cast<int>(ts.descriptor(0, 0).sys_id) << std::dec;
126
127 /*
128 for (size_t m = 0; m < ts.num_microslices(c); ++m) {
129 PrintMicroSliceDescriptor(ts.descriptor(c,m));
130 }
131*/
132 }
133
134 return true;
135}
bool HandleData(FairMQMessagePtr &, int)
bool IsChannelNameAllowed(std::string channelName)
std::vector< std::string > fAllowedChannels
void PrintMicroSliceDescriptor(const fles::MicrosliceDescriptor &mdsc)
bool CheckTimeslice(const fles::Timeslice &ts)
void ChangeState(FairMQDevice *device, cbm::mq::Transition transition)
Definition CbmMQDefs.h:26
Hash for CbmL1LinkKey.