18 using namespace ctpps;
23 verbosity(iConfig.getUntrackedParameter<unsigned
int>(
"verbosity", 0))
30 unsigned int size_in_words = data.
size() / 8;
31 if (size_in_words < 2)
34 LogWarning(
"Totem") <<
"Error in RawDataUnpacker::Run > " <<
35 "Data in FED " << fedId <<
" too short (size = " << size_in_words <<
" words).";
49 unsigned long long head = buf[0];
50 unsigned long long foot = buf[frameSize-1];
55 unsigned int BOE = (head >> 60) & 0xF;
56 unsigned int H0 = (head >> 0) & 0xF;
60 unsigned int OptoRxId = (head >> 8) & 0xFFF;
61 unsigned int FOV = (head >> 4) & 0xF;
63 unsigned int EOE = (foot >> 60) & 0xF;
64 unsigned int F0 = (foot >> 0) & 0xF;
65 unsigned int FSize = (foot >> 32) & 0x3FF;
68 if (BOE != 5 || H0 != 0 || EOE != 10 || F0 != 0 || FSize != frameSize)
71 LogWarning(
"Totem") <<
"Error in RawDataUnpacker::ProcessOptoRxFrame > " <<
"Wrong structure of OptoRx header/footer: " 72 <<
"BOE=" << BOE <<
", H0=" << H0 <<
", EOE=" << EOE <<
", F0=" << F0
73 <<
", size (OptoRx)=" << FSize <<
", size (DATE)=" << frameSize
74 <<
". OptoRxID=" << OptoRxId <<
". Skipping frame." << endl;
79 printf(
">> RawDataUnpacker::ProcessOptoRxFrame > OptoRxId = %u, BX = %lu, LV1 = %lu, frameSize = %u, subFrames = %u)\n",
80 OptoRxId,
BX, LV1, frameSize, subFrames);
94 LogWarning(
"Totem") <<
"Error in RawDataUnpacker::ProcessOptoRxFrame > " <<
"Unknown FOV = " << FOV << endl;
104 unsigned int OptoRxId = (buf[0] >> 8) & 0xFFF;
107 unsigned int subFrames = (frameSize - 2) / 194;
110 unsigned int errorCounter = 0;
111 for (
unsigned int r = 0;
r < subFrames; ++
r)
113 for (
unsigned int c = 0;
c < 4; ++
c)
115 unsigned int head = (buf[1 + 194 *
r] >> (16 *
c)) & 0xFFFF;
116 unsigned int foot = (buf[194 + 194 *
r] >> (16 *
c)) & 0xFFFF;
119 printf(
">>>> r = %i, c = %i: S = %i, BOF = %i, EOF = %i, ID = %i, ID' = %i\n",
r,
c, head & 0
x1, head >> 12, foot >> 12, (head >> 8) & 0xF, (foot >> 8) & 0xF);
123 if ((head & 0x1) == 0)
127 printf(
"\tHeader active (%04x -> %x).\n", head, head & 0x1);
131 if (head >> 12 != 0x4 || foot >> 12 != 0xB || ((head >> 8) & 0xF) != ((foot >> 8) & 0xF))
134 if (head >> 12 != 0x4)
135 sprintf(ss,
"\n\tHeader is not 0x4 as expected (%x).", head);
136 if (foot >> 12 != 0xB)
137 sprintf(ss,
"\n\tFooter is not 0xB as expected (%x).", foot);
138 if (((head >> 8) & 0xF) != ((foot >> 8) & 0xF))
139 sprintf(ss,
"\n\tIncompatible GOH IDs in header (%x) and footer (%x).", ((head >> 8) & 0xF),
140 ((foot >> 8) & 0xF));
143 LogWarning(
"Totem") <<
"Error in RawDataUnpacker::ProcessOptoRxFrame > " <<
"Wrong payload structure (in GOH block row " <<
r <<
144 " and column " <<
c <<
") in OptoRx frame ID " << OptoRxId <<
". GOH block omitted." << ss << endl;
151 unsigned int goh = (head >> 8) & 0xF;
152 vector<VFATFrame::word*> dataPtrs;
153 for (
unsigned int fi = 0; fi < 16; fi++)
160 printf(
">>>> transposing GOH block at prefix: %i, dataPtrs = %p\n", OptoRxId*192 + goh*16, dataPtrs);
164 for (
int i = 0;
i < 192;
i++)
166 int iword = 11 -
i / 16;
167 int ibit = 15 -
i % 16;
168 unsigned int w = (buf[
i + 2 + 194 *
r] >> (16 *
c)) & 0xFFFF;
174 dataPtrs[
idx][iword] |= (1 << ibit);
188 unsigned long long head = buf[0];
189 unsigned int OptoRxId = (head >> 8) & 0xFFF;
192 const uint16_t *
payload = (
const uint16_t *) (buf + 1);
195 const uint32_t *ocPtr = (
const uint32_t *) payload;
200 unsigned int nWords = (frameSize-2) * 4 - 2;
217 unsigned int wordsProcessed = 1;
220 if (buf[0] == 0xFFFF)
221 return wordsProcessed;
224 unsigned int hFlag = (buf[0] >> 8) & 0xFF;
228 LogWarning(
"Totem") <<
"Error in RawDataUnpacker::ProcessVFATDataParallel > " 229 <<
"Unknown header flag " << hFlag <<
". Skipping this word." << endl;
230 return wordsProcessed;
235 unsigned int gohIdx = (buf[0] >> 4) & 0xF;
236 unsigned int fiberIdx = (buf[0] >> 0) & 0xF;
244 uint8_t presenceFlags = 0;
246 if (((buf[wordsProcessed] >> 12) & 0xF) == 0xA)
248 presenceFlags |= 0x1;
249 fd[11] = buf[wordsProcessed];
253 if (((buf[wordsProcessed] >> 12) & 0xF) == 0xC)
255 presenceFlags |= 0x2;
256 fd[10] = buf[wordsProcessed];
260 if (((buf[wordsProcessed] >> 12) & 0xF) == 0xE)
262 presenceFlags |= 0x4;
263 fd[9] = buf[wordsProcessed];
268 unsigned int dataOffset = wordsProcessed;
273 unsigned int nCl = 0;
274 while ( (buf[wordsProcessed + nCl] >> 12) != 0xF && ( wordsProcessed + nCl < maxWords ) ) nCl++;
275 wordsProcessed += nCl;
282 while ( (buf[wordsProcessed] & 0xFFF0)!= 0xF000 && ( wordsProcessed < maxWords ) ) wordsProcessed++;
287 unsigned int tSig = buf[wordsProcessed] >> 12;
288 unsigned int tErrFlags = (buf[wordsProcessed] >> 8) & 0xF;
289 unsigned int tSize = buf[wordsProcessed] & 0xFF;
294 bool skipFrame =
false;
300 ess <<
" Wrong trailer signature (" << tSig <<
")." << endl;
307 ess <<
" Error flags not zero (" << tErrFlags <<
")." << endl;
313 if (tSize != wordsProcessed)
316 ess <<
" Trailer size (" << tSize <<
") does not match with words processed (" << wordsProcessed <<
")." << endl;
323 LogWarning(
"Totem") <<
"Error in RawDataUnpacker::ProcessVFATDataParallel > Frame at " << fp
324 <<
" has the following problems and will be skipped.\n" << endl << ess.rdbuf();
326 return wordsProcessed;
332 for (
unsigned int nCl = 0; (buf[dataOffset + nCl] >> 12) != 0xF && ( dataOffset + nCl < maxWords ); ++nCl)
334 const uint16_t &
w = buf[dataOffset + nCl];
335 unsigned int upperBlock = w >> 8;
336 unsigned int clSize = upperBlock & 0x7F;
337 unsigned int clPos = (w >> 0) & 0xFF;
340 if (upperBlock == 0xD0)
342 presenceFlags |= 0x10;
353 signed int chMax = clPos;
354 signed int chMin = clPos - clSize + 1;
355 if (chMax < 0 || chMax > 127 || chMin < 0 || chMin > 127 || chMin > chMax)
358 LogWarning(
"Totem") <<
"Error in RawDataUnpacker::ProcessVFATDataParallel > " 359 <<
"Invalid cluster (pos=" << clPos
360 <<
", size=" << clSize <<
", min=" << chMin <<
", max=" << chMax <<
") at " << fp
361 <<
". Skipping this cluster." << endl;
365 for (
signed int ch = chMin; ch <= chMax; ch++)
367 unsigned int wi = ch / 16;
368 unsigned int bi = ch % 16;
369 fd[wi + 1] |= (1 << bi);
377 for (
unsigned int i = 0;
i < 8;
i++)
378 fd[8 -
i] = buf[dataOffset +
i];
381 presenceFlags |= 0x8;
382 fd[0] = buf[dataOffset + 8];
388 for (
unsigned int i = 1; (buf[
i+1] & 0xFFF0)!= 0xF000 && (
i+1 < maxWords );
i++) {
394 switch ( buf[
i] & 0xF800 ) {
418 presenceFlags |= 0x8;
426 return wordsProcessed;
OptoRx headers and footers.
static constexpr unsigned int VFAT_DIAMOND_HEADER_OF_WORD_7
VFATFrame::word * getData()
int ProcessOptoRxFrame(const word *buf, unsigned int frameSize, TotemFEDInfo &fedInfo, SimpleVFATFrameCollection *fc) const
Process one Opto-Rx (or LoneG) frame.
static constexpr unsigned int VFAT_DIAMOND_HEADER_OF_WORD_2
static constexpr unsigned int VFAT_HEADER_OF_EC
size_t size() const
Lenght of the data buffer in bytes.
static constexpr unsigned int VFAT_DIAMOND_HEADER_OF_WORD_3
static constexpr unsigned int VFAT_DIAMOND_HEADER_OF_WORD_5
int ProcessOptoRxFrameSerial(const word *buffer, unsigned int frameSize, SimpleVFATFrameCollection *fc) const
Process one Opto-Rx frame in serial (old) format.
void setOrbitCounter(uint32_t _oc)
int ProcessVFATDataParallel(const uint16_t *buf, unsigned int maxWords, unsigned int OptoRxId, SimpleVFATFrameCollection *fc) const
Process data from one VFAT in parallel (new) format.
void setFooter(uint64_t _f)
VFATFrame * InsertEmptyFrame(TotemFramePosition index)
inserts an empty (default) frame to the given position and returns pointer to the frame ...
int ProcessOptoRxFrameParallel(const word *buffer, unsigned int frameSize, TotemFEDInfo &fedInfo, SimpleVFATFrameCollection *fc) const
Process one Opto-Rx frame in parallel (new) format.
void setPresenceFlags(uint8_t v)
Sets presence flags.
void setDAQErrorFlags(uint8_t v)
Sets DAQ error flags.
char data[epos_bytes_allocation]
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
void setHeader(uint64_t _h)
void Insert(const TotemFramePosition &index, const VFATFrame &frame)
void setNumberOfClusters(uint8_t v)
int Run(int fedId, const FEDRawData &data, std::vector< TotemFEDInfo > &fedInfoColl, SimpleVFATFrameCollection &coll) const
Unpack data from FED with fedId into `coll' collection.