CMS 3D CMS Logo

allocators.h
Go to the documentation of this file.
1 #ifndef NPSTAT_ALLOCATORS_HH_
2 #define NPSTAT_ALLOCATORS_HH_
3 
14 #include <cassert>
15 
16 namespace npstat {
21  template <typename T>
22  inline T* makeBuffer(unsigned sizeNeeded, T* stackBuffer, unsigned sizeofStackBuffer) {
23  if (sizeNeeded > sizeofStackBuffer || stackBuffer == nullptr)
24  return new T[sizeNeeded];
25  else
26  return stackBuffer;
27  }
28 
30  template <typename T>
31  inline void destroyBuffer(T* thisBuffer, const T* stackBuffer) {
32  if (thisBuffer != stackBuffer)
33  delete[] thisBuffer;
34  }
35 
37  template <typename T1, typename T2>
38  inline void copyBuffer(T1* dest, const T2* source, const unsigned long len) {
39  if (len) {
40  assert(dest);
41  assert(source);
42  for (unsigned long i = 0; i < len; ++i)
43  *dest++ = static_cast<T1>(*source++);
44  }
45  }
46 
51  template <typename T1, typename T2>
52  inline void transposeBuffer(T1* dest, const T2* source, const unsigned long dim) {
53  if (dim) {
54  assert(dest);
55  assert(source);
56  for (unsigned long i = 0; i < dim; ++i) {
57  for (unsigned long j = 0; j < dim; ++j)
58  dest[j * dim] = static_cast<T1>(*source++);
59  ++dest;
60  }
61  }
62  }
63 
68  template <typename T1, typename T2>
69  inline void transposeBuffer(T1* dest, const T2* source, const unsigned long M, const unsigned long N) {
70  if (M && N) {
71  assert(dest);
72  assert(source);
73  for (unsigned long i = 0; i < M; ++i) {
74  for (unsigned long j = 0; j < N; ++j)
75  dest[j * M] = static_cast<T1>(*source++);
76  ++dest;
77  }
78  }
79  }
80 
85  template <typename T>
86  inline void clearBuffer(T* buf, const unsigned long len) {
87  if (len) {
88  assert(buf);
89  const T zero = T();
90  for (unsigned long i = 0; i < len; ++i)
91  *buf++ = zero;
92  }
93  }
94 } // namespace npstat
95 
96 #endif // NPSTAT_ALLOCATORS_HH_
npstat::copyBuffer
void copyBuffer(T1 *dest, const T2 *source, const unsigned long len)
Definition: allocators.h:38
mps_fire.i
i
Definition: mps_fire.py:428
npstat::transposeBuffer
void transposeBuffer(T1 *dest, const T2 *source, const unsigned long dim)
Definition: allocators.h:52
cms::cuda::assert
assert(be >=bs)
SiPixelPI::zero
Definition: SiPixelPayloadInspectorHelper.h:39
npstat::clearBuffer
void clearBuffer(T *buf, const unsigned long len)
Definition: allocators.h:86
npstat
Definition: AbsArrayProjector.h:14
source
static const std::string source
Definition: EdmProvDump.cc:47
N
#define N
Definition: blowfish.cc:9
npstat::destroyBuffer
void destroyBuffer(T *thisBuffer, const T *stackBuffer)
Definition: allocators.h:31
visDQMUpload.buf
buf
Definition: visDQMUpload.py:154
T
long double T
Definition: Basic3DVectorLD.h:48
npstat::makeBuffer
T * makeBuffer(unsigned sizeNeeded, T *stackBuffer, unsigned sizeofStackBuffer)
Definition: allocators.h:22
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
mps_fire.dest
dest
Definition: mps_fire.py:179