4 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
15 const typename JetMapBase<P>::data_t JetMapBase<P>::m_nullData = data_t();
19 JetMapBase<P>::JetMapBase() //: m_lastIndex(0)
21 m_end = m_store.end();
22 m_ownPolicy = SG::OWN_ELEMENTS;
28 JetMapBase<P>::JetMapBase(const JetMapBase& /*base*/)
29 // : m_lastIndex(base.m_lastIndex)
32 m_end = m_store.end();
33 // not yet clear what we have to do here.
36 // std::copy(base.m_store.begin(),base.m_store.end(),
37 // std::back_insert_iterator<map_t>(m_store));
43 JetMapBase<P>::~JetMapBase()
44 { JetMapBase::clear() ;}
48 bool JetMapBase<P>::addRecord(size_t jetIndex) const
50 auto r = m_store.try_emplace (jetIndex);
55 const typename JetMapBase<P>::record_t* JetMapBase<P>::getRecord(size_t jetIndex) const
57 typename map_t::iterator jetpos = m_store.find(jetIndex);
58 // if record does not exist, create it
59 if ( jetpos == m_end ) return NULL;
60 return (*jetpos).second.get();
65 JetMapBase<P>::assignRecord(size_t jetIndex, record_t* rec) const
67 record_ptr_t & rec_p = m_store[jetIndex];
68 if( rec_p.isValid() ) rec_p.destroy();
74 JetMapBase<P>::removeRecord(size_t jetIndex) const
76 typename map_t::iterator jetpos = m_store.find(jetIndex);
77 if ( jetpos == m_end ) return;
78 (*jetpos).second.destroy();
79 m_store.erase( jetpos ) ;
85 JetMapBase<P>::transferRecord(const JetMapBase<P>* fromMap, size_t oldIndex, size_t newIndex ) const {
86 typename map_t::iterator jetpos = fromMap->m_store.find(oldIndex);
87 if ( jetpos == fromMap->m_end ) return;
88 if((*jetpos).second.isValid()) m_store[newIndex] = (*jetpos).second;
89 if( m_ownPolicy == SG::OWN_ELEMENTS ) fromMap->m_store.erase(jetpos);
94 JetMapBase<P>::addData(size_t jetIndex,size_t keyIndex,const data_t& data)
98 // typename map_t::iterator jetpos = m_store.find(jetIndex);
99 // // if record does not exist, create it
100 // if ( jetpos == m_end ) jetpos = m_store.insert(m_end, std::pair<key_t, record_t*>(jetIndex, new record_t()) );
102 record_ptr_t & rec_ptr = m_store[jetIndex];
103 if( ! rec_ptr.isValid() ) rec_ptr.set( new record_t() ) ;
104 record_t & record = *rec_ptr;
105 if ( keyIndex >= record.size() )
106 record.resize(keyIndex+1,data_t());
107 record[keyIndex] = data;
113 JetMapBase<P>::retrieveData(size_t jetIndex,size_t keyIndex,data_t& data) const
115 // check jet and moment index validity
116 typename map_t::iterator jetpos = m_store.find(jetIndex);
117 if ( jetpos == m_end ) return false;
118 record_ptr_t & record = (*jetpos).second;
119 if( ! record.isValid() ) return false;// this should never happen
120 if ( keyIndex >= record->size() ) return false;
122 data= record->operator[](keyIndex) ;
127 const typename JetMapBase<P>::data_t&
128 JetMapBase<P>::accessData(size_t jetIndex,size_t keyIndex) const
130 // check jet and moment index validity
131 typename map_t::iterator jetpos = m_store.find(jetIndex);
132 if ( jetpos == m_end ) return m_nullData;
133 record_ptr_t & record = (*jetpos).second;
134 if( ! record.isValid() ) return m_nullData; // this should never happen
135 if ( keyIndex >= record->size() ) return m_nullData;
137 return record->operator[](keyIndex) ;
141 size_t JetMapBase<P>::numberOfMoments(size_t jetIndex) const
143 typename map_t::iterator jetpos = m_store.find(jetIndex);
144 if ( jetpos == m_end ) return 0;
145 if((*jetpos).second.isValid()) return (*jetpos).second->size() ;
150 inline typename JetMapBase<P>::map_t& JetMapBase<P>::map() { return m_store; }
153 inline const typename JetMapBase<P>::map_t& JetMapBase<P>::map() const
157 void JetMapBase<P>::clear(){
158 if( m_ownPolicy == SG::OWN_ELEMENTS ) {
159 for (auto& p : m_store) {