ATLAS Offline Software
Loading...
Searching...
No Matches
T_TilePoolContainerCnv.h
Go to the documentation of this file.
1
2
3/*
4 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
5*/
6
7// T_TilePoolContainerCnv.h
8// Base class for Tile converters
9// Author: Alexander Solodkov <Sanya.Solodkov@cern.ch>
10// Date: June 2009
12#ifndef TILETPCNV_T_TILEPOOLCONTAINERCNV_H
13#define TILETPCNV_T_TILEPOOLCONTAINERCNV_H
14
23
24#include <GaudiKernel/IMessageSvc.h>
25#include <GaudiKernel/MsgStream.h>
26#include <algorithm>
27#include <unordered_map>
28#include <vector>
29#include <inttypes.h>
30
31template<class TRANS, class PERS, class CONV>
33public:
36
37 typedef typename PERS::ElemVector pers_ElemVector;
38 typedef typename PERS::const_iterator pers_const_iterator;
39 typedef typename SelectAllObject<TRANS>::const_iterator trans_const_iterator;
40 using Collection = typename TRANS::IDENTIFIABLE;
41
43
50 virtual void persToTrans(const PERS* pers, TRANS* trans, MsgStream &log) const override
51 {
52
53 const std::vector<unsigned int>& param = pers->getParam();
54 const pers_ElemVector& vec = pers->getVector();
55
56 unsigned int pers_type = (param.size()>0) ? param[0] : 0;
57 int hashType = pers_type & 0xF;
58 int type = (pers_type >> 4) & 0xF;
59 int unit = (pers_type >> 8) & 0xF;
60 uint32_t bsflags = pers_type & 0xFFFFF000;
61 if (hashType == 0xF) hashType = TileFragHash::Beam;
62 if (type == 0xF) type = TileFragHash::Beam;
63
64 log << MSG::DEBUG << MSG::hex << "pers_type= 0x" << pers_type
65 << " - " << bsflags << " " << unit << " " << type << " " << hashType
66 << MSG::dec << " Nelements= " << vec.size() << endmsg;
67
68 trans->cleanup(); // remove all collections
69
70 if ( trans->get_hashType() != hashType ) {
71 log << MSG::DEBUG << "Pers hash type " << hashType
72 << " does not match Trans hash type " << trans->get_hashType()
73 << " ==> reinitializing hash " << endmsg;
74
75 trans->initialize(false,(TileFragHash::TYPE)hashType);
76 }
77
78 trans->set_unit((TileRawChannelUnit::UNIT)unit);
79 trans->set_type((TileFragHash::TYPE)type);
80 trans->set_bsflags(bsflags);
81
82
83 auto mutableContainer = std::make_unique<TileMutableDataContainer<TRANS>>();
84 if (mutableContainer->status().isFailure()) {
85 throw std::runtime_error("Failed to initialize Tile mutable Container");
86 }
87
88 for( pers_const_iterator it = vec.begin(), iEnd = vec.end(); it != iEnd; ++it) {
89 if (mutableContainer->push_back(m_elementCnv.createTransientConst(&(*it), log)).isFailure()) {
90 throw std::runtime_error("Failed to add Tile element to Collection");
91 }
92 }
93
94 std::vector<IdentifierHash> hashes = mutableContainer->GetAllCurrentHashes();
95
96 if constexpr (std::is_same_v<TRANS, TileRawChannelContainer> ) {
97 int paramSize = param.size();
98 if (paramSize > 1) {
99 int firstHashPosition = 1;
100 unsigned int goodBCID = 0xDEAD;
101 if (((paramSize - 2) % 5) == 0) {
102 // Not default BCID is saved
103 goodBCID = param[1];
104 firstHashPosition = 2;
105 }
106 if (goodBCID != 0xDEAD) {
107 for (const IdentifierHash& hash : hashes) {
108 TileRawChannelCollection* rawChannelCollection = mutableContainer->indexFindPtr(hash);
109 rawChannelCollection->setFragDSPBCID(goodBCID);
110 }
111 }
112 // 5 elements per module (collection hash, DSP BCID, BCID, global CRC, memory parity)
113 int lastHashPosition = paramSize - 5;
114 for (int i = firstHashPosition; i <= lastHashPosition; ++i) {
115 TileRawChannelCollection* rawChannelCollection = mutableContainer->indexFindPtr(param[i]);
116 if (!rawChannelCollection) {
117 i += 4;
118 continue;
119 }
120 rawChannelCollection->setFragDSPBCID(param[++i]);
121 rawChannelCollection->setFragBCID(param[++i]);
122 rawChannelCollection->setFragGlobalCRC(param[++i]);
123 rawChannelCollection->setFragMemoryPar(param[++i]);
124 }
125 }
126 }
127
128 for (const IdentifierHash& hash : hashes) {
129 Collection* coll = mutableContainer->indexFindPtr(hash);
130 auto newColl = std::make_unique<Collection>(std::move(*coll));
131 if (trans->addOrDelete(std::move(newColl), hash).isFailure()) {
132 throw std::runtime_error("Failed to add Tile collection to Identifiable Container");
133 }
134 }
135
136 }
137
144 virtual void transToPers(const TRANS* trans, PERS* pers, MsgStream &log) const override
145 {
146
147 pers->clear();
148 pers->reserve(1, 12288);
149
150 unsigned int pers_type = ((trans->get_hashType() & 0xF) |
151 ((trans->get_type() & 0xF)<<4) |
152 ((trans->get_unit() & 0xF)<<8) |
153 (trans->get_bsflags() & 0xFFFFF000) ) ;
154 pers->push_back_param(pers_type);
155
156 if constexpr (std::is_same_v<TRANS, TileRawChannelContainer> ) {
157 if ((trans->get_type() == TileFragHash::OptFilterDsp) && !trans->empty()) {
158
159 std::unordered_map<unsigned int, int> bcidFreequency;
160 std::vector<IdentifierHash> hashes = trans->GetAllCurrentHashes();
161 for (const IdentifierHash& hash : hashes) {
162 const TileRawChannelCollection* rawChannelCollection = trans->indexFindPtr(hash);
163 ++bcidFreequency[rawChannelCollection->getFragDSPBCID()];
164 }
165
166 unsigned int goodBCID = (*std::max_element(bcidFreequency.begin(), bcidFreequency.end(),
167 [] (const auto& bcidAndFreequency1, const auto& bcidAndFreequency2) {
168 return bcidAndFreequency1.second < bcidAndFreequency2.second;
169 })).first;
170
171 if (goodBCID != 0xDEAD) { // Do not store default BCID
172 pers->push_back_param(goodBCID);
173 }
174
175 for (const IdentifierHash& hash : hashes) {
176 const TileRawChannelCollection* rawChannelCollection = trans->indexFindPtr(hash);
177
178 int frag = rawChannelCollection->identify();
179 bool extendedBarrel = (frag > 0x2ff);
180 bool specialModule = (frag == 0x30e || frag == 0x411); // EBA15 or EBC18
181
182 unsigned int existingDMUmask = (~(specialModule ? 0xC301 : (extendedBarrel ? 0xC300 : 0))) & 0xFFFF;
183
184 unsigned int feDMUmask = rawChannelCollection->getFragFEChipMask();
185 if (extendedBarrel) { // EBA or EBC
186 if (specialModule) feDMUmask <<= 1; // Shift by one DMU in EBA15 EBC18
187 feDMUmask = (feDMUmask & 0xFF) | ((feDMUmask & 0xF00) << 2); // Shift upper half by two DMUs
188 }
189
190 // Pack all other errors into fragment memory parity
191 unsigned int fragMemoryParity = ((rawChannelCollection->getFragMemoryPar()
192 | rawChannelCollection->getFragHeaderBit()
193 | rawChannelCollection->getFragHeaderPar()
194 | rawChannelCollection->getFragSampleBit()
195 | rawChannelCollection->getFragSamplePar()
196 | ((feDMUmask & rawChannelCollection->getFragRODChipMask()) ^ 0xFFFF)) // These masks are reverted
197 & existingDMUmask);
198
199 unsigned int fragBCID = rawChannelCollection->getFragBCID() & existingDMUmask;
200 if (rawChannelCollection->getFragDSPBCID() != goodBCID
201 || fragBCID
202 || rawChannelCollection->getFragGlobalCRC()
203 || fragMemoryParity) {
204
205 pers->push_back_param(hash);
206 pers->push_back_param(rawChannelCollection->getFragDSPBCID());
207 pers->push_back_param(rawChannelCollection->getFragBCID() & existingDMUmask);
208 pers->push_back_param(rawChannelCollection->getFragGlobalCRC());
209 pers->push_back_param(fragMemoryParity);
210 }
211 }
212 }
213 }
214
215 SelectAllObject<TRANS> selAll(trans);
216 for(trans_const_iterator it = selAll.begin(),
217 iEnd = selAll.end();
218 it != iEnd; ++it) {
219 m_elementCnv.transToPers((*it), pers->newElem(), log);
220 }
221
222 log << MSG::DEBUG << MSG::hex << "pers_type= 0x" << pers_type
223 << " - " << (trans->get_bsflags()>>12)
224 << " " << trans->get_unit()
225 << " " << trans->get_type()
226 << " " << trans->get_hashType()
227 << MSG::dec << " Nelements= " << pers->getVector().size() << endmsg;
228 }
229
230private:
233};
234
235#endif
const PlainObject unit() const
This is a plugin that makes Eigen look like CLHEP & defines some convenience methods.
#define endmsg
std::vector< size_t > vec
RpcSectorLogicContainer_p1 PERS
SelectAllObjectMT< DCC, OBJECT > SelectAllObject
TPConverterConstBase< TRANS, PERS > T_AthenaPoolTPCnvConstBase
Helper for holding non-const raw data prior to recording in SG.
This is a "hash" representation of an Identifier.
const_iterator end()
const_iterator begin()
virtual void transToPers(const TRANS *trans, PERS *pers, MsgStream &log) const override
Converts vector of TRANS::value_type objects to vector of PERS::value_type objects,...
PERS::const_iterator pers_const_iterator
SelectAllObject< TRANS >::const_iterator trans_const_iterator
virtual void persToTrans(const PERS *pers, TRANS *trans, MsgStream &log) const override
Converts vector of PERS::value_type objects to vector of TRANS::value_type objects,...
typename TRANS::IDENTIFIABLE Collection
TYPE
initialize
void setFragGlobalCRC(uint32_t globalcrc)
Various set methods.
uint32_t getFragGlobalCRC() const
Various get methods.
void setFragMemoryPar(uint32_t memorypar)