File indexing completed on 2025-12-16 09:19:57
0001 #include "TruthVertexMap_v1.h"
0002
0003 TruthVertexMap_v1::~TruthVertexMap_v1()
0004 {
0005 clear();
0006 }
0007
0008 void TruthVertexMap_v1::identify(std::ostream& os) const
0009 {
0010 os << "TruthVertexMap_v1 with " << _map.size() << " entries" << std::endl;
0011 }
0012
0013 void TruthVertexMap_v1::clear()
0014 {
0015 for (auto& [id, vtx] : _map)
0016 {
0017 delete vtx;
0018 }
0019 _map.clear();
0020 }
0021
0022 const TruthVertex* TruthVertexMap_v1::get(unsigned int idkey) const
0023 {
0024 auto it = _map.find(idkey);
0025 return (it != _map.end()) ? it->second : nullptr;
0026 }
0027
0028 TruthVertex* TruthVertexMap_v1::get(unsigned int idkey)
0029 {
0030 auto it = _map.find(idkey);
0031 return (it != _map.end()) ? it->second : nullptr;
0032 }
0033
0034 TruthVertex* TruthVertexMap_v1::insert(TruthVertex* vertex)
0035 {
0036 if (!vertex)
0037 {
0038 return nullptr;
0039 }
0040
0041 unsigned int id = vertex->get_id();
0042 auto [it, inserted] = _map.insert({id, vertex});
0043
0044 if (!inserted)
0045 {
0046 delete it->second;
0047 it->second = vertex;
0048 }
0049
0050 return vertex;
0051 }
0052
0053 size_t TruthVertexMap_v1::erase(unsigned int idkey)
0054 {
0055 auto it = _map.find(idkey);
0056 if (it != _map.end())
0057 {
0058 delete it->second;
0059 _map.erase(it);
0060 return 1;
0061 }
0062 return 0;
0063 }