ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4KDTreeResult.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4KDTreeResult.cc
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 // Author: Mathieu Karamitros (kara (AT) cenbg . in2p3 . fr)
28 //
29 // History:
30 // -----------
31 // 10 Oct 2011 M.Karamitros created
32 //
33 // -------------------------------------------------------------------
34 
35 #include "G4KDTreeResult.hh"
36 
37 using namespace std;
38 
40 {
42  return _instance;
43 }
44 
45 struct ResNode
46 {
47 public:
48  ResNode():fNode(0),fDistanceSqr(0){;}
49  ResNode(double distsqr, G4KDNode_Base* node):
50  fNode(node),fDistanceSqr(distsqr)
51  {;}
52 
54  {
55  fNode = right.fNode;
56  fDistanceSqr= right.fDistanceSqr;
57  }
58  ResNode& operator=(const ResNode& rhs)
59  {
60  if(this == &rhs) return *this;
61  fNode = rhs.fNode;
62  fDistanceSqr= rhs.fDistanceSqr;
63  return *this;
64  }
65  ~ResNode(){;}
66 
67  G4bool operator<(const ResNode& right) const
68  {
69  return (fDistanceSqr < right.fDistanceSqr);
70  }
71 
72  G4KDNode_Base* GetNode() { return fNode;}
73  double GetDistanceSqr() { return fDistanceSqr;}
74 
75 protected:
77  double fDistanceSqr;
78 };
79 
80 // comparison
82  const ResNode& right)
83 {
84  return left < right;
85 }
86 
88 //std::list<ResNode>()
90 {
91  fTree = tree;
92 }
93 
95 {
96  KDTR_parent::erase(begin(),end());
97  //std::list<ResNode>::erase(begin(),end());
98 }
99 
100 void G4KDTreeResult::Insert(double dis_sq, G4KDNode_Base* node)
101 {
102  //std::list<ResNode>::push_back(ResNode(dis_sq,node));
103  KDTR_parent::push_back(ResNode(dis_sq,node));
104 }
105 
107 {
108 // std::list<ResNode>::erase(begin(),end());
109 // fIterator = std::list<ResNode>::begin();
110  KDTR_parent::erase(begin(),end());
111  fIterator = KDTR_parent::begin();
112 }
113 
115 {
116  //std::list<ResNode>::sort(CompareResNode);
117  std::sort(begin(), end(), CompareResNode);
118 }
119 
121 {
122  //return std::list<ResNode>::size();
123  return KDTR_parent::size();
124 }
125 
126 size_t G4KDTreeResult::size() const
127 {
128  return KDTR_parent::size();
129  //return std::list<ResNode>::size();
130 }
131 
133 {
134  fIterator = begin();
135 }
136 
138 {
139  return (fIterator == end());
140 }
141 
143 {
144  ++fIterator;
145 }
146 
148 {
149  return (*fIterator).GetDistanceSqr();
150 }
151 
153  return (*fIterator).GetNode();
154 }