Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
T_TilePoolContainerCnv.h
Go to the documentation of this file.
1 
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 
31 template<class TRANS, class PERS, class CONV>
33 public:
36 
37  typedef typename PERS::ElemVector pers_ElemVector;
38  typedef typename PERS::const_iterator pers_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 += 5;
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 ) {
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 
230 private:
233 };
234 
235 #endif
python.root_lsr_rank.hashes
hashes
Definition: root_lsr_rank.py:34
TileRawChannelCollection.h
TileRawDataContainer.h
SelectAllObjectMT::end
const_iterator end()
Definition: SelectAllObjectMT.h:131
TileRawChannelCollection::getFragSampleBit
uint32_t getFragSampleBit() const
Definition: TileRawChannelCollection.h:105
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
T_TilePoolContainerCnv::persToTrans
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,...
Definition: T_TilePoolContainerCnv.h:50
TileRawChannelCollection::getFragHeaderPar
uint32_t getFragHeaderPar() const
Definition: TileRawChannelCollection.h:104
TileRawChannelCollection::setFragGlobalCRC
void setFragGlobalCRC(uint32_t globalcrc)
Various set methods.
Definition: TileRawChannelCollection.h:81
TileFragHash::TYPE
TYPE
initialize
Definition: TileFragHash.h:33
skel.it
it
Definition: skel.GENtoEVGEN.py:407
TileFragHash.h
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:9
TileFragHash::OptFilterDsp
@ OptFilterDsp
Definition: TileFragHash.h:34
TileRawChannelCollection::getFragBCID
uint32_t getFragBCID() const
Definition: TileRawChannelCollection.h:99
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
T_TilePoolContainerCnv::pers_const_iterator
PERS::const_iterator pers_const_iterator
Definition: T_TilePoolContainerCnv.h:38
TileRawChannelContainer.h
TileRawChannelCollection::getFragMemoryPar
uint32_t getFragMemoryPar() const
Definition: TileRawChannelCollection.h:100
SelectAllObjectMT::begin
const_iterator begin()
Definition: SelectAllObjectMT.h:115
T_TilePoolContainerCnv::m_elementCnv
CONV m_elementCnv
TP converter used for vector elements.
Definition: T_TilePoolContainerCnv.h:232
SelectAllObjectMT
Definition: SelectAllObjectMT.h:11
T_TilePoolContainerCnv::Collection
typename TRANS::IDENTIFIABLE Collection
Definition: T_TilePoolContainerCnv.h:40
lumiFormat.i
int i
Definition: lumiFormat.py:85
T_TilePoolContainerCnv::trans_const_iterator
SelectAllObject< TRANS >::const_iterator trans_const_iterator
Definition: T_TilePoolContainerCnv.h:39
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
T_AthenaPoolTPConverter.h
TileMutableDataContainer.h
Helper for holding non-const raw data prior to recording in SG.
SelectAllObjectMT::const_iterator
Definition: SelectAllObjectMT.h:22
TileRawChannelUnit::UNIT
UNIT
Definition: TileRawChannelUnit.h:16
TileFragHash::Beam
@ Beam
Definition: TileFragHash.h:33
TileRawDataCollection::identify
ID identify() const
Definition: TileRawDataCollection.h:71
TileRawChannelCollection::setFragDSPBCID
void setFragDSPBCID(uint32_t bcid)
Definition: TileRawChannelCollection.h:82
IdentifierHash.h
TileRawChannelCollection
Definition: TileRawChannelCollection.h:12
RpcSectorLogicContainer_p1
Class to represent.
Definition: RpcSectorLogicContainer_p1.h:19
TileRawChannelCollection::getFragRODChipMask
uint32_t getFragRODChipMask() const
Definition: TileRawChannelCollection.h:108
T_TilePoolContainerCnv::pers_ElemVector
PERS::ElemVector pers_ElemVector
Definition: T_TilePoolContainerCnv.h:37
T_TilePoolContainerCnv::transToPers
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,...
Definition: T_TilePoolContainerCnv.h:144
TileRawChannelCollection::getFragHeaderBit
uint32_t getFragHeaderBit() const
Definition: TileRawChannelCollection.h:103
T_TilePoolContainerCnv::T_TilePoolContainerCnv
T_TilePoolContainerCnv()
Definition: T_TilePoolContainerCnv.h:42
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
unit
const PlainObject unit() const
This is a plugin that makes Eigen look like CLHEP & defines some convenience methods.
Definition: AmgMatrixBasePlugin.h:21
DeMoScan.first
bool first
Definition: DeMoScan.py:536
DEBUG
#define DEBUG
Definition: page_access.h:11
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
TileRawChannelCollection::getFragSamplePar
uint32_t getFragSamplePar() const
Definition: TileRawChannelCollection.h:106
T_TilePoolContainerCnv
Definition: T_TilePoolContainerCnv.h:32
TileRawChannelCollection::getFragFEChipMask
uint32_t getFragFEChipMask() const
Definition: TileRawChannelCollection.h:107
SelectAllObject.h
TileRawChannelCollection::getFragGlobalCRC
uint32_t getFragGlobalCRC() const
Various get methods.
Definition: TileRawChannelCollection.h:97
IdentifierHash
This is a "hash" representation of an Identifier. This encodes a 32 bit index which can be used to lo...
Definition: IdentifierHash.h:25
TPConverterConstBase
Definition: TPConverter.h:776
TileRawChannelCollection::getFragDSPBCID
uint32_t getFragDSPBCID() const
Definition: TileRawChannelCollection.h:98
TileRawChannelCollection::setFragMemoryPar
void setFragMemoryPar(uint32_t memorypar)
Definition: TileRawChannelCollection.h:84
TileRawChannelCollection::setFragBCID
void setFragBCID(uint32_t bcid)
Definition: TileRawChannelCollection.h:83