ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4TDigiCollection.hh
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4TDigiCollection.hh
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 //
28 
29 #ifndef G4TDigiCollection_h
30 #define G4TDigiCollection_h 1
31 
32 #include "G4VDigiCollection.hh"
33 #include "G4Allocator.hh"
34 #include "globals.hh"
35 #include <vector>
36 
37 // class description:
38 //
39 // This is a template class of digi collection and parametrized by
40 // The concrete class of G4VDigi. This is a uniform collection for
41 // a particular concrete digi class objects.
42 // An intermediate layer class G4DigiCollection appeared in this
43 // header file is used just for G4Allocator, because G4Allocator
44 // cannot be instansiated with a template class. Thus G4DigiCollection
45 // class MUST NOT be directly used by the user.
46 
48 {
49  public:
51  G4DigiCollection(G4String detName,G4String colNam);
52  virtual ~G4DigiCollection();
54 
55  protected:
57 };
58 
59 #if defined G4DIGI_ALLOC_EXPORT
61 #else
63 #endif
64 
65 template <class T> class G4TDigiCollection : public G4DigiCollection
66 {
67  public:
69  public: // with description
70  G4TDigiCollection(G4String detName,G4String colNam);
71  // Constructor.
72  public:
73  virtual ~G4TDigiCollection();
75 
76  inline void *operator new(size_t);
77  inline void operator delete(void* aDC);
78  public: // with description
79  virtual void DrawAllDigi();
80  virtual void PrintAllDigi();
81  // These two methods invokes Draw() and Print() methods of all of
82  // digit objects stored in this collection, respectively.
83 
84  public: // with description
85  inline T* operator[](size_t i) const
86  {
88  return (*((std::vector<T*>*)theCollection))[i];
89  }
90  // Returns a pointer to a concrete digi object.
91  inline std::vector<T*>* GetVector() const
92  {
94  return (std::vector<T*>*)theCollection;
95  }
96  // Returns a collection vector.
97  inline size_t insert(T* aHit)
98  {
100  std::vector<T*>*theDigiCollection
101  = (std::vector<T*>*)theCollection;
102  theDigiCollection->push_back(aHit);
103  return theDigiCollection->size();
104  }
105  // Insert a digi object. Total number of digi objects stored in this
106  // collection is returned.
107  inline size_t entries() const
108  {
110  std::vector<T*>*theDigiCollection
111  = (std::vector<T*>*)theCollection;
112  return theDigiCollection->size();
113  }
114  // Returns the number of digi objcets stored in this collection.
115 
116  public:
117  virtual G4VDigi* GetDigi(size_t i) const
118  {
120  return (*((std::vector<T*>*)theCollection))[i];
121  }
122  virtual size_t GetSize() const
123  {
125  return ((std::vector<T*>*)theCollection)->size();
126  }
127 
128 };
129 
130 template <class T> inline void* G4TDigiCollection<T>::operator new(size_t)
131 {
134  void* aDC;
135  aDC = (void*)aDCAllocator.MallocSingle();
136  return aDC;
137 }
138 
139 template <class T> inline void G4TDigiCollection<T>::operator delete(void* aDC)
140 {
143  aDCAllocator.FreeSingle((G4DigiCollection*)aDC);
144 }
145 
147 {
149  std::vector<T*> * theDigiCollection = new std::vector<T*>;
150  theCollection = (void*)theDigiCollection;
151 }
152 
154 : G4DigiCollection(detName,colNam)
155 {
157 
158  std::vector<T*> * theDigiCollection = new std::vector<T*>;
159  theCollection = (void*)theDigiCollection;
160 }
161 
163 {
165  std::vector<T*> * theDigiCollection = (std::vector<T*>*)theCollection;
166  //theDigiCollection->clearAndDestroy();
167  for(size_t i=0;i<theDigiCollection->size();i++)
168  { delete (*theDigiCollection)[i]; }
169  theDigiCollection->clear();
170  delete theDigiCollection;
171 }
172 
174 {
176  return (collectionName==right.collectionName);
177 }
178 
179 template <class T> void G4TDigiCollection<T>::DrawAllDigi()
180 {
182  std::vector<T*> * theDigiCollection = (std::vector<T*>*)theCollection;
183  size_t n = theDigiCollection->size();
184  for(size_t i=0;i<n;i++)
185  { (*theDigiCollection)[i]->Draw(); }
186 }
187 
188 template <class T> void G4TDigiCollection<T>::PrintAllDigi()
189 {
191  std::vector<T*> * theDigiCollection = (std::vector<T*>*)theCollection;
192  size_t n = theDigiCollection->size();
193  for(size_t i=0;i<n;i++)
194  { (*theDigiCollection)[i]->Print(); }
195 }
196 
197 #endif
198