Project
Loading...
Searching...
No Matches
digi2raw.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
14
15#include <boost/program_options.hpp>
16#include <TTree.h>
17#include <TChain.h>
18#include <TFile.h>
19#include <TStopwatch.h>
20#include "Framework/Logger.h"
21#include <filesystem>
22#include <vector>
23#include <string>
24#include <iomanip>
36
39namespace bpo = boost::program_options;
40
41constexpr int DefRDHVersion = o2::raw::RDHUtils::getVersion<o2::header::RAWDataHeader>();
42
43void setupLinks(o2::itsmft::MC2RawEncoder<MAP>& m2r, std::string_view outDir, std::string_view outPrefix, std::string_view fileFor);
44void digi2raw(std::string_view inpName, std::string_view outDir, std::string_view fileFor, int verbosity, uint32_t rdhV = DefRDHVersion, bool enablePadding = false,
45 bool noEmptyHBF = false, bool noEmptyROF = false, int superPageSizeInB = 1024 * 1024);
46
47int main(int argc, char** argv)
48{
49 bpo::variables_map vm;
50 bpo::options_description opt_general("Usage:\n " + std::string(argv[0]) +
51 "Convert ITS digits to CRU raw data\n");
52 bpo::options_description opt_hidden("");
53 bpo::options_description opt_all;
54 bpo::positional_options_description opt_pos;
55
56 try {
57 auto add_option = opt_general.add_options();
58 add_option("help,h", "Print this help message");
59 add_option("verbosity,v", bpo::value<uint32_t>()->default_value(0), "verbosity level [0 = no output]");
60 add_option("input-file,i", bpo::value<std::string>()->default_value("itsdigits.root"), "input ITS digits file");
61 add_option("file-for,f", bpo::value<std::string>()->default_value("all"), "single file per: all,flp,cruendpoint,link");
62 add_option("output-dir,o", bpo::value<std::string>()->default_value("./"), "output directory for raw data");
63 add_option("rdh-version,r", bpo::value<uint32_t>()->default_value(DefRDHVersion), "RDH version to use");
64 add_option("enable-padding", bpo::value<bool>()->default_value(false)->implicit_value(true), "enable GBT word padding to 128 bits even for RDH V7");
65 add_option("no-empty-hbf,e", bpo::value<bool>()->default_value(false)->implicit_value(true), "do not create empty HBF pages (except for HBF starting TF)");
66 add_option("no-empty-rof", bpo::value<bool>()->default_value(false)->implicit_value(true), "do not create empty ROF blocks");
67 add_option("hbfutils-config,u", bpo::value<std::string>()->default_value(std::string(o2::base::NameConf::DIGITIZATIONCONFIGFILE)), "config file for HBFUtils (or none)");
68 add_option("configKeyValues", bpo::value<std::string>()->default_value(""), "comma-separated configKeyValues");
69
70 opt_all.add(opt_general).add(opt_hidden);
71 bpo::store(bpo::command_line_parser(argc, argv).options(opt_all).positional(opt_pos).run(), vm);
72
73 if (vm.count("help")) {
74 std::cout << opt_general << std::endl;
75 exit(0);
76 }
77
78 bpo::notify(vm);
79 } catch (bpo::error& e) {
80 std::cerr << "ERROR: " << e.what() << std::endl
81 << std::endl;
82 std::cerr << opt_general << std::endl;
83 exit(1);
84 } catch (std::exception& e) {
85 std::cerr << e.what() << ", application will now exit" << std::endl;
86 exit(2);
87 }
88
89 std::string confDig = vm["hbfutils-config"].as<std::string>();
90 if (!confDig.empty() && confDig != "none") {
92 }
93 o2::conf::ConfigurableParam::updateFromString(vm["configKeyValues"].as<std::string>());
94 digi2raw(vm["input-file"].as<std::string>(),
95 vm["output-dir"].as<std::string>(),
96 vm["file-for"].as<std::string>(),
97 vm["verbosity"].as<uint32_t>(),
98 vm["rdh-version"].as<uint32_t>(),
99 vm["enable-padding"].as<bool>(),
100 vm["no-empty-hbf"].as<bool>(),
101 vm["no-empty-rof"].as<bool>());
102 LOG(info) << "HBFUtils settings used for conversion:";
103
105
106 return 0;
107}
108
109void digi2raw(std::string_view inpName, std::string_view outDir, std::string_view fileFor, int verbosity, uint32_t rdhV, bool enablePadding, bool noEmptyHBF, bool noEmptyROF, int superPageSizeInB)
110{
111 TStopwatch swTot;
112 swTot.Start();
113 using ROFR = o2::itsmft::ROFRecord;
114 using ROFRVEC = std::vector<o2::itsmft::ROFRecord>;
115 const uint8_t ruSWMin = 0, ruSWMax = 0xff; // seq.ID of 1st and last RU (stave) to convert
116 if (rdhV < 7 && !enablePadding) {
117 enablePadding = true;
118 LOG(info) << "padding is always ON for RDH version " << rdhV;
119 }
120
121 LOG(info) << "HBFUtil settings:";
123
124 // if needed, create output directory
125 if (!std::filesystem::exists(outDir)) {
126 if (!std::filesystem::create_directories(outDir)) {
127 LOG(fatal) << "could not create output directory " << outDir;
128 } else {
129 LOG(info) << "created output directory " << outDir;
130 }
131 }
132
134 std::string digTreeName{o2::base::NameConf::MCTTREENAME.data()};
135 TChain digTree(digTreeName.c_str());
136 digTree.AddFile(inpName.data());
137 digTree.SetBranchStatus("*MCTruth*", 0); // ignore MC info
138
139 std::vector<o2::itsmft::Digit> digiVec, *digiVecP = &digiVec;
140 std::string digBranchName = o2::utils::Str::concat_string(MAP::getName(), "Digit");
141 if (!digTree.GetBranch(digBranchName.c_str())) {
142 LOG(fatal) << "Failed to find the branch " << digBranchName << " in the tree " << digTreeName;
143 }
144 digTree.SetBranchAddress(digBranchName.c_str(), &digiVecP);
145
146 // ROF record entries in the digit tree
147 ROFRVEC rofRecVec, *rofRecVecP = &rofRecVec;
148 std::string rofRecName = o2::utils::Str::concat_string(MAP::getName(), "DigitROF");
149 if (!digTree.GetBranch(rofRecName.c_str())) {
150 LOG(fatal) << "Failed to find the branch " << rofRecName << " in the tree " << digTreeName;
151 }
152 digTree.SetBranchAddress(rofRecName.c_str(), &rofRecVecP);
154 std::string inputGRP = o2::base::NameConf::getGRPFileName();
155 const auto grp = o2::parameters::GRPObject::loadFrom(inputGRP);
156
159 m2r.setContinuousReadout(grp->isDetContinuousReadOut(MAP::getDetID())); // must be set explicitly
161 m2r.setMinMaxRUSW(ruSWMin, ruSWMax);
162 m2r.getWriter().setSuperPageSize(superPageSizeInB);
163 m2r.getWriter().useRDHVersion(rdhV);
164 m2r.getWriter().useRDHDataFormat(enablePadding ? 0 : 2);
165 if (!enablePadding) { // CRU page alignment padding is used only if no GBT word padding is used
168 }
169 m2r.getWriter().setDontFillEmptyHBF(noEmptyHBF);
170
172 setupLinks(m2r, outDir, MAP::getName(), fileFor);
173 //-------------------------------------------------------------------------------<<<<
174 long nEntProc = 0;
175 for (int i = 0; i < digTree.GetEntries(); i++) {
176 digTree.GetEntry(i);
177 for (const auto& rofRec : rofRecVec) {
178 int nDigROF = rofRec.getNEntries();
179 if (verbosity) {
180 LOG(info) << "Processing ROF:" << rofRec.getROFrame() << " with " << nDigROF << " entries";
181 rofRec.print();
182 }
183 if (!nDigROF && noEmptyROF) {
184 if (verbosity) {
185 LOG(info) << "Frame is empty";
186 }
187 continue;
188 }
189 nEntProc++;
190 auto dgs = nDigROF ? gsl::span<const o2::itsmft::Digit>(&digiVec[rofRec.getFirstEntry()], nDigROF) : gsl::span<const o2::itsmft::Digit>();
191 m2r.digits2raw(dgs, rofRec.getBCData());
192 }
193 } // loop over multiple ROFvectors (in case of chaining)
194
195 m2r.getWriter().writeConfFile(MAP::getName(), "RAWDATA", o2::utils::Str::concat_string(outDir, '/', MAP::getName(), "raw.cfg"));
196 m2r.finalize(); // finish TF and flush data
197 //
198 swTot.Stop();
199 swTot.Print();
200}
201
203 std::string flp{};
204 int cruHWID = 0;
205 int layer = 0;
206 int gbtChannel = 0;
207 int ruHWID = 0;
208 int ruInLayer = 0;
209};
210
211// FLP, CRU_HW, Lr, GBT, RU_HW, RUID_in_layer
213 {
214 {"alio2-cr1-flp187", 183, 0, 0, 28, 0},
215 {"alio2-cr1-flp187", 183, 0, 1, 42, 1},
216 {"alio2-cr1-flp187", 183, 0, 2, 122, 2},
217 {"alio2-cr1-flp187", 183, 0, 3, 94, 3},
218 {"alio2-cr1-flp187", 183, 0, 4, 49, 4},
219 {"alio2-cr1-flp187", 183, 0, 5, 52, 5},
220 {"alio2-cr1-flp198", 172, 0, 0, 187, 6},
221 {"alio2-cr1-flp198", 172, 0, 1, 90, 7},
222 {"alio2-cr1-flp198", 172, 0, 2, 102, 8},
223 {"alio2-cr1-flp198", 172, 0, 3, 134, 9},
224 {"alio2-cr1-flp198", 172, 0, 4, 127, 10},
225 {"alio2-cr1-flp198", 172, 0, 5, 259, 11},
226 {"alio2-cr1-flp188", 181, 1, 0, 54, 0},
227 {"alio2-cr1-flp188", 181, 1, 1, 59, 1},
228 {"alio2-cr1-flp188", 181, 1, 2, 61, 2},
229 {"alio2-cr1-flp188", 181, 1, 3, 62, 3},
230 {"alio2-cr1-flp188", 181, 1, 4, 167, 4},
231 {"alio2-cr1-flp188", 181, 1, 5, 66, 5},
232 {"alio2-cr1-flp188", 181, 1, 6, 64, 6},
233 {"alio2-cr1-flp188", 181, 1, 7, 120, 7},
234 {"alio2-cr1-flp203", 196, 1, 0, 199, 8},
235 {"alio2-cr1-flp203", 196, 1, 1, 201, 9},
236 {"alio2-cr1-flp203", 196, 1, 2, 212, 10},
237 {"alio2-cr1-flp203", 196, 1, 3, 217, 11},
238 {"alio2-cr1-flp203", 196, 1, 4, 230, 12},
239 {"alio2-cr1-flp203", 196, 1, 5, 242, 13},
240 {"alio2-cr1-flp203", 196, 1, 6, 244, 14},
241 {"alio2-cr1-flp203", 196, 1, 7, 250, 15},
242 {"alio2-cr1-flp189", 184, 2, 0, 63, 0},
243 {"alio2-cr1-flp189", 184, 2, 1, 58, 1},
244 {"alio2-cr1-flp189", 184, 2, 2, 44, 2},
245 {"alio2-cr1-flp189", 184, 2, 3, 46, 3},
246 {"alio2-cr1-flp189", 184, 2, 4, 50, 4},
247 {"alio2-cr1-flp189", 191, 2, 0, 51, 5},
248 {"alio2-cr1-flp189", 191, 2, 1, 219, 6},
249 {"alio2-cr1-flp189", 191, 2, 2, 21, 7},
250 {"alio2-cr1-flp189", 191, 2, 3, 29, 8},
251 {"alio2-cr1-flp189", 191, 2, 4, 35, 9},
252 {"alio2-cr1-flp190", 179, 2, 0, 99, 10},
253 {"alio2-cr1-flp190", 179, 2, 1, 93, 11},
254 {"alio2-cr1-flp190", 179, 2, 2, 97, 12},
255 {"alio2-cr1-flp190", 179, 2, 3, 45, 13},
256 {"alio2-cr1-flp190", 179, 2, 4, 92, 14},
257 {"alio2-cr1-flp190", 192, 2, 0, 96, 15},
258 {"alio2-cr1-flp190", 192, 2, 1, 125, 16},
259 {"alio2-cr1-flp190", 192, 2, 2, 169, 17},
260 {"alio2-cr1-flp190", 192, 2, 3, 168, 18},
261 {"alio2-cr1-flp190", 192, 2, 4, 188, 19},
262 {"alio2-cr1-flp191", 175, 3, 0, 106, 0},
263 {"alio2-cr1-flp191", 175, 3, 1, 304, 1},
264 {"alio2-cr1-flp191", 175, 3, 2, 147, 2},
265 {"alio2-cr1-flp191", 175, 3, 3, 222, 3},
266 {"alio2-cr1-flp191", 175, 3, 4, 293, 4},
267 {"alio2-cr1-flp191", 175, 3, 5, 200, 5},
268 {"alio2-cr1-flp191", 175, 3, 6, 233, 6},
269 {"alio2-cr1-flp191", 175, 3, 7, 43, 7},
270 {"alio2-cr1-flp191", 175, 3, 8, 173, 8},
271 {"alio2-cr1-flp191", 175, 3, 9, 172, 9},
272 {"alio2-cr1-flp191", 175, 3, 10, 177, 10},
273 {"alio2-cr1-flp191", 175, 3, 11, 175, 11},
274 {"alio2-cr1-flp191", 182, 3, 0, 2, 12},
275 {"alio2-cr1-flp191", 182, 3, 1, 215, 13},
276 {"alio2-cr1-flp191", 182, 3, 2, 108, 14},
277 {"alio2-cr1-flp191", 182, 3, 3, 265, 15},
278 {"alio2-cr1-flp191", 182, 3, 4, 241, 16},
279 {"alio2-cr1-flp191", 182, 3, 5, 53, 17},
280 {"alio2-cr1-flp191", 182, 3, 6, 183, 18},
281 {"alio2-cr1-flp191", 182, 3, 7, 7, 19},
282 {"alio2-cr1-flp191", 182, 3, 8, 191, 20},
283 {"alio2-cr1-flp191", 182, 3, 9, 190, 21},
284 {"alio2-cr1-flp191", 182, 3, 10, 284, 22},
285 {"alio2-cr1-flp191", 182, 3, 11, 299, 23},
286 {"alio2-cr1-flp192", 187, 4, 0, 273, 0},
287 {"alio2-cr1-flp192", 187, 4, 1, 171, 1},
288 {"alio2-cr1-flp192", 187, 4, 2, 252, 2},
289 {"alio2-cr1-flp192", 187, 4, 3, 251, 3},
290 {"alio2-cr1-flp192", 187, 4, 4, 202, 4},
291 {"alio2-cr1-flp192", 187, 4, 5, 282, 5},
292 {"alio2-cr1-flp192", 187, 4, 6, 181, 6},
293 {"alio2-cr1-flp192", 187, 4, 7, 300, 7},
294 {"alio2-cr1-flp192", 176, 4, 0, 302, 8},
295 {"alio2-cr1-flp192", 176, 4, 1, 309, 9},
296 {"alio2-cr1-flp192", 176, 4, 2, 270, 10},
297 {"alio2-cr1-flp192", 176, 4, 3, 255, 11},
298 {"alio2-cr1-flp192", 176, 4, 4, 203, 12},
299 {"alio2-cr1-flp192", 176, 4, 5, 208, 13},
300 {"alio2-cr1-flp192", 176, 4, 6, 277, 14},
301 {"alio2-cr1-flp193", 177, 4, 0, 105, 23},
302 {"alio2-cr1-flp193", 177, 4, 1, 258, 24},
303 {"alio2-cr1-flp193", 177, 4, 2, 121, 25},
304 {"alio2-cr1-flp193", 177, 4, 3, 119, 26},
305 {"alio2-cr1-flp193", 177, 4, 4, 116, 27},
306 {"alio2-cr1-flp193", 177, 4, 5, 135, 28},
307 {"alio2-cr1-flp193", 177, 4, 6, 126, 29},
308 {"alio2-cr1-flp193", 178, 4, 0, 137, 15},
309 {"alio2-cr1-flp193", 178, 4, 1, 229, 16},
310 {"alio2-cr1-flp193", 178, 4, 2, 272, 17},
311 {"alio2-cr1-flp193", 178, 4, 3, 148, 18},
312 {"alio2-cr1-flp193", 178, 4, 4, 297, 19},
313 {"alio2-cr1-flp193", 178, 4, 5, 253, 20},
314 {"alio2-cr1-flp193", 178, 4, 6, 84, 21},
315 {"alio2-cr1-flp193", 178, 4, 7, 279, 22},
316 {"alio2-cr1-flp194", 194, 5, 0, 132, 0},
317 {"alio2-cr1-flp194", 194, 5, 1, 225, 1},
318 {"alio2-cr1-flp194", 194, 5, 2, 240, 2},
319 {"alio2-cr1-flp194", 194, 5, 3, 266, 3},
320 {"alio2-cr1-flp194", 194, 5, 4, 128, 4},
321 {"alio2-cr1-flp194", 194, 5, 5, 123, 5},
322 {"alio2-cr1-flp194", 194, 5, 6, 170, 6},
323 {"alio2-cr1-flp194", 194, 5, 7, 234, 7},
324 {"alio2-cr1-flp194", 194, 5, 8, 320, 8},
325 {"alio2-cr1-flp194", 194, 5, 9, 186, 9},
326 {"alio2-cr1-flp194", 174, 5, 0, 245, 10},
327 {"alio2-cr1-flp194", 174, 5, 1, 192, 11},
328 {"alio2-cr1-flp194", 174, 5, 2, 206, 12},
329 {"alio2-cr1-flp194", 174, 5, 3, 189, 13},
330 {"alio2-cr1-flp194", 174, 5, 4, 213, 14},
331 {"alio2-cr1-flp194", 174, 5, 5, 6, 15},
332 {"alio2-cr1-flp194", 174, 5, 6, 228, 16},
333 {"alio2-cr1-flp194", 174, 5, 7, 136, 17},
334 {"alio2-cr1-flp194", 174, 5, 8, 197, 18},
335 {"alio2-cr1-flp194", 174, 5, 9, 82, 19},
336 {"alio2-cr1-flp194", 174, 5, 10, 100, 20},
337 {"alio2-cr1-flp195", 180, 5, 0, 246, 31},
338 {"alio2-cr1-flp195", 180, 5, 1, 271, 32},
339 {"alio2-cr1-flp195", 180, 5, 2, 281, 33},
340 {"alio2-cr1-flp195", 180, 5, 3, 285, 34},
341 {"alio2-cr1-flp195", 180, 5, 4, 287, 35},
342 {"alio2-cr1-flp195", 180, 5, 5, 289, 36},
343 {"alio2-cr1-flp195", 180, 5, 6, 113, 37},
344 {"alio2-cr1-flp195", 180, 5, 7, 193, 38},
345 {"alio2-cr1-flp195", 180, 5, 8, 194, 39},
346 {"alio2-cr1-flp195", 180, 5, 9, 195, 40},
347 {"alio2-cr1-flp195", 180, 5, 10, 198, 41},
348 {"alio2-cr1-flp195", 193, 5, 0, 214, 21},
349 {"alio2-cr1-flp195", 193, 5, 1, 207, 22},
350 {"alio2-cr1-flp195", 193, 5, 2, 248, 23},
351 {"alio2-cr1-flp195", 193, 5, 3, 262, 24},
352 {"alio2-cr1-flp195", 193, 5, 4, 263, 25},
353 {"alio2-cr1-flp195", 193, 5, 5, 65, 26},
354 {"alio2-cr1-flp195", 193, 5, 6, 56, 27},
355 {"alio2-cr1-flp195", 193, 5, 7, 1, 28},
356 {"alio2-cr1-flp195", 193, 5, 8, 210, 29},
357 {"alio2-cr1-flp195", 193, 5, 9, 247, 30},
358 {"alio2-cr1-flp196", 185, 6, 0, 36, 0},
359 {"alio2-cr1-flp196", 185, 6, 1, 60, 1},
360 {"alio2-cr1-flp196", 185, 6, 2, 41, 2},
361 {"alio2-cr1-flp196", 185, 6, 3, 40, 3},
362 {"alio2-cr1-flp196", 185, 6, 4, 80, 4},
363 {"alio2-cr1-flp196", 185, 6, 5, 57, 5},
364 {"alio2-cr1-flp196", 185, 6, 6, 185, 6},
365 {"alio2-cr1-flp196", 185, 6, 7, 79, 7},
366 {"alio2-cr1-flp196", 185, 6, 8, 91, 8},
367 {"alio2-cr1-flp196", 185, 6, 9, 78, 9},
368 {"alio2-cr1-flp196", 185, 6, 10, 5, 10},
369 {"alio2-cr1-flp196", 185, 6, 11, 306, 11},
370 {"alio2-cr1-flp196", 189, 6, 0, 39, 12},
371 {"alio2-cr1-flp196", 189, 6, 1, 32, 13},
372 {"alio2-cr1-flp196", 189, 6, 2, 23, 14},
373 {"alio2-cr1-flp196", 189, 6, 3, 24, 15},
374 {"alio2-cr1-flp196", 189, 6, 4, 22, 16},
375 {"alio2-cr1-flp196", 189, 6, 5, 88, 17},
376 {"alio2-cr1-flp196", 189, 6, 6, 25, 18},
377 {"alio2-cr1-flp196", 189, 6, 7, 89, 19},
378 {"alio2-cr1-flp196", 189, 6, 8, 87, 20},
379 {"alio2-cr1-flp196", 189, 6, 9, 47, 21},
380 {"alio2-cr1-flp196", 189, 6, 10, 17, 22},
381 {"alio2-cr1-flp196", 189, 6, 11, 33, 23},
382 {"alio2-cr1-flp197", 186, 6, 0, 180, 36},
383 {"alio2-cr1-flp197", 186, 6, 1, 274, 37},
384 {"alio2-cr1-flp197", 186, 6, 2, 275, 38},
385 {"alio2-cr1-flp197", 186, 6, 3, 278, 39},
386 {"alio2-cr1-flp197", 186, 6, 4, 276, 40},
387 {"alio2-cr1-flp197", 186, 6, 5, 160, 41},
388 {"alio2-cr1-flp197", 186, 6, 6, 280, 42},
389 {"alio2-cr1-flp197", 186, 6, 7, 3, 43},
390 {"alio2-cr1-flp197", 186, 6, 8, 209, 44},
391 {"alio2-cr1-flp197", 186, 6, 9, 227, 45},
392 {"alio2-cr1-flp197", 186, 6, 10, 256, 46},
393 {"alio2-cr1-flp197", 186, 6, 11, 15, 47},
394 {"alio2-cr1-flp197", 195, 6, 0, 115, 24},
395 {"alio2-cr1-flp197", 195, 6, 1, 283, 25},
396 {"alio2-cr1-flp197", 195, 6, 2, 104, 26},
397 {"alio2-cr1-flp197", 195, 6, 3, 290, 27},
398 {"alio2-cr1-flp197", 195, 6, 4, 254, 28},
399 {"alio2-cr1-flp197", 195, 6, 5, 110, 29},
400 {"alio2-cr1-flp197", 195, 6, 6, 103, 30},
401 {"alio2-cr1-flp197", 195, 6, 7, 286, 31},
402 {"alio2-cr1-flp197", 195, 6, 8, 257, 32},
403 {"alio2-cr1-flp197", 195, 6, 9, 174, 33},
404 {"alio2-cr1-flp197", 195, 6, 10, 13, 34},
405 {"alio2-cr1-flp197", 195, 6, 11, 288, 35}};
406
407void setupLinks(o2::itsmft::MC2RawEncoder<MAP>& m2r, std::string_view outDir, std::string_view outPrefix, std::string_view fileFor)
408{
409 //------------------------------------------------------------------------------->>>>
410 // just as an example, we require here that the staves are read via 3 links, with partitioning according to lnkXB below
411 // while OB staves use only 1 link.
412 // Note, that if the RU container is not defined, it will be created automatically
413 // during encoding.
414 // If the links of the container are not defined, a single link readout will be assigned
415
416 const auto& mp = m2r.getMapping();
417 constexpr int MaxLinksPerRU = 3;
418 auto getNLinks = [](int lr) { return lr < 3 ? MaxLinksPerRU : MaxLinksPerRU - 1; };
419 int lnkAssign[3][MaxLinksPerRU] = {
420 // requested link cabling for IB, MB and OB
421 {3, 3, 3}, // IB
422 {14, 14, 0}, // MB
423 {14, 14, 0} // OB
424 };
425 std::unordered_map<int, int> cruMaxRU, cruNRU;
426 std::array<int, o2::itsmft::ChipMappingITS::getNRUs()> ruSWEntry{};
427 ruSWEntry.fill(-1);
428 int ntab = sizeof(itsHWMap) / sizeof(ITSRUMapping);
429 for (int ir = 0; ir < ntab; ir++) {
430 const auto& ru = itsHWMap[ir];
431 cruMaxRU[ru.cruHWID]++;
432 ruSWEntry[mp.getRUIDSW(ru.layer, ru.ruInLayer)] = ir;
433 }
434 std::string outFileLink;
435 for (int ruID = 0; ruID < o2::itsmft::ChipMappingITS::getNRUs(); ruID++) {
436 const auto& ruhw = itsHWMap[ruSWEntry[ruID]];
437 int nRUsOnCRU = cruMaxRU[ruhw.cruHWID], ruOnCRU = cruNRU[ruhw.cruHWID]++;
438 if (ruID < m2r.getRUSWMin() || ruID > m2r.getRUSWMax()) { // ignored RUs ?
439 continue;
440 }
441 m2r.getCreateRUDecode(ruID); // create RU container
442 int* lnkAs = lnkAssign[mp.getRUType(ruID)];
443 int accL = 0;
444 for (int il = 0; il < getNLinks(ruhw.layer); il++) { // create links
445 auto& ru = *m2r.getRUDecode(ruID);
446 ru.links[il] = m2r.addGBTLink();
447 uint32_t lanes = mp.getCablesOnRUType(mp.getRUType(ruID)); // lanes pattern of this RU
448 auto link = m2r.getGBTLink(ru.links[il]);
449 link->lanes = lanes & (((0x1 << lnkAs[il]) - 1) << (accL));
450
451 link->idInCRU = ruOnCRU + il * nRUsOnCRU; // linkID
452 link->cruID = ruhw.cruHWID;
453 link->feeID = mp.RUSW2FEEId(ruID, il);
454 link->endPointID = link->idInCRU > 11 ? 1 : 0;
456 accL += lnkAs[il];
457 outFileLink = o2::utils::Str::concat_string(outDir, "/", outPrefix);
458 if (fileFor != "all") { // single file for all links
459 outFileLink += fmt::format("_{}", ruhw.flp);
460 if (fileFor != "flp") {
461 outFileLink += fmt::format("_cru{}_{}", ruhw.cruHWID, link->endPointID);
462 if (fileFor != "cruendpoint") {
463 outFileLink += fmt::format("_lnk{}_feeid{}", link->idInCRU, link->feeID);
464 if (fileFor != "link") {
465 throw std::runtime_error("invalid option provided for file grouping");
466 }
467 }
468 }
469 }
470 outFileLink += ".raw";
471 m2r.getWriter().registerLink(link->feeID, link->cruID, link->idInCRU, link->endPointID, outFileLink);
472 if (m2r.getVerbosity()) {
473 LOG(info) << "RU" << ruID << '(' << ruhw.ruInLayer << " on lr " << ruhw.layer << ") " << link->describe()
474 << " -> " << outFileLink;
475 }
476 }
477 }
478}
#define verbosity
void digi2raw(const std::string &inpName, const std::string &outDir, int verbosity, const std::string &fileForLink, uint32_t rdhV=4, bool noEmptyHBF=false, bool zsIR=true, bool zsClass=true, bool enablePadding=true, int cruPageAlignment=16, int superPageSizeInB=1024 *1024)
Definition digi2raw.cxx:99
Definition of the ITSMFT digit.
unsigned int uint32_t
int32_t i
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char e
Header of the General Run Parameters object.
constexpr int DefRDHVersion
Definition digi2raw.cxx:41
void setupLinks(o2::itsmft::MC2RawEncoder< MAP > &m2r, std::string_view outDir, std::string_view outPrefix, std::string_view fileFor)
Definition digi2raw.cxx:407
const ITSRUMapping itsHWMap[o2::itsmft::ChipMappingITS::getNRUs()]
Definition digi2raw.cxx:212
Definition of the ITSMFT ROFrame (trigger) record.
Definition of the ITS/MFT Alpide pixel MC->raw converter.
Definition of the Names Generator class.
static std::string getGRPFileName(const std::string_view prefix=STANDARDSIMPREFIX)
Definition NameConf.cxx:59
static constexpr std::string_view DIGITIZATIONCONFIGFILE
Definition NameConf.h:89
static constexpr std::string_view MCTTREENAME
Definition NameConf.h:86
static void updateFromFile(std::string const &, std::string const &paramsList="", bool unchangedOnly=false)
static void updateFromString(std::string const &)
static constexpr o2::detectors::DetID::ID getDetID()
static constexpr int getNRUs()
total number of chips
static constexpr std::string_view getName()
GBTLink * getGBTLink(int i)
void setContinuousReadout(bool v)
RUDecodeData & getCreateRUDecode(int ruSW)
o2::raw::RawFileWriter & getWriter()
void setDefaultSinkName(const std::string &nm)
void setMinMaxRUSW(uint8_t ruMin, uint8_t ruMax)
void digits2raw(gsl::span< const Digit > digits, const o2::InteractionRecord &bcData)
RUDecodeData * getRUDecode(int ruSW)
static GRPObject * loadFrom(const std::string &grpFileName="")
void setAlignmentSize(unsigned char v)
void useRDHDataFormat(unsigned char v)
unsigned char getUsedRDHDataFormat() const
void setSuperPageSize(int nbytes)
void setAlignmentPaddingFiller(unsigned char v)
void setDontFillEmptyHBF(bool v)
LinkData & registerLink(uint16_t fee, uint16_t cru, uint8_t link, uint8_t endpoint, std::string_view outFileName)
void writeConfFile(std::string_view origin="FLP", std::string_view description="RAWDATA", std::string_view cfgname="raw.cfg", bool fullPath=true) const
GLenum GLuint GLint GLint layer
Definition glcorearb.h:1310
constexpr int GBTPaddedWordLength
Definition GBTWord.h:56
constexpr int GBTWordLength
Definition GBTWord.h:55
std::string flp
Definition digi2raw.cxx:203
std::array< int, MaxLinksPerRU > links
void print() const
Definition HBFUtils.h:134
static std::string concat_string(Ts const &... ts)
#define main
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
o2::InteractionRecord ir(0, 0)