ATLAS Offline Software
Loading...
Searching...
No Matches
JemRoiSubBlock.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
5
7
8#include "JemRoiSubBlock.h"
9
10namespace LVL1BS {
11
12// Constant definitions
13
15
24
25
29
33
34// Clear all data
35
37{
39 m_roiData.clear();
40}
41
42// Store header
43
44void JemRoiSubBlock::setRoiHeader(const int version, const int crate,
45 const int module)
46{
48}
49
50// Store RoI
51
53{
54 const LVL1::JEMRoI roiTemp(crate(), module(), 0, 0, 0, 0, 0);
55 if (roi.crate() == roiTemp.crate() && roi.jem() == roiTemp.jem()) {
56 m_roiData.resize(2*s_frames);
57 const int pos = roi.frame() + roi.forward()*s_frames;
58 m_roiData[pos] = roi;
59 }
60}
61
62// Return RoI for given frame and forward
63
64LVL1::JEMRoI JemRoiSubBlock::roi(const int frame, const int forward) const
65{
66 const int pos = frame + forward*s_frames;
67 if (pos >= 0 && pos < 2*s_frames && !m_roiData.empty()) {
68 return m_roiData[pos];
69 } else return LVL1::JEMRoI(0);
70}
71
72// Packing/Unpacking routines
73
75{
76 bool rc = false;
77 switch (version()) {
78 case 1:
79 switch (format()) {
80 case NEUTRAL:
81 rc = packNeutral();
82 break;
83 default:
84 break;
85 }
86 break;
87 default:
88 break;
89 }
90 return rc;
91}
92
94{
95 bool rc = false;
96 switch (version()) {
97 case 1:
98 switch (format()) {
99 case NEUTRAL:
100 rc = unpackNeutral();
101 break;
102 default:
104 break;
105 }
106 break;
107 default:
109 break;
110 }
111 return rc;
112}
113
114// Pack neutral data
115
117{
118 m_roiData.resize(2*s_frames);
119 int maxPin = 0;
120 // RoI data
121 for (int pos = 0; pos < 2*s_frames; ++pos) {
122 const LVL1::JEMRoI& roi(m_roiData[pos]);
123 int pin = pos/s_framesPerPin;
124 if (pin >= s_bunchCrossingPin) ++pin; // forward rois
125 packerNeutral(pin, roi.hits(), s_hitsBits);
126 packerNeutral(pin, roi.error(), s_saturationBits);
127 packerNeutral(pin, roi.location(), s_locationBits);
128 maxPin = pin;
129 }
130 // Bunch Crossing number
133 // G-Link parity
134 for (int pin = 0; pin <= maxPin; ++pin) packerNeutralParity(pin);
135
136 return true;
137}
138
139// Unpack neutral data
140
142{
143 m_roiData.resize(2*s_frames);
144 int maxPin = 0;
145 int forward = 0;
146 int parity = 0;
147 // RoI data
148 for (int pos = 0; pos < 2*s_frames; ++pos) {
149 int pin = pos/s_framesPerPin;
150 if (pin >= s_bunchCrossingPin) {
151 ++pin;
152 forward = 1;
153 }
154 const int hits = unpackerNeutral(pin, s_hitsBits);
155 const int sat = unpackerNeutral(pin, s_saturationBits);
156 const int loc = unpackerNeutral(pin, s_locationBits);
157 const int err = (parity << 1) | sat;
158 m_roiData[pos] = LVL1::JEMRoI(crate(), module(), pos%s_frames, loc,
159 forward, hits, err);
160 maxPin = pin;
161 }
162 // Bunch Crossing number
165 // G-Link parity
166 parity = 1;
167 for (int pin = 0; pin <= maxPin; ++pin) {
168 const bool error = unpackerNeutralParityError(pin);
169 if (pin == s_bunchCrossingPin) continue;
170 if (error) {
171 for (int frame = 0; frame < s_framesPerPin; ++frame) {
172 int pos = pin * s_framesPerPin + frame;
173 if (pin > s_bunchCrossingPin) pos -= s_framesPerPin;
174 const LVL1::JEMRoI roi = m_roiData[pos];
175 const int err = (parity << 1) | roi.error();
176 m_roiData[pos] = LVL1::JEMRoI(roi.crate(), roi.jem(), roi.frame(),
177 roi.location(), roi.forward(),
178 roi.hits(), err);
179 }
180 }
181 }
182 const bool rc = unpackerSuccess();
184 return rc;
185}
186
187} // end namespace
static Double_t rc
static const int s_framesPerPin
std::vector< LVL1::JEMRoI > m_roiData
RoIs.
static const int s_bunchCrossingBits
bool packNeutral()
Pack neutral data.
static const int s_hitsBits
static const int s_bunchCrossingPin
void fillRoi(LVL1::JEMRoI roi)
Store RoI.
void setRoiHeader(int version, int crate, int module)
Store header.
static const int s_paddingBits
static const int s_saturationBits
void clear()
Clear all data.
bool unpackNeutral()
Unpack neutral data.
LVL1::JEMRoI roi(int frame, int forward) const
Return RoI for given frame and forward.
static const int s_locationBits
bool unpack()
Unpack data.
static const int s_frames
static const int s_wordIdVal
Header word ID.
void setUnpackErrorCode(int code)
Set the unpacking error code.
bool unpackerSuccess() const
Return unpacker success flag.
void setHeader(int wordId, int version, int format, int seqno, int crate, int module, int slices2, int slices1)
Store header data.
bool unpackerNeutralParityError(int pin)
Unpack and test G-Link parity bit for given pin.
void clear()
Clear all data.
void packerNeutralParity(int pin)
Pack current G-Link parity bit for given pin.
uint32_t unpackerNeutral(int pin, int nbits)
Unpack given number of bits of neutral data for given pin.
int bunchCrossing() const
Return the Bunch Crossing number (neutral format only)
void packerNeutral(int pin, uint32_t datum, int nbits)
Pack given neutral data from given pin.
void setBunchCrossing(int bc)
Set the Bunch Crossing number (neutral format only)
int jem() const
Return JEM number (0-15)
int crate() const
Return crate number (0-1)