ATLAS Offline Software
Loading...
Searching...
No Matches
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
18
20
24
28 m_hid2re = hid2re;
29}
30
34 m_vRpcPad.push_back(rc);
35}
36
40 m_vRpcPad.erase(m_vRpcPad.begin(), m_vRpcPad.end());
41}
42
46
47void 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
162void 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
175uint32_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}
const boost::regex re(r_e)
static Double_t rc
unsigned short int ubit16
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
ubit16 makeBody(ubit16 *inputData)
ubit16 makeHeader(ubit16 *inputData)
ubit16 makeFooter(ubit16 inputData)
ubit16 makeFooter(ubit16 errorCode)
ubit16 makeHeader(ubit16 *inputData)
RODword getHeaderSize()
RODword getSourceID(ubit16 subsystem, ubit16 RODID)
RODword getFormatVersion()
RODword getHeaderMarker()
ubit16 makeHeader(ubit16 *inputData)
ubit16 makeFooter(ubit16 errorCode)
ubit16 crc() const
ubit16 fel1Id() const
ubit16 onlineId() const
ubit16 bcid() const
ubit16 thr() const
ubit16 channel() const
ubit16 ovl() const
ubit16 ijk() const
ubit16 time() const
ubit16 onlineId() const
Definition RpcPad.h:107
ubit16 status() const
Definition RpcPad.h:105
std::vector< const RpcPad * > m_vRpcPad
static uint32_t set32bits(const unsigned short int *v16, const unsigned short int *pos, const unsigned short int n)
void clear()
clear the current pad list
RpcROD_Encoder()
constructor
const RPC_Hid2RESrcID * m_hid2re
void add(const RpcPad *rc)
add Rpc pads to the current list
void packFragments(const std::vector< uint16_t > &v16, std::vector< uint32_t > &v, int n) const
void set(const RPC_Hid2RESrcID *hid2re)
initialize the map
~RpcROD_Encoder()
destructor
void fillROD(std::vector< uint32_t > &v)
convert all pad in the current list to a vector of 32bit words