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 // 00027 // $Id$ 00028 // 00029 00030 #ifndef G4TDigiCollection_h 00031 #define G4TDigiCollection_h 1 00032 00033 #include "G4VDigiCollection.hh" 00034 #include "G4Allocator.hh" 00035 #include "globals.hh" 00036 #include <vector> 00037 00038 // class description: 00039 // 00040 // This is a template class of digi collection and parametrized by 00041 // The concrete class of G4VDigi. This is a uniform collection for 00042 // a particular concrete digi class objects. 00043 // An intermediate layer class G4DigiCollection appeared in this 00044 // header file is used just for G4Allocator, because G4Allocator 00045 // cannot be instansiated with a template class. Thus G4DigiCollection 00046 // class MUST NOT be directly used by the user. 00047 00048 class G4DigiCollection : public G4VDigiCollection 00049 { 00050 public: 00051 G4DigiCollection(); 00052 G4DigiCollection(G4String detName,G4String colNam); 00053 virtual ~G4DigiCollection(); 00054 G4int operator==(const G4DigiCollection &right) const; 00055 00056 protected: 00057 void* theCollection; 00058 }; 00059 00060 #if defined G4DIGI_ALLOC_EXPORT 00061 extern G4DLLEXPORT G4Allocator<G4DigiCollection> aDCAllocator; 00062 #else 00063 extern G4DLLIMPORT G4Allocator<G4DigiCollection> aDCAllocator; 00064 #endif 00065 00066 template <class T> class G4TDigiCollection : public G4DigiCollection 00067 { 00068 public: 00069 G4TDigiCollection(); 00070 public: // with description 00071 G4TDigiCollection(G4String detName,G4String colNam); 00072 // Constructor. 00073 public: 00074 virtual ~G4TDigiCollection(); 00075 G4int operator==(const G4TDigiCollection &right) const; 00076 00077 inline void *operator new(size_t); 00078 inline void operator delete(void* aDC); 00079 public: // with description 00080 virtual void DrawAllDigi(); 00081 virtual void PrintAllDigi(); 00082 // These two methods invokes Draw() and Print() methods of all of 00083 // digit objects stored in this collection, respectively. 00084 00085 public: // with description 00086 inline T* operator[](size_t i) const 00087 { return (*((std::vector<T*>*)theCollection))[i]; } 00088 // Returns a pointer to a concrete digi object. 00089 inline std::vector<T*>* GetVector() const 00090 { return (std::vector<T*>*)theCollection; } 00091 // Returns a collection vector. 00092 inline G4int insert(T* aHit) 00093 { 00094 std::vector<T*>*theDigiCollection 00095 = (std::vector<T*>*)theCollection; 00096 theDigiCollection->push_back(aHit); 00097 return theDigiCollection->size(); 00098 } 00099 // Insert a digi object. Total number of digi objects stored in this 00100 // collection is returned. 00101 inline G4int entries() const 00102 { 00103 std::vector<T*>*theDigiCollection 00104 = (std::vector<T*>*)theCollection; 00105 return theDigiCollection->size(); 00106 } 00107 // Returns the number of digi objcets stored in this collection. 00108 00109 public: 00110 virtual G4VDigi* GetDigi(size_t i) const 00111 { return (*((std::vector<T*>*)theCollection))[i]; } 00112 virtual size_t GetSize() const 00113 { return ((std::vector<T*>*)theCollection)->size(); } 00114 00115 }; 00116 00117 template <class T> inline void* G4TDigiCollection<T>::operator new(size_t) 00118 { 00119 void* aDC; 00120 aDC = (void*)aDCAllocator.MallocSingle(); 00121 return aDC; 00122 } 00123 00124 template <class T> inline void G4TDigiCollection<T>::operator delete(void* aDC) 00125 { 00126 aDCAllocator.FreeSingle((G4DigiCollection*)aDC); 00127 } 00128 00129 template <class T> G4TDigiCollection<T>::G4TDigiCollection() 00130 { 00131 std::vector<T*> * theDigiCollection 00132 = new std::vector<T*>; 00133 theCollection = (void*)theDigiCollection; 00134 } 00135 00136 template <class T> G4TDigiCollection<T>::G4TDigiCollection(G4String detName,G4String colNam) 00137 : G4DigiCollection(detName,colNam) 00138 { 00139 std::vector<T*> * theDigiCollection 00140 = new std::vector<T*>; 00141 theCollection = (void*)theDigiCollection; 00142 } 00143 00144 template <class T> G4TDigiCollection<T>::~G4TDigiCollection() 00145 { 00146 std::vector<T*> * theDigiCollection 00147 = (std::vector<T*>*)theCollection; 00148 //theDigiCollection->clearAndDestroy(); 00149 for(size_t i=0;i<theDigiCollection->size();i++) 00150 { delete (*theDigiCollection)[i]; } 00151 theDigiCollection->clear(); 00152 delete theDigiCollection; 00153 } 00154 00155 template <class T> G4int G4TDigiCollection<T>::operator==(const G4TDigiCollection<T> &right) const 00156 { return (collectionName==right.collectionName); } 00157 00158 template <class T> void G4TDigiCollection<T>::DrawAllDigi() 00159 { 00160 std::vector<T*> * theDigiCollection 00161 = (std::vector<T*>*)theCollection; 00162 size_t n = theDigiCollection->size(); 00163 for(size_t i=0;i<n;i++) 00164 { (*theDigiCollection)[i]->Draw(); } 00165 } 00166 00167 template <class T> void G4TDigiCollection<T>::PrintAllDigi() 00168 { 00169 std::vector<T*> * theDigiCollection 00170 = (std::vector<T*>*)theCollection; 00171 size_t n = theDigiCollection->size(); 00172 for(size_t i=0;i<n;i++) 00173 { (*theDigiCollection)[i]->Print(); } 00174 } 00175 00176 #endif 00177