ATLAS Offline Software
CaloClusterCellLinkContainerCnv_p1.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
8 
9 namespace {
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 
18 void
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 
55 void
58  const std::string& key,
59  MsgStream &msg) const
60 {
61  const SG::ThinningCache* tcache = SG::getThinningCache();
62 
63  const SG::ThinningDecisionBase* dec_cells = nullptr;
64  const SG::ThinningDecisionBase* dec_clusts = tcache ? tcache->thinning (key) : nullptr;
65 
66  const size_t nClusters=trans->size();
67  if (nClusters>0) {
68  //we assume here all clusters in a container are built from the same cell container
69  m_linkCnv.transToPers((*trans)[0]->getCellContainerLink(),pers->m_cellCont,msg);
70  if (tcache) {
71  dec_cells = SG::getThinningDecision ((*trans)[0]->getCellContainerLink().dataID());
72  }
73  }
74 
75  size_t minCapacity=0;
76  pers->m_nCellsPerCluster.reserve(nClusters);
77  size_t icluster = 0;
78  for(const CaloClusterCellLink* cccl: *trans) {
79  if (!dec_clusts || !dec_clusts->thinned (icluster)) {
80  const size_t nCells=cccl->size();
81  pers->m_nCellsPerCluster.push_back(nCells);
82  minCapacity+=nCells;
83  pers->m_indices.reserve(minCapacity);
84  //pers->m_weights.reserve(minCapacity);
87  for (; it != end; ++it) {
88  unsigned ndx = it.index();
89  if (dec_cells) ndx = dec_cells->index (ndx);
90  // Don't save weights that are exactly 1.0.
91  // But the weights we save are single-precision, while the weights
92  // in the cluster are double-precision. Convert to single-precision
93  // before doing the comparision with 1.0, otherwise the contents
94  // of this object can change if we read and rewrite.
95  // See ATLASRECTS-7129.
96  float fweight = it.weight();
97  if (fweight == 1.0) { //standard weight
98  pers->m_indices.push_back(ndx & INDEXBIT_MASK);
99  }
100  else {
101  pers->m_indices.push_back((ndx & INDEXBIT_MASK) | HAS_WEIGHT_BIT);
102  pers->m_weights.push_back(fweight);
103  }
104  }//end loop over cells in cellLink object
105  }
106  ++icluster;
107  }//end loop over transient CaloClusterCellLinkContainer
108 
109  return;
110 }
DataVector::reserve
void reserve(size_type n)
Attempt to preallocate enough memory for a specified number of elements.
CaloClusterCellLinkContainerCnv_p1.h
CaloClusterCellLinkContainerCnv_p1::m_linkCnv
DataLinkCnv_p2< DataLink< CaloCellContainer > > m_linkCnv
Definition: CaloClusterCellLinkContainerCnv_p1.h:56
index
Definition: index.py:1
SG::ThinningDecisionBase
Hold thinning decisions for one container.
Definition: ThinningDecisionBase.h:39
DataLinkCnv_p2::persToTrans
virtual void persToTrans(const PersDLink_t &pers, DLink_t &trans, MsgStream &log) const
skel.it
it
Definition: skel.GENtoEVGEN.py:423
SG::ThinningDecisionBase::thinned
bool thinned(size_t ndx) const
Return true if element ndx should be thinned.
CaloClusterCellLinkContainerCnv_p1::persToTransWithKey
virtual void persToTransWithKey(const CaloClusterCellLinkContainer_p1 *pers, CaloClusterCellLinkContainer *trans, const std::string &key, MsgStream &log) const override
Convert from persistent to transient object.
Definition: CaloClusterCellLinkContainerCnv_p1.cxx:19
DataLinkCnv_p2::transToPers
virtual void transToPers(const DLink_t &trans, PersDLink_t &pers, MsgStream &log) const
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
xAOD::nCells
setRawEt setRawPhi nCells
Definition: TrigCaloCluster_v1.cxx:33
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
getThinningCache.h
Helpers to retrieve the current thinning cache from the event context.
SG::getThinningCache
const SG::ThinningCache * getThinningCache(const EventContext &ctx)
Retrieve the current thinning cache from the event context.
Definition: getThinningCache.cxx:28
SG::getThinningDecision
const SG::ThinningDecisionBase * getThinningDecision(const EventContext &ctx, const std::string &key)
Retrieve the current thinning decision for key.
Definition: getThinningCache.cxx:83
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
SG::ThinningDecisionBase::index
size_t index(size_t ndxOrig) const
Return the index corresponding to ndxOrig after thinning.
SG::ThinningCache::thinning
const ThinningDecisionBase * thinning(const std::string &key) const
Return thinning for key.
Definition: ThinningCache.cxx:36
CaloClusterCellLinkContainerCnv_p1::transToPersWithKey
virtual void transToPersWithKey(const CaloClusterCellLinkContainer *trans, CaloClusterCellLinkContainer_p1 *pers, const std::string &key, MsgStream &log) const override
Convert from transient to persistent object.
Definition: CaloClusterCellLinkContainerCnv_p1.cxx:56
SG::ThinningCache
Cache thinning decisions for converters.
Definition: ThinningCache.h:48
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
ThinningCache.h