-
Notifications
You must be signed in to change notification settings - Fork 496
Expand file tree
/
Copy pathSACProcessorSpec.cxx
More file actions
187 lines (161 loc) · 7.86 KB
/
SACProcessorSpec.cxx
File metadata and controls
187 lines (161 loc) · 7.86 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
// 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 SACProcessorSpec.cxx
/// @brief TPC Integrated Analogue Current processing
/// @author Jens Wiechula
#include <vector>
#include <chrono>
#include "Framework/Task.h"
#include "Framework/InputRecordWalker.h"
#include "Framework/WorkflowSpec.h"
#include "Framework/ConfigParamRegistry.h"
#include "DetectorsRaw/RDHUtils.h"
#include "DPLUtils/RawParser.h"
#include "CommonUtils/TreeStreamRedirector.h"
#include "DetectorsBase/GRPGeomHelper.h"
#include "Framework/CCDBParamSpec.h"
#include "TPCBaseRecSim/CDBInterface.h"
#include "DataFormatsTPC/RawDataTypes.h"
#include "TPCBase/RDHUtils.h"
#include "TPCCalibration/SACDecoder.h"
#include "TPCWorkflow/SACProcessorSpec.h"
using HighResClock = std::chrono::steady_clock;
using namespace o2::framework;
namespace o2::tpc
{
class SACProcessorDevice : public Task
{
public:
enum class DebugFlags {
HBFInfo = 0x10, ///< Show data for each HBF
};
using FEEIDType = rdh_utils::FEEIDType;
SACProcessorDevice(std::shared_ptr<o2::base::GRPGeomRequest> req) : mCCDBRequest(req) {}
void init(InitContext& ic) final
{
o2::base::GRPGeomHelper::instance().setRequest(mCCDBRequest);
mDebugLevel = ic.options().get<uint32_t>("debug-level");
mDecoder.setDebugLevel(mDebugLevel);
mAggregateTFs = ic.options().get<uint32_t>("aggregate-tfs");
const auto nthreadsDecoding = ic.options().get<uint32_t>("nthreads-decoding");
sac::Decoder::setNThreads(nthreadsDecoding);
const auto reAlignType = ic.options().get<uint32_t>("try-re-align");
if (reAlignType <= uint32_t(sac::Decoder::ReAlignType::MaxType)) {
mDecoder.setReAlignType(sac::Decoder::ReAlignType(reAlignType));
}
}
void run(ProcessingContext& pc) final
{
o2::base::GRPGeomHelper::instance().checkUpdates(pc);
const auto& tinfo = pc.services().get<o2::framework::TimingInfo>();
const auto startTime = HighResClock::now();
std::vector<InputSpec> filter = {{"check", ConcreteDataTypeMatcher{o2::header::gDataOriginTPC, "RAWDATA"}, Lifetime::Timeframe}}; // TODO: Change to SAC when changed in DD
for (auto const& ref : InputRecordWalker(pc.inputs(), filter)) {
const auto* dh = DataRefUtils::getHeader<o2::header::DataHeader*>(ref);
// ---| extract hardware information to do the processing |---
const auto feeId = (FEEIDType)dh->subSpecification;
const auto link = rdh_utils::getLink(feeId);
const uint32_t cruID = rdh_utils::getCRU(feeId);
const auto endPoint = rdh_utils::getEndPoint(feeId);
// only select SACs
// ToDo: cleanup once SACs will be propagated not as RAWDATA, but SAC.
if (link != rdh_utils::SACLinkID) {
continue;
}
if (mDebugLevel & (uint32_t)DebugFlags::HBFInfo) {
LOGP(info, "SAC Processing firstTForbit {:9}, tfCounter {:5}, run {:6}, feeId {:6} ({:3}/{}/{:2})", tinfo.firstTForbit, tinfo.tfCounter, tinfo.runNumber, feeId, cruID, endPoint, link);
}
// ---| data loop |---
const gsl::span<const char> raw = pc.inputs().get<gsl::span<char>>(ref);
RawParser parser(raw.data(), raw.size());
for (auto it = parser.begin(), end = parser.end(); it != end; ++it) {
const auto size = it.size();
if (size == 0) {
auto rdhPtr = reinterpret_cast<const o2::header::RDHAny*>(it.raw());
const auto rdhVersion = raw::RDHUtils::getVersion(rdhPtr);
if (!rdhPtr || rdhVersion < 6) {
throw std::runtime_error(fmt::format("could not get RDH from packet, or version {} < 6", rdhVersion).data());
}
// TODO: should only be done once for the first packet
if ((mDecoder.getReferenceTime() < 0) && (raw::RDHUtils::getPacketCounter(rdhPtr))) {
const double referenceTime = o2::base::GRPGeomHelper::instance().getOrbitResetTimeMS() + tinfo.firstTForbit * o2::constants::lhc::LHCOrbitMUS * 0.001;
LOGP(info, "setting time stamp reset reference to: {}, at tfCounter: {}, firstTForbit: {}", referenceTime, tinfo.tfCounter, tinfo.firstTForbit);
mDecoder.setReferenceTime(referenceTime); // TODO set proper time
}
continue;
}
auto data = (const char*)it.data();
mDecoder.process(data, size);
}
}
if ((mProcessedTFs > 0) && !(mProcessedTFs % mAggregateTFs)) {
mDecoder.runDecoding();
sendData(pc.outputs());
}
if (mDebugLevel & (uint32_t)sac::Decoder::DebugFlags::TimingInfo) {
auto endTime = HighResClock::now();
auto elapsed_seconds = std::chrono::duration_cast<std::chrono::duration<double>>(endTime - startTime);
LOGP(info, "Time spent for TF {}, firstTForbit {}: {} s", tinfo.tfCounter, tinfo.firstTForbit, elapsed_seconds.count());
}
++mProcessedTFs;
}
void sendData(DataAllocator& output)
{
output.snapshot(Output{"TPC", "REFTIMESAC", 0}, mDecoder.getDecodedData().referenceTime);
output.snapshot(Output{"TPC", "DECODEDSAC", 0}, mDecoder.getDecodedData().getGoodData());
mDecoder.clearDecodedData();
}
void endOfStream(EndOfStreamContext& ec) final
{
LOGP(info, "endOfStream");
mDecoder.finalize();
sendData(ec.outputs());
}
void finaliseCCDB(o2::framework::ConcreteDataMatcher& matcher, void* obj) final
{
o2::base::GRPGeomHelper::instance().finaliseCCDB(matcher, obj);
}
private:
size_t mProcessedTFs{0}; ///< Number of processed TFs
uint32_t mDebugLevel{0}; ///< Debug level
uint32_t mAggregateTFs{0}; ///< Number of TFs over which to aggregate the data before decoding and sending
sac::Decoder mDecoder; ///< Decoder for SAC data
std::shared_ptr<o2::base::GRPGeomRequest> mCCDBRequest;
};
o2::framework::DataProcessorSpec getSACProcessorSpec()
{
using device = o2::tpc::SACProcessorDevice;
std::vector<InputSpec> inputs;
inputs.emplace_back(InputSpec{"tpcraw", ConcreteDataTypeMatcher{"TPC", "RAWDATA"}, Lifetime::Timeframe});
auto ccdbRequest = std::make_shared<o2::base::GRPGeomRequest>(true, // orbitResetTime
true, // GRPECS=true
false, // GRPLHCIF
false, // GRPMagField
false, // askMatLUT
o2::base::GRPGeomRequest::None, // geometry
inputs);
std::vector<OutputSpec> outputs;
outputs.emplace_back("TPC", "DECODEDSAC", 0, Lifetime::Sporadic);
outputs.emplace_back("TPC", "REFTIMESAC", 0, Lifetime::Sporadic);
return DataProcessorSpec{
"tpc-sac-processor",
inputs,
outputs,
AlgorithmSpec{adaptFromTask<device>(ccdbRequest)},
Options{
{"debug-level", VariantType::UInt32, 0u, {"amount of debug to show"}},
{"nthreads-decoding", VariantType::UInt32, 1u, {"Number of threads used for decoding"}},
{"aggregate-tfs", VariantType::UInt32, 1u, {"Number of TFs to aggregate before running decoding"}},
{"try-re-align", VariantType::UInt32, 0u, {"Try to re-align data stream in case of missing packets. 0 - no; 1 - yes; 2 - yes, and fill missing packets"}},
} // end Options
}; // end DataProcessorSpec
}
} // namespace o2::tpc