ATLAS Offline Software
MuonSpectrometer
MuonCnv
MuonNSWCommonDecode
src
NSWElink.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3
*/
4
#include <vector>
5
#include <exception>
6
#include <sstream>
7
8
#include "ers/ers.h"
9
10
#include "
MuonNSWCommonDecode/NSWDecodeBitmaps.h
"
11
#include "
MuonNSWCommonDecode/NSWDecodeHelper.h
"
12
13
#include "
MuonNSWCommonDecode/NSWElink.h
"
14
#include "
MuonNSWCommonDecode/VMMChannel.h
"
15
#include "
MuonNSWCommonDecode/NSWResourceId.h
"
16
17
#include "
MuonNSWCommonDecode/NSWDecodeExceptions.h
"
18
19
Muon::nsw::NSWElink::NSWElink
(
const
uint32_t
*bs,
const
uint32_t
remaining)
20
: m_wordCount (0)
21
{
22
m_rocId
= 0;
// Fix coverity warning
23
24
// Felix header (2 words)
25
// Packet length includes Felix header
26
27
uint32_t
word = bs[
m_wordCount
++];
28
unsigned
int
packet_nbytes =
Muon::nsw::helper::get_bits
(word,
Muon::nsw::bitMaskFlxLENGTH
,
Muon::nsw::bitPosFlxLENGTH
);
29
m_packet_status
=
Muon::nsw::helper::get_bits
(word,
Muon::nsw::bitMaskFlxSTATUS
,
Muon::nsw::bitPosFlxSTATUS
);
30
31
if
(
m_packet_status
!= 0)
32
{
33
std::ostringstream
s
;
34
s
<<
"Packet status in FELIX header 0x"
<< std::hex <<
m_packet_status
<< std::dec;
35
Muon::nsw::MuonNSWCommonDecoder::NSWElinkFelixHeaderException
e
(ERS_HERE,
s
.str ());
36
throw
e
;
37
}
38
39
if
(remaining *
sizeof
(
uint32_t
) < packet_nbytes)
40
{
41
std::ostringstream
s
;
42
s
<<
"Packet length in FELIX header "
<< packet_nbytes <<
" is larger than available data"
;
43
Muon::nsw::MuonNSWCommonDecoder::NSWElinkFelixHeaderException
e
(ERS_HERE,
s
.str ());
44
throw
e
;
45
}
46
47
m_elinkWord
= bs[
m_wordCount
++];
48
m_elinkId
=
new
Muon::nsw::NSWResourceId
(
m_elinkWord
);
49
50
// Decode sROC header
51
52
word = bs[
m_wordCount
++];
53
54
ERS_DEBUG (2,
"=============================================================="
);
55
ERS_DEBUG (2,
"FELIX HEADER: LENGTH (BYTES) = "
<< packet_nbytes <<
56
" | STATUS = "
<<
m_packet_status
<<
" | RESOURCE ID = 0x"
<< std::hex <<
m_elinkWord
<< std::dec);
57
58
if
((
m_isNull
=
Muon::nsw::helper::get_bits
(word,
Muon::nsw::bitMaskSRocNULL
,
Muon::nsw::bitPosSRocNULL
)) ==
true
)
59
{
60
m_l1Id
=
Muon::nsw::helper::get_bits
(word,
Muon::nsw::bitMaskSRocNullL1ID
,
Muon::nsw::bitPosSRocNullL1ID
);
61
m_rocId
=
Muon::nsw::helper::get_bits
(word,
Muon::nsw::bitMaskSRocNullID
,
Muon::nsw::bitPosSRocNullID
);
62
63
ERS_DEBUG (2,
"ROC HEADER: | NULL = "
<<
m_isNull
<<
64
" | ROCID = "
<<
m_rocId
<<
" | L1ID = "
<<
m_l1Id
);
65
66
// It may happen that the packet is flagged as a null packet but there are additional bytes
67
68
if
(packet_nbytes !=
s_null_packet_length
)
69
{
70
std::ostringstream
s
;
71
s
<<
"Additional data detected in packet flagged as null "
<< packet_nbytes;
72
Muon::nsw::MuonNSWCommonDecoder::NSWElinkROCHeaderException
e
(ERS_HERE,
s
.str ());
73
74
// Additional words are ignored
75
76
m_wordCount
= packet_nbytes /
sizeof
(
uint32_t
);
77
}
78
}
79
else
80
{
81
// It may happen that the null packet flag is wrong (or the size is wrong)
82
// In that case, throw an exception
83
84
if
(packet_nbytes ==
s_null_packet_length
)
85
{
86
std::ostringstream
s
;
87
s
<<
"Packet length in FELIX header "
<< packet_nbytes <<
" and null event flag in packet are inconsistent"
;
88
Muon::nsw::MuonNSWCommonDecoder::NSWElinkROCHeaderException
e
(ERS_HERE,
s
.str ());
89
throw
e
;
90
}
91
92
// Calculate packet checksum
93
94
const
uint8_t
*
p
=
reinterpret_cast <
const
uint8_t
*
>
(bs + 2);
95
m_running_checksum
= this->
test_checksum
(p, (packet_nbytes - 2 *
sizeof
(
uint32_t
)));
96
97
// m_noTDC will only affect data size, hit words should be re-aligned to uint32_t
98
99
m_noTdc
=
Muon::nsw::helper::get_bits
(word,
Muon::nsw::bitMaskSRocNOTDC
,
Muon::nsw::bitPosSRocNOTDC
);
100
m_l1Id
=
Muon::nsw::helper::get_bits
(word,
Muon::nsw::bitMaskSRocL1ID
,
Muon::nsw::bitPosSRocL1ID
);
101
m_bcId
=
Muon::nsw::helper::get_bits
(word,
Muon::nsw::bitMaskSRocBCID
,
Muon::nsw::bitPosSRocBCID
);
102
m_orbit
=
Muon::nsw::helper::get_bits
(word,
Muon::nsw::bitMaskSRocORBIT
,
Muon::nsw::bitPosSRocORBIT
);
103
104
// Set hit bytes to correspond to the length in Flx header
105
// Everything should be re-aligned in the swROD, though
106
107
// const unsigned int hit_size = m_noTdc ? 3 : 4; // set hit bytes to correspond to the length in Flx header
108
109
// Hit size should always be 4, since (at least for run 3) the detector is always configured to get the TDC info
110
// Please keep the previous commented out line. Having noTdc = true is a legal condition, in principle,
111
// but given the actual configuration of the detector, that should never happen and a crash is provoked when it does if
112
// it is taken into account. I (EP) added a warning exception to report that condition.
113
114
static
const
unsigned
int
hit_size = 4;
115
116
if
(
m_noTdc
)
117
{
118
std::ostringstream
s
;
119
s
<<
"Hit size is not compatible with flags in ROC header, elink ID = "
<<
m_elinkWord
<<
" L1 ID = "
<<
m_l1Id
;
120
Muon::nsw::MuonNSWCommonDecoder::NSWElinkROCHeaderException
e
(ERS_HERE,
s
.str ());
121
ers::warning (
e
);
122
}
123
124
// Two 32-bits words for Felix header, 1 word for ROC header, 1 word for the ROC trailer
125
126
m_nhits
= (packet_nbytes - 4 *
sizeof
(
uint32_t
)) / hit_size;
127
if
(packet_nbytes % 4) ++
m_nhits
;
128
129
ERS_DEBUG (2,
"ROC HEADER: T = "
<<
m_noTdc
<<
" | NULL = "
<<
m_isNull
<<
130
" | ORBIT = "
<<
m_orbit
<<
" | BCID = "
<<
m_bcId
<<
" | L1ID = "
<<
m_l1Id
);
131
132
// Hit Data
133
134
for
(
unsigned
int
i
=0;
i
<
m_nhits
; ++
i
)
135
{
136
Muon::nsw::VMMChannel
*
c
=
new
Muon::nsw::VMMChannel
(bs[
m_wordCount
++],
this
);
137
m_channels
.push_back(
c
);
138
}
139
140
// ROC Trailer (1 word)
141
142
word = bs[
m_wordCount
++];
143
144
m_checksum
=
Muon::nsw::helper::get_bits
(word,
Muon::nsw::bitMaskTrailCHECKSUM
,
Muon::nsw::bitPosTrailCHECKSUM
);
145
m_nhitsTrail
=
Muon::nsw::helper::get_bits
(word,
Muon::nsw::bitMaskTrailLENGTH
,
Muon::nsw::bitPosTrailLENGTH
);
146
m_l0Id
=
Muon::nsw::helper::get_bits
(word,
Muon::nsw::bitMaskTrailL0ID
,
Muon::nsw::bitPosTrailL0ID
);
147
m_flagMiss
=
Muon::nsw::helper::get_bits
(word,
Muon::nsw::bitMaskTrailFLAGMISS
,
Muon::nsw::bitPosTrailFLAGMISS
);
148
m_tout
=
Muon::nsw::helper::get_bits
(word,
Muon::nsw::bitMaskTrailTO
,
Muon::nsw::bitPosTrailTO
);
149
m_extended
=
Muon::nsw::helper::get_bits
(word,
Muon::nsw::bitMaskTrailEXTENDED
,
Muon::nsw::bitPosTrailEXTENDED
);
150
151
ERS_DEBUG (2,
"ROC TRAILER: EXTENDED = "
<<
m_extended
<<
" | TIMEOUT = "
<<
m_tout
<< std::hex <<
152
" | FLAGMISS = 0x"
<<
m_flagMiss
<< std::dec <<
" | L0ID = "
<<
m_l0Id
<<
" | NHITS = "
<<
m_nhits
<<
153
" | CHECKSUM = 0x"
<< std::hex <<
static_cast <
unsigned
int
>
(
m_checksum
) << std::dec);
154
ERS_DEBUG (2,
"PACKET CHECKSUM = "
<<
m_running_checksum
);
155
}
156
}
157
158
Muon::nsw::NSWElink::~NSWElink
()
159
{
160
for
(
auto
i
= m_channels.begin ();
i
!= m_channels.end (); ++
i
)
161
delete
*
i
;
162
163
delete
m_elinkId;
164
}
165
Muon::nsw::bitMaskSRocORBIT
@ bitMaskSRocORBIT
Definition:
NSWDecodeBitmaps.h:57
AllowedVariables::e
e
Definition:
AsgElectronSelectorTool.cxx:37
Muon::nsw::bitMaskSRocNULL
@ bitMaskSRocNULL
Definition:
NSWDecodeBitmaps.h:58
Muon::nsw::bitPosTrailTO
@ bitPosTrailTO
Definition:
NSWDecodeBitmaps.h:109
python.SystemOfUnits.s
int s
Definition:
SystemOfUnits.py:131
Muon::nsw::bitMaskFlxLENGTH
@ bitMaskFlxLENGTH
Definition:
NSWDecodeBitmaps.h:48
Muon::nsw::NSWElink::m_packet_status
unsigned int m_packet_status
Definition:
NSWElink.h:67
Muon::nsw::NSWElink::m_running_checksum
unsigned int m_running_checksum
Definition:
NSWElink.h:66
Muon::nsw::bitPosFlxLENGTH
@ bitPosFlxLENGTH
Definition:
NSWDecodeBitmaps.h:82
xAOD::uint8_t
uint8_t
Definition:
Muon_v1.cxx:557
Muon::nsw::bitMaskSRocNullL1ID
@ bitMaskSRocNullL1ID
Definition:
NSWDecodeBitmaps.h:53
xAOD::uint32_t
setEventNumber uint32_t
Definition:
EventInfo_v1.cxx:127
Muon::nsw::bitMaskTrailL0ID
@ bitMaskTrailL0ID
Definition:
NSWDecodeBitmaps.h:73
Muon::nsw::bitMaskSRocL1ID
@ bitMaskSRocL1ID
Definition:
NSWDecodeBitmaps.h:55
Muon::nsw::bitMaskSRocBCID
@ bitMaskSRocBCID
Definition:
NSWDecodeBitmaps.h:56
Muon::nsw::bitPosSRocL1ID
@ bitPosSRocL1ID
Definition:
NSWDecodeBitmaps.h:89
NSWElink.h
Muon::nsw::bitPosTrailLENGTH
@ bitPosTrailLENGTH
Definition:
NSWDecodeBitmaps.h:106
Muon::nsw::bitPosSRocBCID
@ bitPosSRocBCID
Definition:
NSWDecodeBitmaps.h:90
Muon::nsw::bitPosTrailL0ID
@ bitPosTrailL0ID
Definition:
NSWDecodeBitmaps.h:107
Muon::nsw::bitPosTrailEXTENDED
@ bitPosTrailEXTENDED
Definition:
NSWDecodeBitmaps.h:110
Muon::nsw::NSWElink::test_checksum
unsigned int test_checksum(const uint8_t *buffer, unsigned int buflen)
Definition:
NSWElink.h:93
Muon::nsw::bitPosSRocNOTDC
@ bitPosSRocNOTDC
Definition:
NSWDecodeBitmaps.h:93
Muon::nsw::bitPosSRocNullID
@ bitPosSRocNullID
Definition:
NSWDecodeBitmaps.h:88
Muon::nsw::bitPosSRocNULL
@ bitPosSRocNULL
Definition:
NSWDecodeBitmaps.h:92
Muon::nsw::NSWElink::m_tout
bool m_tout
Definition:
NSWElink.h:71
Muon::nsw::NSWElink::NSWElink
NSWElink(const uint32_t *bs, uint32_t remaining)
Definition:
NSWElink.cxx:19
NSWDecodeBitmaps.h
Muon::nsw::bitPosTrailCHECKSUM
@ bitPosTrailCHECKSUM
Definition:
NSWDecodeBitmaps.h:105
Muon::nsw::helper::get_bits
uint32_t get_bits(uint32_t word, uint32_t mask, uint8_t position)
Definition:
NSWDecodeHelper.h:168
Muon::nsw::NSWElink::m_rocId
uint16_t m_rocId
Definition:
NSWElink.h:77
Muon::nsw::bitPosSRocNullL1ID
@ bitPosSRocNullL1ID
Definition:
NSWDecodeBitmaps.h:87
Muon::nsw::NSWElink::m_l1Id
uint16_t m_l1Id
Definition:
NSWElink.h:76
Muon::nsw::bitMaskSRocNullID
@ bitMaskSRocNullID
Definition:
NSWDecodeBitmaps.h:54
python.utils.AtlRunQueryDQUtils.p
p
Definition:
AtlRunQueryDQUtils.py:210
Muon::nsw::NSWElink::s_null_packet_length
static const unsigned int s_null_packet_length
Definition:
NSWElink.h:88
Muon::nsw::bitMaskTrailEXTENDED
@ bitMaskTrailEXTENDED
Definition:
NSWDecodeBitmaps.h:76
Muon::nsw::NSWElink::m_elinkWord
uint32_t m_elinkWord
Definition:
NSWElink.h:84
Muon::nsw::bitPosFlxSTATUS
@ bitPosFlxSTATUS
Definition:
NSWDecodeBitmaps.h:83
lumiFormat.i
int i
Definition:
lumiFormat.py:85
Muon::nsw::NSWElink::m_wordCount
unsigned int m_wordCount
Definition:
NSWElink.h:64
Muon::nsw::bitMaskTrailLENGTH
@ bitMaskTrailLENGTH
Definition:
NSWDecodeBitmaps.h:72
Muon::nsw::NSWElink::m_elinkId
Muon::nsw::NSWResourceId * m_elinkId
Definition:
NSWElink.h:85
Muon::nsw::NSWElink::m_l0Id
uint16_t m_l0Id
Definition:
NSWElink.h:81
Muon::nsw::NSWElink::m_nhitsTrail
uint16_t m_nhitsTrail
Definition:
NSWElink.h:80
VMMChannel.h
Muon::nsw::NSWResourceId
Definition:
NSWResourceId.h:42
Muon::nsw::bitMaskTrailCHECKSUM
@ bitMaskTrailCHECKSUM
Definition:
NSWDecodeBitmaps.h:71
Muon::nsw::VMMChannel
Definition:
VMMChannel.h:16
Muon::nsw::NSWElinkROCHeaderException
NSWElinkROCHeaderException
Definition:
NSWDecodeExceptions.h:21
Muon::nsw::bitMaskFlxSTATUS
@ bitMaskFlxSTATUS
Definition:
NSWDecodeBitmaps.h:49
Muon::nsw::NSWElink::m_flagMiss
uint16_t m_flagMiss
Definition:
NSWElink.h:82
NSWDecodeHelper.h
Muon::nsw::NSWElink::m_orbit
uint16_t m_orbit
Definition:
NSWElink.h:79
NSWDecodeExceptions.h
Muon::nsw::bitMaskSRocNOTDC
@ bitMaskSRocNOTDC
Definition:
NSWDecodeBitmaps.h:59
NSWResourceId.h
Muon::nsw::bitMaskTrailTO
@ bitMaskTrailTO
Definition:
NSWDecodeBitmaps.h:75
Muon::nsw::NSWElink::m_channels
std::vector< Muon::nsw::VMMChannel * > m_channels
Definition:
NSWElink.h:86
Muon::nsw::bitPosSRocORBIT
@ bitPosSRocORBIT
Definition:
NSWDecodeBitmaps.h:91
Muon::nsw::NSWElink::m_extended
bool m_extended
Definition:
NSWElink.h:72
Muon::nsw::NSWElink::m_isNull
bool m_isNull
Definition:
NSWElink.h:69
Muon::nsw::bitPosTrailFLAGMISS
@ bitPosTrailFLAGMISS
Definition:
NSWDecodeBitmaps.h:108
Muon::nsw::NSWElink::m_checksum
uint8_t m_checksum
Definition:
NSWElink.h:74
Muon::nsw::NSWElink::m_noTdc
bool m_noTdc
Definition:
NSWElink.h:70
Muon::nsw::NSWElink::m_nhits
unsigned int m_nhits
Definition:
NSWElink.h:65
python.compressB64.c
def c
Definition:
compressB64.py:93
Muon::nsw::NSWElink::~NSWElink
virtual ~NSWElink()
Definition:
NSWElink.cxx:158
Muon::nsw::bitMaskTrailFLAGMISS
@ bitMaskTrailFLAGMISS
Definition:
NSWDecodeBitmaps.h:74
Muon::nsw::NSWElink::m_bcId
uint16_t m_bcId
Definition:
NSWElink.h:78
Generated on Mon Dec 23 2024 21:15:53 for ATLAS Offline Software by
1.8.18