AlcapDAQ  1
MqlNtupleColumn.h
Go to the documentation of this file.
1 #ifndef MQLNTUPLECOLUMN
2 #define MQLNTUPLECOLUMN
3 
4 #include <stdlib.h>
5 #include "TTree.h"
6 #include "TBranch.h"
7 #include "TLeaf.h"
8 
9 static const int MQLNTUPLECOLUMN_REALLOC_N = 2;
10 static const int MQLNTUPLECOLUMN_REALLOC_C = 8;
11 
12 template<typename T> class MqlNtupleColumn
13 {
14  public:
15 
17  fArray = NULL;
18  fAllocation = 0;
19  }
20 
22  if(fArray != NULL) {
23  delete[] fArray;
24  }
25  }
26 
27  inline T& operator[] (int i) {
28  return fArray[i];
29  }
30 
31  void realloc(int newSize) {
32 
33  // make a new array and put it into place
34  T *oldArray = fArray;
35  T *newArray = new T[newSize];
36  fArray = newArray;
37  int oldSize = fAllocation;
38  fAllocation = newSize;
39 
40  // copy the contents and delete the old array
41  if(oldArray != NULL) {
42  memcpy(newArray, oldArray, oldSize*sizeof(T));
43  delete[] oldArray;
44  }
45 
46  }
47  private:
48 
49  T *fArray;
51 };
52 
53 #endif