forked from mcoquet642/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompressorTask.cxx
More file actions
158 lines (128 loc) · 5.73 KB
/
CompressorTask.cxx
File metadata and controls
158 lines (128 loc) · 5.73 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// 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 CompressorTask.cxx
/// @author Roberto Preghenella
/// @since 2019-12-18
/// @brief TOF raw data compressor task
#include "TOFCompression/CompressorTask.h"
#include "Framework/ControlService.h"
#include "Framework/ConfigParamRegistry.h"
#include "Framework/RawDeviceService.h"
#include "Framework/DeviceSpec.h"
#include "Framework/DataSpecUtils.h"
#include "Framework/InputRecordWalker.h"
#include <fairmq/FairMQDevice.h>
using namespace o2::framework;
namespace o2
{
namespace tof
{
template <typename RDH, bool verbose, bool paranoid>
void CompressorTask<RDH, verbose, paranoid>::init(InitContext& ic)
{
LOG(INFO) << "Compressor init";
auto decoderCONET = ic.options().get<bool>("tof-compressor-conet-mode");
auto decoderVerbose = ic.options().get<bool>("tof-compressor-decoder-verbose");
auto encoderVerbose = ic.options().get<bool>("tof-compressor-encoder-verbose");
auto checkerVerbose = ic.options().get<bool>("tof-compressor-checker-verbose");
mOutputBufferSize = ic.options().get<int>("tof-compressor-output-buffer-size");
mCompressor.setDecoderCONET(decoderCONET);
mCompressor.setDecoderVerbose(decoderVerbose);
mCompressor.setEncoderVerbose(encoderVerbose);
mCompressor.setCheckerVerbose(checkerVerbose);
auto finishFunction = [this]() {
mCompressor.checkSummary();
};
ic.services().get<CallbackService>().set(CallbackService::Id::Stop, finishFunction);
}
template <typename RDH, bool verbose, bool paranoid>
void CompressorTask<RDH, verbose, paranoid>::run(ProcessingContext& pc)
{
LOG(DEBUG) << "Compressor run";
auto device = pc.services().get<o2::framework::RawDeviceService>().device();
auto outputRoutes = pc.services().get<o2::framework::RawDeviceService>().spec().outputs;
auto fairMQChannel = outputRoutes.at(0).channel;
FairMQParts partsOut;
/** to store data sorted by subspec id **/
std::map<int, std::vector<o2::framework::DataRef>> subspecPartMap;
std::map<int, int> subspecBufferSize;
/** loop over inputs routes **/
std::vector<InputSpec> sel{InputSpec{"filter", ConcreteDataTypeMatcher{"TOF", "RAWDATA"}}};
for (const auto& ref : InputRecordWalker(pc.inputs(), sel)) {
// for (auto iit = pc.inputs().begin(), iend = pc.inputs().end(); iit != iend; ++iit) {
// if (!iit.isValid()) {
// continue;
// }
/** loop over input parts **/
// for (auto const& ref : iit) {
/** store parts in map **/
auto headerIn = DataRefUtils::getHeader<o2::header::DataHeader*>(ref);
auto subspec = headerIn->subSpecification;
subspecPartMap[subspec].push_back(ref);
/** increase subspec buffer size **/
if (!subspecBufferSize.count(subspec)) {
subspecBufferSize[subspec] = 0;
}
subspecBufferSize[subspec] += headerIn->payloadSize;
// }
}
/** loop over subspecs **/
for (auto& subspecPartEntry : subspecPartMap) {
auto subspec = subspecPartEntry.first;
auto parts = subspecPartEntry.second;
auto& firstPart = parts.at(0);
/** use the first part to define output headers **/
auto headerOut = *DataRefUtils::getHeader<o2::header::DataHeader*>(firstPart);
auto dataProcessingHeaderOut = *DataRefUtils::getHeader<o2::framework::DataProcessingHeader*>(firstPart);
headerOut.dataDescription = "CRAWDATA";
headerOut.payloadSize = 0;
headerOut.splitPayloadParts = 1;
/** initialise output message **/
auto bufferSize = mOutputBufferSize >= 0 ? mOutputBufferSize + subspecBufferSize[subspec] : std::abs(mOutputBufferSize);
auto payloadMessage = device->NewMessage(bufferSize);
auto bufferPointer = (char*)payloadMessage->GetData();
/** loop over subspec parts **/
for (const auto& ref : parts) {
/** input **/
auto headerIn = DataRefUtils::getHeader<o2::header::DataHeader*>(ref);
auto dataProcessingHeaderIn = DataRefUtils::getHeader<o2::framework::DataProcessingHeader*>(ref);
auto payloadIn = ref.payload;
auto payloadInSize = headerIn->payloadSize;
/** prepare compressor **/
mCompressor.setDecoderBuffer(payloadIn);
mCompressor.setDecoderBufferSize(payloadInSize);
mCompressor.setEncoderBuffer(bufferPointer);
mCompressor.setEncoderBufferSize(bufferSize);
/** run **/
mCompressor.run();
auto payloadOutSize = mCompressor.getEncoderByteCounter();
bufferPointer += payloadOutSize;
bufferSize -= payloadOutSize;
headerOut.payloadSize += payloadOutSize;
}
/** finalise output message **/
payloadMessage->SetUsedSize(headerOut.payloadSize);
o2::header::Stack headerStack{headerOut, dataProcessingHeaderOut};
auto headerMessage = device->NewMessage(headerStack.size());
std::memcpy(headerMessage->GetData(), headerStack.data(), headerStack.size());
/** add parts **/
partsOut.AddPart(std::move(headerMessage));
partsOut.AddPart(std::move(payloadMessage));
}
/** send message **/
device->Send(partsOut, fairMQChannel);
}
template class CompressorTask<o2::header::RAWDataHeaderV6, false, false>;
template class CompressorTask<o2::header::RAWDataHeaderV6, false, true>;
template class CompressorTask<o2::header::RAWDataHeaderV6, true, false>;
template class CompressorTask<o2::header::RAWDataHeaderV6, true, true>;
} // namespace tof
} // namespace o2