File indexing completed on 2025-01-18 09:59:09
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 #ifndef G4TDigiCollection_h
0030 #define G4TDigiCollection_h 1
0031
0032 #include "G4Allocator.hh"
0033 #include "G4VDigiCollection.hh"
0034 #include "globals.hh"
0035
0036 #include <vector>
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048 class G4DigiCollection : public G4VDigiCollection
0049 {
0050 public:
0051 using G4VDigiCollection::G4VDigiCollection;
0052 ~G4DigiCollection() override = default;
0053
0054 G4bool operator==(const G4DigiCollection& right) const { return (this == &right); }
0055
0056 protected:
0057 void* theCollection = nullptr;
0058 };
0059
0060 #if defined G4DIGI_ALLOC_EXPORT
0061 extern G4DLLEXPORT G4Allocator<G4DigiCollection>*& aDCAllocator_G4MT_TLS_();
0062 #else
0063 extern G4DLLIMPORT G4Allocator<G4DigiCollection>*& aDCAllocator_G4MT_TLS_();
0064 #endif
0065
0066 template <class T>
0067 class G4TDigiCollection : public G4DigiCollection
0068 {
0069 public:
0070 G4TDigiCollection();
0071 G4TDigiCollection(G4String detName, G4String colNam);
0072 ~G4TDigiCollection() override;
0073
0074 G4bool operator==(const G4TDigiCollection& right) const;
0075
0076 inline void* operator new(size_t);
0077 inline void operator delete(void* aDC);
0078
0079
0080 void DrawAllDigi() override;
0081
0082
0083 void PrintAllDigi() override;
0084
0085
0086
0087 inline T* operator[](size_t i) const { return (*((std::vector<T*>*)theCollection))[i]; }
0088
0089
0090 inline std::vector<T*>* GetVector() const { return (std::vector<T*>*)theCollection; }
0091
0092
0093
0094 inline size_t insert(T* aHit)
0095 {
0096 auto theDigiCollection = (std::vector<T*>*)theCollection;
0097 theDigiCollection->push_back(aHit);
0098 return theDigiCollection->size();
0099 }
0100
0101
0102 inline size_t entries() const
0103 {
0104 auto theDigiCollection = (std::vector<T*>*)theCollection;
0105 return theDigiCollection->size();
0106 }
0107
0108 G4VDigi* GetDigi(size_t i) const override { return (*((std::vector<T*>*)theCollection))[i]; }
0109
0110 size_t GetSize() const override { return ((std::vector<T*>*)theCollection)->size(); }
0111 };
0112
0113 template <class T>
0114 inline void* G4TDigiCollection<T>::operator new(size_t)
0115 {
0116 if (aDCAllocator_G4MT_TLS_() == nullptr) {
0117 aDCAllocator_G4MT_TLS_() = new G4Allocator<G4DigiCollection>;
0118 }
0119 return (void*)aDCAllocator_G4MT_TLS_()->MallocSingle();
0120 }
0121
0122 template <class T>
0123 inline void G4TDigiCollection<T>::operator delete(void* aDC)
0124 {
0125 aDCAllocator_G4MT_TLS_()->FreeSingle((G4DigiCollection*)aDC);
0126 }
0127
0128 template <class T>
0129 G4TDigiCollection<T>::G4TDigiCollection()
0130 {
0131 auto theDigiCollection = new std::vector<T*>;
0132 theCollection = (void*)theDigiCollection;
0133 }
0134
0135 template <class T>
0136 G4TDigiCollection<T>::G4TDigiCollection(G4String detName, G4String colNam)
0137 : G4DigiCollection(detName, colNam)
0138 {
0139 auto theDigiCollection = new std::vector<T*>;
0140 theCollection = (void*)theDigiCollection;
0141 }
0142
0143 template <class T>
0144 G4TDigiCollection<T>::~G4TDigiCollection()
0145 {
0146 auto theDigiCollection = (std::vector<T*>*)theCollection;
0147 for (const auto* digi : *theDigiCollection) {
0148 delete digi;
0149 }
0150 theDigiCollection->clear();
0151 delete theDigiCollection;
0152 }
0153
0154 template <class T>
0155 G4bool G4TDigiCollection<T>::operator==(const G4TDigiCollection<T>& right) const
0156 {
0157 return (collectionName == right.collectionName);
0158 }
0159
0160 template <class T>
0161 void G4TDigiCollection<T>::DrawAllDigi()
0162 {
0163 auto theDigiCollection = (std::vector<T*>*)theCollection;
0164 for (auto* digi : *theDigiCollection) {
0165 digi->Draw();
0166 }
0167 }
0168
0169 template <class T>
0170 void G4TDigiCollection<T>::PrintAllDigi()
0171 {
0172 auto theDigiCollection = (std::vector<T*>*)theCollection;
0173 for (auto* digi : *theDigiCollection) {
0174 digi->Print();
0175 }
0176 }
0177
0178 #endif