15 #include "Identifier/Identifier.h"
22 const int formatter{
static_cast<int>((fibre/12) & 0x7)};
23 const int linkNum{
static_cast<int>((fibre - (
formatter*12)) & 0xF)};
24 const int rodLink{(
formatter << 4) | linkNum};
27 bool isOdd(
const int someNumber)
29 return static_cast<bool>(someNumber & 1);
32 bool isEven(
const int someNumber)
34 return not isOdd(someNumber);
37 bool swappedCable(
const int moduleSide,
const int linkNumber)
39 return isOdd(linkNumber) ? (moduleSide==0) : (moduleSide==1);
46 const IInterface*
parent) :
74 if (sctDetElement->swapPhiReadoutDirection()) {
79 return StatusCode::SUCCESS;
86 return StatusCode::SUCCESS;
92 const std::vector<const SCT_RDORawData*>& vecRDOs)
const
95 const EventContext& ctx{Gaudi::Hive::currentContext()};
96 const std::set<IdentifierHash> timeOutErrors{
m_bsErrTool->getErrorSet(SCT_ByteStreamErrors::TimeOutError,ctx)};
97 const std::set<IdentifierHash> lvl1IDErrors{
m_bsErrTool->getErrorSet(SCT_ByteStreamErrors::LVL1IDError,ctx)};
99 const std::set<IdentifierHash> preambleErrors{
m_bsErrTool->getErrorSet(SCT_ByteStreamErrors::PreambleError,ctx)};
100 const std::set<IdentifierHash> formatterErrors{
m_bsErrTool->getErrorSet(SCT_ByteStreamErrors::FormatterError,ctx)};
101 const std::set<IdentifierHash> trailerErrors{
m_bsErrTool->getErrorSet(SCT_ByteStreamErrors::TrailerError,ctx)};
102 const std::set<IdentifierHash> headerTrailerErrors{
m_bsErrTool->getErrorSet(SCT_ByteStreamErrors::HeaderTrailerLimitError,ctx)};
103 const std::set<IdentifierHash> trailerOverflowErrors{
m_bsErrTool->getErrorSet(SCT_ByteStreamErrors::TrailerOverflowError,ctx)};
104 const std::set<IdentifierHash> abcdErrors{
m_bsErrTool->getErrorSet(SCT_ByteStreamErrors::ABCDError,ctx)};
105 const std::set<IdentifierHash> rawErrors{
m_bsErrTool->getErrorSet(SCT_ByteStreamErrors::RawError,ctx)};
107 std::vector<uint16_t> vec16Data;
123 std::vector<bool> vec_isDuplicated(vecRDOs.size(),
false);
126 for (
unsigned int iRDO1{0}; iRDO1<vecRDOs.size(); iRDO1++) {
128 if (rdo1 ==
nullptr) {
130 vec_isDuplicated.at(iRDO1) =
true;
135 for (
unsigned int iRDO2{0}; iRDO2<iRDO1; iRDO2++) {
137 if (vec_isDuplicated.at(iRDO2))
continue;
139 if (rdo1->identify() == rdo2->identify()) {
141 if (rdo1->getGroupSize() >= rdo2->getGroupSize()) {
142 vec_isDuplicated.at(iRDO2) =
true;
145 vec_isDuplicated.at(iRDO1) =
true;
152 std::vector<int> vecTimeBins;
158 bool firstInROD{
true};
162 for (
unsigned int iRDO{0}; iRDO<vecRDOs.size(); iRDO++) {
164 if (vec_isDuplicated.at(iRDO))
continue;
167 if (
header != lastHeader) {
168 if (not firstInROD) {
169 vec16Data.push_back(lastTrailer);
172 vec16Data.push_back(
header);
178 groupSize = rdo->getGroupSize();
179 if (groupSize == 1) {
180 const int constGroupSize{1};
181 const int constStrip{
strip};
182 encodeData(vecTimeBins, vec16Data, rdo, constGroupSize, constStrip);
186 const int chipFirst{
strip/128};
187 const int chipLast{(
strip+groupSize-1)/128};
189 for (
int chip{chipFirst}; chip<=chipLast; chip++) {
190 int tmpGroupSize = 0;
191 if (chipFirst == chipLast) tmpGroupSize = groupSize;
192 else if (chip == chipLast) tmpGroupSize =
strip+groupSize-chip*128;
193 else if (chip == chipFirst) tmpGroupSize = (chip+1)*128-
strip;
194 else tmpGroupSize = 128;
195 const int tmpStrip1{chip==chipFirst ?
strip : 128*chip};
197 const int numPairedRDO{tmpGroupSize/2};
198 for (
int i =0;
i<numPairedRDO;
i++) {
199 const int constGroupSize{2};
200 const int constStrip{tmpStrip1+ (2*
i)};
201 encodeData(vecTimeBins, vec16Data, rdo, constGroupSize, constStrip);
203 if ((tmpGroupSize != 0) and isOdd(tmpGroupSize)) {
204 const int constGroupSize{1};
205 const int constStrip{tmpStrip1+ (tmpGroupSize - 1)};
206 encodeData(vecTimeBins, vec16Data, rdo, constGroupSize, constStrip);
218 groupSize = rdo->getGroupSize();
220 for (
int t{0};
t < groupSize;
t++) {
221 vecTimeBins.push_back(timeBin);
224 const int constStrip{
getStrip(rdo)};
225 const int constGroupSize{rdo->getGroupSize()};
226 encodeData(vecTimeBins, vec16Data, rdo, constGroupSize, constStrip);
231 if ((not firstInROD) and (lastTrailer != 0)) {
232 vec16Data.push_back(lastTrailer);
244 const SCT_RDORawData* rdo,
const int& groupSize,
const int& strip)
const
246 const int encodedSide{
side(rdo) << 14};
251 tmpStrip= 767 - tmpStrip;
252 tmpStrip= tmpStrip-(groupSize-1);
255 const int chipNum{((tmpStrip/128) & 0x7) << 11};
256 const int clustBaseAddr{((tmpStrip-(chipNum*128)) & 0x7F) << 4};
259 int firstHitErr{0 << 2};
260 int secondHitErr{0 << 3};
263 if (rdoCosmic !=
nullptr) {
265 firstHitErr = ((rdoCosmic)->FirstHitError()) << 2;
266 secondHitErr = ((rdoCosmic)->SecondHitError()) << 3;
270 if (groupSize == 1) {
271 const uint16_t hitCondSingle{
static_cast<uint16_t>(0x8000 | encodedSide | chipNum | clustBaseAddr | firstHitErr)};
272 vec16Words.push_back(hitCondSingle);
274 else if (groupSize == 2) {
275 const uint16_t hitCondPaired{
static_cast<uint16_t>(0x8001 | encodedSide | chipNum | clustBaseAddr | secondHitErr | firstHitErr)};
276 vec16Words.push_back(hitCondPaired);
281 const int numEven{
static_cast<int>((vecTimeBins.size() - 1)/2)};
284 const uint16_t hitExpFirst{
static_cast<uint16_t>(0x8000 | encodedSide | chipNum | clustBaseAddr | timeBin)};
285 vec16Words.push_back(hitExpFirst);
288 for (
int i{1};
i<=numEven;
i++) {
289 const uint16_t hitExpEven{
static_cast<uint16_t>(0x8088 | ((vecTimeBins[(2*
i-1)] & 0xF) << 4) | (vecTimeBins[2*
i] & 0xF))};
290 vec16Words.push_back(hitExpEven);
293 if ((not vecTimeBins.empty()) and isEven(vecTimeBins.size())) {
294 const uint16_t hitExpLast{
static_cast<uint16_t>(0x8008 | (vecTimeBins[vecTimeBins.size()-1] & 0xF))};
295 vec16Words.push_back(hitExpLast);
305 std::vector<uint32_t>& vec32Words)
const
307 int num16Words{
static_cast<int>(vec16Words.size())};
308 if (isOdd(num16Words)) {
310 vec16Words.push_back(0x4000);
314 const unsigned short int numWords{2};
315 const unsigned short int position[numWords]{0, 16};
316 unsigned short int arr16Words[numWords]{0, 0};
317 for (
int i{0};
i<num16Words;
i += numWords) {
318 arr16Words[
i%numWords] = vec16Words[
i+1];
319 arr16Words[(
i+1)%numWords] = vec16Words[
i];
321 vec32Words.push_back(uint32Word);
323 ATH_MSG_INFO(
"SCT encoder -> PackFragments: Output rod 0x"<<std::hex<<uint32Word<<std::dec);
333 const unsigned short int* position,
334 const unsigned short int& numWords)
const
340 uint16Word =
static_cast<uint32_t>(*(arr16Words+
i));
342 uint32Word |= (uint16Word<<
pos);
370 return rodLinkFromOnlineID(
onlineID(rdo));
379 if (swappedCable(sctSide,linkNum)) sctSide = 1-sctSide;
387 if (rdoCosmic !=
nullptr) timeBin = rdoCosmic->
getTimeBin();
402 const int rodLink{rodLinkFromOnlineID(
m_cabling->getOnlineIdFromHash(linkHash))};
416 const ErrorWords& errType, std::vector<uint16_t>& vec16Data)
const
420 if (errROBID == robID) {
422 vec16Data.push_back(
header);
424 vec16Data.push_back(trailer);
431 const ErrorWords& errType, std::vector<uint16_t>& vec16Data)
const
435 if (errROBID == robID) {
438 vec16Data.push_back(
header);
439 vec16Data.push_back(trailer);
445 const ErrorWords& errType, std::vector<uint16_t>& vec16Data)
const
449 if (errROBID == robID) {
452 vec16Data.push_back(
header);
453 vec16Data.push_back(errType);
454 vec16Data.push_back(trailer);