Additional protection in case of negative indexes. More investigation is needed
[u/mrichter/AliRoot.git] / ITS / AliITSpList.cxx
CommitLineData
2134176d 1/**************************************************************************
2 * Copyright(c) 1998-1999, 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/* $Id$ */
16
fb4e90e0 17//***********************************************************************
18//
9881a682 19// It consist of a TClonesArray of
fb4e90e0 20// AliITSpListItem objects
21// This array can be accessed via 2 indexed
22// it is used at digitization level by
23// all the 3 ITS subdetectors
24//
25// ***********************************************************************
26
2134176d 27#include "AliITSpList.h"
fb4e90e0 28#include "AliITSpListItem.h"
29
2134176d 30
31//______________________________________________________________________
32
925e6570 33ClassImp(AliITSpList)
2134176d 34//______________________________________________________________________
35AliITSpList::AliITSpList(){
36 // Default constructor
c7d528c6 37 // Inputs:
38 // none.
39 // Outputs:
40 // none.
41 // Return:
42 // A zeroed/empty AliITSpList class.
2134176d 43
44 fNi = 0;
45 fNj = 0;
46 fa = 0;
47}
48//______________________________________________________________________
49AliITSpList::AliITSpList(Int_t imax,Int_t jmax){
50 // Standard constructor
c7d528c6 51 // Inputs:
52 // none.
53 // Outputs:
54 // none.
55 // Return:
56 // A setup AliITSpList class.
2134176d 57
58 fNi = imax;
59 fNj = jmax;
9881a682 60 fEntries = 0;
61 fa = new TClonesArray("AliITSpListItem",fNi*fNj);
2134176d 62}
63//______________________________________________________________________
64AliITSpList::~AliITSpList(){
65 // Default destructor
c7d528c6 66 // Inputs:
67 // none.
68 // Outputs:
69 // none.
70 // Return:
71 // a properly destroyed class
2134176d 72
9881a682 73 if(fa){
74 fa->Delete();
75 delete fa;
76 fa = 0;
77 }
2134176d 78 fNi = 0;
79 fNj = 0;
9881a682 80
81 fEntries = 0;
2134176d 82}
fb4e90e0 83
2134176d 84//______________________________________________________________________
85void AliITSpList::ClearMap(){
9881a682 86 // Delete all AliITSpListItems and zero TClonesArray.
c7d528c6 87 // Inputs:
88 // none.
89 // Outputs:
90 // none.
91 // Return:
92 // A zeroed AliITSpList class.
2134176d 93
9ce4d38b 94 fa->Delete();
9881a682 95 fEntries = 0;
2134176d 96}
97//______________________________________________________________________
98void AliITSpList::DeleteHit(Int_t i,Int_t j){
9881a682 99 // Delete a particular AliITSpListItems.
c7d528c6 100 // Inputs:
101 // Int_t i Row number
102 // Int_t j Columns number
103 // Outputs:
104 // none.
105 // Return:
106 // none.
2134176d 107 Int_t k = GetIndex(i,j);
108
109 if(fa->At(k)!=0){
9881a682 110 fa->RemoveAt(k);
2134176d 111 } // end for i && if
9881a682 112 if(k==fEntries-1) fEntries--;
2134176d 113}
114//______________________________________________________________________
115AliITSpList& AliITSpList::operator=(const AliITSpList &source){
116 // = operator
c7d528c6 117 // Inputs:
118 // const AliITSpList &source A AliITSpList object.
119 // Outputs:
120 // none.
121 // Return:
122 // A copied AliITSpList object.
2134176d 123
124 if(this == &source) return *this;
125
126 if(this->fa!=0){ // if this->fa exists delete it first.
9881a682 127 fa->Delete();
128 delete fa;
129 fa = 0;
2134176d 130 } // end if this->fa!=0
131 this->fNi = source.fNi;
132 this->fNj = source.fNj;
9881a682 133 this->fa = new TClonesArray(*(source.fa));
134 this->fEntries = source.fEntries;
2134176d 135
136 return *this;
137}
138//______________________________________________________________________
fb4e90e0 139AliITSpList::AliITSpList(const AliITSpList &source) : AliITSMap(source){
140 // Copy constructor
2134176d 141
fb4e90e0 142 fNi = source.fNi;
143 fNj = source.fNj;
9881a682 144 fa = new TClonesArray(*(source.fa));
145 fEntries = source.fEntries;
2134176d 146}
147//______________________________________________________________________
c7d528c6 148void AliITSpList::AddItemTo(Int_t fileIndex, AliITSpListItem *pl) {
149 // Adds the contents of pl to the list with track number off set given by
150 // fileIndex.
151 // Creates the AliITSpListItem if needed.
152 // Inputs:
153 // Int_t fileIndex track number offset value
154 // AliITSpListItem *pl an AliITSpListItem to be added to this class.
155 // Outputs:
156 // none.
157 // Return:
158 // none.
159 Int_t index = pl->GetIndex();
9881a682 160 TClonesArray &rfa = *fa;
c7d528c6 161 if( fa->At( index ) == 0 ) { // most create AliITSpListItem
9881a682 162 new(rfa[index])AliITSpListItem(-2,-1,pl->GetModule(),index,0.0);
c7d528c6 163 } // end if
164
cab0142f 165 ((AliITSpListItem*)(fa->At(index)))->AddTo( fileIndex,pl);
9881a682 166 if(index>=fEntries) fEntries = index +1;
c7d528c6 167}
168//______________________________________________________________________
2134176d 169void AliITSpList::AddSignal(Int_t i,Int_t j,Int_t trk,Int_t ht,Int_t mod,
c7d528c6 170 Double_t signal){
9881a682 171 // Adds a Signal value to the TClonesArray at i,j.
172 // Creates the AliITSpListItem
2134176d 173 // if needed.
c7d528c6 174 // Inputs:
175 // Int_t i Row number for this signal
176 // Int_t j Column number for this signal
177 // Int_t trk Track number creating this signal
178 // Int_t ht Hit number creating this signal
179 // Int_t mod The module where this signal is in
180 // Double_t signal The signal (ionization)
181 // Outputs:
182 // none.
183 // Return:
184 // none.
9ce4d38b 185 Int_t index = GetIndex(i,j);
d7f298dd 186 if (index<0) return;
9881a682 187 TClonesArray &rfa = *fa;
188 if(GetpListItem(index)==0){ // must create AliITSpListItem
189 new(rfa[index])AliITSpListItem(trk,ht,mod,index,signal);
2134176d 190 }else{ // AliITSpListItem exists, just add signal to it.
9ce4d38b 191 GetpListItem(index)->AddSignal(trk,ht,mod,index,signal);
2134176d 192 } // end if
9881a682 193 if(index>=fEntries) fEntries = index +1;
2134176d 194}
195//______________________________________________________________________
196void AliITSpList::AddNoise(Int_t i,Int_t j,Int_t mod,Double_t noise){
9881a682 197 // Adds a noise value to the TClonesArray at i,j.
198 // Creates the AliITSpListItem
2134176d 199 // if needed.
c7d528c6 200 // Inputs:
201 // Int_t i Row number for this noise
202 // Int_t j Column number for this noise
203 // Double_t noise The noise signal value.
204 // Outputs:
205 // none.
206 // Return:
207 // none.
9ce4d38b 208 Int_t index = GetIndex(i,j);
9881a682 209 TClonesArray &rfa = *fa;
9ce4d38b 210 if(GetpListItem(index)==0){ // most create AliITSpListItem
9881a682 211 new(rfa[index]) AliITSpListItem(mod,index,noise);
2134176d 212 }else{ // AliITSpListItem exists, just add signal to it.
9ce4d38b 213 GetpListItem(index)->AddNoise(mod,index,noise);
2134176d 214 } // end if
9881a682 215 if(index>=fEntries) fEntries = index +1;
2134176d 216}
217//______________________________________________________________________
fb4e90e0 218void AliITSpList::GetCell(Int_t index,Int_t &i,Int_t &j) const {
219 // returns the i,j index numbers from the linearized index computed
220 // with GetIndex
221 if(index<0 || index>=fNi*fNj){
222 Warning("GetCell","Index out of range 0<=index=%d<%d",
223 index,fNi*fNj);
224 i=-1;j=-1;
2134176d 225 return;
fb4e90e0 226 } // end if
227 i = index/fNj;
228 j = index - fNj*i;
229 return;
230}
231//______________________________________________________________________
232Int_t AliITSpList::GetIndex(Int_t i, Int_t j) const {
9881a682 233 // returns the TClonesArray index for a given set of map indexes.
fb4e90e0 234 if(i<0||i>=fNi || j<0||j>=fNj){
235 Warning("GetIndex","Index out of range 0<i=%d<%d and 0<0j=%d<%d",i,fNi,j,fNj);
236 return -1;
237 }
238 else {
239 return fNj*i+j;
240 }
2134176d 241}