ATLAS Offline Software
Loading...
Searching...
No Matches
CpmRoiSubBlockV2.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 "CpmRoiSubBlockV2.h"
9
10namespace LVL1BS {
11
12// Constant definitions
13
15
21
22
26
30
31// Clear all data
32
38
39// Store header
40
42 const int module)
43{
45}
46
47// Store RoI
48
50{
51 const LVL1::CPMTobRoI roiTemp(crate(), module(), 0, 0, 0, 0, 0);
52 if (roi.crate() == roiTemp.crate() && roi.cpm() == roiTemp.cpm()) {
53 m_roiData.resize(2*s_glinkPins);
54 const int pin = (roi.chip() << 1) |
55 ((roi.location() >> s_locationLen) & 0x1);
56 const int type = roi.type(); // em or tau (0/1)
57 m_roiData[2*pin+type] = roi;
58 }
59}
60
61// Return RoI for given chip and location (left/right) and type (em/tau)
62
63LVL1::CPMTobRoI CpmRoiSubBlockV2::roi(const int chip, const int loc,
64 const int type) const
65{
66 const int pin = (chip << 1) | (loc & 0x1);
67 if (pin < s_glinkPins && !m_roiData.empty()) return m_roiData[2*pin+type];
68 else return LVL1::CPMTobRoI(0);
69}
70
71// Packing/Unpacking routines
72
74{
75 bool rc = false;
76 switch (version()) {
77 case 2: // <<== CHECK
78 switch (format()) {
79 case NEUTRAL:
80 rc = packNeutral();
81 break;
82 default:
83 break;
84 }
85 break;
86 default:
87 break;
88 }
89 return rc;
90}
91
93{
94 bool rc = false;
95 switch (version()) {
96 case 2: // <<== CHECK
97 switch (format()) {
98 case NEUTRAL:
99 rc = unpackNeutral();
100 break;
101 default:
103 break;
104 }
105 break;
106 default:
108 break;
109 }
110 return rc;
111}
112
113// Pack neutral data
114
116{
117 m_roiData.resize(2*s_glinkPins);
118 for (int pin = 0; pin < s_glinkPins; ++pin) {
119 // RoI data
120 const int idx = 2*pin;
121 const LVL1::CPMTobRoI& roiEm(m_roiData[idx]);
122 const LVL1::CPMTobRoI& roiTau(m_roiData[idx+1]);
123 packerNeutral(pin, roiEm.energy(), s_energyLen);
124 packerNeutral(pin, roiEm.isolation(), s_isolLen);
125 packerNeutral(pin, 0, 1); //parity
126 packerNeutral(pin, roiTau.energy(), s_energyLen);
127 packerNeutral(pin, roiTau.isolation(), s_isolLen);
128 packerNeutral(pin, 0, 1); //parity
129 packerNeutral(pin, 0, 1); //error
130 packerNeutral(pin, (roiEm.location()|roiTau.location()), s_locationLen);
131 // Bunch Crossing number
132 if (pin < s_bunchCrossingBits) {
133 packerNeutral(pin, bunchCrossing() >> pin, 1);
134 } else packerNeutral(pin, 0, 1);
135 // G-Link parity
137 }
138 return true;
139}
140
141// Unpack neutral data
142
144{
145 m_roiData.resize(2*s_glinkPins);
146 int bunchCrossing = 0;
147 for (int pin = 0; pin < s_glinkPins; ++pin) {
148 // RoI data
149 const int energyEm = unpackerNeutral(pin, s_energyLen);
150 const int isolEm = unpackerNeutral(pin, s_isolLen);
151 unpackerNeutral(pin, 1); //parity
152 const int energyTau = unpackerNeutral(pin, s_energyLen);
153 const int isolTau = unpackerNeutral(pin, s_isolLen);
154 unpackerNeutral(pin, 1); //parity
155 unpackerNeutral(pin, 1); //error
156 const int loc = unpackerNeutral(pin, s_locationLen) |
157 ((pin & 0x1) << s_locationLen);
158 const int chip = pin >> 1;
159 const int idx = 2*pin;
160 m_roiData[idx] = LVL1::CPMTobRoI(crate(), module(), chip, loc, 0,
161 energyEm, isolEm);
162 m_roiData[idx+1] = LVL1::CPMTobRoI(crate(), module(), chip, loc, 1,
163 energyTau, isolTau);
164 // Bunch Crossing number
165 if (pin < s_bunchCrossingBits) {
166 bunchCrossing |= unpackerNeutral(pin, 1) << pin;
167 } else unpackerNeutral(pin, 1);
168 // G-Link parity error
170 }
172 const bool rc = unpackerSuccess();
174 return rc;
175}
176
177} // end namespace
static Double_t rc
static const int s_energyLen
bool unpackNeutral()
Unpack neutral data.
static const int s_locationLen
bool packNeutral()
Pack neutral data.
void clear()
Clear all data.
void setRoiHeader(int version, int crate, int module)
Store header.
static const int s_wordIdVal
Header word ID.
static const int s_bunchCrossingBits
static const int s_glinkPins
std::vector< LVL1::CPMTobRoI > m_roiData
RoI words.
void fillRoi(LVL1::CPMTobRoI roi)
Store RoI.
LVL1::CPMTobRoI roi(int chip, int loc, int type) const
Return RoI for given chip and location (left/right) and type (em/tau)
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 location() const
Return location (RoI local coords) (0-7)