forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathZeroSuppressionSpec.cxx
More file actions
116 lines (99 loc) · 4.27 KB
/
ZeroSuppressionSpec.cxx
File metadata and controls
116 lines (99 loc) · 4.27 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
// 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 MID/Workflow/src/ZeroSuppressionSpec.cxx
/// \brief MID zero suppression spec
/// \author Diego Stocco <Diego.Stocco at cern.ch>
/// \date 23 October 2020
#include "MIDWorkflow/ZeroSuppressionSpec.h"
#include <vector>
#include <gsl/gsl>
#include "Framework/Output.h"
#include "Framework/Task.h"
#include "DataFormatsMID/ColumnData.h"
#include "DataFormatsMID/ROFRecord.h"
#include "DataFormatsMID/MCLabel.h"
#include "SimulationDataFormat/MCTruthContainer.h"
#include "MIDRaw/ColumnDataToLocalBoard.h"
#include "MIDRaw/DecodedDataAggregator.h"
#include "MIDRaw/ROBoardResponse.h"
#include "MIDWorkflow/ColumnDataSpecsUtils.h"
namespace of = o2::framework;
namespace o2
{
namespace mid
{
class ZeroSuppressionDeviceDPL
{
public:
ZeroSuppressionDeviceDPL(bool useMC) : mUseMC(useMC) {}
void init(o2::framework::InitContext& ic)
{
}
void run(o2::framework::ProcessingContext& pc)
{
const auto patterns = specs::getDataEventType(pc, "mid_zs_in", EventType::Standard);
const auto inROFRecords = specs::getRofsEventType(pc, "mid_zs_in", EventType::Standard);
const auto inMCContainer = mUseMC ? specs::getLabels(pc, "mid_zs_in") : nullptr;
o2::dataformats::MCTruthContainer<MCLabel> outMCContainer;
auto& zsData = pc.outputs().make<std::vector<ColumnData>>(of::OutputRef{"mid_zs_out_0"});
auto& zsROFs = pc.outputs().make<std::vector<ROFRecord>>(of::OutputRef{"mid_zs_out_rof_0"});
zsData.reserve(patterns.size());
zsROFs.reserve(inROFRecords.size());
std::vector<ROFRecord> tmpROFs(1);
for (auto& rof : inROFRecords) {
mConverter.process(patterns.subspan(rof.firstEntry, rof.nEntries));
if (!mConverter.getData().empty()) {
std::vector<ROBoard> decodedData = mConverter.getData();
mResponse.applyZeroSuppression(decodedData);
tmpROFs.front().interactionRecord = rof.interactionRecord;
tmpROFs.front().eventType = rof.eventType;
tmpROFs.front().firstEntry = 0;
tmpROFs.front().nEntries = decodedData.size();
mAggregator.process(decodedData, tmpROFs);
auto& tmpOut = mAggregator.getData();
zsROFs.emplace_back(rof.interactionRecord, rof.eventType, zsData.size(), tmpOut.size());
zsData.insert(zsData.end(), tmpOut.begin(), tmpOut.end());
if (mUseMC) {
for (auto outColIt = zsData.begin() + zsROFs.back().firstEntry, outEnd = zsData.begin() + zsROFs.back().firstEntry + zsROFs.back().nEntries; outColIt != outEnd; ++outColIt) {
for (auto inColIt = patterns.begin() + rof.firstEntry, inEnd = patterns.begin() + rof.firstEntry + rof.nEntries; inColIt != inEnd; ++inColIt) {
if (inColIt->deId == outColIt->deId && inColIt->columnId == outColIt->columnId) {
auto inIdx = std::distance(patterns.begin(), inColIt);
auto outIdx = std::distance(zsData.begin(), outColIt);
outMCContainer.addElements(outIdx, inMCContainer->getLabels(inIdx));
break;
}
}
}
}
}
}
if (mUseMC) {
pc.outputs().snapshot(of::Output{header::gDataOriginMID, "DATALABELS", 0}, outMCContainer);
}
}
private:
ColumnDataToLocalBoard mConverter{};
DecodedDataAggregator mAggregator{};
ROBoardResponse mResponse{};
bool mUseMC{true};
};
framework::DataProcessorSpec getZeroSuppressionSpec(bool useMC, std::string_view dataDesc)
{
auto inputSpecs = specs::buildStandardInputSpecs("mid_zs_in", dataDesc, useMC);
auto outputSpecs = specs::buildStandardOutputSpecs("mid_zs_out", "DATA", useMC);
return of::DataProcessorSpec{
"MIDZeroSuppression",
{inputSpecs},
{outputSpecs},
of::AlgorithmSpec{of::adaptFromTask<o2::mid::ZeroSuppressionDeviceDPL>(useMC)}};
}
} // namespace mid
} // namespace o2