ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4KDTreeResult.hh
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4KDTreeResult.hh
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
28 
29 // The code is developed in the framework of the ESA AO7146
30 //
31 // We would be very happy hearing from you, send us your feedback! :)
32 //
33 // In order for Geant4-DNA to be maintained and still open-source,
34 // article citations are crucial.
35 // If you use Geant4-DNA chemistry and you publish papers about your software,
36 // in addition to the general paper on Geant4-DNA:
37 //
38 // Int. J. Model. Simul. Sci. Comput. 1 (2010) 157–178
39 //
40 // we would be very happy if you could please also cite the following
41 // reference papers on chemistry:
42 //
43 // J. Comput. Phys. 274 (2014) 841-882
44 // Prog. Nucl. Sci. Tec. 2 (2011) 503-508
45 
46 #ifndef G4KDTREERESULT_HH
47 #define G4KDTREERESULT_HH
48 
49 #include <list>
50 #include "globals.hh"
52 #include "G4KDNode.hh"
53 
54 class G4KDTree;
55 class G4KDNode_Base;
56 struct ResNode;
58 
61 
67 #define KDTR_parent std::vector<ResNode>
68 
69 class G4KDTreeResult : protected KDTR_parent//protected std::list<ResNode>
70 {
71 protected:
73 // std::list<ResNode>::iterator fIterator;
74  KDTR_parent::iterator fIterator;
75 
76 public:
78  virtual ~G4KDTreeResult();
79 
80  // new/delete operators are overloded to use G4Allocator
81  inline void *operator new(size_t);
82 #ifdef __IBMCPP__
83  inline void *operator new(size_t sz, void* p)
84  { return p;}
85 #endif
86  inline void operator delete(void*);
87 
88  void Insert(double, G4KDNode_Base*);
89 
90  void Clear();
91 
92  void Sort();
93 
94  /* returns the size of the result set (in elements) */
95  size_t GetSize() const;
96 
97  size_t size() const;
98 
99  /* rewinds the result set iterator */
100  void Rewind();
101 
102  /* returns non-zero if the set iterator reached the end after the last element*/
103  bool End();
104 
105  /* advances the result set iterator
106  */
107  void Next();
108 
109  /* returns the data pointer (can be null) of the current result set item
110  * and optionally sets its position to the pointers(s) if not null.
111  */
112  template<typename PointT>
113  PointT* GetItem() const;
114  G4KDNode_Base* GetNode() const;
115  template<typename PointT>
116  PointT* GetItemNDistanceSQ(double& /*distance*/) const;
117  double GetDistanceSqr() const;
118 };
119 
120 //------------------------------------------------------------------------------
121 #if defined G4EM_ALLOC_EXPORT
123 #else
125 #endif
126 
127 inline void * G4KDTreeResult::operator new(size_t)
128 {
130  return (void *) aKDTreeAllocator()->MallocSingle();
131 }
132 
133 inline void G4KDTreeResult::operator delete(void * object)
134 {
135  aKDTreeAllocator()->FreeSingle((G4KDTreeResult *) object);
136 }
137 //------------------------------------------------------------------------------
138 template<typename PointT>
139  PointT* G4KDTreeResult::GetItem() const
140  {
142  return node->GetPoint();
143  }
144 
145 template<typename PointT>
146  PointT* G4KDTreeResult::GetItemNDistanceSQ(double& dist_sq) const
147  {
148  dist_sq = GetDistanceSqr();
149  return this->GetItem<PointT>();
150  }
151 
152 #endif // G4KDTREERESULT_HH