Execute decoding for an event.
some of this info should be used in the LatomeHeader class and for cross checks also (same as for the mon header)
not we have the packet size from the first packet, check all packet headers before decoding we can decide later if we drop decoding if we have inconsistency
OK all headers checked and we have all info we need to decode each packet, so lets start
for now just getting the ADCs from AT0 Change later to add energy as well and use the BC shift to determine at which BC there is energy
start of packet, bcid still unvalid / should increase by one but take care of rotation at s_nBunches;
the data is packed with 64 bits words. Will be padded with 0s at the end of the timeslot time slot.
lets fill now, using the older code structure but this should be change to support having energy.
449 {
451 const unsigned int sourceID = robFrag->rob_source_id();
452 m_l1ID = robFrag->rod_lvl1_id();
455 const unsigned int n = robFrag->rod_ndata();
456 if (0 == n) {
459 return;
460 }
462
464 const uint32_t* rod_status = robFrag->rod_status();
465 const unsigned int rod_nstatus = robFrag->rod_nstatus();
466 if (rod_nstatus != 27) {
467 ATH_MSG_WARNING(
"Inconsistent number of rod header status elements: nstatus= " << rod_nstatus);
468 return;
469 }
470 if (rod_nstatus > 8) {
478 }
479
480 }
483
484 LatomeCalibPatterns pat1, pat2, pat3;
485 pat1.DAC = rod_status[9];
486 pat1.delay = rod_status[10];
487 pat1.patterns.resize(4);
488 for (
unsigned int i = 0;
i < 4; ++
i)
489 pat1.patterns[i] = rod_status[i + 11];
490
491 pat2.DAC = rod_status[15];
492 pat2.delay = rod_status[16];
493 pat2.patterns.resize(4);
494 for (
unsigned int i = 0;
i < 4; ++
i)
495 pat2.patterns[i] = rod_status[i + 17];
496
497 pat3.DAC = rod_status[21];
498 pat3.delay = rod_status[22];
499 pat3.patterns.resize(4);
500 for (
unsigned int i = 0;
i < 4; ++
i)
501 pat3.patterns[i] = rod_status[i + 23];
502
504
505 const HWIdentifier hwidEmpty;
506
508
509
510
512 ATH_MSG_WARNING(
"Data corruption, offset found at pos 0 (" << offset <<
") is larger than the ROB fragment size (" <<
m_ROBFragSize <<
"). Ignoring data.");
513 return;
514 }
515
521 << " " << sourceID << std::dec);
522 return;
523 }
524 }
530 << " " << sourceID << std::dec);
531 return;
532 }
533 }
534
541 ATH_MSG_WARNING(
"Data corruption, offset found at pos 0 (" << offset <<
") is larger than the ROB fragment size (" <<
m_ROBFragSize <<
"). Ignoring data.");
542 return;
543 }
544
547 ATH_MSG_WARNING(
"Data corruption, offset found at pos 0 (" << offset <<
") is larger than the ROB fragment size (" <<
m_ROBFragSize <<
"). Ignoring data.");
548 return;
549 }
552 }
553
554 ATH_MSG_DEBUG(
" end of header check computed offset=" << std::dec << offset <<
" nwords in payload=" << n);
555
560 return;
561 }
562
565 return;
566 }
567
570 }
571
572
574 std::vector<unsigned int> bc_size;
577
578 short nBC = 0;
579 short nBC1 = 0;
580 short startBC1 = 0;
583
588 startBC1 = 0;
595 val.latomeChannel = 99999;
596 }
597 } else {
600 }
601
609 } else {
615 }
622 } else {
624 return;
625 }
626
627 switch (type0) {
631 break;
635 break;
639 break;
643 break;
645 break;
646 default:
648 return;
649 }
650
651 switch (type1) {
656 break;
661 break;
666 break;
671 break;
673 break;
674 default:
676 return;
677 }
678
690 }
691
692 val.latomeChannel = 99999;
693 }
694 }
695
697
700
701 for (short iBC = 0; iBC < nBC; ++iBC) {
705 if (iBC < startBC1 || iBC >= startBC1 + nBC1)
707 }
709
710 int nsc = 0;
711 unsigned int oldipacket = 0;
712 for (unsigned int itimeslot = 0; itimeslot < 6; ++itimeslot) {
713 unsigned int l_bcid = (std::byteswap(p[s]))>>16;
714 if(itimeslot!=0){
715 if(l_bcid!=bcid){
717 }
718 }
719 else{
722 unsigned int bcid_c =
bcid+1;
725 bcid_c = 0;
726 }
727 if(bcid_c != l_bcid){
728 ATH_MSG_WARNING(
"ERROR: BCID not increasing properly between samples, sourceId: " <<
m_nthLATOME <<
" L1ID is: " <<
m_l1ID <<
", BCID is from payload: " << l_bcid <<
", expected BCID is: " << bcid_c <<
", LATOME channel is: " << nsc );
729 }
730 }
732 }
734
735 unsigned int mux = ((std::byteswap(p[s])) >> 8) & 0xff;
739 if (s >= n)
740 break;
741
742 unsigned int timeslotsize = timeslot_nsc[itimeslot];
743 unsigned int nbytes = timeslotsize * nbytesPerChannel;
744 unsigned int n64word = nbytes / 8;
745 if (nbytes % 8)
746 ++n64word;
747 ATH_MSG_DEBUG(
" at BC " << iBC <<
" timeslot " << itimeslot <<
" " << bcid <<
" " << mux <<
" n64word " << n64word <<
" at0 " << (
int)at0 <<
" at1 "
748 << (int)at1 << " l_bcid " << bcid);
749
750 unsigned int wordshift =
s;
751 unsigned int byteshift = 0;
752
755 for (
unsigned int ichan = 0;
ichan < timeslotsize; ++
ichan) {
756 unsigned int at0Data = 0, at1Data = 0, satData = 0;
757 bool at0val = false, at1val = false;
758
759
761 break;
762
763 }
765 decodeChannel(wordshift, byteshift, p, at0, at1, at0Data, at1Data, satData, at0val, at1val);
766 ATH_MSG_DEBUG(
" wordshift " << wordshift <<
" byteshift " << byteshift <<
" at0data " << at0Data <<
" at1Data " << at1Data <<
" satData " << satData
767 << " at0val " << at0val << " at1val " << at1val << " nsc " << nsc);
768
770 const HWIdentifier SCID = nsc < (
int) LATOME_Channels->size() ? (*LATOME_Channels)[nsc] : hwidEmpty;
771 if (SCID == hwidEmpty) {
773 }
774 int RAWValue0 = -999;
776 ATH_MSG_DEBUG(
"at0 bad quality bit for SC:" << nsc <<
" BC " << iBC <<
" latome " << robFrag->rod_source_id());
777 } else {
779 RAWValue0 = at0Data;
780 }
781 int defaultADCValue = -1;
782 int defaultEValue = -99999;
784 switch (at0) {
786 if ((unsigned)iBC < rawValuesInEvent.adc.size()) {
787 rawValuesInEvent.adc[iBC] = (at0val) ? RAWValue0 : defaultADCValue;
788 }
789 break;
791 if ((unsigned)iBC < rawValuesInEvent.adc_bas.size()) {
792 rawValuesInEvent.adc_bas[iBC] = (at0val) ? RAWValue0 : defaultADCValue;
793 }
794 break;
796 if ((unsigned)iBC < rawValuesInEvent.et.size()) {
797 rawValuesInEvent.et[iBC] = (at0val) ?
signEnergy(RAWValue0) : defaultEValue;
798 rawValuesInEvent.saturation[iBC] = satData;
799 }
800 break;
802 if ((unsigned)iBC < rawValuesInEvent.et_id.size()) {
803 rawValuesInEvent.et_id[iBC] = (at0val) ?
signEnergy(RAWValue0) : defaultEValue;
804 rawValuesInEvent.saturation[iBC] = satData;
805 }
806 break;
808 break;
809 default:
811 return;
812 }
813
814 int RAWValue1 = -999;
816 ATH_MSG_DEBUG(
"at1 bad quality bit for SC:" << nsc <<
" BC " << iBC <<
" latome " << robFrag->rod_source_id());
817 } else {
819 RAWValue1 = at1Data;
820 }
821
822 const size_t BCidx = iBC - startBC1;
823 switch (at1) {
825 if (BCidx < rawValuesInEvent.adc.size()) {
826 rawValuesInEvent.adc[BCidx] = (at1val) ? RAWValue1 : defaultADCValue;
827 }
828 break;
830 if (BCidx < rawValuesInEvent.adc_bas.size()) {
831 rawValuesInEvent.adc_bas[BCidx] = (at1val) ? RAWValue1 : defaultADCValue;
832 }
833 break;
835 if (BCidx < rawValuesInEvent.et.size()) {
836 rawValuesInEvent.et[BCidx] = (at1val) ?
signEnergy(RAWValue1) : defaultEValue;
837 rawValuesInEvent.saturation[BCidx] = satData;
838 }
839 break;
841 if (BCidx < rawValuesInEvent.et_id.size()) {
844 }
845 break;
847 break;
848 default:
850 return;
851 }
852
854
855 } else {
856 if (wordshift % 2) {
857 ATH_MSG_ERROR(
"inconsistant wordshift in decoding everaged data");
858 return;
859 }
860 unsigned int averageword = std::byteswap(p[wordshift]);
861 wordshift += 1;
862 unsigned int sumSq = std::byteswap(p[wordshift]);
863 wordshift += 1;
864 unsigned long long sumsqMSB = averageword >> 28;
865 sumsqMSB = sumsqMSB << 32;
866
871 }
872
873 ++nsc;
874
875 }
876
878 if(byteshift!=0){
880 byteshift=0;
881 }
882 ATH_MSG_DEBUG(
"wordshift before: " << wordshift <<
", s: " << s);
883 if ((wordshift - s) % 2)
885 ATH_MSG_DEBUG(
"wordshift after : " << wordshift <<
", s: " << s);
888 <<
"!=" << n64word * 2 <<
" m_ipacket " <<
m_iPacket);
889 }
892 }
893
894 }
895
898 } else {
899 if (onoffmap && clmap) {
900 fillCalib(LATOME_Channels, onoffmap, clmap);
901 } else {
903 }
904 }
906}
int signEnergy(unsigned int energy)
void fillRaw(const std::vector< HWIdentifier > *LATOME_Channels)
Pass ADC values from an event.
void decodeChannel(unsigned int &wordshift, unsigned int &byteshift, const uint32_t *p, MonDataType at0, MonDataType at1, unsigned int &at0Data, unsigned int &at1Data, unsigned int &satData, bool &at0val, bool &at1val)
unsigned int decodeHeader(const uint32_t *p, unsigned int offset)
std::vector< unsigned short > m_BCIDsInEvent
void increaseWordShift(unsigned int &wordshift)
void fillCalib(const std::vector< HWIdentifier > *LATOME_Channels, const LArOnOffIdMapping *onoffmap, const LArCalibLineMapping *clmap)
std::vector< Word > m_packetEnd
unsigned int decodeTrailer(const uint32_t *p, unsigned int offset)
static const int s_nBunches
Maximum value of BCID.
void swap(ElementLinkVector< DOBJ > &lhs, ElementLinkVector< DOBJ > &rhs)
setEventNumber setTimeStamp bcid