Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-10-17 08:19:38

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) return nullptr;
0037 
0038   unsigned int id = vertex->get_id();
0039   auto [it, inserted] = _map.insert({id, vertex});
0040 
0041   if (!inserted)
0042   {
0043     delete it->second;
0044     it->second = vertex;
0045   }
0046 
0047   return vertex;
0048 }
0049 
0050 size_t TruthVertexMap_v1::erase(unsigned int idkey)
0051 {
0052   auto it = _map.find(idkey);
0053   if (it != _map.end())
0054   {
0055     delete it->second;
0056     _map.erase(it);
0057     return 1;
0058   }
0059   return 0;
0060 }