forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFakeTimeframeGeneratorDevice.cxx
More file actions
92 lines (79 loc) · 2.47 KB
/
FakeTimeframeGeneratorDevice.cxx
File metadata and controls
92 lines (79 loc) · 2.47 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
// Copyright CERN and copyright holders of ALICE O2. This software is
// distributed under the terms of the GNU General Public License v3 (GPL
// Version 3), copied verbatim in the file "COPYING".
//
// See http://alice-o2.web.cern.ch/license for full licensing information.
//
// 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.
#include <cstring>
#include "DataFlow/FakeTimeframeGeneratorDevice.h"
#include "DataFlow/FakeTimeframeBuilder.h"
#include "DataFlow/TimeframeParser.h"
#include "Headers/SubframeMetadata.h"
#include "Headers/DataHeader.h"
#include <options/FairMQProgOptions.h>
#include <vector>
using DataHeader = o2::header::DataHeader;
namespace
{
struct OneShotReadBuf : public std::streambuf {
OneShotReadBuf(char* s, std::size_t n)
{
setg(s, s, s + n);
}
};
} // namespace
namespace o2
{
namespace data_flow
{
FakeTimeframeGeneratorDevice::FakeTimeframeGeneratorDevice()
: O2Device{}, mOutChannelName{}, mMaxTimeframes{}, mTimeframeCount{0}
{
}
void FakeTimeframeGeneratorDevice::InitTask()
{
mOutChannelName = GetConfig()->GetValue<std::string>(OptionKeyOutputChannelName);
mMaxTimeframes = GetConfig()->GetValue<size_t>(OptionKeyMaxTimeframes);
}
bool FakeTimeframeGeneratorDevice::ConditionalRun()
{
auto addPartFn = [this](FairMQParts& parts, char* buffer, size_t size) {
parts.AddPart(this->NewMessage(
buffer,
size,
[](void* data, void* hint) { delete[](char*) data; },
nullptr));
};
auto sendFn = [this](FairMQParts& parts) { this->Send(parts, this->mOutChannelName); };
auto zeroFiller = [](char* b, size_t s) { memset(b, 0, s); };
std::vector<o2::data_flow::FakeTimeframeSpec> specs = {
{.origin = "TPC",
.dataDescription = "CLUSTERS",
.bufferFiller = zeroFiller,
.bufferSize = 1000},
{.origin = "ITS",
.dataDescription = "CLUSTERS",
.bufferFiller = zeroFiller,
.bufferSize = 500}};
try {
size_t totalSize;
auto buffer = fakeTimeframeGenerator(specs, totalSize);
OneShotReadBuf osrb(buffer.get(), totalSize);
std::istream s(&osrb);
streamTimeframe(s,
addPartFn,
sendFn);
} catch (std::runtime_error& e) {
LOG(ERROR) << e.what() << "\n";
}
mTimeframeCount++;
if (mTimeframeCount < mMaxTimeframes) {
return true;
}
return false;
}
} // namespace data_flow
} // namespace o2