AlcapDAQ  1
Public Member Functions | Private Attributes
MqlArray< T > Class Template Reference

#include <MqlArray.h>

Public Member Functions

 MqlArray ()
 
 ~MqlArray ()
 
T & operator[] (int i)
 
int next ()
 
int size ()
 
void setSize (int size)
 
void reset ()
 
void finish ()
 
void sort (int(*compar)(const void *, const void *))
 
bool checkSort (int(*compar)(const void *, const void *))
 
void realloc (int minSize)
 
void fromBank (void *pevent, char *bankName)
 
void toBank (void *pevent, char *bankName)
 

Private Attributes

T * fArray
 
int fAllocation
 
int fSize
 
int fLastSize
 
bool fImmutable
 

Detailed Description

template<typename T>
class MqlArray< T >

Definition at line 18 of file MqlArray.h.

Constructor & Destructor Documentation

template<typename T>
MqlArray< T >::MqlArray ( )
inline

Definition at line 22 of file MqlArray.h.

References MqlArray< T >::fAllocation, MqlArray< T >::fArray, MqlArray< T >::fImmutable, MqlArray< T >::fLastSize, and MqlArray< T >::fSize.

22  {
23  fArray = NULL;
24  fSize = 0;
25  fLastSize = 0;
26  fAllocation = 0;
27  fImmutable = false;
28  }
template<typename T>
MqlArray< T >::~MqlArray ( )
inline

Definition at line 30 of file MqlArray.h.

References MqlArray< T >::fArray, and MqlArray< T >::fImmutable.

30  {
31  if(!fImmutable && fArray != NULL) {
32  delete[] fArray;
33  }
34  }

Member Function Documentation

template<typename T>
bool MqlArray< T >::checkSort ( int(*)(const void *, const void *)  compar)
inline

Definition at line 90 of file MqlArray.h.

References MqlArray< T >::fSize, i, and printf().

Referenced by MMuPC1AnalysisMQL(), and MMuSCAnalysisMQL().

90  {
91  for(int i = 1; i < fSize; i++) {
92 // if(compar(&fArray[i-1], &fArray[i]) > 0) {
93  if(compar(&(*this)[i-1], &(*this)[i]) > 0) {
94 printf("checkSort: problem at element %d\n", i);
95  return false;
96  }
97  }
98 
99  return true;
100  }
template<typename T>
void MqlArray< T >::finish ( )
inline

Definition at line 67 of file MqlArray.h.

References MqlArray< T >::fAllocation, MqlArray< T >::fArray, MqlArray< T >::fImmutable, MqlArray< T >::fLastSize, and MqlArray< T >::fSize.

Referenced by MMuPC1AnalysisMQL(), and MMuSCAnalysisMQL().

67  {
68 #if 0
69  if(!fImmutable) {
70  fAllocation = 0;
71  fLastSize = fSize;
72  fSize = 0;
73 
74  if(fArray != NULL) {
75  delete[] fArray;
76  fArray = NULL;
77  }
78  }
79 #else
80  if(!fImmutable) {
81  fSize = 0;
82  }
83 #endif
84  }
template<typename T>
void MqlArray< T >::fromBank ( void *  pevent,
char *  bankName 
)
inline

Definition at line 126 of file MqlArray.h.

References MqlArray< T >::fArray, MqlArray< T >::fImmutable, MqlArray< T >::fSize, and printf().

Referenced by MMuPC1AnalysisMQL(), and MMuSCAnalysisMQL().

126  {
127  fSize = bk_locate(pevent, bankName, (DWORD*) &fArray)
128  * sizeof(DWORD) / sizeof(T);
129  if(fArray == NULL)
130  {
131  printf("Warning: could not find bank %s\n", bankName);
132  }
133  fImmutable = true;
134  }
template<typename T>
int MqlArray< T >::next ( )
inline

Definition at line 40 of file MqlArray.h.

References MqlArray< T >::fSize, and MqlArray< T >::setSize().

Referenced by MMuPC1AnalysisMQL(), and MMuSCAnalysisMQL().

40  {
41  int retval = fSize;
42  setSize(fSize + 1);
43  return retval;
44  }
template<typename T>
T& MqlArray< T >::operator[] ( int  i)
inline

Definition at line 36 of file MqlArray.h.

References MqlArray< T >::fArray, and i.

36  {
37  return fArray[i];
38  }
template<typename T>
void MqlArray< T >::realloc ( int  minSize)
inline

Definition at line 102 of file MqlArray.h.

References MqlArray< T >::fAllocation, MqlArray< T >::fArray, MqlArray< T >::fSize, REALLOC_C, and REALLOC_N.

Referenced by MqlArray< T >::reset(), and MqlArray< T >::setSize().

102  {
103 
104  int newSize = REALLOC_N*fAllocation + REALLOC_C;
105 
106  if(minSize > newSize) {
107  newSize = minSize;
108  }
109 
110  // make a new array and put it into place
111  T *oldArray = fArray;
112  T *newArray = new T[newSize];
113  fArray = newArray;
114  fAllocation = newSize;
115 
116  // copy the contents and delete the old array
117  if(oldArray != NULL) {
118  memcpy(newArray, oldArray, fSize*sizeof(T));
119  memset(newArray+fSize, 0, (newSize-fSize)*sizeof(T));
120  delete[] oldArray;
121  } else {
122  memset(newArray, 0, (newSize)*sizeof(T));
123  }
124  }
template<typename T>
void MqlArray< T >::reset ( )
inline

Definition at line 57 of file MqlArray.h.

References MqlArray< T >::fImmutable, MqlArray< T >::fLastSize, MqlArray< T >::fSize, and MqlArray< T >::realloc().

Referenced by MMuPC1AnalysisMQL(), and MMuSCAnalysisMQL().

57  {
58 #if 0
59  if(!fImmutable) {
60  int nextSize = (int) (fLastSize * 0.9);
61  fSize = 0;
62  realloc(nextSize);
63  }
64 #endif
65  }
template<typename T>
void MqlArray< T >::setSize ( int  size)
inline

Definition at line 50 of file MqlArray.h.

References MqlArray< T >::fAllocation, MqlArray< T >::fSize, MqlArray< T >::realloc(), and MqlArray< T >::size().

Referenced by MqlArray< T >::next().

50  {
51  if(size > fAllocation) {
52  realloc(size);
53  }
54  fSize = size;
55  }
template<typename T>
int MqlArray< T >::size ( )
inline

Definition at line 46 of file MqlArray.h.

References MqlArray< T >::fSize.

Referenced by MMuPC1AnalysisMQL(), MMuSCAnalysisMQL(), and MqlArray< T >::setSize().

46  {
47  return fSize;
48  }
template<typename T>
void MqlArray< T >::sort ( int(*)(const void *, const void *)  compar)
inline

Definition at line 86 of file MqlArray.h.

References MqlArray< T >::fArray, and MqlArray< T >::fSize.

Referenced by MMuPC1AnalysisMQL().

86  {
87  qsort(fArray, fSize, sizeof(T), compar);
88  }
template<typename T>
void MqlArray< T >::toBank ( void *  pevent,
char *  bankName 
)
inline

Definition at line 136 of file MqlArray.h.

References MqlArray< T >::fArray, and MqlArray< T >::fSize.

Referenced by MMuPC1AnalysisMQL().

136  {
137  T *outputArray;
138  bk_create(pevent, bankName, TID_DWORD, (DWORD*) &outputArray);
139  memcpy(outputArray, fArray, fSize * sizeof(T));
140  bk_close(pevent, outputArray + fSize);
141  }

Field Documentation

template<typename T>
int MqlArray< T >::fAllocation
private
template<typename T>
T* MqlArray< T >::fArray
private
template<typename T>
bool MqlArray< T >::fImmutable
private
template<typename T>
int MqlArray< T >::fLastSize
private
template<typename T>
int MqlArray< T >::fSize
private

The documentation for this class was generated from the following file: