]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TOF/AliTOFArray.cxx
Coverity fixes.
[u/mrichter/AliRoot.git] / TOF / AliTOFArray.cxx
CommitLineData
4db98a6a 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
17//
18// Class to hold variable size arrays of Float_t
19//
20
21#include <TObject.h>
22#include <TArrayF.h>
23#include <TCollection.h>
24#include "AliTOFArray.h"
25//#include "AliLog.h"
26
27ClassImp(AliTOFArray)
28
29//-------------------------------------------------------------------
30AliTOFArray::AliTOFArray(Int_t size):
31 TObject(),
32 fSize(size),
33 fArray(new TArrayF*[size]){
34
35 // constructor
36
37 for (Int_t i=0;i<size;i++){
38 fArray[i] = NULL;
39 }
40}
41//-------------------------------------------------------------------
42AliTOFArray::AliTOFArray(const AliTOFArray & source):
43 TObject(),fSize(0),fArray(0x0){
44
45 //
46 // copy constructor
47 //
48
49 this->fSize= source.fSize;
227c3238 50 fArray = new TArrayF*[fSize];
51 for (Int_t ich = 0; ich<fSize; ich ++){
52 fArray[ich] = new TArrayF();
53 fArray[ich]->Set(source.fArray[ich]->GetSize());
54 for (Int_t j = 0; j < fArray[ich]->GetSize(); j++){
55 fArray[ich]->AddAt(fArray[ich]->GetAt(j),j);
56 }
57 }
4db98a6a 58}
59
60//-------------------------------------------------------------------
61AliTOFArray& AliTOFArray::operator=(const AliTOFArray & source) {
62
63 //
64 // assignment operator
65 //
66
227c3238 67 if (this != &source){
68 this->fSize= source.fSize;
4afeaa51 69 //fArray = new TArrayF*[fSize];
227c3238 70 for (Int_t ich = 0; ich<fSize; ich ++){
4afeaa51 71 //fArray[ich] = new TArrayF();
227c3238 72 fArray[ich]->Set(source.fArray[ich]->GetSize());
73 for (Int_t j = 0; j < fArray[ich]->GetSize(); j++){
74 fArray[ich]->AddAt(fArray[ich]->GetAt(j),j);
75 }
76 }
77 }
4db98a6a 78 return *this;
79}
80
81//------------------------------------------------------------------
82AliTOFArray::~AliTOFArray(){
83
84 //
85 // Destructor
86 //
87
88 delete [] fArray;
89}
90
91//-------------------------------------------------------------------
92void AliTOFArray::SetArray(Int_t pos, Int_t size) {
93
94 //
95 // adding an array of Float_t with size=size
96 //
97
98 if (pos>-1 && pos < fSize){
99 if (!fArray[pos]) {
100 // printf("Creating array\n");
101 fArray[pos] = new TArrayF();
102 }
103 fArray[pos]->Reset();
104 fArray[pos]->Set(size);
105 }
106 else printf("Position out of bounds, returning\n");
107 return;
108}
109
110//-------------------------------------------------------------------
111void AliTOFArray::SetAt(Int_t pos, Int_t nelements, Float_t* content) {
112
113 // pos = index of the array to be modified
114 // nelements = n. of elements to be modified in array
115 // content = values to be set in array
116
117 if (pos>-1 && pos < fSize){
118 if (fArray[pos]){
119 Int_t size = fArray[pos]->GetSize();
120 if (nelements <= size){
121 for (Int_t i=0;i<nelements;i++){
122 fArray[pos]->AddAt(content[i],i);
123 }
124 }
125 else printf("Too many elements to be added, returning without adding any\n");
126 }
127 else printf("Non-existing array, returning\n");
128 }
129 else printf("Position out of bounds, returning\n");
130 return;
131}
132
133//-------------------------------------------------------------------
134void AliTOFArray::SetAt(Int_t pos, Int_t ielement, Float_t content) {
135
136 // pos = index of the array to be modified
137 // ielement = index of the element to be modified in array
138 // content = value to be set in array
139
140 if (pos>-1 && pos < fSize){
141 if (fArray[pos]){
142 Int_t size = fArray[pos]->GetSize();
143 if (ielement < size){
144 //printf("Adding %f content in position %d to array %d \n",content, ielement, pos);
145 fArray[pos]->AddAt(content,ielement);
146 }
f2baaf12 147 else if (ielement == size) {
4db98a6a 148 printf ("Increasing the size by 1 and adding a new element to the array\n");
149 fArray[pos]->Set(size+1);
150 fArray[pos]->AddAt(content,ielement);
151 }
152 else printf("Not possible to add element %d, size of the array too small, and this would not be the next entry!\n",ielement);
153 }
154 else printf("Non-existing array, returning\n");
155 }
156 else printf("Position out of bounds, returning\n");
157 return;
158}
159
160//-------------------------------------------------------------------
161void AliTOFArray::RemoveArray(Int_t pos) {
162
163 //
164 // removing the array at position pos
165 //
166
167 if (fArray[pos]) fArray[pos]->Reset();
168 else printf("Not possible to remove array, array does not exist\n");
169 return;
170}
171
172//-------------------------------------------------------------------
173Float_t* AliTOFArray::GetArray(Int_t pos) {
174
175 //
176 // Getting back array at position pos
177 //
178
179 if (pos>-1 && pos < fSize){
180 if (fArray[pos]){
181 return fArray[pos]->GetArray();
182 }
183 else printf("Non-existing array, returning\n");
184 }
185 else printf("Position out of bounds, returning\n");
186 return 0;
187}
188
189//-------------------------------------------------------------------
190Float_t AliTOFArray::GetArrayAt(Int_t pos, Int_t ielement) {
191
192 //
193 // Getting back ielement of array at position pos
194 //
195
196 if (pos>-1 && pos < fSize){
197 if (fArray[pos]){
198 if (ielement<fArray[pos]->GetSize()){
199 return fArray[pos]->GetAt(ielement);
200 }
201 else printf("Element in array out of bounds, returning\n");
202 }
203 else printf("Non-existing array, returning\n");
204 }
205 else printf("Position out of bounds, returning\n");
206 return 0;
207}
208
209//-------------------------------------------------------------------
210void AliTOFArray::ReSetArraySize(Int_t pos, Int_t size) {
211
212 //
213 // Changing size of array at position pos, using TArrayF::Set method
214 // (without loosing what is already there)
215 //
216
217 if (pos>-1 && pos < fSize){
218 if (fArray[pos]){
219 fArray[pos]->Set(size);
220 }
221 else printf("Non-existing array, returning\n");
222 }
223 else printf("Position out of bounds, returning\n");
224 return;
225}
226
227//-------------------------------------------------------------------
228Int_t AliTOFArray::GetArraySize(Int_t pos) {
229
230 //
231 // Getting back size of array at position pos
232 //
233
234 if (pos>-1 && pos < fSize){
235 if (fArray[pos]){
236 return fArray[pos]->GetSize();
237 }
238 else printf("Non-existing array, returning\n");
239 }
240 else printf("Position out of bounds, returning\n");
241 return -1;
242}
243
244//-------------------------------------------------------------------
245Long64_t AliTOFArray::Merge(TCollection *list){
246
247 //
248 // Merging method
249 //
250
251 if (!list) return 0;
252 if (list->IsEmpty()) return 1;
253 printf("Merging %d AliTOFArrays %s\n", list->GetSize()+1, GetName());
254
255 // iterating over the entries in the TList
256 TIter next(list);
257 AliTOFArray *tofArray;
258 Int_t count = 0; // object counter
259 while ((tofArray=(AliTOFArray*)next())) {
260 // printf("Count = %d \n",count);
de40f9c1 261 //if (!tofArray) continue; // dead_code x coverity
4db98a6a 262 if (tofArray->GetSize() != fSize){
263 printf("Merging with current entry in list not possible, AliTOFArray in the list has size different from the current one\n");
264 continue;
265 }
266 for (Int_t i = 0; i<fSize; i++){
267 Float_t* tempArray = tofArray->GetArray(i);
268 Int_t tempSize = tofArray->GetArraySize(i);
269 Int_t currentSize = GetArraySize(i);
270 Int_t mergeSize = currentSize+tempSize;
271 fArray[i]->Set(mergeSize);
272 if (tempSize !=0){
273 for (Int_t j = currentSize; j<mergeSize; j++){
274 SetAt(i,j,tempArray[j-currentSize]);
275 }
276 }
277 }
278 count++;
279 printf("Count = %d \n",count);
280
281 }
282 return count+1;
283
284}
285