Project
Loading...
Searching...
No Matches
rawdump.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
17#include <iostream>
18#include "fmt/format.h"
19#include "boost/program_options.hpp"
20#include "DPLUtils/RawParser.h"
21#include "MIDRaw/Decoder.h"
23#include "MIDRaw/Utils.h"
24
25namespace po = boost::program_options;
26
27template <class RDH>
28void decode(o2::mid::Decoder& decoder, gsl::span<const uint8_t> payload, const RDH& rdh, std::ostream& out)
29{
30 decoder.clear();
31 decoder.process(payload, rdh);
32 for (auto& rof : decoder.getROFRecords()) {
33 out << fmt::format("BCid: 0x{:x} Orbit: 0x{:x} EvtType: {:d}", rof.interactionRecord.bc, rof.interactionRecord.orbit, (int)rof.eventType) << std::endl;
34 for (auto colIt = decoder.getData().begin() + rof.firstEntry; colIt != decoder.getData().begin() + rof.firstEntry + rof.nEntries; ++colIt) {
35 out << *colIt << std::endl;
36 }
37 }
38}
39
40int main(int argc, char* argv[])
41{
42 po::variables_map vm;
43 po::options_description generic("Generic options");
44 std::string outFilename = "";
45 unsigned long int nHBs = 0;
46 unsigned long int firstHB = 0;
47
48 // clang-format off
49 generic.add_options()
50 ("help", "produce help message")
51 ("output", po::value<std::string>(&outFilename),"Output text file")
52 ("first", po::value<unsigned long int>(&firstHB),"First HB to read")
53 ("nHBs", po::value<unsigned long int>(&nHBs),"Number of HBs read")
54 ("rdh-only", po::value<bool>()->implicit_value(true),"Only show RDHs")
55 ("decode", po::value<bool>()->implicit_value(true),"Decode output")
56 ("feeId-config-file", po::value<std::string>()->default_value(""),"Filename with crate FEE ID correspondence")
57 ("electronics-delay-file", po::value<std::string>()->default_value(""),"Filename with electronics delay");
58
59
60 po::options_description hidden("hidden options");
61 hidden.add_options()
62 ("input", po::value<std::vector<std::string>>(),"Input filename");
63 // clang-format on
64
65 po::options_description cmdline;
66 cmdline.add(generic).add(hidden);
67
68 po::positional_options_description pos;
69 pos.add("input", -1);
70
71 po::store(po::command_line_parser(argc, argv).options(cmdline).positional(pos).run(), vm);
72 po::notify(vm);
73
74 if (vm.count("help")) {
75 std::cout << "Usage: " << argv[0] << " <input_raw_filename> [input_raw_filename_1 ...]\n";
76 std::cout << generic << std::endl;
77 return 2;
78 }
79 if (vm.count("input") == 0) {
80 std::cout << "no input file specified" << std::endl;
81 return 1;
82 }
83
84 std::vector<std::string> inputfiles{vm["input"].as<std::vector<std::string>>()};
85
86 bool runDecoder = (vm.count("decode") > 0 && vm["decode"].as<bool>() == true);
87 std::unique_ptr<o2::mid::Decoder> decoder{nullptr};
88
89 std::ofstream outFile;
90 std::ostream& out = (outFilename.empty()) ? std::cout : (outFile.open(outFilename), outFile);
91
92 unsigned long int iHB = 0;
93 bool isRdhOnly = vm.count("rdh-only") > 0;
94
95 for (auto& filename : inputfiles) {
96 // Here we use a custom file reader to be able to read all kind of raw data,
97 // even those with a malformed structure in terms of number of HBFs per time frame
98 o2::mid::RawFileReader rawFileReader;
99 if (!rawFileReader.init(filename.c_str())) {
100 return 2;
101 }
102 while (rawFileReader.readHB()) {
103 if (iHB >= firstHB) {
104 o2::framework::RawParser parser(rawFileReader.getData().data(), rawFileReader.getData().size());
105 auto it = parser.begin(); // We only have 1 HB
106 auto const* rdhPtr = reinterpret_cast<const o2::header::RDHAny*>(it.raw());
108 if (it.size() > 0) {
109 gsl::span<const uint8_t> payload(it.data(), it.size());
110 if (runDecoder) {
111 if (!decoder) {
112 decoder = o2::mid::createDecoder(*rdhPtr, true, vm["electronics-delay-file"].as<std::string>().c_str(), "", vm["feeId-config-file"].as<std::string>().c_str());
113 }
114 decode(*decoder, payload, *rdhPtr, out);
115 } else if (!isRdhOnly) {
116 bool isBare = o2::mid::raw::isBare(*rdhPtr);
117 size_t wordLength = isBare ? 16 : 32;
118 for (size_t iword = 0; iword < payload.size(); iword += wordLength) {
119 auto word = payload.subspan(iword, wordLength);
120 if (isBare) {
121 for (auto it = word.rbegin(); it != word.rend(); ++it) {
122 auto ibInWord = word.rend() - it;
123 if (ibInWord == 4 || ibInWord == 9) {
124 out << " ";
125 }
126 if (ibInWord == 5 || ibInWord == 10) {
127 out << " ";
128 }
129 out << fmt::format("{:02x}", static_cast<int>(*it));
130 }
131 } else {
132 for (auto it = word.begin(); it != word.end(); ++it) {
133 out << fmt::format("{:02x}", static_cast<int>(*it));
134 }
135 }
136 out << "\n";
137 }
138 }
139 }
140 }
141 rawFileReader.clear();
142 ++iHB;
143 if (nHBs > 0 && iHB >= nHBs + firstHB) {
144 break;
145 }
146 } // loop on HBs
147 } // loop on files
148 outFile.close();
149
150 return 0;
151}
MID raw data decoder.
Raw data utilities for MID.
void decode(o2::mid::Decoder &decoder, gsl::span< const uint8_t > payload, const RDH &rdh, std::ostream &out)
Definition rawdump.cxx:28
MID raw file reader.
uint16_t pos
Definition RawData.h:3
Generic parser for consecutive raw pages.
const_iterator begin() const
Definition RawParser.h:618
const std::vector< ROFRecord > & getROFRecords() const
Gets the vector of data RO frame records.
Definition Decoder.h:67
const std::vector< ROBoard > & getData() const
Gets the vector of data.
Definition Decoder.h:64
void process(gsl::span< const uint8_t > bytes)
Definition Decoder.cxx:48
bool readHB(bool sendCompleteHBs=false)
const std::vector< uint8_t > & getData()
Gets the vector of data.
bool init(const char *inFilename, bool readContinuous=false)
bool isBare(const o2::header::RDHAny &rdh)
Test if the data comes from the common logic.
Definition Utils.h:31
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
std::string filename()
static void printRDH(const RDHv4 &rdh)
Definition RDHUtils.cxx:26
#define main