AliPhysics  vAN-20151016 (8d2b0e8)
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros
AliEmcalTriggerDataGrid.cxx
Go to the documentation of this file.
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  **************************************************************************/
16 
18 templateClassImp(AliEmcalTriggerDataGrid)
20 
21 template<typename T>
23  fNCols(0),
24  fNRows(0),
25  fValues(NULL)
26 {
27 }
28 
29 template<typename T>
31  fNCols(ncols),
32  fNRows(nrows),
33  fValues(NULL)
34 {
35  fValues = new T[fNCols * fNRows];
36  memset(fValues, 0, sizeof(T) * fNCols * fNRows);
37 }
38 
39 template<typename T>
41  fNCols(ref.fNCols),
42  fNRows(ref.fNRows),
43  fValues(NULL)
44 {
45  fValues = new T[fNCols * fNRows];
46  memcpy(fValues, ref.fValues, sizeof(T) * fNCols * fNRows);
47 }
48 
49 template<typename T>
51  TObject::operator =(ref);
52  if(this != &ref){
53  if(fValues) delete[] fValues;
54  fNCols = ref.fNCols;
55  fNRows = ref.fNRows;
56  fValues = new T[fNCols * fNRows];
57  memcpy(fValues, ref.fValues, sizeof(T) * fNCols * fNRows);
58  }
59  return *this;
60 }
61 
62 template<typename T>
63 const T &AliEmcalTriggerDataGrid<T>::operator()(Int_t col, Int_t row) const{
64  if(!fValues) throw UninitException();
65  if(row >= fNRows) throw OutOfBoundsException(OutOfBoundsException::kRowDir, row, fNRows);
66  if(col >= fNCols) throw OutOfBoundsException(OutOfBoundsException::kColDir, col, fNCols);
67  return fValues[GetIndex(col, row)];
68 }
69 
70 template<typename T>
71 T &AliEmcalTriggerDataGrid<T>::operator()(Int_t col, Int_t row) {
72  if(!fValues) throw UninitException();
73  if(row >= fNRows) throw OutOfBoundsException(OutOfBoundsException::kRowDir, row, fNRows);
74  if(col >= fNCols) throw OutOfBoundsException(OutOfBoundsException::kColDir, col, fNCols);
75  return fValues[GetIndex(col, row)];
76 }
77 
78 template<typename T>
80  if(fValues) delete[] fValues;
81 }
82 
83 template<typename T>
84 void AliEmcalTriggerDataGrid<T>::Allocate(Int_t ncols, Int_t nrows){
85  if(fValues){
86  T *tempstorage = new T[ncols * nrows];
87  memset(tempstorage, 0, sizeof(T) * ncols * nrows);
88  // Copy old content in new array
89  for(int irow = 0; irow < fNRows; irow++){
90  for(int icol = 0; icol < fNCols; icol++){
91  int indexnew = irow * ncols + icol,
92  indexold = irow * fNCols + icol;
93  tempstorage[indexnew] = fValues[indexold];
94  }
95  }
96  delete[] fValues;
97  fValues = tempstorage;
98  } else {
99  fValues = new T[ncols * nrows];
100  memset(fValues, 0, sizeof(T) * ncols * nrows);
101  }
102  fNCols = ncols;
103  fNRows = nrows;
104 }
105 
106 template<typename T>
107 void AliEmcalTriggerDataGrid<T>::SetADC(Int_t col, Int_t row, const T &adc) {
108  if(!fValues)
109  throw UninitException();
110  if(row >= fNRows)
111  throw OutOfBoundsException(OutOfBoundsException::kRowDir, row, fNRows);
112  if(col >= fNCols)
113  throw OutOfBoundsException(OutOfBoundsException::kColDir, col, fNCols);
114  fValues[GetIndex(col, row)] = adc;
115 }
116 
117 template<typename T>
119  memset(fValues, 0, sizeof(T) * fNCols * fNRows);
120 }
121 
122 template<typename T>
123 const T &AliEmcalTriggerDataGrid<T>::GetADC(Int_t col, Int_t row) const {
124  if(!fValues)
125  throw UninitException();
126  if(row >= fNRows)
127  throw OutOfBoundsException(OutOfBoundsException::kRowDir, row, fNRows);
128  if(col >= fNCols)
129  throw OutOfBoundsException(OutOfBoundsException::kColDir, col, fNCols);
130  return fValues[GetIndex(col, row)];
131 }
132 
133 template<typename T>
134 Int_t AliEmcalTriggerDataGrid<T>::GetIndex(Int_t col, Int_t row) const {
135  return row * fNCols + col;
136 }
137 
138 template class AliEmcalTriggerDataGrid<int>;
139 template class AliEmcalTriggerDataGrid<double>;
140 template class AliEmcalTriggerDataGrid<float>;
141 template class AliEmcalTriggerDataGrid<char>;
Exception class handling access to non-existing container element.
AliEmcalTriggerDataGrid< T > & operator=(const AliEmcalTriggerDataGrid< T > &ref)
const T & GetADC(Int_t col, Int_t row) const
T * fValues
Array of Trigger ADC values.
Int_t fNRows
Number of rows.
Int_t GetIndex(Int_t col, Int_t row) const
void SetADC(Int_t col, Int_t row, const T &adc)
const T & operator()(Int_t col, Int_t row) const
Error handling for uninitialized grid.
Container for ADC / Amplitudes from the EMCAL triggers.
Int_t GetIndex(TObjArray *triggersB, Int_t trigNr, Int_t centNr)
Definition: PlotMuonQA.C:2046
void Allocate(Int_t ncols, Int_t nrows)
Int_t fNCols
Number of columns.