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;
58 unsigned long lv1 = (head >> 32) & 0xFFFFFF;
59 unsigned long bx = (head >> 20) & 0xFFF;
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;
78 LogDebug(
"Totem" ) <<
"RawDataUnpacker::processOptoRxFrame: " 79 <<
"OptoRxId = " << optoRxId <<
", BX = " << bx <<
", LV1 = " << lv1 <<
", frameSize = " << frameSize;
98 LogWarning(
"Totem") <<
"Error in RawDataUnpacker::processOptoRxFrame > " <<
"Unknown FOV = " << fov << endl;
108 unsigned int optoRxId = (buf[0] >> 8) & 0xFFF;
111 unsigned int subFrames = (frameSize - 2) / 194;
114 unsigned int errorCounter = 0;
115 for (
unsigned int r = 0;
r < subFrames; ++
r)
117 for (
unsigned int c = 0;
c < 4; ++
c)
119 unsigned int head = (buf[1 + 194 *
r] >> (16 *
c)) & 0xFFFF;
120 unsigned int foot = (buf[194 + 194 *
r] >> (16 *
c)) & 0xFFFF;
123 <<
"r = " <<
r <<
", c = " <<
c <<
": " 124 <<
"S = " << ( head & 0x1 ) <<
", BOF = " << ( head >> 12 ) <<
", EOF = " << ( foot >> 12 )
125 <<
", ID = " << ( ( head >> 8 ) & 0xF ) <<
", ID' = " << ( ( foot >> 8) & 0xF );
128 if ((head & 0
x1) == 0)
132 <<
"Header active (" << head <<
" -> " << ( head & 0x1 ) <<
").";
135 if (head >> 12 != 0x4 || foot >> 12 != 0xB || ((head >> 8) & 0xF) != ((foot >> 8) & 0xF))
137 std::ostringstream oss;
138 if (head >> 12 != 0x4)
139 oss <<
"\n\tHeader is not 0x4 as expected (0x" << std::hex << head <<
").";
140 if (foot >> 12 != 0xB)
141 oss <<
"\n\tFooter is not 0xB as expected (0x" << std::hex << foot <<
").";
142 if (((head >> 8) & 0xF) != ((foot >> 8) & 0xF))
143 oss <<
"\n\tIncompatible GOH IDs in header (0x" << std::hex << ( ( head >> 8 ) & 0xF ) <<
") and footer (0x" << std::hex << ( ( foot >> 8 ) & 0xF ) <<
").";
146 LogWarning(
"Totem") <<
"Error in RawDataUnpacker::processOptoRxFrame > " <<
"Wrong payload structure (in GOH block row " <<
r <<
147 " and column " <<
c <<
") in OptoRx frame ID " << optoRxId <<
". GOH block omitted." << oss.str() << endl;
154 unsigned int goh = (head >> 8) & 0xF;
155 vector<VFATFrame::word*> dataPtrs;
156 for (
unsigned int fi = 0; fi < 16; fi++)
164 l <<
"transposing GOH block at prefix: " << ( optoRxId*192+goh*16 ) <<
", dataPtrs = ";
165 for(
auto p: dataPtrs) {
170 for (
int i = 0;
i < 192;
i++)
172 int iword = 11 -
i / 16;
173 int ibit = 15 -
i % 16;
174 unsigned int w = (buf[
i + 2 + 194 *
r] >> (16 *
c)) & 0xFFFF;
180 dataPtrs[
idx][iword] |= (1 << ibit);
194 unsigned long long head = buf[0];
195 unsigned int optoRxId = (head >> 8) & 0xFFF;
198 const uint16_t *
payload = (
const uint16_t *) (buf + 1);
201 const uint32_t *ocPtr = (
const uint32_t *) payload;
206 unsigned int nWords = (frameSize-2) * 4 - 2;
223 unsigned int wordsProcessed = 1;
226 if (buf[0] == 0xFFFF)
227 return wordsProcessed;
230 unsigned int hFlag = (buf[0] >> 8) & 0xFF;
234 LogWarning(
"Totem") <<
"Error in RawDataUnpacker::processVFATDataParallel > " 235 <<
"Unknown header flag " << hFlag <<
". Skipping this word." << endl;
236 return wordsProcessed;
241 unsigned int gohIdx = (buf[0] >> 4) & 0xF;
242 unsigned int fiberIdx = (buf[0] >> 0) & 0xF;
250 uint8_t presenceFlags = 0;
252 if (((buf[wordsProcessed] >> 12) & 0xF) == 0xA)
254 presenceFlags |= 0x1;
255 fd[11] = buf[wordsProcessed];
259 if (((buf[wordsProcessed] >> 12) & 0xF) == 0xC)
261 presenceFlags |= 0x2;
262 fd[10] = buf[wordsProcessed];
266 if (((buf[wordsProcessed] >> 12) & 0xF) == 0xE)
268 presenceFlags |= 0x4;
269 fd[9] = buf[wordsProcessed];
274 unsigned int dataOffset = wordsProcessed;
279 unsigned int nCl = 0;
280 while ( (buf[wordsProcessed + nCl] >> 12) != 0xF && ( wordsProcessed + nCl < maxWords ) ) nCl++;
281 wordsProcessed += nCl;
288 while ( (buf[wordsProcessed] & 0xFFF0)!= 0xF000 && ( wordsProcessed < maxWords ) ) wordsProcessed++;
293 unsigned int tSig = buf[wordsProcessed] >> 12;
294 unsigned int tErrFlags = (buf[wordsProcessed] >> 8) & 0xF;
295 unsigned int tSize = buf[wordsProcessed] & 0xFF;
300 bool skipFrame =
false;
306 ess <<
" Wrong trailer signature (" << tSig <<
")." << endl;
313 ess <<
" Error flags not zero (" << tErrFlags <<
")." << endl;
319 if (tSize != wordsProcessed)
322 ess <<
" Trailer size (" << tSize <<
") does not match with words processed (" << wordsProcessed <<
")." << endl;
329 LogWarning(
"Totem") <<
"Error in RawDataUnpacker::processVFATDataParallel > Frame at " << fp
330 <<
" has the following problems and will be skipped.\n" << endl << ess.rdbuf();
332 return wordsProcessed;
338 for (
unsigned int nCl = 0; (buf[dataOffset + nCl] >> 12) != 0xF && ( dataOffset + nCl < maxWords ); ++nCl)
340 const uint16_t &
w = buf[dataOffset + nCl];
341 unsigned int upperBlock = w >> 8;
342 unsigned int clSize = upperBlock & 0x7F;
343 unsigned int clPos = (w >> 0) & 0xFF;
346 if (upperBlock == 0xD0)
348 presenceFlags |= 0x10;
359 signed int chMax = clPos;
360 signed int chMin = clPos - clSize + 1;
361 if (chMax < 0 || chMax > 127 || chMin < 0 || chMin > 127 || chMin > chMax)
364 LogWarning(
"Totem") <<
"Error in RawDataUnpacker::processVFATDataParallel > " 365 <<
"Invalid cluster (pos=" << clPos
366 <<
", size=" << clSize <<
", min=" << chMin <<
", max=" << chMax <<
") at " << fp
367 <<
". Skipping this cluster." << endl;
371 for (
signed int ch = chMin; ch <= chMax; ch++)
373 unsigned int wi = ch / 16;
374 unsigned int bi = ch % 16;
375 fd[wi + 1] |= (1 << bi);
383 for (
unsigned int i = 0;
i < 8;
i++)
384 fd[8 -
i] = buf[dataOffset +
i];
387 presenceFlags |= 0x8;
388 fd[0] = buf[dataOffset + 8];
394 for (
unsigned int i = 1; (buf[
i+1] & 0xFFF0)!= 0xF000 && (
i+1 < maxWords );
i++) {
400 switch ( buf[
i] & 0xF800 ) {
424 presenceFlags |= 0x8;
432 return wordsProcessed;
439 unsigned int optoRxId = (buf[0] >> 8) & 0xFFF;
441 LogDebug(
"RawDataUnpacker::processOptoRxFrameSampic" )
442 <<
"Processing sampic frame: OptoRx " << optoRxId <<
" framesize: " << frameSize;
444 unsigned int orbitCounterVFATFrameWords = 6;
445 unsigned int sizeofVFATPayload = 12;
448 VFATFrameWordPtr += orbitCounterVFATFrameWords - 1;
450 LogDebug(
"RawDataUnpacker::processOptoRxFrameSampic" )
451 <<
"Framesize: " << frameSize <<
"\tframes: " << frameSize/(sizeofVFATPayload+2);
453 unsigned int nWords = (frameSize-2) * 4 - 2;
455 for (
unsigned int i=1;
i*(sizeofVFATPayload+2)<nWords; ++
i) {
458 unsigned int fiberIdx = (*(++VFATFrameWordPtr)) & 0xF;
459 unsigned int gohIdx = (*VFATFrameWordPtr >> 4) & 0xF;
462 LogDebug(
"RawDataUnpacker::processOptoRxFrameSampic" )
463 <<
"OptoRx: " << optoRxId <<
" Goh: " << gohIdx <<
" Idx: " << fiberIdx;
467 VFATFrameWordPtr += sizeofVFATPayload;
469 if ( *(VFATFrameWordPtr) != 0xf00e ) {
471 <<
"Wrong trailer " << *VFATFrameWordPtr;
478 LogDebug(
"RawDataUnpacker::processOptoRxFrameSampic" )
479 <<
"Trailer: " << std::hex << *VFATFrameWordPtr;
OptoRx headers and footers.
int processVFATDataParallel(const uint16_t *buf, unsigned int maxWords, unsigned int OptoRxId, SimpleVFATFrameCollection *fc) const
Process data from one VFAT in parallel (new) format.
int processOptoRxFrameParallel(const word *buffer, unsigned int frameSize, TotemFEDInfo &fedInfo, SimpleVFATFrameCollection *fc) const
Process one Opto-Rx frame in parallel (new) format.
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.
int run(int fedId, const FEDRawData &data, std::vector< TotemFEDInfo > &fedInfoColl, SimpleVFATFrameCollection &coll) const
Unpack data from FED with fedId into `coll' collection.
static constexpr unsigned int VFAT_DIAMOND_HEADER_OF_WORD_2
int processOptoRxFrameSampic(const word *buffer, unsigned int frameSize, TotemFEDInfo &fedInfo, SimpleVFATFrameCollection *fc) const
Process one Opto-Rx frame that contains SAMPIC frames.
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
int processOptoRxFrameSerial(const word *buffer, unsigned int frameSize, SimpleVFATFrameCollection *fc) const
Process one Opto-Rx frame in serial (old) format.
static constexpr unsigned int VFAT_DIAMOND_HEADER_OF_WORD_5
void setOrbitCounter(uint32_t _oc)
void setFooter(uint64_t _f)
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]
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)