| 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 | // $Id: G4TDigiCollection.hh,v 1.6 2006/06/29 18:06:16 gunter Exp $
|
|---|
| 28 | // GEANT4 tag $Name: geant4-09-02-ref-02 $
|
|---|
| 29 | //
|
|---|
| 30 |
|
|---|
| 31 | #ifndef G4TDigiCollection_h
|
|---|
| 32 | #define G4TDigiCollection_h 1
|
|---|
| 33 |
|
|---|
| 34 | #include "G4VDigiCollection.hh"
|
|---|
| 35 | #include "G4Allocator.hh"
|
|---|
| 36 | #include "globals.hh"
|
|---|
| 37 | #include <vector>
|
|---|
| 38 |
|
|---|
| 39 | // class description:
|
|---|
| 40 | //
|
|---|
| 41 | // This is a template class of digi collection and parametrized by
|
|---|
| 42 | // The concrete class of G4VDigi. This is a uniform collection for
|
|---|
| 43 | // a particular concrete digi class objects.
|
|---|
| 44 | // An intermediate layer class G4DigiCollection appeared in this
|
|---|
| 45 | // header file is used just for G4Allocator, because G4Allocator
|
|---|
| 46 | // cannot be instansiated with a template class. Thus G4DigiCollection
|
|---|
| 47 | // class MUST NOT be directly used by the user.
|
|---|
| 48 |
|
|---|
| 49 | class G4DigiCollection : public G4VDigiCollection
|
|---|
| 50 | {
|
|---|
| 51 | public:
|
|---|
| 52 | G4DigiCollection();
|
|---|
| 53 | G4DigiCollection(G4String detName,G4String colNam);
|
|---|
| 54 | virtual ~G4DigiCollection();
|
|---|
| 55 | G4int operator==(const G4DigiCollection &right) const;
|
|---|
| 56 |
|
|---|
| 57 | protected:
|
|---|
| 58 | void* theCollection;
|
|---|
| 59 | };
|
|---|
| 60 |
|
|---|
| 61 | #if defined G4DIGI_ALLOC_EXPORT
|
|---|
| 62 | extern G4DLLEXPORT G4Allocator<G4DigiCollection> aDCAllocator;
|
|---|
| 63 | #else
|
|---|
| 64 | extern G4DLLIMPORT G4Allocator<G4DigiCollection> aDCAllocator;
|
|---|
| 65 | #endif
|
|---|
| 66 |
|
|---|
| 67 | template <class T> class G4TDigiCollection : public G4DigiCollection
|
|---|
| 68 | {
|
|---|
| 69 | public:
|
|---|
| 70 | G4TDigiCollection();
|
|---|
| 71 | public: // with description
|
|---|
| 72 | G4TDigiCollection(G4String detName,G4String colNam);
|
|---|
| 73 | // Constructor.
|
|---|
| 74 | public:
|
|---|
| 75 | virtual ~G4TDigiCollection();
|
|---|
| 76 | G4int operator==(const G4TDigiCollection &right) const;
|
|---|
| 77 |
|
|---|
| 78 | inline void *operator new(size_t);
|
|---|
| 79 | inline void operator delete(void* aDC);
|
|---|
| 80 | public: // with description
|
|---|
| 81 | virtual void DrawAllDigi();
|
|---|
| 82 | virtual void PrintAllDigi();
|
|---|
| 83 | // These two methods invokes Draw() and Print() methods of all of
|
|---|
| 84 | // digit objects stored in this collection, respectively.
|
|---|
| 85 |
|
|---|
| 86 | public: // with description
|
|---|
| 87 | inline T* operator[](size_t i) const
|
|---|
| 88 | { return (*((std::vector<T*>*)theCollection))[i]; }
|
|---|
| 89 | // Returns a pointer to a concrete digi object.
|
|---|
| 90 | inline std::vector<T*>* GetVector() const
|
|---|
| 91 | { return (std::vector<T*>*)theCollection; }
|
|---|
| 92 | // Returns a collection vector.
|
|---|
| 93 | inline G4int insert(T* aHit)
|
|---|
| 94 | {
|
|---|
| 95 | std::vector<T*>*theDigiCollection
|
|---|
| 96 | = (std::vector<T*>*)theCollection;
|
|---|
| 97 | theDigiCollection->push_back(aHit);
|
|---|
| 98 | return theDigiCollection->size();
|
|---|
| 99 | }
|
|---|
| 100 | // Insert a digi object. Total number of digi objects stored in this
|
|---|
| 101 | // collection is returned.
|
|---|
| 102 | inline G4int entries() const
|
|---|
| 103 | {
|
|---|
| 104 | std::vector<T*>*theDigiCollection
|
|---|
| 105 | = (std::vector<T*>*)theCollection;
|
|---|
| 106 | return theDigiCollection->size();
|
|---|
| 107 | }
|
|---|
| 108 | // Returns the number of digi objcets stored in this collection.
|
|---|
| 109 |
|
|---|
| 110 | public:
|
|---|
| 111 | virtual G4VDigi* GetDigi(size_t i) const
|
|---|
| 112 | { return (*((std::vector<T*>*)theCollection))[i]; }
|
|---|
| 113 | virtual size_t GetSize() const
|
|---|
| 114 | { return ((std::vector<T*>*)theCollection)->size(); }
|
|---|
| 115 |
|
|---|
| 116 | };
|
|---|
| 117 |
|
|---|
| 118 | template <class T> inline void* G4TDigiCollection<T>::operator new(size_t)
|
|---|
| 119 | {
|
|---|
| 120 | void* aDC;
|
|---|
| 121 | aDC = (void*)aDCAllocator.MallocSingle();
|
|---|
| 122 | return aDC;
|
|---|
| 123 | }
|
|---|
| 124 |
|
|---|
| 125 | template <class T> inline void G4TDigiCollection<T>::operator delete(void* aDC)
|
|---|
| 126 | {
|
|---|
| 127 | aDCAllocator.FreeSingle((G4DigiCollection*)aDC);
|
|---|
| 128 | }
|
|---|
| 129 |
|
|---|
| 130 | template <class T> G4TDigiCollection<T>::G4TDigiCollection()
|
|---|
| 131 | {
|
|---|
| 132 | std::vector<T*> * theDigiCollection
|
|---|
| 133 | = new std::vector<T*>;
|
|---|
| 134 | theCollection = (void*)theDigiCollection;
|
|---|
| 135 | }
|
|---|
| 136 |
|
|---|
| 137 | template <class T> G4TDigiCollection<T>::G4TDigiCollection(G4String detName,G4String colNam)
|
|---|
| 138 | : G4DigiCollection(detName,colNam)
|
|---|
| 139 | {
|
|---|
| 140 | std::vector<T*> * theDigiCollection
|
|---|
| 141 | = new std::vector<T*>;
|
|---|
| 142 | theCollection = (void*)theDigiCollection;
|
|---|
| 143 | }
|
|---|
| 144 |
|
|---|
| 145 | template <class T> G4TDigiCollection<T>::~G4TDigiCollection()
|
|---|
| 146 | {
|
|---|
| 147 | std::vector<T*> * theDigiCollection
|
|---|
| 148 | = (std::vector<T*>*)theCollection;
|
|---|
| 149 | //theDigiCollection->clearAndDestroy();
|
|---|
| 150 | for(size_t i=0;i<theDigiCollection->size();i++)
|
|---|
| 151 | { delete (*theDigiCollection)[i]; }
|
|---|
| 152 | theDigiCollection->clear();
|
|---|
| 153 | delete theDigiCollection;
|
|---|
| 154 | }
|
|---|
| 155 |
|
|---|
| 156 | template <class T> G4int G4TDigiCollection<T>::operator==(const G4TDigiCollection<T> &right) const
|
|---|
| 157 | { return (collectionName==right.collectionName); }
|
|---|
| 158 |
|
|---|
| 159 | template <class T> void G4TDigiCollection<T>::DrawAllDigi()
|
|---|
| 160 | {
|
|---|
| 161 | std::vector<T*> * theDigiCollection
|
|---|
| 162 | = (std::vector<T*>*)theCollection;
|
|---|
| 163 | size_t n = theDigiCollection->size();
|
|---|
| 164 | for(size_t i=0;i<n;i++)
|
|---|
| 165 | { (*theDigiCollection)[i]->Draw(); }
|
|---|
| 166 | }
|
|---|
| 167 |
|
|---|
| 168 | template <class T> void G4TDigiCollection<T>::PrintAllDigi()
|
|---|
| 169 | {
|
|---|
| 170 | std::vector<T*> * theDigiCollection
|
|---|
| 171 | = (std::vector<T*>*)theCollection;
|
|---|
| 172 | size_t n = theDigiCollection->size();
|
|---|
| 173 | for(size_t i=0;i<n;i++)
|
|---|
| 174 | { (*theDigiCollection)[i]->Print(); }
|
|---|
| 175 | }
|
|---|
| 176 |
|
|---|
| 177 | #endif
|
|---|
| 178 |
|
|---|