ATLAS Offline Software
RpcROD_Encoder.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // Implementation of RpcROD_Encoder class
6 
7 #include "RpcROD_Encoder.h"
8 
9 #include <algorithm>
10 
15 
19 RpcROD_Encoder::RpcROD_Encoder() : m_hid2re(nullptr) {}
20 
24 
27 void RpcROD_Encoder::set(const RPC_Hid2RESrcID* hid2re) {
28  m_hid2re = hid2re;
29 }
30 
33 void RpcROD_Encoder::add(const RpcPad* rc) {
34  m_vRpcPad.push_back(rc);
35 }
36 
40  m_vRpcPad.erase(m_vRpcPad.begin(), m_vRpcPad.end());
41 }
42 
47 void RpcROD_Encoder::fillROD(std::vector<uint32_t>& v) {
48  if (m_vRpcPad.empty()) { return; }
49  std::vector<unsigned short int> v16;
50 
51  RPCRODStructure rodReadout;
52  RXReadOutStructure rxReadout;
53  PadReadOutStructure padReadout;
54  MatrixReadOutStructure matrixReadout;
55 
56  // first group the pads into their receivers
57 
58  typedef std::vector<const RpcPad*> receiver;
59  std::map<int, receiver> mapReceiver;
60 
61  for (const auto& pPad : m_vRpcPad) {
62  int sector = pPad->sector();
63  mapReceiver[sector].push_back(pPad);
64  }
65 
66  std::map<int, receiver>::iterator re = mapReceiver.begin();
67  std::map<int, receiver>::iterator re_end = mapReceiver.end();
68 
69  // make the header of the ROD
70  v.push_back(rodReadout.getHeaderMarker());
71  v.push_back(rodReadout.getHeaderSize());
72  v.push_back(rodReadout.getFormatVersion());
73  uint16_t side = ((*re).first < 32) ? 0 : 1;
74  uint16_t rodId = ((*re).first % 32) / 2;
75  assert(rodId <= 15);
76 
77  v.push_back(rodReadout.getSourceID(side, rodId));
78  v.push_back(0); // Level1ID
79  v.push_back(0); // BunchCrossingID
80  v.push_back(0); // Level1TriggerType
81  v.push_back(0); // DetectorEventType
82 
83  // make the body of the ROD
84  for (; re != re_end; ++re) {
85  // make the header of the receiver
86  uint16_t rxHeader[3];
87  rxHeader[0] = 0;
88  rxHeader[1] = ((*re).first % 32) % 2 << 3;
89  rxHeader[2] = 0;
90 
91  uint16_t receiverHeader = rxReadout.makeHeader(rxHeader);
92 
93  v16.push_back(receiverHeader);
94 
95  // make the receiver body
96  std::vector<const RpcPad*>::const_iterator it = (*re).second.begin();
97  std::vector<const RpcPad*>::const_iterator it_end = (*re).second.end();
98 
99  for (; it != it_end; ++it) {
100  const RpcPad* pad = (*it);
101 
102  // make the pad header
103  unsigned short int padHeader[3];
104  padHeader[0] = 0;
105  padHeader[1] = pad->onlineId();
106  padHeader[2] = pad->status();
107  v16.push_back(padReadout.makeHeader(padHeader));
108  // make the pad body:: cma header, sub-header, body, and footer
109  RpcPad::const_iterator it_cma = pad->begin();
110  RpcPad::const_iterator it_cma_end = pad->end();
111  for (; it_cma != it_cma_end; ++it_cma) {
112  const RpcCoinMatrix* cma = (*it_cma);
113  unsigned short int cmaHeader[3];
114  cmaHeader[0] = 0;
115  cmaHeader[1] = cma->onlineId();
116  cmaHeader[2] = cma->fel1Id();
117  v16.push_back(matrixReadout.makeHeader(cmaHeader));
118  v16.push_back(matrixReadout.makeSubHeader());
119  RpcCoinMatrix::const_iterator it_fCh = cma->begin();
120  RpcCoinMatrix::const_iterator it_fCh_end = cma->end();
121  for (; it_fCh != it_fCh_end; ++it_fCh) {
122  const RpcFiredChannel* firedChannel = (*it_fCh);
123  unsigned short int body[5];
124  body[0] = 0;
125  body[1] = firedChannel->bcid();
126  body[2] = firedChannel->time();
127  body[3] = firedChannel->ijk();
128 
129  if (body[3] < 7) {
130  body[4] = firedChannel->channel();
131  } else {
132  body[4] = firedChannel->thr() | ((firedChannel->ovl()) << 2);
133  }
134 
135  v16.push_back(matrixReadout.makeBody(body));
136  }
137  v16.push_back(matrixReadout.makeFooter(cma->crc()));
138  }
139 
140  // make the pad footer
141 
142  ubit16 errorCodes[6] = {0, 0, 0, 0, 0, 0};
143  v16.push_back(padReadout.makeFooter(errorCodes));
144  }
145  // make the receiver footer
146  v16.push_back(rxReadout.makeFooter((uint16_t)0));
147  } // end of receivers
148 
149  // if numbers of 16 words is odd, add 0 to make it even
150  int n16words = v16.size();
151  if (n16words % 2 == 1) {
152  v16.push_back(0);
153  n16words++;
154  }
155  packFragments(v16, v, n16words);
156 
157  // finally make the ROD footer
158  v.push_back(0); // NumberOfStatusElements
159  v.push_back(0); // NumberOfDataElements
160  v.push_back(0); }
161 
162 void RpcROD_Encoder::packFragments(const std::vector<uint16_t>& v16, std::vector<uint32_t>& v, int n) const {
163  // now merge 2 consecutive 16 bit words in 32 bit words
164  const unsigned short int nWords = 2;
165  unsigned short int position[nWords] = {0, 16};
166  unsigned short int v16words[nWords] = {0, 0};
167  for (int i = 0; i < n;) {
168  v16words[i % nWords] = v16[i];
169  v16words[(i + 1) % nWords] = v16[i + 1];
170  v.push_back(set32bits(v16words, position, nWords));
171  i += nWords;
172  }
173  }
174 
175 uint32_t RpcROD_Encoder::set32bits(const unsigned short int* v16, const unsigned short int* pos, const unsigned short int n) {
176  uint32_t v32 = 0;
177  uint32_t p = 0, v = 0;
178 
179  for (ubit16 i = 0; i < n; i++) {
180  v = (uint32_t)(*(v16 + i));
181  p = (uint32_t)(*(pos + i));
182  v32 = v32 | (v << p);
183  }
184  return v32;
185 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
MatrixReadOutStructure::makeBody
ubit16 makeBody(ubit16 *inputData)
Definition: MatrixReadOutStructure.cxx:83
RpcFiredChannel::ijk
ubit16 ijk() const
Definition: RpcFiredChannel.h:56
RpcFiredChannel::time
ubit16 time() const
Definition: RpcFiredChannel.h:54
PadReadOutStructure.h
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
RPCRODStructure.h
RPCRODStructure::getFormatVersion
RODword getFormatVersion()
Definition: RPCRODStructure.h:46
RpcFiredChannel::ovl
ubit16 ovl() const
Definition: RpcFiredChannel.h:61
RpcFiredChannel::thr
ubit16 thr() const
Definition: RpcFiredChannel.h:65
RpcCoinMatrix::crc
ubit16 crc() const
Definition: RpcCoinMatrix.h:69
MatrixReadOutStructure::makeSubHeader
ubit16 makeSubHeader()
Definition: MatrixReadOutStructure.cxx:76
PadReadOutStructure::makeHeader
ubit16 makeHeader(ubit16 *inputData)
Definition: PadReadOutStructure.cxx:74
RpcFiredChannel::channel
ubit16 channel() const
Definition: RpcFiredChannel.h:58
PadReadOutStructure
Definition: PadReadOutStructure.h:13
RpcROD_Encoder.h
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
RpcROD_Encoder::m_vRpcPad
std::vector< const RpcPad * > m_vRpcPad
Definition: RpcROD_Encoder.h:65
RpcROD_Encoder::set32bits
static uint32_t set32bits(const unsigned short int *v16, const unsigned short int *pos, const unsigned short int n)
Definition: RpcROD_Encoder.cxx:175
skel.it
it
Definition: skel.GENtoEVGEN.py:396
RpcROD_Encoder::m_hid2re
const RPC_Hid2RESrcID * m_hid2re
Definition: RpcROD_Encoder.h:64
RpcPad::status
ubit16 status() const
Definition: RpcPad.h:105
RpcCoinMatrix
Definition: RpcCoinMatrix.h:20
RpcFiredChannel
Definition: RpcFiredChannel.h:20
RPCRODStructure::getHeaderSize
RODword getHeaderSize()
Definition: RPCRODStructure.h:44
TRT::Hit::side
@ side
Definition: HitInfo.h:83
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
RpcROD_Encoder::clear
void clear()
clear the current pad list
Definition: RpcROD_Encoder.cxx:39
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:93
RXReadOutStructure::makeFooter
ubit16 makeFooter(ubit16 errorCode)
Definition: RXReadOutStructure.cxx:55
lumiFormat.i
int i
Definition: lumiFormat.py:85
beamspotman.n
n
Definition: beamspotman.py:731
RpcROD_Encoder::packFragments
void packFragments(const std::vector< uint16_t > &v16, std::vector< uint32_t > &v, int n) const
Definition: RpcROD_Encoder.cxx:162
RPCRODStructure::getSourceID
RODword getSourceID(ubit16 subsystem, ubit16 RODID)
Definition: RPCRODStructure.cxx:43
PadReadOutStructure::makeFooter
ubit16 makeFooter(ubit16 errorCode)
Definition: PadReadOutStructure.h:25
MatrixReadOutStructure::makeFooter
ubit16 makeFooter(ubit16 inputData)
Definition: MatrixReadOutStructure.cxx:100
RXReadOutStructure::makeHeader
ubit16 makeHeader(ubit16 *inputData)
Definition: RXReadOutStructure.cxx:47
RpcCoinMatrix::onlineId
ubit16 onlineId() const
Definition: RpcCoinMatrix.h:67
RpcPad::onlineId
ubit16 onlineId() const
Definition: RpcPad.h:107
RPCRODStructure
Definition: RPCRODStructure.h:16
RPC_Hid2RESrcID
Definition: RPC_Hid2RESrcID.h:16
MatrixReadOutStructure::makeHeader
ubit16 makeHeader(ubit16 *inputData)
Definition: MatrixReadOutStructure.cxx:68
MatrixReadOutStructure
Definition: MatrixReadOutStructure.h:13
RpcROD_Encoder::RpcROD_Encoder
RpcROD_Encoder()
constructor
Definition: RpcROD_Encoder.cxx:19
RpcPad
Definition: RpcPad.h:21
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
python.PyAthena.v
v
Definition: PyAthena.py:154
RpcFiredChannel::bcid
ubit16 bcid() const
Definition: RpcFiredChannel.h:52
RpcROD_Encoder::fillROD
void fillROD(std::vector< uint32_t > &v)
convert all pad in the current list to a vector of 32bit words
Definition: RpcROD_Encoder.cxx:47
RpcCoinMatrix::fel1Id
ubit16 fel1Id() const
Definition: RpcCoinMatrix.h:71
RPCRODStructure::getHeaderMarker
RODword getHeaderMarker()
Definition: RPCRODStructure.h:43
RXReadOutStructure
Definition: RXReadOutStructure.h:14
re
const boost::regex re(r_e)
MatrixReadOutStructure.h
RpcROD_Encoder::add
void add(const RpcPad *rc)
add Rpc pads to the current list
Definition: RpcROD_Encoder.cxx:33
RpcROD_Encoder::set
void set(const RPC_Hid2RESrcID *hid2re)
initialize the map
Definition: RpcROD_Encoder.cxx:27
ubit16
unsigned short int ubit16
Definition: RpcByteStreamEncoder.h:20
RXReadOutStructure.h
RpcROD_Encoder::~RpcROD_Encoder
~RpcROD_Encoder()
destructor
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.