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++)
163 <<
"transposing GOH block at prefix: " << ( optoRxId*192+goh*16 ) <<
", dataPtrs = " << dataPtrs;
166 for (
int i = 0;
i < 192;
i++)
168 int iword = 11 -
i / 16;
169 int ibit = 15 -
i % 16;
170 unsigned int w = (buf[
i + 2 + 194 *
r] >> (16 *
c)) & 0xFFFF;
176 dataPtrs[
idx][iword] |= (1 << ibit);
190 unsigned long long head = buf[0];
191 unsigned int optoRxId = (head >> 8) & 0xFFF;
194 const uint16_t *
payload = (
const uint16_t *) (buf + 1);
197 const uint32_t *ocPtr = (
const uint32_t *) payload;
202 unsigned int nWords = (frameSize-2) * 4 - 2;
219 unsigned int wordsProcessed = 1;
222 if (buf[0] == 0xFFFF)
223 return wordsProcessed;
226 unsigned int hFlag = (buf[0] >> 8) & 0xFF;
230 LogWarning(
"Totem") <<
"Error in RawDataUnpacker::processVFATDataParallel > " 231 <<
"Unknown header flag " << hFlag <<
". Skipping this word." << endl;
232 return wordsProcessed;
237 unsigned int gohIdx = (buf[0] >> 4) & 0xF;
238 unsigned int fiberIdx = (buf[0] >> 0) & 0xF;
246 uint8_t presenceFlags = 0;
248 if (((buf[wordsProcessed] >> 12) & 0xF) == 0xA)
250 presenceFlags |= 0x1;
251 fd[11] = buf[wordsProcessed];
255 if (((buf[wordsProcessed] >> 12) & 0xF) == 0xC)
257 presenceFlags |= 0x2;
258 fd[10] = buf[wordsProcessed];
262 if (((buf[wordsProcessed] >> 12) & 0xF) == 0xE)
264 presenceFlags |= 0x4;
265 fd[9] = buf[wordsProcessed];
270 unsigned int dataOffset = wordsProcessed;
275 unsigned int nCl = 0;
276 while ( (buf[wordsProcessed + nCl] >> 12) != 0xF && ( wordsProcessed + nCl < maxWords ) ) nCl++;
277 wordsProcessed += nCl;
284 while ( (buf[wordsProcessed] & 0xFFF0)!= 0xF000 && ( wordsProcessed < maxWords ) ) wordsProcessed++;
289 unsigned int tSig = buf[wordsProcessed] >> 12;
290 unsigned int tErrFlags = (buf[wordsProcessed] >> 8) & 0xF;
291 unsigned int tSize = buf[wordsProcessed] & 0xFF;
296 bool skipFrame =
false;
302 ess <<
" Wrong trailer signature (" << tSig <<
")." << endl;
309 ess <<
" Error flags not zero (" << tErrFlags <<
")." << endl;
315 if (tSize != wordsProcessed)
318 ess <<
" Trailer size (" << tSize <<
") does not match with words processed (" << wordsProcessed <<
")." << endl;
325 LogWarning(
"Totem") <<
"Error in RawDataUnpacker::processVFATDataParallel > Frame at " << fp
326 <<
" has the following problems and will be skipped.\n" << endl << ess.rdbuf();
328 return wordsProcessed;
334 for (
unsigned int nCl = 0; (buf[dataOffset + nCl] >> 12) != 0xF && ( dataOffset + nCl < maxWords ); ++nCl)
336 const uint16_t &
w = buf[dataOffset + nCl];
337 unsigned int upperBlock = w >> 8;
338 unsigned int clSize = upperBlock & 0x7F;
339 unsigned int clPos = (w >> 0) & 0xFF;
342 if (upperBlock == 0xD0)
344 presenceFlags |= 0x10;
355 signed int chMax = clPos;
356 signed int chMin = clPos - clSize + 1;
357 if (chMax < 0 || chMax > 127 || chMin < 0 || chMin > 127 || chMin > chMax)
360 LogWarning(
"Totem") <<
"Error in RawDataUnpacker::processVFATDataParallel > " 361 <<
"Invalid cluster (pos=" << clPos
362 <<
", size=" << clSize <<
", min=" << chMin <<
", max=" << chMax <<
") at " << fp
363 <<
". Skipping this cluster." << endl;
367 for (
signed int ch = chMin; ch <= chMax; ch++)
369 unsigned int wi = ch / 16;
370 unsigned int bi = ch % 16;
371 fd[wi + 1] |= (1 << bi);
379 for (
unsigned int i = 0;
i < 8;
i++)
380 fd[8 -
i] = buf[dataOffset +
i];
383 presenceFlags |= 0x8;
384 fd[0] = buf[dataOffset + 8];
390 for (
unsigned int i = 1; (buf[
i+1] & 0xFFF0)!= 0xF000 && (
i+1 < maxWords );
i++) {
396 switch ( buf[
i] & 0xF800 ) {
420 presenceFlags |= 0x8;
428 return wordsProcessed;
435 unsigned int optoRxId = (buf[0] >> 8) & 0xFFF;
437 LogDebug(
"RawDataUnpacker::processOptoRxFrameSampic" )
438 <<
"Processing sampic frame: OptoRx " << optoRxId <<
" framesize: " << frameSize;
440 unsigned int orbitCounterVFATFrameWords = 6;
441 unsigned int sizeofVFATPayload = 12;
444 VFATFrameWordPtr += orbitCounterVFATFrameWords - 1;
446 LogDebug(
"RawDataUnpacker::processOptoRxFrameSampic" )
447 <<
"Framesize: " << frameSize <<
"\tframes: " << frameSize/(sizeofVFATPayload+2);
449 unsigned int nWords = (frameSize-2) * 4 - 2;
451 for (
unsigned int i=1;
i*(sizeofVFATPayload+2)<nWords; ++
i) {
454 unsigned int fiberIdx = (*(++VFATFrameWordPtr)) & 0xF;
455 unsigned int gohIdx = (*VFATFrameWordPtr >> 4) & 0xF;
458 LogDebug(
"RawDataUnpacker::processOptoRxFrameSampic" )
459 <<
"OptoRx: " << optoRxId <<
" Goh: " << gohIdx <<
" Idx: " << fiberIdx;
463 VFATFrameWordPtr += sizeofVFATPayload;
465 if ( *(VFATFrameWordPtr) != 0xf00e ) {
467 <<
"Wrong trailer " << *VFATFrameWordPtr;
474 LogDebug(
"RawDataUnpacker::processOptoRxFrameSampic" )
475 <<
"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)