Project
Loading...
Searching...
No Matches
RawData.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
12#include <iomanip>
13#include <iostream>
14#include <bitset>
15#include "fairlogger/Logger.h"
20
21using namespace o2::trd::constants;
22
23namespace o2
24{
25
26namespace trd
27{
28
30{
31 for (int linkIn = 0; linkIn < MAXHALFCHAMBER; ++linkIn) {
32 int hcid = getHCID(linkIn);
33 if (linkIn != getLink(hcid)) {
34 return false;
35 }
36 }
37 return true;
38}
39
40// linkA and linkB refer to the global ORI index and not to the half-chamber ID
41void LinkToHCIDMapping::swapLinks(int linkA, int linkB)
42{
43 int hcidA = HelperMethods::getHCIDFromLinkID(linkA);
44 int hcidB = HelperMethods::getHCIDFromLinkID(linkB);
45 linkIDToHCID.erase(linkA);
46 linkIDToHCID.insert({linkA, hcidB});
47 linkIDToHCID.erase(linkB);
48 linkIDToHCID.insert({linkB, hcidA});
49 hcIDToLinkID.erase(hcidA);
50 hcIDToLinkID.insert({hcidA, linkB});
51 hcIDToLinkID.erase(hcidB);
52 hcIDToLinkID.insert({hcidB, linkA});
53}
54
55//
56// Printing methods to dump and display the various structures above in pretty format or hexdump
57// printNameOfStruct(const NameOfStruct& nameofstruct);
58// dumpNameOfStruct(const NameOfStruct& nameofstruct);
59// std::ostrea& operator<<(std::ostream& stream, const NameOfStruct& nameofstruct);
60//
61
62std::ostream& operator<<(std::ostream& stream, const TrackletHCHeader halfchamberheader)
63{
64 stream << "TrackletHCHeader : Raw:0x" << std::hex << halfchamberheader.word << " "
65 << (int)halfchamberheader.format << " ;; " << (int)halfchamberheader.MCLK << " :: "
66 << halfchamberheader.one << " :: (" << (int)halfchamberheader.supermodule << ","
67 << (int)halfchamberheader.stack << "," << (int)halfchamberheader.layer << ") on side :"
68 << (int)halfchamberheader.side << std::endl;
69 return stream;
70}
71
72std::ostream& operator<<(std::ostream& stream, const TrackletMCMData& tracklet)
73{
74 // make a pretty output of the tracklet.
75 stream << "TrackletMCMData: Raw:0x" << std::hex << tracklet.word << " pos=" << tracklet.pos
76 << "::slope=" << tracklet.slope << "::pid=" << tracklet.pid << "::checkbit="
77 << tracklet.checkbit << std::endl;
78 return stream;
79}
80
81std::ostream& operator<<(std::ostream& stream, const TrackletMCMHeader& mcmhead)
82{
83 // make a pretty output of the mcm header.
84 stream << "TrackletMCMRawHeader: Raw:0x" << std::hex << mcmhead.word << " " << mcmhead.onea << "::"
85 << mcmhead.pid2 << ":" << mcmhead.pid1 << ":" << mcmhead.pid0 << "::"
86 << mcmhead.oneb << std::endl;
87 return stream;
88}
89
90//functions updated/checked/new for new raw reader. above methods left for cross checking what changes have occured.
91// construct a tracklet half chamber header according to the tdp and assembler found in
92
93//HalfCRUHeader first :
94//
95//this only sets the first 64 bit word of the half cru header.
96uint32_t setHalfCRUHeaderFirstWord(HalfCRUHeader& cruhead, int crurdhversion, int bunchcrossing, int stopbits, int endpoint, int eventtype, int feeid, int cruid)
97{
98 cruhead.word0 = 0;
100 cruhead.StopBit = stopbits;
101 cruhead.EndPoint = endpoint;
102 cruhead.EventType = eventtype;
103 cruhead.HeaderVersion = crurdhversion;
104 //This is undefiend behaviour if the rest of cruhead has not been set to zero ...
105 //TODO check where this is called from
106 return 0;
107}
108
109void setHalfCRUHeaderLinkSizeAndFlags(HalfCRUHeader& cruhead, int link, int size, int errors)
110{
111 cruhead.datasizes[link].size = size;
112 cruhead.errorflags[link].errorflag = errors;
113}
114
115uint8_t getHalfCRULinkErrorFlag(const HalfCRUHeader& cruhead, const uint32_t link)
116{
117 // link is the link you are requesting information on, 0-14
118 uint8_t errorflag = 0;
119 //dealing with word0-2
120 errorflag = cruhead.errorflags[link].errorflag;
121 return errorflag;
122}
123
124uint16_t getHalfCRULinkDataSize(const HalfCRUHeader& cruhead, const uint32_t link)
125{
126 // link is the link you are requesting information on, 0-14
127 //return number 32 byte blocks for the link 3x64bit ints.
128 return cruhead.datasizes[link].size;
129}
130
131void getHalfCRULinkErrorFlags(const HalfCRUHeader& cruheader, std::array<uint8_t, 15>& linkerrorflags)
132{
133 // retrieve all the link error flags for this half cru
134 for (uint32_t link = 0; link < 15; link++) {
135 linkerrorflags[link] = getHalfCRULinkErrorFlag(cruheader, link);
136 }
137}
138
139void getHalfCRULinkDataSizes(const HalfCRUHeader& cruheader, std::array<uint16_t, 15>& linksizes)
140{
141 // retrieve all the link error flags for this half cru
142 for (uint32_t link = 0; link < 15; link++) {
143 linksizes[link] = getHalfCRULinkDataSize(cruheader, link);
144 }
145}
146
147std::ostream& operator<<(std::ostream& stream, const HalfCRUHeader& halfcru)
148{ // make a pretty output of the header.
149 stream << std::hex;
150 stream << "EventType : " << halfcru.EventType << std::endl;
151 stream << "StopBit : " << halfcru.StopBit << std::endl;
152 stream << "BunchCrossing : " << halfcru.BunchCrossing << std::endl;
153 stream << "HeaderVersion : " << halfcru.HeaderVersion << std::endl;
154 stream << "link sizes : ";
155 for (int link = 0; link < 15; link++) {
156 stream << link << ":" << std::hex << std::setw(4) << getHalfCRULinkDataSize(halfcru, link) << ",";
157 }
158 stream << std::endl;
159 stream << "link errorflags : ";
160 for (int link = 0; link < 15; link++) {
161 stream << link << ":" << std::hex << std::setw(2) << getHalfCRULinkErrorFlag(halfcru, link) << ",";
162 }
163 stream << std::endl;
164 stream << "0x" << std::hex << halfcru.word0 << " 0x" << halfcru.word12[0] << " 0x" << halfcru.word12[1] << " 0x" << halfcru.word3 << " 0x" << halfcru.word47[0] << " 0x" << halfcru.word47[1] << " 0x" << halfcru.word47[2] << " 0x" << halfcru.word47[3] << std::endl;
165 return stream;
166}
167
168//Tracklet HC Header
169
170void constructTrackletHCHeader(TrackletHCHeader& header, int hcid, int chipclock, int format)
171{
172 int detector = hcid / 2;
173 int sector = HelperMethods::getSector(detector);
174 int stack = HelperMethods::getStack(detector);
175 int layer = HelperMethods::getLayer(detector);
176 int side = hcid % 2;
177 header.word = 0;
178 header.format = format;
179 header.supermodule = ~sector;
180 header.stack = ~stack;
181 header.layer = ~layer;
182 header.side = ~side;
183 header.MCLK = chipclock;
184 header.one = 1;
185}
186
188{
189 TRDFeeID feeid;
190 feeid.word = 0;
191 feeid.supermodule = supermodule;
192 feeid.side = side;
193 feeid.endpoint = endpoint;
194 feeid.unused1 = 0;
195 feeid.unused2 = 0;
196 return feeid.word;
197}
198
200{
201 //set the default values for the mask.
203 mask.word = 0;
204 mask.c = 0x1f;
205 mask.n = 0x1;
206 mask.j = 0xc;
207 mask.adcmask = 0;
208 // actual mask will beset somewhere else, the above values are *always* that.
209 return mask;
210}
211
213{
214 LOGF(info, "TrackletHCHeader: Raw:0x%08x SM : %d stack %d layer %d side : %d MCLK: 0x%0x Format: 0x%0x Always1:0x%0x",
215 halfchamber.word, (int)(~halfchamber.supermodule) & 0x1f, (int)(~halfchamber.stack) & 0x7, (int)(~halfchamber.layer) & 0x7, (int)(~halfchamber.side) & 0x1, (int)halfchamber.MCLK, (int)halfchamber.format, (int)halfchamber.one);
216}
217
219{
220 LOGF(info, "TrackletMCMData: Raw:0x%08x pos:%d slope:%d pid:0x%03x checkbit:0x%02x",
221 tracklet.word, tracklet.pos, tracklet.slope, tracklet.pid, tracklet.checkbit);
222}
224{
225 LOGF(info, "MCMRawHeader: Raw:0x%08x 1:%d padrow: 0x%02x col: 0x%01x pid2 0x%02x pid1: 0x%02x pid0: 0x%02x 1:%d",
226 mcmhead.word, mcmhead.onea, mcmhead.padrow, mcmhead.col,
227 mcmhead.pid2, mcmhead.pid1, mcmhead.pid0, mcmhead.oneb);
228}
229
231{
232 std::array<uint16_t, 15> sizes;
233 std::array<uint8_t, 15> errorflags;
235 getHalfCRULinkErrorFlags(halfcru, errorflags);
236 LOGF(info, "V:%d BC:%d SB:%d EType:%d", halfcru.HeaderVersion, halfcru.BunchCrossing,
237 halfcru.StopBit, halfcru.EventType);
238 for (int i = 0; i < 15; i++) {
239 LOGF(info, "Link %d size: %lu eflag: 0x%02x", i, sizes[i], errorflags[i]);
240 }
241 LOG(info) << "Raw: " << std::hex << halfcru.word0 << " " << halfcru.word12[0] << " " << halfcru.word12[1] << " " << halfcru.word3 << " " << halfcru.word47[0] << " " << halfcru.word47[1] << " " << halfcru.word47[2] << " " << halfcru.word47[3];
242}
243
245{
246 std::memset(&halfcru, 0, sizeof(o2::trd::HalfCRUHeader));
247}
248
250{
251 // check the sizes for less than max value
252 // check the errors for either < 0x3, for now (may 2022) there is only no error, 1, or 2.
253 //
254 for (int link = 0; link < 15; ++link) {
255 if (header.datasizes[link].size > MAXDATAPERLINK256) {
256 return false;
257 }
258 if (header.errorflags[link].errorflag > MAXCRUERRORVALUE) {
259 return false;
260 }
261 }
262 if (header.EndPoint > 1) {
263 // end point can only be zero or 1, for each of the 2 pci end points in the cru
264 return false;
265 }
266 return true;
267}
268
270{
271 if (header.one != 1) {
272 return false;
273 }
274 if (((~header.supermodule) & 0x1f) >= NSECTOR) {
275 return false;
276 }
277 if (((~header.stack) & 0x7) >= NSTACK) {
278 return false;
279 }
280 if (((~header.layer) & 0x7) >= NLAYER) {
281 return false;
282 }
283 return true;
284}
285
287{
288 // a bit limited to what we can check.
289 if (header.onea != 1) {
290 return false;
291 }
292 if (header.oneb != 1) {
293 return false;
294 }
295 return true;
296}
297
299{
300 // a bit limited to what we can check.
301 if (header.res != 0xc) {
302 return false;
303 }
304 if (header.yearflag == 0) { // we only have data after 2007 now in run3.
305 return false;
306 }
307 return true;
308}
309
311{
312 if (mask.n != 0x1) {
313 return false;
314 }
315 if (mask.j != 0xc) {
316 return false;
317 }
318 unsigned int counter = (~mask.c) & 0x1f;
319 std::bitset<NADCMCM> headerMask(mask.adcmask);
320 return (counter == headerMask.count());
321}
322
324{
325 mask.adcmask |= 1UL << channel;
326 int bitcount = (~mask.c) & 0x1f;
327 bitcount++;
328 mask.c = ~((bitcount)&0x1f);
329}
330
332{
333 LOGF(info, "DigitMCMHeader: Raw:0x%08x, res: 0x%02x mcm: 0x%x rob: 0x%x eventcount 0x%05x year(>2007?): 0x%x ",
334 digitmcmhead.word, digitmcmhead.res, digitmcmhead.mcm, digitmcmhead.rob, digitmcmhead.eventcount,
335 digitmcmhead.yearflag);
336}
337
339{
340 LOGF(info, "DigitMCMRawData: Raw:0x%08x res:0x%x x: 0x%03x y: 0x%03x z 0x%03x ",
341 digitmcmdata.word, digitmcmdata.f, digitmcmdata.x, digitmcmdata.y, digitmcmdata.z);
342}
344{
345 LOGF(info, "DigitMCMADCMask: Raw:0x%08x j(0xc):0x%01x mask: 0x%05x count: 0x%02x n(0x1) 0x%01x ",
346 digitmcmadcmask.word, digitmcmadcmask.j, digitmcmadcmask.adcmask, digitmcmadcmask.c, digitmcmadcmask.n);
347}
348
349int getDigitHCHeaderWordType(uint32_t word)
350{
351 // all digit HC headers end with the bit pattern 01
352 // the bits 5..2 are used to distinguish the different header types
353 // the bit patterns 0b11001 and 0b110101 are outside the valid range
354 // for the header type 1
355 if ((word & 0x3f) == 0b110001) {
356 return 2;
357 }
358 if ((word & 0x3f) == 0b110101) {
359 return 3;
360 }
361 if ((word & 0x3) == 0b01) {
362 return 1;
363 }
364 return -1;
365}
366// this method just exists to make the printDigitHCHeader simpler to read.
367void printDigitHCHeaders(o2::trd::DigitHCHeader& header, uint32_t headers[3], int index, int offset, bool good)
368{
369 switch (index) {
370 case -1:
371 LOGF(info, "Digit HalfChamber Header: Raw:0x%08x reserve:0x%01x side:0x%01x stack:0x%02x layer:0x%02x supermod:0x%02x numberHCW:0x%02x minor:0x%03x major:0x%03x version(>2007):0x%01x",
372 header.word, header.res, header.side, header.stack, header.layer, header.supermodule,
373 header.numberHCW, header.minor, header.major, header.version);
374 break;
375 case 0:
377 header1.word = headers[offset];
378 LOGF(info, "%s Digit HalfChamber Header1 Raw:0x%08x reserve:0x%02x pretriggercount=0x%02x pretriggerphase=0x%02x bunchxing:0x%05x number of timebins : 0x%03x", (good) ? "" : "*Corrupt*", header1.word, header1.res, header1.ptrigcount, header1.ptrigphase, header1.bunchcrossing, header1.numtimebins);
379 break;
380 case 1:
382 header2.word = headers[offset];
383 LOGF(info, "%s Digit HalfChamber Header2 Raw:0x%08x reserve:0x%08x PedestalFilter:0x%01x GainFilter:0x%01x TailFilter:0x%01x CrosstalkFilter:0x%01x Non-linFilter:0x%01x RawDataBypassFilter:0x%01x DigitFilterCommonAdditive:0x%02x ", (good) ? "" : "*Corrupt*", header2.word, header2.res, header2.dfilter, header2.rfilter, header2.nlfilter, header2.xtfilter, header2.tfilter, header2.gfilter, header2.pfilter);
384 break;
385 case 2:
387 header3.word = headers[offset];
388 LOGF(info, "%s Digit HalfChamber Header3: Raw:0x%08x reserve:0x%08x readout program revision:0x%08x assembler program version:0x%01x", (good) ? "" : "*Corrupt*", header3.word, header3.res, header3.svnrver, header3.svnver);
389 break;
390 }
391}
392
393void printDigitHCHeader(o2::trd::DigitHCHeader& header, uint32_t headers[3])
394{
395 printDigitHCHeaders(header, headers, -1, 0, true);
396 int index;
397 //for the currently 3 implemented other header words, they can come in any order, and are identified by their reserved portion
398 for (int countheaderwords = 0; countheaderwords < header.numberHCW; ++countheaderwords) {
399 switch (getDigitHCHeaderWordType(headers[countheaderwords])) {
400 case 1:
401 DigitHCHeader1 header1;
402 header1.word = headers[countheaderwords];
403 index = 0;
404 if (header1.res != 0x1) {
405 printDigitHCHeaders(header, headers, index, countheaderwords, false);
406 } else {
407 printDigitHCHeaders(header, headers, index, countheaderwords, true);
408 }
409 break;
410 case 2:
411 DigitHCHeader2 header2;
412 header2.word = headers[countheaderwords];
413 index = 1;
414 if (header2.res != 0b110001) {
415 printDigitHCHeaders(header, headers, index, countheaderwords, false);
416 } else {
417 printDigitHCHeaders(header, headers, index, countheaderwords, true);
418 }
419 break;
420 case 3:
421 DigitHCHeader3 header3;
422 header3.word = headers[countheaderwords];
423 index = 2;
424 if (header3.res != 0b110101) {
425 printDigitHCHeaders(header, headers, index, countheaderwords, false);
426 } else {
427 printDigitHCHeaders(header, headers, index, countheaderwords, true);
428 }
429 break;
430 }
431 }
432}
433
434} // namespace trd
435} // namespace o2
int32_t i
uint32_t supermodule
Definition RawData.h:3
uint32_t side
Definition RawData.h:0
uint8_t endpoint
Definition RawData.h:0
uint8_t errorflag
Definition RawData.h:0
uint32_t stack
Definition RawData.h:1
uint32_t bunchcrossing
Definition RawData.h:3
GLsizeiptr size
Definition glcorearb.h:659
GLuint GLsizei const GLuint const GLintptr const GLsizeiptr * sizes
Definition glcorearb.h:2595
GLuint index
Definition glcorearb.h:781
GLintptr offset
Definition glcorearb.h:660
GLenum GLuint GLint GLint layer
Definition glcorearb.h:1310
GLuint GLuint stream
Definition glcorearb.h:1806
GLint GLuint mask
Definition glcorearb.h:291
GLint GLint GLsizei GLint GLenum format
Definition glcorearb.h:275
GLuint counter
Definition glcorearb.h:3987
constexpr int MAXDATAPERLINK256
max number of linkwords per cru link. (256bit words)
Definition Constants.h:92
constexpr int NLAYER
the number of layers
Definition Constants.h:27
constexpr int NSECTOR
the number of sectors
Definition Constants.h:25
constexpr int NSTACK
the number of stacks per sector
Definition Constants.h:26
constexpr int MAXHALFCHAMBER
the maximum number of installed half-chambers
Definition Constants.h:31
constexpr int MAXCRUERRORVALUE
Max possible value for a CRU Halfchamber link error. As of may 2022, can only be 0x0,...
Definition Constants.h:99
DigitMCMADCMask constructBlankADCMask()
Definition RawData.cxx:199
void printHalfCRUHeader(const o2::trd::HalfCRUHeader &halfcru)
Definition RawData.cxx:230
void printDigitMCMADCMask(const o2::trd::DigitMCMADCMask &digitmcmadcmask)
Definition RawData.cxx:343
bool sanityCheckDigitMCMHeader(const o2::trd::DigitMCMHeader &header)
Definition RawData.cxx:298
int getDigitHCHeaderWordType(uint32_t word)
Definition RawData.cxx:349
uint8_t getHalfCRULinkErrorFlag(const HalfCRUHeader &cruhead, const uint32_t link)
Definition RawData.cxx:115
void printDigitHCHeaders(o2::trd::DigitHCHeader &header, uint32_t headers[3], int index, int offset, bool good)
Definition RawData.cxx:367
void printTrackletMCMHeader(const o2::trd::TrackletMCMHeader &mcmhead)
Definition RawData.cxx:223
void constructTrackletHCHeader(TrackletHCHeader &header, int hcid, int chipclock, int format)
Definition RawData.cxx:170
uint16_t constructTRDFeeID(int supermodule, int side, int endpoint)
Definition RawData.cxx:187
void getHalfCRULinkErrorFlags(const HalfCRUHeader &cruheader, std::array< uint8_t, 15 > &linkerrorflags)
Definition RawData.cxx:131
uint32_t setHalfCRUHeaderFirstWord(HalfCRUHeader &cruhead, int crurdhversion, int bunchcrossing, int stopbits, int endpoint, int eventtype, int feeid, int cruid)
Definition RawData.cxx:96
bool sanityCheckTrackletHCHeader(const o2::trd::TrackletHCHeader &header)
Definition RawData.cxx:269
void clearHalfCRUHeader(o2::trd::HalfCRUHeader &halfcru)
Definition RawData.cxx:244
void printDigitMCMData(const o2::trd::DigitMCMData &digitmcmdata)
Definition RawData.cxx:338
void incrementADCMask(DigitMCMADCMask &mask, int channel)
Definition RawData.cxx:323
void setHalfCRUHeaderLinkSizeAndFlags(HalfCRUHeader &cruhead, int link, int size, int errors)
Definition RawData.cxx:109
void printTrackletHCHeader(const o2::trd::TrackletHCHeader &tracklet)
Definition RawData.cxx:212
bool sanityCheckDigitMCMADCMask(const o2::trd::DigitMCMADCMask &mask)
Definition RawData.cxx:310
void getHalfCRULinkDataSizes(const HalfCRUHeader &cruheader, std::array< uint16_t, 15 > &linksizes)
Definition RawData.cxx:139
bool halfCRUHeaderSanityCheck(const o2::trd::HalfCRUHeader &header)
Definition RawData.cxx:249
uint16_t getHalfCRULinkDataSize(const HalfCRUHeader &cruhead, const uint32_t link)
Definition RawData.cxx:124
bool sanityCheckTrackletMCMHeader(const o2::trd::TrackletMCMHeader &header)
Definition RawData.cxx:286
void printDigitMCMHeader(const o2::trd::DigitMCMHeader &digitmcmhead)
Definition RawData.cxx:331
void printTrackletMCMData(const o2::trd::TrackletMCMData &tracklet)
Definition RawData.cxx:218
std::ostream & operator<<(std::ostream &stream, const Digit &d)
Definition Digit.cxx:78
void printDigitHCHeader(o2::trd::DigitHCHeader &header, uint32_t headers[3])
Definition RawData.cxx:393
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
Digit version of the TrackletHCHeader above, although contents are rather different.
Definition RawData.h:231
Header for half a cru, each cru has 2 output, 1 for each pciid.
Definition RawData.h:35
uint64_t BunchCrossing
Definition RawData.h:89
uint64_t word12[2]
Definition RawData.h:98
uint64_t HeaderVersion
Definition RawData.h:88
uint64_t word47[4]
Definition RawData.h:114
static int getStack(int det)
static int getHCIDFromLinkID(int link)
static int getLayer(int det)
static int getSector(int det)
std::map< int, int > linkIDToHCID
Definition RawData.h:427
int getHCID(int link) const
Definition RawData.h:423
void swapLinks(int linkA, int linkB)
Definition RawData.cxx:41
int getLink(int hcid) const
Definition RawData.h:424
std::map< int, int > hcIDToLinkID
Definition RawData.h:428
Frontend Electronics ID, is made up of supermodule, a/c side and the end point encoded as below.
Definition RawData.h:207
uint8_t supermodule
Definition RawData.h:223
uint8_t unused1
Definition RawData.h:222
uint8_t unused2
Definition RawData.h:220
uint16_t word
Definition RawData.h:217
uint8_t endpoint
Definition RawData.h:219
Header for each half chamber.
Definition RawData.h:129
Header for MCM tracklet data outuput.
Definition RawData.h:162
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"