28 unsigned int size_in_words = data.
size() / 8;
29 if (size_in_words < 2)
31 LogProblem(
"Totem") <<
"Error in RawDataUnpacker::Run > " <<
32 "Data in FED " << fedId <<
" too short (size = " << size_in_words <<
" words).";
38 return ProcessOptoRxFrame((
const word *) data.
data(), size_in_words, fedInfoColl.back(), &
coll);
46 unsigned long long head = buf[0];
47 unsigned long long foot = buf[frameSize-1];
52 unsigned int BOE = (head >> 60) & 0xF;
53 unsigned int H0 = (head >> 0) & 0xF;
57 unsigned int OptoRxId = (head >> 8) & 0xFFF;
58 unsigned int FOV = (head >> 4) & 0xF;
60 unsigned int EOE = (foot >> 60) & 0xF;
61 unsigned int F0 = (foot >> 0) & 0xF;
62 unsigned int FSize = (foot >> 32) & 0x3FF;
65 if (BOE != 5 || H0 != 0 || EOE != 10 || F0 != 0 || FSize != frameSize)
67 LogProblem(
"Totem") <<
"Error in RawDataUnpacker::ProcessOptoRxFrame > " <<
"Wrong structure of OptoRx header/footer: "
68 <<
"BOE=" << BOE <<
", H0=" << H0 <<
", EOE=" << EOE <<
", F0=" << F0
69 <<
", size (OptoRx)=" << FSize <<
", size (DATE)=" << frameSize
70 <<
". OptoRxID=" << OptoRxId <<
". Skipping frame." << endl;
75 printf(
">> RawDataUnpacker::ProcessOptoRxFrame > OptoRxId = %u, BX = %lu, LV1 = %lu, frameSize = %u, subFrames = %u)\n",
76 OptoRxId,
BX, LV1, frameSize, subFrames);
81 return ProcessOptoRxFrameSerial(buf, frameSize, fc);
84 return ProcessOptoRxFrameParallel(buf, frameSize, fedInfo, fc);
86 LogProblem(
"Totem") <<
"Error in RawDataUnpacker::ProcessOptoRxFrame > " <<
"Unknown FOV = " << FOV << endl;
96 unsigned int OptoRxId = (buf[0] >> 8) & 0xFFF;
99 unsigned int subFrames = (frameSize - 2) / 194;
102 unsigned int errorCounter = 0;
103 for (
unsigned int r = 0;
r < subFrames; ++
r)
105 for (
unsigned int c = 0;
c < 4; ++
c)
107 unsigned int head = (buf[1 + 194 *
r] >> (16 *
c)) & 0xFFFF;
108 unsigned int foot = (buf[194 + 194 *
r] >> (16 *
c)) & 0xFFFF;
111 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);
115 if ((head & 0x1) == 0)
119 printf(
"\tHeader active (%04x -> %x).\n", head, head & 0x1);
123 if (head >> 12 != 0x4 || foot >> 12 != 0xB || ((head >> 8) & 0xF) != ((foot >> 8) & 0xF))
126 if (head >> 12 != 0x4)
127 sprintf(ss,
"\n\tHeader is not 0x4 as expected (%x).", head);
128 if (foot >> 12 != 0xB)
129 sprintf(ss,
"\n\tFooter is not 0xB as expected (%x).", foot);
130 if (((head >> 8) & 0xF) != ((foot >> 8) & 0xF))
131 sprintf(ss,
"\n\tIncompatible GOH IDs in header (%x) and footer (%x).", ((head >> 8) & 0xF),
132 ((foot >> 8) & 0xF));
134 LogProblem(
"Totem") <<
"Error in RawDataUnpacker::ProcessOptoRxFrame > " <<
"Wrong payload structure (in GOH block row " <<
r <<
135 " and column " <<
c <<
") in OptoRx frame ID " << OptoRxId <<
". GOH block omitted." << ss << endl;
142 unsigned int goh = (head >> 8) & 0xF;
143 vector<VFATFrame::word*> dataPtrs;
144 for (
unsigned int fi = 0; fi < 16; fi++)
151 printf(
">>>> transposing GOH block at prefix: %i, dataPtrs = %p\n", OptoRxId*192 + goh*16, dataPtrs);
155 for (
int i = 0;
i < 192;
i++)
157 int iword = 11 -
i / 16;
158 int ibit = 15 -
i % 16;
159 unsigned int w = (buf[
i + 2 + 194 *
r] >> (16 *
c)) & 0xFFFF;
165 dataPtrs[
idx][iword] |= (1 << ibit);
179 unsigned long long head = buf[0];
180 unsigned int OptoRxId = (head >> 8) & 0xFFF;
183 const uint16_t *payload = (
const uint16_t *) (buf + 1);
186 const uint32_t *ocPtr = (
const uint32_t *) payload;
191 unsigned int nWords = (frameSize-2) * 4 - 2;
196 unsigned int wordsProcessed = ProcessVFATDataParallel(payload +
offset, OptoRxId, fc);
208 unsigned int wordsProcessed = 1;
211 if (buf[0] == 0xFFFF)
212 return wordsProcessed;
215 unsigned int hFlag = (buf[0] >> 8) & 0xFF;
216 if (hFlag != vmCluster && hFlag != vmRaw)
218 LogProblem(
"Totem") <<
"Error in RawDataUnpacker::ProcessVFATDataParallel > "
219 <<
"Unknown header flag " << hFlag <<
". Skipping this word." << endl;
220 return wordsProcessed;
225 unsigned int gohIdx = (buf[0] >> 4) & 0xF;
226 unsigned int fiberIdx = (buf[0] >> 0) & 0xF;
234 uint8_t presenceFlags = 0;
236 if (((buf[wordsProcessed] >> 12) & 0xF) == 0xA)
238 presenceFlags |= 0x1;
239 fd[11] = buf[wordsProcessed];
243 if (((buf[wordsProcessed] >> 12) & 0xF) == 0xC)
245 presenceFlags |= 0x2;
246 fd[10] = buf[wordsProcessed];
250 if (((buf[wordsProcessed] >> 12) & 0xF) == 0xE)
252 presenceFlags |= 0x4;
253 fd[9] = buf[wordsProcessed];
258 unsigned int dataOffset = wordsProcessed;
261 if (hFlag == vmCluster)
263 unsigned int nCl = 0;
264 while ( (buf[wordsProcessed + nCl] >> 12) != 0xF )
267 wordsProcessed += nCl;
274 unsigned int tSig = buf[wordsProcessed] >> 12;
275 unsigned int tErrFlags = (buf[wordsProcessed] >> 8) & 0xF;
276 unsigned int tSize = buf[wordsProcessed] & 0xFF;
280 bool skipFrame =
false;
281 bool suppressChannelErrors =
false;
285 LogProblem(
"Totem") <<
"Error in RawDataUnpacker::ProcessVFATDataParallel > "
286 <<
"Wrong trailer signature (" << tSig <<
") at "
287 << fp <<
". This frame will be skipped." << endl;
293 LogProblem(
"Totem") <<
"Error in RawDataUnpacker::ProcessVFATDataParallel > "
294 <<
"Error flags not zero (" << tErrFlags <<
") at "
295 << fp <<
". Channel errors will be suppressed." << endl;
296 suppressChannelErrors =
true;
301 if (tSize != wordsProcessed)
303 LogProblem(
"Totem") <<
"Error in RawDataUnpacker::ProcessVFATDataParallel > "
304 <<
"Trailer size (" << tSize <<
") does not match with words processed ("
305 << wordsProcessed <<
") at " << fp <<
". This frame will be skipped." << endl;
310 return wordsProcessed;
313 if (hFlag == vmCluster)
315 for (
unsigned int nCl = 0; (buf[dataOffset + nCl] >> 12) != 0xF; ++nCl)
317 const uint16_t &
w = buf[dataOffset + nCl];
318 unsigned int upperBlock = w >> 8;
319 unsigned int clSize = upperBlock & 0x7F;
320 unsigned int clPos = (w >> 0) & 0xFF;
323 if (upperBlock == 0xD0)
325 presenceFlags |= 0x10;
336 signed int chMax = clPos;
337 signed int chMin = clPos - clSize + 1;
338 if (chMax < 0 || chMax > 127 || chMin < 0 || chMin > 127 || chMin > chMax)
340 if (!suppressChannelErrors)
341 LogProblem(
"Totem") <<
"Error in RawDataUnpacker::ProcessVFATDataParallel > "
342 <<
"Invalid cluster (pos=" << clPos
343 <<
", size=" << clSize <<
", min=" << chMin <<
", max=" << chMax <<
") at " << fp
344 <<
". Skipping this cluster." << endl;
349 for (
signed int ch = chMin; ch <= chMax; ch++)
351 unsigned int wi = ch / 16;
352 unsigned int bi = ch % 16;
353 fd[wi + 1] |= (1 << bi);
361 for (
unsigned int i = 0;
i < 8;
i++)
362 fd[8 -
i] = buf[dataOffset +
i];
365 presenceFlags |= 0x8;
366 fd[0] = buf[dataOffset + 8];
373 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.
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.
tuple idx
DEBUGGING if hasattr(process,"trackMonIterativeTracking2012"): print "trackMonIterativeTracking2012 D...
void setDAQErrorFlags(uint8_t v)
Sets DAQ error flags.
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)