Geant4  10.00.p01
G4ITManager.hh
Go to the documentation of this file.
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 // $Id: G4ITManager.hh 66872 2013-01-15 01:25:57Z japost $
27 //
28 // Author: Mathieu Karamitros (kara (AT) cenbg . in2p3 . fr)
29 //
30 // WARNING : This class is released as a prototype.
31 // It might strongly evolve or even disapear in the next releases.
32 //
33 // History:
34 // -----------
35 // 10 Oct 2011 M.Karamitros created
36 //
37 // -------------------------------------------------------------------
38 
39 #ifndef G4ITManager_hh
40 #define G4ITManager_hh 1
41 
42 #include "globals.hh"
43 #include <map>
44 #include "G4AllITManager.hh"
45 #include "G4ITBox.hh"
46 #include "G4KDTree.hh"
47 #include "G4Track.hh"
48 
56 {
57 protected :
60 
61 public :
62  G4VITManager();
63  virtual ~G4VITManager(){;}
64 
65  void SetVerboseLevel(G4int level)
66  {
67  fVerbose = level;
68  }
70  {
71  return fVerbose;
72  }
73 
74  virtual void UpdatePositionMap() = 0;
75  virtual void CreateTree() {;}
76 
77  virtual void Push(G4Track*) = 0 ;
79  {
80  return fType;
81  }
82 
83  G4ITBox* GetBox(const G4Track* track)
84  {
85  return GetBox(GetIT(track));
86  }
87 
88  virtual G4ITBox* GetBox(const G4IT*) = 0;
89 
90  // Navigate between boxes
91  virtual G4ITBox* GetFirstBox() = 0;
92  virtual G4ITBox* GetNextBox(G4ITBox*) = 0;
93  virtual G4ITBox* GetLastBox() = 0;
94 
95 public :
96 
97  class iterator
98  {
99  public :
100  iterator(G4ITBox*);
101  virtual ~iterator(){;}
102  virtual G4bool begin();
103  virtual G4bool end();
104  iterator& operator= (const iterator& i);
106  G4IT* operator*();
107  G4ITBox* GetBox();
108 
109  protected :
110  //_____________________________________
111  // Print "G4IT* friendIT" status :
112  void PrintNext() const;
113  //_____________________________________
114  // Attributes
115  G4IT* fNextIT; // the one you are looking reactants for
117  };
118 
119  class allbox_iterator : public iterator
120  {
121  public :
124  virtual ~allbox_iterator() {;}
127 
128  protected :
130 
131  };
132 
134  {
135  public :
137  virtual ~const_iterator(){;}
138  const G4IT* operator*();
139  };
140 };
141 
150 template<typename T>
151 class G4ITManager : public G4VITManager
152 {
154  G4ITManager<T>();
155 
156  typedef std::map<T,G4ITBox* > BoxMap;
157  BoxMap fBox;
158 
159  typedef std::map<T, G4KDTree* > TreeMap;
160  TreeMap fTree;
161  TreeMap fPrevious_tree;
162 
163 public :
164  static G4ITManager<T> * Instance();
165  virtual ~G4ITManager();
166  virtual void Push(G4Track*);
167 
168  //Make a method to extract number of IT from Box
169  G4int NbElements(const G4IT*);
170 
171  void EraseABox(T*);
172  void EraseABox(G4ITBox*);
173 
174  void SetVerboseLevel(G4int level)
175  {
176  fVerbose = level;
177  }
179  {
180  return fVerbose;
181  }
182 
183  virtual void UpdatePositionMap();
184  static void iUpdatePositionMap();
185 
186  G4KDTreeResultHandle FindNearestInRange(const T*, const T*, G4double);
187  G4KDTreeResultHandle FindNearest(const G4ThreeVector&, const T* it);
188  G4KDTreeResultHandle FindNearest(const T* it0, const T* it);
190 
191  inline G4ITBox* GetBox(const T* IT)
192  {
193  typename BoxMap::const_iterator it = fBox.find(*IT);
194  if(it == fBox.end()) return 0;
195  return it->second;
196  }
197 
198  inline virtual G4ITBox* GetBox(const G4IT* IT)
199  {
200  const T* myIT = dynamic_cast<const T*>(IT);
201 
202  if(myIT == 0)
203  {
204  G4ExceptionDescription exceptionDescription ("You are requested a bad IT");
205  G4Exception("G4ITManager::GetBox","ITManager001",
206  FatalErrorInArgument,exceptionDescription);
207  return 0; // coverity
208  }
209 
210  return GetBox(myIT);
211  }
212 
213  virtual G4ITBox* GetFirstBox()
214  {
215  typename BoxMap::iterator it = fBox.begin();
216  if(it != fBox.end())
217  {
218  return it->second;
219  }
220  return 0;
221  }
222 
223  virtual G4ITBox* GetNextBox(G4ITBox* box)
224  {
225  if(box)
226  {
227  return box->GetNextBox();
228  }
229  return 0;
230  }
231 
232  virtual G4ITBox* GetLastBox()
233  {
234  typename BoxMap::reverse_iterator it = fBox.rbegin();
235  if(it != fBox.rend())
236  {
237  return it->second;
238  }
239  return 0;
240  }
241 
242 };
243 
244 #ifdef TEMPLATE
245 #undef TEMPLATE
246 #endif
247 
248 #define TEMPLATE template<typename T>
249 #define G4ITMANAGER G4ITManager<T>
250 
251 #include "G4ITManager.icc"
252 
253 #undef TEMPLATE
254 #undef G4ITMANAGER
255 
256 #endif
virtual ~G4VITManager()
Definition: G4ITManager.hh:63
G4IT is a interface which allows the inheriting object :
Definition: G4IT.hh:82
static G4ThreadLocal G4ITManager< T > * fInstance
Definition: G4ITManager.hh:153
G4ITType fType
Definition: G4ITManager.hh:58
G4int GetVerboseLevel()
Definition: G4ITManager.hh:69
static void iUpdatePositionMap()
allbox_iterator & operator=(const allbox_iterator &i)
TreeMap fPrevious_tree
Definition: G4ITManager.hh:161
iterator & operator++(G4int)
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
CLHEP::Hep3Vector G4ThreeVector
G4ITType GetITType()
Definition: G4ITManager.hh:78
virtual ~G4ITManager()
G4ITBox * GetBox(const T *IT)
Definition: G4ITManager.hh:191
G4KDTreeResultHandle FindNearestInRange(const T *, const T *, G4double)
virtual G4ITBox * GetLastBox()
Definition: G4ITManager.hh:232
Tag the G4IT Should be automatically setup by G4IT using : ITDef(MyIT) and ITImp(MyIT) ...
Definition: G4ITType.hh:51
G4int NbElements(const G4IT *)
void EraseABox(T *)
G4ITBox * GetNextBox()
Definition: G4ITBox.hh:127
#define G4ThreadLocal
Definition: tls.hh:52
virtual void Push(G4Track *)=0
G4KDTreeResultHandle FindNearest(const G4ThreeVector &, const T *it)
int G4int
Definition: G4Types.hh:78
std::map< T, G4ITBox * > BoxMap
Definition: G4ITManager.hh:156
virtual G4ITBox * GetNextBox(G4ITBox *)=0
virtual G4ITBox * GetNextBox(G4ITBox *box)
Definition: G4ITManager.hh:223
G4IT * GetIT(const G4Track *track)
Definition: G4IT.cc:48
virtual G4ITBox * GetFirstBox()=0
TreeMap fTree
Definition: G4ITManager.hh:160
bool G4bool
Definition: G4Types.hh:79
virtual G4ITBox * GetBox(const G4IT *IT)
Definition: G4ITManager.hh:198
G4int GetVerboseLevel()
Definition: G4ITManager.hh:178
iterator & operator=(const iterator &i)
virtual void CreateTree()
Definition: G4ITManager.hh:75
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
static G4ITManager< T > * Instance()
virtual G4ITBox * GetLastBox()=0
A G4ITBox contains all IT of the same kind.
Definition: G4ITBox.hh:50
virtual void Push(G4Track *)
void SetVerboseLevel(G4int level)
Definition: G4ITManager.hh:174
virtual void UpdatePositionMap()
std::map< T, G4KDTree * > TreeMap
Definition: G4ITManager.hh:159
G4VITManager is just a virtual interface for G4ITManager.
Definition: G4ITManager.hh:55
G4ITBox * GetBox(const G4Track *track)
Definition: G4ITManager.hh:83
virtual G4ITBox * GetFirstBox()
Definition: G4ITManager.hh:213
double G4double
Definition: G4Types.hh:76
G4ITManager is able to save into different boxes the ITs that will be used in the simulation...
virtual void UpdatePositionMap()=0
void SetVerboseLevel(G4int level)
Definition: G4ITManager.hh:65
G4int fVerbose
Definition: G4ITManager.hh:59