Project
Loading...
Searching...
No Matches
RawDumpSpec.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
16
18
19#include <fstream>
20
22#include "Framework/Logger.h"
23#include "Framework/Output.h"
24#include "Framework/Task.h"
26#include "Headers/RDHAny.h"
27#include "MIDRaw/Decoder.h"
29
30namespace of = o2::framework;
31
32namespace o2
33{
34namespace mid
35{
36
37class RawDumpDeviceDPL
38{
39 public:
40 RawDumpDeviceDPL(bool isDebugMode, const FEEIdConfig& feeIdConfig, const CrateMasks& crateMasks, const ElectronicsDelay& electronicsDelay, header::DataHeader::SubSpecificationType subSpec) : mIsDebugMode(isDebugMode), mFeeIdConfig(feeIdConfig), mCrateMasks(crateMasks), mElectronicsDelay(electronicsDelay), mSubSpec(subSpec) {}
41
43 {
44 auto rdhOnly = ic.options().get<bool>("rdh-only");
45 auto dumpDecoded = ic.options().get<bool>("decode");
46 auto dumpAll = ic.options().get<bool>("payload-and-decode");
47
48 if (rdhOnly) {
49 mDumpDecoded = false;
50 mDumpPayload = false;
51 } else if (dumpDecoded) {
52 mDumpDecoded = true;
53 mDumpPayload = false;
54 } else if (dumpAll) {
55 mDumpDecoded = true;
56 mDumpPayload = false;
57 }
58 }
59
60 void printRDHHex(const o2::header::RDHAny* rdhPtr, bool isBare)
61 {
62 std::stringstream ss;
63 size_t nWordsPerLine = isBare ? 2 : 4;
64 std::vector<uint64_t> words{rdhPtr->word0, rdhPtr->word1, rdhPtr->word2, rdhPtr->word3, rdhPtr->word4, rdhPtr->word5, rdhPtr->word6, rdhPtr->word7};
65 for (size_t iword = 0; iword < words.size(); ++iword) {
66 auto word = words[iword];
67 if (iword % nWordsPerLine == 0) {
68 ss << "\n";
69 }
70 for (size_t ibyte = 0, end = sizeof(word); ibyte < end; ++ibyte) {
71 ss << fmt::format("{:02x}", (word >> 8 * ibyte) & 0xf);
72 }
73 }
74 LOG(info) << ss.str();
75 }
76
77 void printPayload(gsl::span<const uint8_t> payload, bool isBare)
78 {
79 std::stringstream ss;
80 size_t wordLength = isBare ? 16 : 32;
81 ss << "\n";
82 for (size_t iword = 0; iword < payload.size(); iword += wordLength) {
83 auto word = payload.subspan(iword, wordLength);
84 if (isBare) {
85 for (auto it = word.rbegin(); it != word.rend(); ++it) {
86 auto ibInWord = word.rend() - it;
87 if (ibInWord == 4 || ibInWord == 9) {
88 ss << " ";
89 }
90 if (ibInWord == 5 || ibInWord == 10) {
91 ss << " ";
92 }
93 ss << fmt::format("{:02x}", static_cast<int>(*it));
94 }
95 } else {
96 for (auto it = word.begin(); it != word.end(); ++it) {
97 ss << fmt::format("{:02x}", static_cast<int>(*it));
98 }
99 }
100 ss << "\n";
101 }
102 LOG(info) << ss.str();
103 }
104
106 {
108 std::vector<ROBoard> data;
109 std::vector<ROFRecord> rofs;
110 pc.outputs().snapshot(of::Output{header::gDataOriginMID, "DECODED", mSubSpec}, data);
111 pc.outputs().snapshot(of::Output{header::gDataOriginMID, "DECODEDROF", mSubSpec}, rofs);
112 return;
113 }
114
115 std::vector<of::InputSpec> filter{of::InputSpec{"filter", of::ConcreteDataTypeMatcher{header::gDataOriginMID, header::gDataDescriptionRawData}, of::Lifetime::Timeframe}};
116
117 of::DPLRawParser parser(pc.inputs(), filter);
118
119 if (!mDecoder) {
120 auto const* rdhPtr = reinterpret_cast<const o2::header::RDHAny*>(parser.begin().raw());
121 mDecoder = createDecoder(*rdhPtr, mIsDebugMode, mElectronicsDelay, mCrateMasks, mFeeIdConfig);
122 }
123
124 mDecoder->clear();
125 size_t firstRof = 0;
126 for (auto it = parser.begin(), end = parser.end(); it != end; ++it) {
127 auto const* rdhPtr = reinterpret_cast<const o2::header::RDHAny*>(it.raw());
128 gsl::span<const uint8_t> payload(it.data(), it.size());
129 bool isBare = o2::mid::raw::isBare(*rdhPtr);
131 printRDHHex(rdhPtr, isBare);
132 if (mDumpPayload) {
133 printPayload(payload, isBare);
134 }
135
136 if (mDumpDecoded) {
137 mDecoder->process(payload, *rdhPtr);
138 std::stringstream ss;
139 for (auto rofIt = mDecoder->getROFRecords().begin() + firstRof, end = mDecoder->getROFRecords().end(); rofIt != end; ++rofIt) {
140 ss << fmt::format("BCid: 0x{:x} Orbit: 0x{:x} EvtType: {:d}", rofIt->interactionRecord.bc, rofIt->interactionRecord.orbit, static_cast<int>(rofIt->eventType)) << std::endl;
141 for (auto colIt = mDecoder->getData().begin() + rofIt->firstEntry, end = mDecoder->getData().begin() + rofIt->getEndIndex(); colIt != end; ++colIt) {
142 ss << *colIt << std::endl;
143 }
144 }
145 LOG(info) << ss.str();
146 firstRof = mDecoder->getROFRecords().size();
147 }
148 }
149 }
150
151 private:
152 std::unique_ptr<Decoder> mDecoder{nullptr};
153 bool mIsDebugMode{false};
154 FEEIdConfig mFeeIdConfig{};
155 CrateMasks mCrateMasks{};
156 ElectronicsDelay mElectronicsDelay{};
158 bool mDumpPayload = true;
159 bool mDumpDecoded = false;
160};
161
162of::DataProcessorSpec getRawDumpSpec(bool isDebugMode, const FEEIdConfig& feeIdConfig, const CrateMasks& crateMasks, const ElectronicsDelay& electronicsDelay, std::vector<of::InputSpec> inputSpecs, bool askDISTSTF, o2::header::DataHeader::SubSpecificationType subSpecType)
163{
164 if (askDISTSTF) {
165 inputSpecs.emplace_back(getDiSTSTFSpec());
166 }
167
169 "MIDRawDump",
170 {inputSpecs},
171 {},
172 of::adaptFromTask<o2::mid::RawDumpDeviceDPL>(isDebugMode, feeIdConfig, crateMasks, electronicsDelay, subSpecType),
173 o2::framework::Options{{"decode", o2::framework::VariantType::Bool, false, {"Dump decoded raw data"}},
174 {"rdh-only", o2::framework::VariantType::Bool, false, {"Only dump RDH"}},
175 {"payload-and-decode", o2::framework::VariantType::Bool, false, {"Dump payload and decoded data"}}}};
176}
177
179{
180 return getRawDumpSpec(isDebugMode, FEEIdConfig(), CrateMasks(), ElectronicsDelay(), true);
181}
182
183of::DataProcessorSpec getRawDumpSpec(bool isDebugMode, const FEEIdConfig& feeIdConfig, const CrateMasks& crateMasks, const ElectronicsDelay& electronicsDelay, bool askDISTSTF)
184{
185 std::vector<of::InputSpec> inputSpecs{{"mid_raw", of::ConcreteDataTypeMatcher{header::gDataOriginMID, header::gDataDescriptionRawData}, of::Lifetime::Timeframe}};
187 return getRawDumpSpec(isDebugMode, feeIdConfig, crateMasks, electronicsDelay, inputSpecs, askDISTSTF, subSpec);
188}
189
190of::DataProcessorSpec getRawDumpSpec(bool isDebugMode, const FEEIdConfig& feeIdConfig, const CrateMasks& crateMasks, const ElectronicsDelay& electronicsDelay, bool askDISTSTF, header::DataHeader::SubSpecificationType subSpec)
191{
192 std::vector<of::InputSpec> inputSpecs{{"mid_raw", header::gDataOriginMID, header::gDataDescriptionRawData, subSpec, o2::framework::Lifetime::Timeframe}};
193
194 return getRawDumpSpec(isDebugMode, feeIdConfig, crateMasks, electronicsDelay, inputSpecs, askDISTSTF, subSpec);
195}
196} // namespace mid
197} // namespace o2
A raw page parser for DPL input.
MID raw data decoder.
Device to dump decoded raw data.
Handler for raw data input specs.
buffer_type const * raw() const
get pointer to raw block at current position, rdh starts here
The parser handles transparently input in the format of raw pages.
const_iterator end() const
const_iterator begin() const
void snapshot(const Output &spec, T const &object)
ConfigParamRegistry const & options()
Definition InitContext.h:33
DataAllocator & outputs()
The data allocator is used to allocate memory for the output data.
InputRecord & inputs()
The inputs associated with this processing context.
void printPayload(gsl::span< const uint8_t > payload, bool isBare)
void init(of::InitContext &ic)
void printRDHHex(const o2::header::RDHAny *rdhPtr, bool isBare)
RawDumpDeviceDPL(bool isDebugMode, const FEEIdConfig &feeIdConfig, const CrateMasks &crateMasks, const ElectronicsDelay &electronicsDelay, header::DataHeader::SubSpecificationType subSpec)
void run(of::ProcessingContext &pc)
GLuint GLuint end
Definition glcorearb.h:469
GLboolean * data
Definition glcorearb.h:298
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition glcorearb.h:1308
constexpr o2::header::DataOrigin gDataOriginMID
Definition DataHeader.h:573
constexpr o2::header::DataDescription gDataDescriptionRawData
Definition DataHeader.h:597
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< ConfigParamSpec > Options
bool isBare(const o2::header::RDHAny &rdh)
Test if the data comes from the common logic.
Definition Utils.h:31
bool isDroppedTF(o2::framework::ProcessingContext &pc, o2::header::DataOrigin origin=o2::header::gDataOriginMID)
o2::framework::InputSpec getDiSTSTFSpec()
std::unique_ptr< Decoder > createDecoder(const o2::header::RDHAny &rdh, bool isDebugMode, const ElectronicsDelay &electronicsDelay, const CrateMasks &crateMasks, const FEEIdConfig &feeIdConfig)
Definition Decoder.cxx:63
framework::DataProcessorSpec getRawDumpSpec()
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
uint32_t SubSpecificationType
Definition DataHeader.h:620
uint64_t word7
Definition RDHAny.h:37
uint64_t word6
Definition RDHAny.h:36
uint64_t word0
Definition RDHAny.h:30
uint64_t word1
Definition RDHAny.h:31
uint64_t word3
Definition RDHAny.h:33
uint64_t word2
Definition RDHAny.h:32
uint64_t word4
Definition RDHAny.h:34
uint64_t word5
Definition RDHAny.h:35
static void printRDH(const RDHv4 &rdh)
Definition RDHUtils.cxx:26
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"