Project
Loading...
Searching...
No Matches
raw-ul-checker.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 <cstdint>
18#include <iostream>
19#include <fstream>
20#include <unordered_map>
21#include <vector>
22#include <fmt/format.h>
23#include "boost/program_options.hpp"
26#include "MIDRaw/FEEIdConfig.h"
27#include "MIDRaw/CrateMasks.h"
28#include "MIDRaw/Decoder.h"
30
31namespace po = boost::program_options;
32
33bool readFile(std::string filename, o2::mid::Decoder& decoder, std::vector<o2::mid::ROBoard>& data, std::vector<o2::mid::ROFRecord>& rofRecords, unsigned long int nHBFs)
34{
35 std::cout << "Reading " << filename << std::endl;
36 o2::mid::RawFileReader rawFileReader;
37 if (!rawFileReader.init(filename.c_str())) {
38 std::cout << "Cannot initialize file reader with " << filename << std::endl;
39 return false;
40 }
41 long int hbfsRead = 0;
42 while (rawFileReader.readHB(true)) {
43 decoder.process(rawFileReader.getData());
44 rawFileReader.clear();
45 size_t offset = data.size();
46 data.insert(data.end(), decoder.getData().begin(), decoder.getData().end());
47 for (auto& rof : decoder.getROFRecords()) {
48 rofRecords.emplace_back(rof.interactionRecord, rof.eventType, rof.firstEntry + offset, rof.nEntries);
49 }
50 ++hbfsRead;
51 if (hbfsRead == nHBFs) {
52 break;
53 }
54 }
55 if (data.empty()) {
56 std::cout << "No data found in " << filename << std::endl;
57 return false;
58 }
59 return true;
60}
61
62std::vector<std::string> split(const std::string& str, char delimiter = ',')
63{
64 std::vector<std::string> tokens;
65 std::string token;
66 std::istringstream tokenStream(str);
67 while (std::getline(tokenStream, token, delimiter)) {
68 tokens.push_back(token);
69 }
70 return tokens;
71}
72
73int main(int argc, char* argv[])
74{
75 po::variables_map vm;
76 po::options_description generic("Generic options");
77 std::string ulFilenames, bareFilenames, feeIdConfigFilename, crateMasksFilename;
78 std::string outFilename = "check_ul.txt";
79 unsigned long int nHBFs = 0;
80
81 // clang-format off
82 generic.add_options()
83 ("help", "produce help message")
84 ("ul-filenames", po::value<std::string>(&ulFilenames),"Comma-separated input raw filenames with CRU User Logic")
85 ("bare-filenames", po::value<std::string>(&bareFilenames),"Comma-separated input raw filenames with bare CRU")
86 ("feeId-config-file", po::value<std::string>(&feeIdConfigFilename),"Filename with crate FEE ID correspondence")
87 ("crate-masks-file", po::value<std::string>(&crateMasksFilename),"Filename with crate masks")
88 ("electronics-delay-file", po::value<std::string>(),"Filename with electronics delay")
89 ("outFilename", po::value<std::string>(&outFilename),"Output filename")
90 ("nHBFs", po::value<unsigned long int>(&nHBFs),"Number of HBFs to test")
91 ("full", po::value<bool>()->implicit_value(true),"Full check");
92
93
94 po::options_description hidden("hidden options");
95 hidden.add_options()
96 ("input", po::value<std::vector<std::string>>(),"Input filename");
97 // clang-format on
98
99 po::options_description cmdline;
100 cmdline.add(generic).add(hidden);
101
102 po::store(po::command_line_parser(argc, argv).options(cmdline).run(), vm);
103 po::notify(vm);
104
105 if (vm.count("help")) {
106 std::cout << "Usage: " << argv[0] << "\n";
107 std::cout << generic << std::endl;
108 return 2;
109 }
110 if (ulFilenames.empty() || bareFilenames.empty()) {
111 std::cout << "Please specify ul-filenames and bare-filenames" << std::endl;
112 return 1;
113 }
114
115 o2::mid::FEEIdConfig feeIdConfig;
116 if (!feeIdConfigFilename.empty()) {
117 feeIdConfig = o2::mid::FEEIdConfig(feeIdConfigFilename.c_str());
118 }
119
120 o2::mid::CrateMasks crateMasks;
121 if (!crateMasksFilename.empty()) {
122 crateMasks = o2::mid::CrateMasks(crateMasksFilename.c_str());
123 }
124
125 o2::mid::ElectronicsDelay electronicsDelay;
126 if (vm.count("electronics-delay-file")) {
127 electronicsDelay = o2::mid::readElectronicsDelay(vm["electronics-delay-file"].as<std::string>().c_str());
128 }
129
130 auto bareDecoder = o2::mid::Decoder(true, true, electronicsDelay, crateMasks, feeIdConfig);
131 auto ulDecoder = o2::mid::Decoder(true, false, electronicsDelay, crateMasks, feeIdConfig);
132
133 std::vector<o2::mid::ROBoard> bareData, ulData;
134 std::vector<o2::mid::ROFRecord> bareRofs, ulRofs;
135
136 auto bareFnames = split(bareFilenames);
137 auto ulFnames = split(ulFilenames);
138
140
141 for (auto& fname : bareFnames) {
142 if (!readFile(fname, bareDecoder, bareData, bareRofs, nHBFs)) {
143 return 3;
144 }
145 }
146
147 for (auto& fname : ulFnames) {
148 if (!readFile(fname, ulDecoder, ulData, ulRofs, bareFnames.size() * nHBFs)) {
149 return 3;
150 }
151 }
152
153 if (false) {
154 // The orbit information in the UL is not correctly treated
155 // This means that its orbit will always be 0, unlike the bare data orbit
156 // Let us set the orbit of the raw data to 0 so that the results can be synchronized
157 for (auto& rof : bareRofs) {
158 rof.interactionRecord.orbit = 0;
159 }
160
161 for (auto& rof : ulRofs) {
162 rof.interactionRecord.orbit = 0;
163 }
164 }
165
166 std::ofstream outFile(outFilename.c_str());
167 if (!outFile.is_open()) {
168 std::cout << "Cannot open output file " << outFilename << std::endl;
169 return 3;
170 }
171
172 if (checker.process(bareData, bareRofs, ulData, ulRofs, vm.count("full"))) {
173 std::cout << "Everything ok!" << std::endl;
174 } else {
175 std::cout << "Problems found. See " << outFilename << " for details" << std::endl;
176 outFile << checker.getDebugMessage() << std::endl;
177 }
178 outFile << checker.getSummary() << std::endl;
179 outFile.close();
180
181 return 0;
182}
MID crate masks.
MID raw data decoder.
Delay parameters for MID electronics.
Hardware Id to FeeId mapper.
MID raw file reader.
Class to check the CRU user logic.
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 process(gsl::span< const ROBoard > bareData, gsl::span< const ROFRecord > bareRofs, gsl::span< const ROBoard > ulData, gsl::span< const ROFRecord > ulRofs, bool isFull=false)
std::string getSummary() const
std::string getDebugMessage() const
Gets the debug message.
GLboolean * data
Definition glcorearb.h:298
GLintptr offset
Definition glcorearb.h:660
ElectronicsDelay readElectronicsDelay(const char *filename)
std::string filename()
bool readFile(std::string filename, o2::mid::Decoder &decoder, std::vector< o2::mid::ROBoard > &data, std::vector< o2::mid::ROFRecord > &rofRecords, unsigned long int nHBFs)
std::vector< std::string > split(const std::string &str, char delimiter=',')
#define main
const std::string str