forked from wiechula/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathO2MessageMonitor.cxx
More file actions
111 lines (92 loc) · 3.61 KB
/
O2MessageMonitor.cxx
File metadata and controls
111 lines (92 loc) · 3.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/// @copyright
/// © Copyright 2014 Copyright Holders of the ALICE O2 collaboration.
/// See https://aliceinfo.cern.ch/AliceO2 for details on the Copyright holders.
/// This software is distributed under the terms of the
/// GNU General Public License version 3 (GPL Version 3).
///
/// License text in a separate file.
///
/// In applying this license, CERN does not waive the privileges and immunities
/// granted to it by virtue of its status as an Intergovernmental Organization
/// or submit itself to any jurisdiction.
/// @file O2MessageMonitor.cxx
///
/// @since 2014-12-10
/// @author M. Krzewicki <mkrzewic@cern.ch>
#include <thread> // this_thread::sleep_for
#include <chrono>
#include "O2MessageMonitor/O2MessageMonitor.h"
#include <options/FairMQProgOptions.h>
#include <FairMQLogger.h>
#include "Headers/DataHeader.h"
using namespace std;
using namespace AliceO2::Header;
using namespace AliceO2::Base;
using NameHeader48 = NameHeader<48>; //header holding 16 characters
//__________________________________________________________________________________________________
O2MessageMonitor::O2MessageMonitor()
: mDataHeader()
, mPayload("I am the info payload")
, mName(R"(My name is "gDataDescriptionInfo")")
, mDelay(1000)
, mIterations(10)
, mLimitOutputCharacters(1024)
{
mDataHeader = gDataOriginAny;
mDataHeader = gDataDescriptionInfo;
mDataHeader = gSerializationMethodNone;
}
//__________________________________________________________________________________________________
void O2MessageMonitor::InitTask()
{
mDelay = GetConfig()->GetValue<int>("sleep");
mIterations = GetConfig()->GetValue<int>("n");
mPayload = GetConfig()->GetValue<std::string>("payload");
std::string tmp = GetConfig()->GetValue<std::string>("name");
if (!tmp.empty()) mName = tmp;
mLimitOutputCharacters = GetConfig()->GetValue<int>("limit");
}
//__________________________________________________________________________________________________
void O2MessageMonitor::Run()
{
//check socket type of data channel
std::string type;
std::vector<FairMQChannel> subChannels = fChannels["data"];
if (subChannels.size()>0) {
type = subChannels[0].GetType();
}
while (CheckCurrentState(RUNNING) && (--mIterations)!=0) {
this_thread::sleep_for(chrono::milliseconds(mDelay));
O2Message message;
NameHeader48 nameHeader;
//maybe send a request
nameHeader = mName;
AddMessage(message,{mDataHeader,nameHeader},NewSimpleMessage(mPayload));
Send(message, "data");
message.fParts.clear();
//message in;
Receive(message, "data");
LOG(INFO) << "== New message=============================";
ForEach(message, &O2MessageMonitor::HandleO2frame);
message.fParts.clear();
//maybe a reply message
if (type=="rep") {
nameHeader = "My name is reply";
AddMessage(message,{mDataHeader,nameHeader},NewSimpleMessage("I am a reply"));
Send(message, "data");
}
}
}
//__________________________________________________________________________________________________
bool O2MessageMonitor::HandleO2frame(const byte* headerBuffer, size_t headerBufferSize,
const byte* dataBuffer, size_t dataBufferSize)
{
hexDump("headerBuffer", headerBuffer, headerBufferSize);
hexDump("dataBuffer", dataBuffer, dataBufferSize, mLimitOutputCharacters);
const DataHeader* dataHeader = get<DataHeader>(headerBuffer);
if (!dataHeader) { LOG(INFO) << "data header empty!"; return false; }
if ( (*dataHeader)==gDataDescriptionInfo ) {}
const NameHeader<0>* nameHeader = get<NameHeader<0>>(headerBuffer);
if (nameHeader) {size_t sizeNameHeader=nameHeader->size();}
return true;
}