19 :
verbosity(iConfig.getUntrackedParameter<unsigned
int>(
"verbosity", 0)) {}
23 vector<TotemFEDInfo> &fedInfoColl,
25 unsigned int size_in_words =
data.size() / 8;
26 if (size_in_words < 2) {
28 LogWarning(
"Totem") <<
"Error in RawDataUnpacker::run > " 29 <<
"Data in FED " <<
fedId <<
" too short (size = " << size_in_words <<
" words).";
33 fedInfoColl.emplace_back(
fedId);
39 unsigned int frameSize,
43 unsigned long long head =
buf[0];
44 unsigned long long foot =
buf[frameSize - 1];
49 unsigned int boe = (head >> 60) & 0xF;
50 unsigned int h0 = (head >> 0) & 0xF;
52 unsigned long lv1 = (head >> 32) & 0xFFFFFF;
53 unsigned long bx = (head >> 20) & 0xFFF;
54 unsigned int optoRxId = (head >> 8) & 0xFFF;
55 unsigned int fov = (head >> 4) & 0xF;
57 unsigned int eoe = (foot >> 60) & 0xF;
58 unsigned int f0 = (foot >> 0) & 0xF;
59 unsigned int fSize = (foot >> 32) & 0x3FF;
62 if (boe != 5 || h0 != 0 || eoe != 10 || f0 != 0 || fSize != frameSize) {
64 LogWarning(
"Totem") <<
"Error in RawDataUnpacker::processOptoRxFrame > " 65 <<
"Wrong structure of OptoRx header/footer: " 66 <<
"BOE=" << boe <<
", H0=" << h0 <<
", EOE=" << eoe <<
", F0=" << f0
67 <<
", size (OptoRx)=" << fSize <<
", size (DATE)=" << frameSize <<
". OptoRxID=" << optoRxId
68 <<
". Skipping frame." << endl;
72 LogDebug(
"Totem") <<
"RawDataUnpacker::processOptoRxFrame: " 73 <<
"OptoRxId = " << optoRxId <<
", BX = " <<
bx <<
", LV1 = " << lv1
74 <<
", frameSize = " << frameSize <<
", fov = " << fov;
98 LogWarning(
"Totem") <<
"Error in RawDataUnpacker::processOptoRxFrame > " 99 <<
"Unknown FOV = " << fov << endl;
105 unsigned int frameSize,
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) {
116 for (
unsigned int c = 0;
c < 4; ++
c) {
117 unsigned int head = (
buf[1 + 194 * r] >> (16 *
c)) & 0xFFFF;
118 unsigned int foot = (
buf[194 + 194 * r] >> (16 *
c)) & 0xFFFF;
120 LogDebug(
"Totem") <<
"r = " << r <<
", c = " <<
c <<
": " 121 <<
"S = " << (head & 0x1) <<
", BOF = " << (head >> 12) <<
", EOF = " << (foot >> 12)
122 <<
", ID = " << ((head >> 8) & 0xF) <<
", ID' = " << ((foot >> 8) & 0xF);
125 if ((head & 0x1) == 0)
128 LogDebug(
"Totem") <<
"Header active (" << head <<
" -> " << (head & 0x1) <<
").";
131 if (head >> 12 != 0x4 || foot >> 12 != 0xB || ((head >> 8) & 0xF) != ((foot >> 8) & 0xF)) {
132 std::ostringstream oss;
133 if (head >> 12 != 0x4)
134 oss <<
"\n\tHeader is not 0x4 as expected (0x" << std::hex << head <<
").";
135 if (foot >> 12 != 0xB)
136 oss <<
"\n\tFooter is not 0xB as expected (0x" << std::hex << foot <<
").";
137 if (((head >> 8) & 0xF) != ((foot >> 8) & 0xF))
138 oss <<
"\n\tIncompatible GOH IDs in header (0x" << std::hex << ((head >> 8) & 0xF) <<
") and footer (0x" 139 << std::hex << ((foot >> 8) & 0xF) <<
").";
142 LogWarning(
"Totem") <<
"Error in RawDataUnpacker::processOptoRxFrame > " 143 <<
"Wrong payload structure (in GOH block row " << r <<
" and column " <<
c 144 <<
") in OptoRx frame ID " << optoRxId <<
". GOH block omitted." << oss.str() << endl;
151 unsigned int goh = (head >> 8) & 0xF;
152 vector<VFATFrame::word *> dataPtrs;
153 for (
unsigned int fi = 0; fi < 16; fi++) {
159 l <<
"transposing GOH block at prefix: " << (optoRxId * 192 + goh * 16) <<
", dataPtrs = ";
160 for (
auto p : dataPtrs) {
165 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;
173 dataPtrs[
idx][iword] |= (1 << ibit);
183 unsigned int frameSize,
187 unsigned long long head =
buf[0];
188 unsigned int optoRxId = (head >> 8) & 0xFFF;
191 const uint16_t *
payload = (
const uint16_t *)(
buf + 1);
194 const uint32_t *ocPtr = (
const uint32_t *)
payload;
199 unsigned int nWords = (frameSize - 2) * 4 - 2;
211 unsigned int maxWords,
212 unsigned int optoRxId,
215 unsigned int wordsProcessed = 1;
218 if (
buf[0] == 0xFFFF)
219 return wordsProcessed;
222 unsigned int hFlag = (
buf[0] >> 8) & 0xFF;
225 LogWarning(
"Totem") <<
"Error in RawDataUnpacker::processVFATDataParallel > " 226 <<
"Unknown header flag " << hFlag <<
". Skipping this word." << endl;
227 return wordsProcessed;
232 unsigned int gohIdx = (
buf[0] >> 4) & 0xF;
233 unsigned int fiberIdx = (
buf[0] >> 0) & 0xF;
241 uint8_t presenceFlags = 0;
243 if (((
buf[wordsProcessed] >> 12) & 0xF) == 0xA)
245 presenceFlags |= 0x1;
246 fd[11] =
buf[wordsProcessed];
250 if (((
buf[wordsProcessed] >> 12) & 0xF) == 0xC)
252 presenceFlags |= 0x2;
253 fd[10] =
buf[wordsProcessed];
257 if (((
buf[wordsProcessed] >> 12) & 0xF) == 0xE)
259 presenceFlags |= 0x4;
260 fd[9] =
buf[wordsProcessed];
265 unsigned int dataOffset = wordsProcessed;
270 unsigned int nCl = 0;
271 while ((
buf[wordsProcessed + nCl] >> 12) != 0xF && (wordsProcessed + nCl < maxWords))
273 wordsProcessed += nCl;
280 while ((
buf[wordsProcessed] & 0xFFF0) != 0xF000 && (wordsProcessed < maxWords))
286 unsigned int tSig =
buf[wordsProcessed] >> 12;
287 unsigned int tErrFlags = (
buf[wordsProcessed] >> 8) & 0xF;
288 unsigned int tSize =
buf[wordsProcessed] & 0xFF;
290 f.setDAQErrorFlags(tErrFlags);
293 bool skipFrame =
false;
298 ess <<
" Wrong trailer signature (" << tSig <<
")." << endl;
302 if (tErrFlags != 0) {
304 ess <<
" Error flags not zero (" << tErrFlags <<
")." << endl;
310 if (tSize != wordsProcessed) {
312 ess <<
" Trailer size (" << tSize <<
") does not match with words processed (" << wordsProcessed <<
")." 319 LogWarning(
"Totem") <<
"Error in RawDataUnpacker::processVFATDataParallel > Frame at " <<
fp 320 <<
" has the following problems and will be skipped.\n" 324 return wordsProcessed;
329 for (
unsigned int nCl = 0; (
buf[dataOffset + nCl] >> 12) != 0xF && (dataOffset + nCl < maxWords); ++nCl) {
330 const uint16_t &
w =
buf[dataOffset + nCl];
331 unsigned int upperBlock =
w >> 8;
332 unsigned int clSize = upperBlock & 0x7F;
333 unsigned int clPos = (
w >> 0) & 0xFF;
336 if (upperBlock == 0xD0) {
337 presenceFlags |= 0x10;
338 f.setNumberOfClusters(clPos);
348 signed int chMax = clPos;
349 signed int chMin = clPos - clSize + 1;
350 if (chMax < 0 || chMax > 127 || chMin < 0 || chMin > 127 || chMin > chMax) {
352 LogWarning(
"Totem") <<
"Error in RawDataUnpacker::processVFATDataParallel > " 353 <<
"Invalid cluster (pos=" << clPos <<
", size=" << clSize <<
", min=" << chMin
354 <<
", max=" << chMax <<
") at " <<
fp <<
". Skipping this cluster." << endl;
358 for (
signed int ch = chMin; ch <= chMax; ch++) {
359 unsigned int wi = ch / 16;
360 unsigned int bi = ch % 16;
361 fd[wi + 1] |= (1 << bi);
367 if (hFlag ==
vmRaw) {
368 for (
unsigned int i = 0;
i < 8;
i++)
369 fd[8 -
i] =
buf[dataOffset +
i];
372 presenceFlags |= 0x8;
373 fd[0] =
buf[dataOffset + 8];
378 for (
unsigned int i = 1; (
buf[
i + 1] & 0xFFF0) != 0xF000 && (
i + 1 < maxWords);
i++) {
384 switch (
buf[
i] & 0xF800) {
408 presenceFlags |= 0x8;
413 f.setPresenceFlags(presenceFlags);
416 return wordsProcessed;
420 unsigned int frameSize,
423 unsigned int optoRxId = (
buf[0] >> 8) & 0xFFF;
425 LogDebug(
"RawDataUnpacker::processOptoRxFrameSampic")
426 <<
"Processing sampic frame: OptoRx " << optoRxId <<
" framesize: " << frameSize;
428 unsigned int orbitCounterVFATFrameWords = 6;
429 unsigned int sizeofVFATPayload = 12;
432 VFATFrameWordPtr += orbitCounterVFATFrameWords - 1;
434 LogDebug(
"RawDataUnpacker::processOptoRxFrameSampic")
435 <<
"Framesize: " << frameSize <<
"\tframes: " << frameSize / (sizeofVFATPayload + 2);
437 unsigned int nWords = (frameSize - 2) * 4 - 2;
439 for (
unsigned int i = 1;
i * (sizeofVFATPayload + 2) <
nWords; ++
i) {
442 unsigned int fiberIdx = (*(++VFATFrameWordPtr)) & 0xF;
443 unsigned int gohIdx = (*VFATFrameWordPtr >> 4) & 0xF;
448 LogDebug(
"RawDataUnpacker::processOptoRxFrameSampic")
449 <<
"OptoRx: " << optoRxId <<
" Goh: " << gohIdx <<
" Idx: " << fiberIdx;
453 VFATFrameWordPtr += sizeofVFATPayload;
455 if (*(VFATFrameWordPtr) != 0xf00e) {
456 edm::LogError(
"RawDataUnpacker::processOptoRxFrameSampic") <<
"Wrong trailer " << *VFATFrameWordPtr;
460 frame.setPresenceFlags(1);
462 frame.setPresenceFlags(15);
464 edm::LogWarning(
"Totem") <<
"T2 Frame Positions created: " << fp2a <<
"/" << fp2b << std::endl;
473 LogDebug(
"RawDataUnpacker::processOptoRxFrameSampic") <<
"Trailer: " << std::hex << *VFATFrameWordPtr;
OptoRx headers and footers.
static constexpr unsigned int VFAT_DIAMOND_HEADER_OF_WORD_7
static constexpr unsigned int VFAT_HEADER_OF_EC
VFATFrame::word * getData()
int processOptoRxFrame(const word *buf, unsigned int frameSize, TotemFEDInfo &fedInfo, SimpleVFATFrameCollection *fc) const
Process one Opto-Rx (or LoneG) frame.
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_DIAMOND_HEADER_OF_WORD_5
int processVFATDataParallel(const uint16_t *buf, unsigned int maxWords, unsigned int OptoRxId, SimpleVFATFrameCollection *fc) const
Process data from one VFAT in parallel (new) format.
Log< level::Error, false > LogError
static constexpr unsigned int VFAT_DIAMOND_HEADER_OF_WORD_3
void setFooter(uint64_t _f)
static constexpr unsigned int VFAT_DIAMOND_HEADER_OF_WORD_2
VFATFrame * InsertEmptyFrame(TotemFramePosition index)
inserts an empty (default) frame to the given position and returns pointer to the frame ...
int run(int fedId, const FEDRawData &data, std::vector< TotemFEDInfo > &fedInfoColl, SimpleVFATFrameCollection &coll) const
Unpack data from FED with fedId into ‘coll’ collection.
void setOrbitCounter(uint32_t oc)
char data[epos_bytes_allocation]
int processOptoRxFrameSerial(const word *buffer, unsigned int frameSize, SimpleVFATFrameCollection *fc) const
Process one Opto-Rx frame in serial (old) format.
Log< level::Warning, false > LogWarning
int processOptoRxFrameParallel(const word *buffer, unsigned int frameSize, TotemFEDInfo &fedInfo, SimpleVFATFrameCollection *fc) const
Process one Opto-Rx frame in parallel (new) format.
void setHeader(uint64_t _h)
void Insert(const TotemFramePosition &index, const VFATFrame &frame)