Line data Source code
1 : /**************************************************************************
2 : * Copyright(c) 1998-2013, ALICE Experiment at CERN, All rights reserved. *
3 : * *
4 : * Author: The ALICE Off-line Project. *
5 : * Contributors are mentioned in the code where appropriate. *
6 : * *
7 : * Permission to use, copy, modify and distribute this software and its *
8 : * documentation strictly for non-commercial purposes is hereby granted *
9 : * without fee, provided that the above copyright notice appears in all *
10 : * copies and that both the copyright notice and this permission notice *
11 : * appear in the supporting documentation. The authors make no claims *
12 : * about the suitability of this software for any purpose. It is *
13 : * provided "as is" without express or implied warranty. *
14 : **************************************************************************/
15 : #include "AliEMCALTriggerDataGrid.h"
16 :
17 : /// \cond CLASSIMP
18 22 : templateClassImp(AliEMCALTriggerDataGrid)
19 : /// \endcond
20 :
21 : template<typename T>
22 : AliEMCALTriggerDataGrid<T>::AliEMCALTriggerDataGrid():
23 0 : fNCols(0),
24 0 : fNRows(0),
25 0 : fValues(NULL)
26 0 : {
27 0 : }
28 :
29 : template<typename T>
30 : AliEMCALTriggerDataGrid<T>::AliEMCALTriggerDataGrid(Int_t ncols, Int_t nrows):
31 0 : fNCols(ncols),
32 0 : fNRows(nrows),
33 0 : fValues(NULL)
34 0 : {
35 0 : fValues = new T[fNCols * fNRows];
36 0 : memset(fValues, 0, sizeof(T) * fNCols * fNRows);
37 0 : }
38 :
39 : template<typename T>
40 : AliEMCALTriggerDataGrid<T>::AliEMCALTriggerDataGrid(const AliEMCALTriggerDataGrid &ref):
41 0 : fNCols(ref.fNCols),
42 0 : fNRows(ref.fNRows),
43 0 : fValues(NULL)
44 0 : {
45 0 : fValues = new T[fNCols * fNRows];
46 0 : memcpy(fValues, ref.fValues, sizeof(T) * fNCols * fNRows);
47 0 : }
48 :
49 : template<typename T>
50 : AliEMCALTriggerDataGrid<T> &AliEMCALTriggerDataGrid<T>::operator=(const AliEMCALTriggerDataGrid<T> &ref){
51 0 : TObject::operator =(ref);
52 0 : if(this != &ref){
53 0 : if(fValues) delete[] fValues;
54 0 : fNCols = ref.fNCols;
55 0 : fNRows = ref.fNRows;
56 0 : fValues = new T[fNCols * fNRows];
57 0 : memcpy(fValues, ref.fValues, sizeof(T) * fNCols * fNRows);
58 0 : }
59 0 : return *this;
60 : }
61 :
62 : template<typename T>
63 : const T &AliEMCALTriggerDataGrid<T>::operator()(Int_t col, Int_t row) const{
64 0 : if(!fValues) throw UninitException();
65 0 : if(row >= fNRows) throw OutOfBoundsException(OutOfBoundsException::kRowDir, row, fNRows);
66 0 : if(col >= fNCols) throw OutOfBoundsException(OutOfBoundsException::kColDir, col, fNCols);
67 0 : return fValues[GetIndex(col, row)];
68 0 : }
69 :
70 : template<typename T>
71 : T &AliEMCALTriggerDataGrid<T>::operator()(Int_t col, Int_t row) {
72 0 : if(!fValues) throw UninitException();
73 0 : if(row >= fNRows) throw OutOfBoundsException(OutOfBoundsException::kRowDir, row, fNRows);
74 0 : if(col >= fNCols) throw OutOfBoundsException(OutOfBoundsException::kColDir, col, fNCols);
75 0 : return fValues[GetIndex(col, row)];
76 0 : }
77 :
78 : template<typename T>
79 0 : AliEMCALTriggerDataGrid<T>::~AliEMCALTriggerDataGrid() {
80 0 : if(fValues) delete[] fValues;
81 0 : }
82 :
83 : template<typename T>
84 : void AliEMCALTriggerDataGrid<T>::Allocate(Int_t ncols, Int_t nrows){
85 0 : if(fValues){
86 0 : T *tempstorage = new T[ncols * nrows];
87 0 : memset(tempstorage, 0, sizeof(T) * ncols * nrows);
88 : // Copy old content in new array
89 0 : for(int irow = 0; irow < fNRows; irow++){
90 0 : for(int icol = 0; icol < fNCols; icol++){
91 0 : int indexnew = irow * ncols + icol,
92 0 : indexold = irow * fNCols + icol;
93 0 : tempstorage[indexnew] = fValues[indexold];
94 : }
95 : }
96 0 : delete[] fValues;
97 0 : fValues = tempstorage;
98 0 : } else {
99 0 : fValues = new T[ncols * nrows];
100 0 : memset(fValues, 0, sizeof(T) * ncols * nrows);
101 : }
102 0 : fNCols = ncols;
103 0 : fNRows = nrows;
104 0 : }
105 :
106 : template<typename T>
107 : void AliEMCALTriggerDataGrid<T>::SetADC(Int_t col, Int_t row, const T &adc) {
108 0 : if(!fValues)
109 0 : throw UninitException();
110 0 : if(row >= fNRows)
111 0 : throw OutOfBoundsException(OutOfBoundsException::kRowDir, row, fNRows);
112 0 : if(col >= fNCols)
113 0 : throw OutOfBoundsException(OutOfBoundsException::kColDir, col, fNCols);
114 0 : fValues[GetIndex(col, row)] = adc;
115 0 : }
116 :
117 : template<typename T>
118 : void AliEMCALTriggerDataGrid<T>::Reset() {
119 0 : memset(fValues, 0, sizeof(T) * fNCols * fNRows);
120 0 : }
121 :
122 : template<typename T>
123 : const T &AliEMCALTriggerDataGrid<T>::GetADC(Int_t col, Int_t row) const {
124 0 : if(!fValues)
125 0 : throw UninitException();
126 0 : if(row >= fNRows)
127 0 : throw OutOfBoundsException(OutOfBoundsException::kRowDir, row, fNRows);
128 0 : if(col >= fNCols)
129 0 : throw OutOfBoundsException(OutOfBoundsException::kColDir, col, fNCols);
130 0 : return fValues[GetIndex(col, row)];
131 0 : }
132 :
133 0 : template<typename T>
134 : Int_t AliEMCALTriggerDataGrid<T>::GetIndex(Int_t col, Int_t row) const {
135 0 : return row * fNCols + col;
136 : }
137 :
138 : template class AliEMCALTriggerDataGrid<int>;
139 : template class AliEMCALTriggerDataGrid<double>;
140 : template class AliEMCALTriggerDataGrid<float>;
141 0 : template class AliEMCALTriggerDataGrid<char>;
142 : template class AliEMCALTriggerDataGrid<unsigned char>;
|