BmnRoot
Loading...
Searching...
No Matches
decoder_proxy.cxx
Go to the documentation of this file.
1#include "DigiArrays.h"
2
3#include <RootSerializer.h>
4#include <TBuffer.h>
5#include <TFile.h>
6#include <TString.h>
7#include <TTree.h>
8#include <fairmq/Device.h>
9#include <fairmq/runDevice.h>
10#include <string>
11
12namespace bpo = boost::program_options;
13
14namespace bmn::online
15{
16struct DecoderProxy : fair::mq::Device
17{
18 protected:
19 static constexpr auto INPUT_CHANNEL_NAME = "in-channel";
20 static constexpr auto OUTPUT_CHANNEL_NAME = "out-channel";
21
22 void Init() override { OnData(INPUT_CHANNEL_NAME, &DecoderProxy::HandleData); }
23
24 Bool_t HandleData(fair::mq::MessagePtr& inputMessage, Int_t)
25 {
26 LOG(info) << "Event Received. Message size: " << inputMessage->GetSize();
27
28 auto buffer = std::make_unique<TBufferFile>(TBuffer::kRead);
29 buffer->SetBuffer(inputMessage->GetData(), inputMessage->GetSize());
30 auto eventData = std::unique_ptr<DigiArrays>(static_cast<DigiArrays*>(buffer->ReadObject(DigiArrays::Class())));
31
32 auto tree = std::make_unique<TTree>();
33 tree->Branch("SILICON", eventData->silicon);
34 tree->Branch("GEM", eventData->gem);
35 tree->Branch("CSC", eventData->csc);
36 tree->Branch("TOF400", eventData->tof400);
37 tree->Branch("TOF700", eventData->tof700);
38 tree->Branch("TOF701", eventData->tof701);
39 tree->Branch("ScWallDigi", eventData->scwall);
40 tree->Branch("FHCalDigi", eventData->fhcal);
41 tree->Branch("HodoDigi", eventData->hodo);
42 tree->Branch("HdetDigi", eventData->ndet);
43 tree->Branch("SiBT", eventData->sibt);
44 tree->Branch("BC2AT", eventData->trigAr);
45 tree->Fill();
46
47 auto message = NewMessage();
48 RootSerializer().Serialize(*message, tree);
49
50 if (Send(message, OUTPUT_CHANNEL_NAME) < 0) {
51 LOG(error) << "Sending message failed!";
52 return kFALSE;
53 }
54
55 buffer.release();
56
57 return kTRUE;
58 }
59};
60
61} // namespace bmn::online
62
63void addCustomOptions(bpo::options_description& options) {}
64
65std::unique_ptr<fair::mq::Device> getDevice(fair::mq::ProgOptions&)
66{
67 return std::make_unique<bmn::online::DecoderProxy>();
68}
std::unique_ptr< fair::mq::Device > getDevice(fair::mq::ProgOptions &)
void addCustomOptions(bpo::options_description &options)
static constexpr auto OUTPUT_CHANNEL_NAME
static constexpr auto INPUT_CHANNEL_NAME
Bool_t HandleData(fair::mq::MessagePtr &inputMessage, Int_t)