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