00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #ifndef G4ITManager_hh
00040 #define G4ITManager_hh 1
00041
00042 #include "globals.hh"
00043 #include <map>
00044 #include "G4AllITManager.hh"
00045 #include "G4ITBox.hh"
00046 #include "G4KDTree.hh"
00047 #include "G4Track.hh"
00048
00055 class G4VITManager
00056 {
00057 protected :
00058 G4ITType fType ;
00059 G4int fVerbose;
00060
00061 public :
00062 G4VITManager();
00063 virtual ~G4VITManager(){;}
00064
00065 void SetVerboseLevel(G4int level)
00066 {
00067 fVerbose = level;
00068 }
00069 G4int GetVerboseLevel()
00070 {
00071 return fVerbose;
00072 }
00073
00074 virtual void UpdatePositionMap() = 0;
00075 virtual void CreateTree() {;}
00076
00077 virtual void Push(G4Track*) = 0 ;
00078 G4ITType GetITType()
00079 {
00080 return fType;
00081 }
00082
00083 G4ITBox* GetBox(const G4Track* track)
00084 {
00085 return GetBox(GetIT(track));
00086 }
00087
00088 virtual G4ITBox* GetBox(const G4IT*) = 0;
00089
00090
00091 virtual G4ITBox* GetFirstBox() = 0;
00092 virtual G4ITBox* GetNextBox(G4ITBox*) = 0;
00093 virtual G4ITBox* GetLastBox() = 0;
00094
00095 public :
00096
00097 class iterator
00098 {
00099 public :
00100 iterator(G4ITBox*);
00101 virtual ~iterator(){;}
00102 virtual G4bool begin();
00103 virtual G4bool end();
00104 iterator& operator= (const iterator& i);
00105 iterator& operator++(G4int);
00106 G4IT* operator*();
00107 G4ITBox* GetBox();
00108
00109 protected :
00110
00111
00112 void PrintNext() const;
00113
00114
00115 G4IT* fNextIT;
00116 G4ITBox* fCurrentBox;
00117 };
00118
00119 class allbox_iterator : public iterator
00120 {
00121 public :
00122 allbox_iterator(G4ITType);
00123 allbox_iterator(G4VITManager*);
00124 virtual ~allbox_iterator() {;}
00125 allbox_iterator& operator= (const allbox_iterator& i);
00126 allbox_iterator& operator++(G4int);
00127
00128 protected :
00129 G4VITManager* fInstance ;
00130
00131 };
00132
00133 class const_iterator : public G4VITManager::iterator
00134 {
00135 public :
00136 const_iterator(G4ITBox*);
00137 virtual ~const_iterator(){;}
00138 const G4IT* operator*();
00139 };
00140 };
00141
00150 template<typename T>
00151 class G4ITManager : public G4VITManager
00152 {
00153 static G4ITManager<T> * fInstance;
00154 G4ITManager<T>();
00155
00156 typedef std::map<T,G4ITBox* > BoxMap;
00157 BoxMap fBox;
00158
00159 typedef std::map<T, G4KDTree* > TreeMap;
00160 TreeMap fTree;
00161 TreeMap fPrevious_tree;
00162
00163 public :
00164 static G4ITManager<T> * Instance();
00165 virtual ~G4ITManager();
00166 virtual void Push(G4Track*);
00167
00168
00169 G4int NbElements(const G4IT*);
00170
00171 void EraseABox(T*);
00172 void EraseABox(G4ITBox*);
00173
00174 void SetVerboseLevel(G4int level)
00175 {
00176 fVerbose = level;
00177 }
00178 G4int GetVerboseLevel()
00179 {
00180 return fVerbose;
00181 }
00182
00183 virtual void UpdatePositionMap();
00184 static void iUpdatePositionMap();
00185
00186 G4KDTreeResultHandle FindNearestInRange(const T*, const T*, G4double);
00187 G4KDTreeResultHandle FindNearest(const G4ThreeVector&, const T* it);
00188 G4KDTreeResultHandle FindNearest(const T* it0, const T* it);
00189 G4KDTreeResultHandle FindNearestInRange(const G4ThreeVector&, const T*, G4double);
00190
00191 inline G4ITBox* GetBox(const T* IT)
00192 {
00193 typename BoxMap::const_iterator it = fBox.find(*IT);
00194 if(it == fBox.end()) return 0;
00195 return it->second;
00196 }
00197
00198 inline virtual G4ITBox* GetBox(const G4IT* IT)
00199 {
00200 const T* myIT = dynamic_cast<const T*>(IT);
00201
00202 if(myIT == 0)
00203 {
00204 G4ExceptionDescription exceptionDescription ("You are requested a bad IT");
00205 G4Exception("G4ITManager::GetBox","ITManager001",
00206 FatalErrorInArgument,exceptionDescription);
00207 return 0;
00208 }
00209
00210 return GetBox(myIT);
00211 }
00212
00213 virtual G4ITBox* GetFirstBox()
00214 {
00215 typename BoxMap::iterator it = fBox.begin();
00216 if(it != fBox.end())
00217 {
00218 return it->second;
00219 }
00220 return 0;
00221 }
00222
00223 virtual G4ITBox* GetNextBox(G4ITBox* box)
00224 {
00225 if(box)
00226 {
00227 return box->GetNextBox();
00228 }
00229 return 0;
00230 }
00231
00232 virtual G4ITBox* GetLastBox()
00233 {
00234 typename BoxMap::reverse_iterator it = fBox.rbegin();
00235 if(it != fBox.rend())
00236 {
00237 return it->second;
00238 }
00239 return 0;
00240 }
00241
00242 };
00243
00244 #ifdef TEMPLATE
00245 #undef TEMPLATE
00246 #endif
00247
00248 #define TEMPLATE template<typename T>
00249 #define G4ITMANAGER G4ITManager<T>
00250
00251 #include "G4ITManager.icc"
00252
00253 #undef TEMPLATE
00254 #undef G4ITMANAGER
00255
00256 #endif