ATLAS Offline Software
Loading...
Searching...
No Matches
CaloClusterCellLinkContainerCnv_p1.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
8
9namespace {
10
11 const unsigned INDEXBITS=18;
12 const unsigned INDEXBIT_MASK = (0x1 << INDEXBITS) -1;
13 const unsigned HAS_WEIGHT_BIT=0x1 << INDEXBITS;
14
15} //anonymous namespace
16
17
18void
21 const std::string& /*key*/,
22 MsgStream& msg) const
23{
24 const size_t nClusters=pers->m_nCellsPerCluster.size();
25 size_t maxPersIdx=pers->m_indices.size();
26
27 trans->reserve(nClusters);
28 size_t persIdx=0;
29 size_t weightIdx=0;
30 for (size_t iCluster=0;iCluster<nClusters;++iCluster) {
32 m_linkCnv.persToTrans(pers->m_cellCont,link,msg);
34 trans->push_back(cccl);
35 size_t nextStep=persIdx+pers->m_nCellsPerCluster[iCluster];
36 if (nextStep > maxPersIdx) {
37 msg << MSG::ERROR << "Inconsistent persistent object: To few persistent values, expected at least " << nextStep
38 << " got only "<< maxPersIdx << endmsg;
39 nextStep=maxPersIdx;
40 }
41 cccl->reserve(nextStep-persIdx);
42 for (;persIdx<nextStep;++persIdx) {
43 const unsigned index=(pers->m_indices[persIdx] & INDEXBIT_MASK);
44 if (pers->m_indices[persIdx] & HAS_WEIGHT_BIT) {
45 cccl->addCell(index, pers->m_weights[weightIdx++]);
46 }
47 else {
48 cccl->addCell(index,1.0);
49 }
50 }//end loop over cells in cluster
51 }//end loop over clusters
52}
53
54
55void
58 const std::string& key,
59 MsgStream &msg) const
60{
62
63 const SG::ThinningDecisionBase* dec_cells = nullptr;
64 const SG::ThinningDecisionBase* dec_clusts = tcache ? tcache->thinning (key) : nullptr;
65
66 bool firstCluster = true;
67 size_t minCapacity=0;
68 const size_t nClusters=trans->size();
69 pers->m_nCellsPerCluster.reserve(nClusters);
70 size_t icluster = 0;
71 for(const CaloClusterCellLink* cccl: *trans) {
72 if (!dec_clusts || !dec_clusts->thinned (icluster)) {
73 if (firstCluster) {
74 //we assume here all clusters in a container are built from the same cell container
75 m_linkCnv.transToPers((*trans)[0]->getCellContainerLink(),pers->m_cellCont,msg);
76 if (tcache) {
77 dec_cells = SG::getThinningDecision ((*trans)[0]->getCellContainerLink().dataID());
78 }
79 firstCluster = false;
80 }
81
82 const size_t nCells=cccl->size();
83 pers->m_nCellsPerCluster.push_back(nCells);
84 minCapacity+=nCells;
85 pers->m_indices.reserve(minCapacity);
86 //pers->m_weights.reserve(minCapacity);
87 CaloClusterCellLink::const_iterator it = cccl->begin();
89 for (; it != end; ++it) {
90 unsigned ndx = it.index();
91 if (dec_cells) ndx = dec_cells->index (ndx);
92 // Don't save weights that are exactly 1.0.
93 // But the weights we save are single-precision, while the weights
94 // in the cluster are double-precision. Convert to single-precision
95 // before doing the comparision with 1.0, otherwise the contents
96 // of this object can change if we read and rewrite.
97 // See ATLASRECTS-7129.
98 float fweight = it.weight();
99 if (fweight == 1.0) { //standard weight
100 pers->m_indices.push_back(ndx & INDEXBIT_MASK);
101 }
102 else {
103 pers->m_indices.push_back((ndx & INDEXBIT_MASK) | HAS_WEIGHT_BIT);
104 pers->m_weights.push_back(fweight);
105 }
106 }//end loop over cells in cellLink object
107 }
108 ++icluster;
109 }//end loop over transient CaloClusterCellLinkContainer
110
111 return;
112}
#define endmsg
DataLinkCnv_p2< DataLink< CaloCellContainer > > m_linkCnv
virtual void transToPersWithKey(const CaloClusterCellLinkContainer *trans, CaloClusterCellLinkContainer_p1 *pers, const std::string &key, MsgStream &log) const override
Convert from transient to persistent object.
virtual void persToTransWithKey(const CaloClusterCellLinkContainer_p1 *pers, CaloClusterCellLinkContainer *trans, const std::string &key, MsgStream &log) const override
Convert from persistent to transient object.
void reserve(size_type n)
Attempt to preallocate enough memory for a specified number of elements.
value_type push_back(value_type pElem)
Add an element to the end of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
Cache thinning decisions for converters.
const ThinningDecisionBase * thinning(const std::string &key) const
Return thinning for key.
Hold thinning decisions for one container.
bool thinned(size_t ndx) const
Return true if element ndx should be thinned.
size_t index(size_t ndxOrig) const
Return the index corresponding to ndxOrig after thinning.
Helpers to retrieve the current thinning cache from the event context.
const SG::ThinningCache * getThinningCache()
Retrieve the current thinning cache from the current event context.
const SG::ThinningDecisionBase * getThinningDecision(const EventContext &ctx, const std::string &key)
Retrieve the current thinning decision for key.
Definition index.py:1
MsgStream & msg
Definition testRead.cxx:32