G4ITManager.hh

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 // $Id: G4ITManager.hh 65022 2012-11-12 16:43:12Z gcosmo $
00027 //
00028 // Author: Mathieu Karamitros (kara (AT) cenbg . in2p3 . fr) 
00029 //
00030 // WARNING : This class is released as a prototype.
00031 // It might strongly evolve or even disapear in the next releases.
00032 //
00033 // History:
00034 // -----------
00035 // 10 Oct 2011 M.Karamitros created
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     // Navigate between boxes
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         // Print "G4IT* friendIT" status :
00112         void PrintNext() const;
00113         //_____________________________________
00114         // Attributes
00115         G4IT* fNextIT; // the one you are looking reactants for
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     //Make a method to extract number of IT from Box
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; // coverity
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

Generated on Mon May 27 17:48:41 2013 for Geant4 by  doxygen 1.4.7