Convert ROB fragments to ZdcCollection.
145{
146
148
150
151
154
155
156
157 typedef std::map<uint32_t,ZdcDigits*> hashmapType;
158 hashmapType digits_map;
159
160
161
162 int robCount = 0;
165 for (; rob != robEnd; ++rob)
166 {
167
168 ++robCount;
170 {
171 msg() <<
"ZDC: Treating ROB fragment " << robCount <<
endmsg;
172 }
173
174
175
179 (*rob)->rod_data(payloadBeg);
180 payloadEnd = payloadBeg + (*rob)->rod_ndata();
182 if (payload == payloadEnd)
183 {
185 continue;
186 }
187
188
189 const uint32_t sourceID = (*rob)->rod_source_id();
191 {
193 != 0)
194 {
195 msg() <<
"ZDC: Wrong source identifier in data: " << MSG::hex << sourceID << MSG::dec
197 }
198 }
201 {
204 }
205
206
207
208
209
210
211
212 ZdcUserHeader userHeader(*payload);
213 const int minorVersion = (*rob)->rod_version() & 0xffff;
214 userHeader.setVersion(minorVersion);
215 const int headerWords = userHeader.words();
216 if (headerWords != 1 &&
debug)
217 {
218 msg() <<
"ZDC: Unexpected number of user header words: " << headerWords <<
endmsg;
219 }
220
221 for (
int i = 0;
i < headerWords; ++
i)
222 ++payload;
223
224 const int trigLut = userHeader.ppmLut();
225 const int trigFadc = userHeader.ppmFadc();
226
229 {
230 msg() <<
"ZDC: Minor format version number: " << MSG::hex << minorVersion << MSG::dec
231 <<
endmsg <<
"ZDC: LUT triggered slice offset: " << trigLut <<
endmsg
232 <<
"ZDC: FADC triggered slice offset: " << trigFadc <<
endmsg
234 }
235 const int runNumber = (*rob)->rod_run_no() & 0xffffff;
236
237
238 int chanPerSubBlock = 0;
239 if (payload != payloadEnd)
240 {
242 {
243 msg(MSG::ERROR) <<
"Missing Sub-block header" <<
endmsg;
244 return StatusCode::FAILURE;
245 }
246 ZdcPpmSubBlock testBlock;
247
248
249 testBlock.
read(payload, payloadEnd);
251 if (chanPerSubBlock == 0)
252 {
253 msg(MSG::ERROR) <<
"Unsupported version/data format: " << testBlock.
version()
255 return StatusCode::FAILURE;
256 }
258 {
259 msg(MSG::ERROR) <<
"Invalid channels per sub-block: " << chanPerSubBlock <<
endmsg;
260 return StatusCode::FAILURE;
261 }
262 if (
debug)
msg() <<
"Channels per sub-block: " << chanPerSubBlock <<
endmsg;
263 }
264 else
265 {
266 if (
debug)
msg() <<
"ROB fragment contains user header only" <<
endmsg;
267 continue;
268 }
269 const int numSubBlocks =
m_channels / chanPerSubBlock;
270
271
272
274 for (
int i = 0;
i < headerWords; ++
i)
275 ++payload;
276 while (payload != payloadEnd)
277 {
278
279
280
281 int crate = 0;
284 for (int block = 0; block < numSubBlocks; ++block)
285 {
288 {
289 msg(MSG::ERROR) <<
"Unexpected data sequence" <<
endmsg;
290 return StatusCode::FAILURE;
291 }
293 * chanPerSubBlock)
294 {
296 {
297 msg() <<
"Unexpected channel sequence number: "
299 * chanPerSubBlock <<
endmsg;
300 }
302 else
303 {
305 {
306 msg(MSG::ERROR) <<
"Unexpected channel sequence number" <<
endmsg;
307 }
308 return StatusCode::FAILURE;
309 }
310 }
311 ZdcPpmSubBlock* const subBlock = new ZdcPpmSubBlock();
314 if (block == 0)
315 {
316 crate = subBlock->
crate();
317 module = subBlock->module();
319 {
320 msg() <<
"Module " <<
module << endmsg;
321 if (crate != rodCrate)
322 {
323 msg() <<
"Inconsistent crate number in ROD source ID" <<
endmsg;
324 }
325 }
326 }
327 else
328 {
329 if (subBlock->
crate() != crate)
330 {
331 msg(MSG::ERROR) <<
"Inconsistent crate number in sub-blocks" <<
endmsg;
332 return StatusCode::FAILURE;
333 }
334 if (subBlock->
module() != module)
335 {
336 msg(MSG::ERROR) <<
"Inconsistent module number in sub-blocks" <<
endmsg;
337 return StatusCode::FAILURE;
338 }
339 }
340 if (payload == payloadEnd && block != numSubBlocks - 1)
341 {
343 break;
344 }
345 }
346
347
348
349
350
352 if (payload != payloadEnd)
353 {
356 {
358
361 {
362 msg(MSG::ERROR) <<
"Inconsistent crate number in error block" <<
endmsg;
363 return StatusCode::FAILURE;
364 }
366 {
367 msg(MSG::ERROR) <<
"Inconsistent module number in error block" <<
endmsg;
368 return StatusCode::FAILURE;
369 }
371 {
373 {
375 msg() <<
"Unpacking error block failed: " << errMsg <<
endmsg;
376 }
377 }
378
379 }
380 }
381
382
383
385 for (int block = 0; block < actualSubBlocks; ++block)
386 {
387 ZdcPpmSubBlock*
const subBlock =
m_ppmBlocks[block];
394 {
395 msg() <<
"Unpacking sub-block version/format/seqno: " << subBlock->
version()
397 }
399 {
401 {
403 msg() <<
"Unpacking PPM sub-block failed: " << errMsg <<
endmsg;
404 }
405 }
407 for (
int chan = 0;
chan < chanPerSubBlock; ++
chan)
408 {
409 const int channel = block * chanPerSubBlock +
chan;
410 std::vector<int>
lut;
411 std::vector<int> fadc;
412 std::vector<int> bcidLut;
413 std::vector<int> bcidFadc;
414 subBlock->
ppmData(channel, lut, fadc, bcidLut, bcidFadc);
415
416
417 if (
lut.size() <
size_t(trigLut + 1))
418 {
420 {
421 msg() <<
"Triggered LUT slice from header "
422 << "inconsistent with number of slices: " << trigLut << ", "
423 <<
lut.size() <<
", reset to 0" <<
endmsg;
424 }
425
426 }
427 if (fadc.size() < size_t(trigFadc + 1))
428 {
430 {
431 msg() <<
"Triggered FADC slice from header "
432 << "inconsistent with number of slices: " << trigFadc << ", "
433 << fadc.size() <<
", reset to 0" <<
endmsg;
434 }
435
436 }
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461 const bool any = std::accumulate(
lut.begin(),
lut.end(), 0)
462 || std::accumulate(fadc.begin(), fadc.end(), 0)
463 || std::accumulate(bcidLut.begin(), bcidLut.end(), 0)
464 || std::accumulate(bcidFadc.begin(), bcidFadc.end(), 0);
465
466
467
468
469
470
471
472
473
474 Identifier chan_id;
475
477
480
482 msg(MSG::DEBUG) <<
"chan_hash = " << chan_hash <<
endmsg;
483
484
485
486 if (any)
487 {
491 {
493 msg(MSG::DEBUG) <<
" --------------------------------------" <<
endmsg;
495 "--> ZDC: [SubDet., Crate, Mod., Slink Chn., PPM Chan.] ";
499
500 msg(MSG::DEBUG) <<
"--> ZDC: LUT: ";
503
504 msg(MSG::DEBUG) <<
"--> ZDC: FADC: ";
507
508 msg(MSG::DEBUG) <<
"--> ZDC: bcidLUT: ";
511
512 msg(MSG::DEBUG) <<
"--> ZDC: bcidFADC: ";
515
520 msg(MSG::DEBUG) <<
"--> ID channel: " <<
m_zdcID->channel(chan_id) <<
endmsg;
521
523
524 msg(MSG::DEBUG) <<
" --------------------------------------" <<
endmsg;
525
526 }
527
528 hashmapType::iterator
iter = digits_map.find(chan_hash);
529 if (iter == digits_map.end())
530 {
531 digits_map.insert(std::pair<uint32_t,ZdcDigits*>(chan_hash,new ZdcDigits(chan_id)));
532 iter = digits_map.find(chan_hash);
533 }
534 if (iter != digits_map.end())
535 {
536 if (gain==0&&
delay==0) (*iter).second->set_digits_gain0_delay0(fadc);
537 if (gain==1&&
delay==0) (*iter).second->set_digits_gain1_delay0(fadc);
538 if (gain==0&&
delay==1) (*iter).second->set_digits_gain0_delay1(fadc);
539 if (gain==1&&
delay==1) (*iter).second->set_digits_gain1_delay1(fadc);
540 }
541
542 }
543 }
544 }
545 }
546 }
547
548 hashmapType::iterator
iter = digits_map.begin();
549 hashmapType::iterator iter_end = digits_map.end();
550
551 while (iter != iter_end)
552 {
555 }
556
557 msg(MSG::DEBUG) <<
"-->ZDC: Collection has " << ttCollection->
size() <<
" elements " <<
endmsg;
558
559 return StatusCode::SUCCESS;
560}
double delay(std::size_t d)
bool msgLvl(const MSG::Level lvl) const
value_type push_back(value_type pElem)
Add an element to the end of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
value_type get_compact() const
Get the compact id.
std::string getString() const
Provide a string form of the identifier - hexadecimal.
Identifier32 get_identifier32() const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
int hwid2gain(int crate, int channel) const
static const ZdcCablingService * getInstance()
get pointer to service instance
int hwid2delay(int crate, int channel) const
Identifier h2s_channel_id(int crate, int channel) const
void setPedestal(int pedval)
void setLutOffset(int offset)
void ppmData(int chan, std::vector< int > &lut, std::vector< int > &fadc, std::vector< int > &bcidLut, std::vector< int > &bcidFadc) const
Return unpacked data for given channel.
void setFadcBaseline(int baseline)
const std::vector< uint32_t > & compStats() const
Return reference to compression stats.
bool unpack()
Unpack data.
void setRunNumber(int run)
static bool errorBlock(uint32_t word)
Check if a header word is for an error block.
void setFadcOffset(int offset)
static int channelsPerSubBlock(int version, int format)
Return the number of channels per sub-block.
int getPpmChannel(const int channel) const
static eformat::SubDetector subDet(uint32_t code)
ID -> sub-detector.
static int crate(uint32_t code)
moduleID -> crate
static int daqOrRoi(uint32_t code)
moduleID -> daqOrRoi
static int slink(uint32_t code)
moduleID -> slink
OFFLINE_FRAGMENTS_NAMESPACE::PointerType read(const OFFLINE_FRAGMENTS_NAMESPACE::PointerType beg, const OFFLINE_FRAGMENTS_NAMESPACE::PointerType end)
Input complete packed sub-block from ROD array.
int dataWords() const
Return number of data words.
std::string unpackErrorMsg() const
Return the unpacking error message for printing.
static SubBlockWordType wordType(uint32_t word)
Word identification.
constexpr auto lut(Generator &&f)