21 verbosity(conf.getUntrackedParameter<unsigned
int>(
"verbosity", 0))
29 unsigned int size_in_words = data.
size() / 8;
30 if (size_in_words < 2)
33 LogWarning(
"Totem") <<
"Error in RawDataUnpacker::Run > " <<
34 "Data in FED " << fedId <<
" too short (size = " << size_in_words <<
" words).";
48 unsigned long long head = buf[0];
49 unsigned long long foot = buf[frameSize-1];
54 unsigned int BOE = (head >> 60) & 0xF;
55 unsigned int H0 = (head >> 0) & 0xF;
59 unsigned int OptoRxId = (head >> 8) & 0xFFF;
60 unsigned int FOV = (head >> 4) & 0xF;
62 unsigned int EOE = (foot >> 60) & 0xF;
63 unsigned int F0 = (foot >> 0) & 0xF;
64 unsigned int FSize = (foot >> 32) & 0x3FF;
67 if (BOE != 5 || H0 != 0 || EOE != 10 || F0 != 0 || FSize != frameSize)
70 LogWarning(
"Totem") <<
"Error in RawDataUnpacker::ProcessOptoRxFrame > " <<
"Wrong structure of OptoRx header/footer: " 71 <<
"BOE=" << BOE <<
", H0=" << H0 <<
", EOE=" << EOE <<
", F0=" << F0
72 <<
", size (OptoRx)=" << FSize <<
", size (DATE)=" << frameSize
73 <<
". OptoRxID=" << OptoRxId <<
". Skipping frame." << endl;
78 printf(
">> RawDataUnpacker::ProcessOptoRxFrame > OptoRxId = %u, BX = %lu, LV1 = %lu, frameSize = %u, subFrames = %u)\n",
79 OptoRxId,
BX, LV1, frameSize, subFrames);
90 LogWarning(
"Totem") <<
"Error in RawDataUnpacker::ProcessOptoRxFrame > " <<
"Unknown FOV = " << FOV << endl;
100 unsigned int OptoRxId = (buf[0] >> 8) & 0xFFF;
103 unsigned int subFrames = (frameSize - 2) / 194;
106 unsigned int errorCounter = 0;
107 for (
unsigned int r = 0;
r < subFrames; ++
r)
109 for (
unsigned int c = 0;
c < 4; ++
c)
111 unsigned int head = (buf[1 + 194 *
r] >> (16 *
c)) & 0xFFFF;
112 unsigned int foot = (buf[194 + 194 *
r] >> (16 *
c)) & 0xFFFF;
115 printf(
">>>> r = %i, c = %i: S = %i, BOF = %i, EOF = %i, ID = %i, ID' = %i\n",
r,
c, head & 0x1, head >> 12, foot >> 12, (head >> 8) & 0xF, (foot >> 8) & 0xF);
119 if ((head & 0x1) == 0)
123 printf(
"\tHeader active (%04x -> %x).\n", head, head & 0x1);
127 if (head >> 12 != 0x4 || foot >> 12 != 0xB || ((head >> 8) & 0xF) != ((foot >> 8) & 0xF))
130 if (head >> 12 != 0x4)
131 sprintf(ss,
"\n\tHeader is not 0x4 as expected (%x).", head);
132 if (foot >> 12 != 0xB)
133 sprintf(ss,
"\n\tFooter is not 0xB as expected (%x).", foot);
134 if (((head >> 8) & 0xF) != ((foot >> 8) & 0xF))
135 sprintf(ss,
"\n\tIncompatible GOH IDs in header (%x) and footer (%x).", ((head >> 8) & 0xF),
136 ((foot >> 8) & 0xF));
139 LogWarning(
"Totem") <<
"Error in RawDataUnpacker::ProcessOptoRxFrame > " <<
"Wrong payload structure (in GOH block row " <<
r <<
140 " and column " <<
c <<
") in OptoRx frame ID " << OptoRxId <<
". GOH block omitted." << ss << endl;
147 unsigned int goh = (head >> 8) & 0xF;
148 vector<VFATFrame::word*> dataPtrs;
149 for (
unsigned int fi = 0; fi < 16; fi++)
156 printf(
">>>> transposing GOH block at prefix: %i, dataPtrs = %p\n", OptoRxId*192 + goh*16, dataPtrs);
160 for (
int i = 0;
i < 192;
i++)
162 int iword = 11 -
i / 16;
163 int ibit = 15 -
i % 16;
164 unsigned int w = (buf[
i + 2 + 194 *
r] >> (16 *
c)) & 0xFFFF;
170 dataPtrs[
idx][iword] |= (1 << ibit);
184 unsigned long long head = buf[0];
185 unsigned int OptoRxId = (head >> 8) & 0xFFF;
188 const uint16_t *
payload = (
const uint16_t *) (buf + 1);
191 const uint32_t *ocPtr = (
const uint32_t *) payload;
196 unsigned int nWords = (frameSize-2) * 4 - 2;
213 unsigned int wordsProcessed = 1;
216 if (buf[0] == 0xFFFF)
217 return wordsProcessed;
220 unsigned int hFlag = (buf[0] >> 8) & 0xFF;
224 LogWarning(
"Totem") <<
"Error in RawDataUnpacker::ProcessVFATDataParallel > " 225 <<
"Unknown header flag " << hFlag <<
". Skipping this word." << endl;
226 return wordsProcessed;
231 unsigned int gohIdx = (buf[0] >> 4) & 0xF;
232 unsigned int fiberIdx = (buf[0] >> 0) & 0xF;
240 uint8_t presenceFlags = 0;
242 if (((buf[wordsProcessed] >> 12) & 0xF) == 0xA)
244 presenceFlags |= 0x1;
245 fd[11] = buf[wordsProcessed];
249 if (((buf[wordsProcessed] >> 12) & 0xF) == 0xC)
251 presenceFlags |= 0x2;
252 fd[10] = buf[wordsProcessed];
256 if (((buf[wordsProcessed] >> 12) & 0xF) == 0xE)
258 presenceFlags |= 0x4;
259 fd[9] = buf[wordsProcessed];
264 unsigned int dataOffset = wordsProcessed;
269 unsigned int nCl = 0;
270 while ( (buf[wordsProcessed + nCl] >> 12) != 0xF )
273 wordsProcessed += nCl;
280 unsigned int tSig = buf[wordsProcessed] >> 12;
281 unsigned int tErrFlags = (buf[wordsProcessed] >> 8) & 0xF;
282 unsigned int tSize = buf[wordsProcessed] & 0xFF;
287 bool skipFrame =
false;
293 ess <<
" Wrong trailer signature (" << tSig <<
")." << endl;
300 ess <<
" Error flags not zero (" << tErrFlags <<
")." << endl;
306 if (tSize != wordsProcessed)
309 ess <<
" Trailer size (" << tSize <<
") does not match with words processed (" << wordsProcessed <<
")." << endl;
316 LogWarning(
"Totem") <<
"Error in RawDataUnpacker::ProcessVFATDataParallel > Frame at " << fp
317 <<
" has the following problems and will be skipped.\n" << endl << ess.rdbuf();
319 return wordsProcessed;
325 for (
unsigned int nCl = 0; (buf[dataOffset + nCl] >> 12) != 0xF; ++nCl)
327 const uint16_t &
w = buf[dataOffset + nCl];
328 unsigned int upperBlock = w >> 8;
329 unsigned int clSize = upperBlock & 0x7F;
330 unsigned int clPos = (w >> 0) & 0xFF;
333 if (upperBlock == 0xD0)
335 presenceFlags |= 0x10;
346 signed int chMax = clPos;
347 signed int chMin = clPos - clSize + 1;
348 if (chMax < 0 || chMax > 127 || chMin < 0 || chMin > 127 || chMin > chMax)
351 LogWarning(
"Totem") <<
"Error in RawDataUnpacker::ProcessVFATDataParallel > " 352 <<
"Invalid cluster (pos=" << clPos
353 <<
", size=" << clSize <<
", min=" << chMin <<
", max=" << chMax <<
") at " << fp
354 <<
". Skipping this cluster." << endl;
358 for (
signed int ch = chMin; ch <= chMax; ch++)
360 unsigned int wi = ch / 16;
361 unsigned int bi = ch % 16;
362 fd[wi + 1] |= (1 << bi);
370 for (
unsigned int i = 0;
i < 8;
i++)
371 fd[8 -
i] = buf[dataOffset +
i];
374 presenceFlags |= 0x8;
375 fd[0] = buf[dataOffset + 8];
382 return wordsProcessed;
int ProcessOptoRxFrame(const word *buf, unsigned int frameSize, TotemFEDInfo &fedInfo, SimpleVFATFrameCollection *fc) const
Process one Opto-Rx (or LoneG) frame.
OptoRx headers and footers.
VFATFrame::word * getData()
int ProcessOptoRxFrameSerial(const word *buffer, unsigned int frameSize, SimpleVFATFrameCollection *fc) const
Process one Opto-Rx frame in serial (old) format.
size_t size() const
Lenght of the data buffer in bytes.
payload
payload postfix for testing
void setOrbitCounter(uint32_t _oc)
void setFooter(uint64_t _f)
int ProcessOptoRxFrameParallel(const word *buffer, unsigned int frameSize, TotemFEDInfo &fedInfo, SimpleVFATFrameCollection *fc) const
Process one Opto-Rx frame in parallel (new) format.
VFATFrame * InsertEmptyFrame(TotemFramePosition index)
inserts an empty (default) frame to the given position and returns pointer to the frame ...
void setPresenceFlags(uint8_t v)
Sets presence flags.
void setDAQErrorFlags(uint8_t v)
Sets DAQ error flags.
char data[epos_bytes_allocation]
int ProcessVFATDataParallel(const uint16_t *buf, unsigned int OptoRxId, SimpleVFATFrameCollection *fc) const
Process data from one VFAT in parallel (new) format.
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
void setHeader(uint64_t _h)
int Run(int fedId, const FEDRawData &data, std::vector< TotemFEDInfo > &fedInfoColl, SimpleVFATFrameCollection &coll) const
Unpack data from FED with fedId into `coll' collection.
void Insert(const TotemFramePosition &index, const VFATFrame &frame)
void setNumberOfClusters(uint8_t v)