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;
94 LogWarning(
"Totem") <<
"Error in RawDataUnpacker::processOptoRxFrame > " 95 <<
"Unknown FOV = " << fov << endl;
101 unsigned int frameSize,
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) {
112 for (
unsigned int c = 0;
c < 4; ++
c) {
113 unsigned int head = (
buf[1 + 194 *
r] >> (16 *
c)) & 0xFFFF;
114 unsigned int foot = (
buf[194 + 194 *
r] >> (16 *
c)) & 0xFFFF;
116 LogDebug(
"Totem") <<
"r = " <<
r <<
", c = " <<
c <<
": " 117 <<
"S = " << (head & 0x1) <<
", BOF = " << (head >> 12) <<
", EOF = " << (foot >> 12)
118 <<
", ID = " << ((head >> 8) & 0xF) <<
", ID' = " << ((foot >> 8) & 0xF);
121 if ((head & 0
x1) == 0)
124 LogDebug(
"Totem") <<
"Header active (" << head <<
" -> " << (head & 0x1) <<
").";
127 if (head >> 12 != 0x4 || foot >> 12 != 0xB || ((head >> 8) & 0xF) != ((foot >> 8) & 0xF)) {
128 std::ostringstream oss;
129 if (head >> 12 != 0x4)
130 oss <<
"\n\tHeader is not 0x4 as expected (0x" << std::hex << head <<
").";
131 if (foot >> 12 != 0xB)
132 oss <<
"\n\tFooter is not 0xB as expected (0x" << std::hex << foot <<
").";
133 if (((head >> 8) & 0xF) != ((foot >> 8) & 0xF))
134 oss <<
"\n\tIncompatible GOH IDs in header (0x" << std::hex << ((head >> 8) & 0xF) <<
") and footer (0x" 135 << std::hex << ((foot >> 8) & 0xF) <<
").";
138 LogWarning(
"Totem") <<
"Error in RawDataUnpacker::processOptoRxFrame > " 139 <<
"Wrong payload structure (in GOH block row " <<
r <<
" and column " <<
c 140 <<
") in OptoRx frame ID " << optoRxId <<
". GOH block omitted." << oss.str() << endl;
147 unsigned int goh = (head >> 8) & 0xF;
148 vector<VFATFrame::word *> dataPtrs;
149 for (
unsigned int fi = 0; fi < 16; fi++) {
155 l <<
"transposing GOH block at prefix: " << (optoRxId * 192 + goh * 16) <<
", dataPtrs = ";
156 for (
auto p : dataPtrs) {
161 for (
int i = 0;
i < 192;
i++) {
162 int iword = 11 -
i / 16;
163 int ibit = 15 -
i % 16;
164 unsigned int w = (
buf[
i + 2 + 194 *
r] >> (16 *
c)) & 0xFFFF;
169 dataPtrs[
idx][iword] |= (1 << ibit);
179 unsigned int frameSize,
183 unsigned long long head =
buf[0];
184 unsigned int optoRxId = (head >> 8) & 0xFFF;
187 const uint16_t *
payload = (
const uint16_t *)(
buf + 1);
190 const uint32_t *ocPtr = (
const uint32_t *)
payload;
195 unsigned int nWords = (frameSize - 2) * 4 - 2;
207 unsigned int maxWords,
208 unsigned int optoRxId,
211 unsigned int wordsProcessed = 1;
214 if (
buf[0] == 0xFFFF)
215 return wordsProcessed;
218 unsigned int hFlag = (
buf[0] >> 8) & 0xFF;
221 LogWarning(
"Totem") <<
"Error in RawDataUnpacker::processVFATDataParallel > " 222 <<
"Unknown header flag " << hFlag <<
". Skipping this word." << endl;
223 return wordsProcessed;
228 unsigned int gohIdx = (
buf[0] >> 4) & 0xF;
229 unsigned int fiberIdx = (
buf[0] >> 0) & 0xF;
237 uint8_t presenceFlags = 0;
239 if (((
buf[wordsProcessed] >> 12) & 0xF) == 0xA)
241 presenceFlags |= 0x1;
242 fd[11] =
buf[wordsProcessed];
246 if (((
buf[wordsProcessed] >> 12) & 0xF) == 0xC)
248 presenceFlags |= 0x2;
249 fd[10] =
buf[wordsProcessed];
253 if (((
buf[wordsProcessed] >> 12) & 0xF) == 0xE)
255 presenceFlags |= 0x4;
256 fd[9] =
buf[wordsProcessed];
261 unsigned int dataOffset = wordsProcessed;
266 unsigned int nCl = 0;
267 while ((
buf[wordsProcessed + nCl] >> 12) != 0xF && (wordsProcessed + nCl < maxWords))
269 wordsProcessed += nCl;
276 while ((
buf[wordsProcessed] & 0xFFF0) != 0xF000 && (wordsProcessed < maxWords))
282 unsigned int tSig =
buf[wordsProcessed] >> 12;
283 unsigned int tErrFlags = (
buf[wordsProcessed] >> 8) & 0xF;
284 unsigned int tSize =
buf[wordsProcessed] & 0xFF;
286 f.setDAQErrorFlags(tErrFlags);
289 bool skipFrame =
false;
294 ess <<
" Wrong trailer signature (" << tSig <<
")." << endl;
298 if (tErrFlags != 0) {
300 ess <<
" Error flags not zero (" << tErrFlags <<
")." << endl;
306 if (tSize != wordsProcessed) {
308 ess <<
" Trailer size (" << tSize <<
") does not match with words processed (" << wordsProcessed <<
")." 315 LogWarning(
"Totem") <<
"Error in RawDataUnpacker::processVFATDataParallel > Frame at " <<
fp 316 <<
" has the following problems and will be skipped.\n" 320 return wordsProcessed;
325 for (
unsigned int nCl = 0; (
buf[dataOffset + nCl] >> 12) != 0xF && (dataOffset + nCl < maxWords); ++nCl) {
326 const uint16_t &
w =
buf[dataOffset + nCl];
327 unsigned int upperBlock =
w >> 8;
328 unsigned int clSize = upperBlock & 0x7F;
329 unsigned int clPos = (
w >> 0) & 0xFF;
332 if (upperBlock == 0xD0) {
333 presenceFlags |= 0x10;
334 f.setNumberOfClusters(clPos);
344 signed int chMax = clPos;
345 signed int chMin = clPos - clSize + 1;
346 if (chMax < 0 || chMax > 127 || chMin < 0 || chMin > 127 || chMin > chMax) {
348 LogWarning(
"Totem") <<
"Error in RawDataUnpacker::processVFATDataParallel > " 349 <<
"Invalid cluster (pos=" << clPos <<
", size=" << clSize <<
", min=" << chMin
350 <<
", max=" << chMax <<
") at " <<
fp <<
". Skipping this cluster." << endl;
354 for (
signed int ch = chMin; ch <= chMax; ch++) {
355 unsigned int wi = ch / 16;
356 unsigned int bi = ch % 16;
357 fd[wi + 1] |= (1 << bi);
363 if (hFlag ==
vmRaw) {
364 for (
unsigned int i = 0;
i < 8;
i++)
365 fd[8 -
i] =
buf[dataOffset +
i];
368 presenceFlags |= 0x8;
369 fd[0] =
buf[dataOffset + 8];
374 for (
unsigned int i = 1; (
buf[
i + 1] & 0xFFF0) != 0xF000 && (
i + 1 < maxWords);
i++) {
380 switch (
buf[
i] & 0xF800) {
404 presenceFlags |= 0x8;
409 f.setPresenceFlags(presenceFlags);
412 return wordsProcessed;
416 unsigned int frameSize,
419 unsigned int optoRxId = (
buf[0] >> 8) & 0xFFF;
421 LogDebug(
"RawDataUnpacker::processOptoRxFrameSampic")
422 <<
"Processing sampic frame: OptoRx " << optoRxId <<
" framesize: " << frameSize;
424 unsigned int orbitCounterVFATFrameWords = 6;
425 unsigned int sizeofVFATPayload = 12;
428 VFATFrameWordPtr += orbitCounterVFATFrameWords - 1;
430 LogDebug(
"RawDataUnpacker::processOptoRxFrameSampic")
431 <<
"Framesize: " << frameSize <<
"\tframes: " << frameSize / (sizeofVFATPayload + 2);
433 unsigned int nWords = (frameSize - 2) * 4 - 2;
435 for (
unsigned int i = 1;
i * (sizeofVFATPayload + 2) < nWords; ++
i) {
438 unsigned int fiberIdx = (*(++VFATFrameWordPtr)) & 0xF;
439 unsigned int gohIdx = (*VFATFrameWordPtr >> 4) & 0xF;
442 LogDebug(
"RawDataUnpacker::processOptoRxFrameSampic")
443 <<
"OptoRx: " << optoRxId <<
" Goh: " << gohIdx <<
" Idx: " << fiberIdx;
447 VFATFrameWordPtr += sizeofVFATPayload;
449 if (*(VFATFrameWordPtr) != 0xf00e) {
450 edm::LogError(
"RawDataUnpacker::processOptoRxFrameSampic") <<
"Wrong trailer " << *VFATFrameWordPtr;
454 frame.setPresenceFlags(1);
457 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)