1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 // Class to hold variable size arrays of Float_t
23 #include <TCollection.h>
24 #include "AliTOFArray.h"
29 //-------------------------------------------------------------------
30 AliTOFArray::AliTOFArray(Int_t size):
33 fArray(new TArrayF*[size]){
37 for (Int_t i=0;i<size;i++){
41 //-------------------------------------------------------------------
42 AliTOFArray::AliTOFArray(const AliTOFArray & source):
43 TObject(),fSize(0),fArray(0x0){
49 this->fSize= source.fSize;
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);
60 //-------------------------------------------------------------------
61 AliTOFArray& AliTOFArray::operator=(const AliTOFArray & source) {
64 // assignment operator
68 this->fSize= source.fSize;
70 fArray = new TArrayF*[fSize];
71 for (Int_t ich = 0; ich<fSize; ich ++){
72 fArray[ich] = new TArrayF();
73 fArray[ich]->Set(source.fArray[ich]->GetSize());
74 for (Int_t j = 0; j < fArray[ich]->GetSize(); j++){
75 fArray[ich]->AddAt(fArray[ich]->GetAt(j),j);
82 //------------------------------------------------------------------
83 AliTOFArray::~AliTOFArray(){
92 //-------------------------------------------------------------------
93 void AliTOFArray::SetArray(Int_t pos, Int_t size) {
96 // adding an array of Float_t with size=size
99 if (pos>-1 && pos < fSize){
101 // printf("Creating array\n");
102 fArray[pos] = new TArrayF();
104 fArray[pos]->Reset();
105 fArray[pos]->Set(size);
107 else printf("Position out of bounds, returning\n");
111 //-------------------------------------------------------------------
112 void AliTOFArray::SetAt(Int_t pos, Int_t nelements, Float_t* content) {
114 // pos = index of the array to be modified
115 // nelements = n. of elements to be modified in array
116 // content = values to be set in array
118 if (pos>-1 && pos < fSize){
120 Int_t size = fArray[pos]->GetSize();
121 if (nelements <= size){
122 for (Int_t i=0;i<nelements;i++){
123 fArray[pos]->AddAt(content[i],i);
126 else printf("Too many elements to be added, returning without adding any\n");
128 else printf("Non-existing array, returning\n");
130 else printf("Position out of bounds, returning\n");
134 //-------------------------------------------------------------------
135 void AliTOFArray::SetAt(Int_t pos, Int_t ielement, Float_t content) {
137 // pos = index of the array to be modified
138 // ielement = index of the element to be modified in array
139 // content = value to be set in array
141 if (pos>-1 && pos < fSize){
143 Int_t size = fArray[pos]->GetSize();
144 if (ielement < size){
145 //printf("Adding %f content in position %d to array %d \n",content, ielement, pos);
146 fArray[pos]->AddAt(content,ielement);
148 else if (ielement == size) {
149 printf ("Increasing the size by 1 and adding a new element to the array\n");
150 fArray[pos]->Set(size+1);
151 fArray[pos]->AddAt(content,ielement);
153 else printf("Not possible to add element %d, size of the array too small, and this would not be the next entry!\n",ielement);
155 else printf("Non-existing array, returning\n");
157 else printf("Position out of bounds, returning\n");
161 //-------------------------------------------------------------------
162 void AliTOFArray::RemoveArray(Int_t pos) {
165 // removing the array at position pos
168 if (fArray[pos]) fArray[pos]->Reset();
169 else printf("Not possible to remove array, array does not exist\n");
173 //-------------------------------------------------------------------
174 Float_t* AliTOFArray::GetArray(Int_t pos) {
177 // Getting back array at position pos
180 if (pos>-1 && pos < fSize){
182 return fArray[pos]->GetArray();
184 else printf("Non-existing array, returning\n");
186 else printf("Position out of bounds, returning\n");
190 //-------------------------------------------------------------------
191 Float_t AliTOFArray::GetArrayAt(Int_t pos, Int_t ielement) {
194 // Getting back ielement of array at position pos
197 if (pos>-1 && pos < fSize){
199 if (ielement<fArray[pos]->GetSize()){
200 return fArray[pos]->GetAt(ielement);
202 else printf("Element in array out of bounds, returning\n");
204 else printf("Non-existing array, returning\n");
206 else printf("Position out of bounds, returning\n");
210 //-------------------------------------------------------------------
211 void AliTOFArray::ReSetArraySize(Int_t pos, Int_t size) {
214 // Changing size of array at position pos, using TArrayF::Set method
215 // (without loosing what is already there)
218 if (pos>-1 && pos < fSize){
220 fArray[pos]->Set(size);
222 else printf("Non-existing array, returning\n");
224 else printf("Position out of bounds, returning\n");
228 //-------------------------------------------------------------------
229 Int_t AliTOFArray::GetArraySize(Int_t pos) {
232 // Getting back size of array at position pos
235 if (pos>-1 && pos < fSize){
237 return fArray[pos]->GetSize();
239 else printf("Non-existing array, returning\n");
241 else printf("Position out of bounds, returning\n");
245 //-------------------------------------------------------------------
246 Long64_t AliTOFArray::Merge(TCollection *list){
253 if (list->IsEmpty()) return 1;
254 printf("Merging %d AliTOFArrays %s\n", list->GetSize()+1, GetName());
256 // iterating over the entries in the TList
258 AliTOFArray *tofArray;
259 Int_t count = 0; // object counter
260 while ((tofArray=(AliTOFArray*)next())) {
261 // printf("Count = %d \n",count);
262 //if (!tofArray) continue; // dead_code x coverity
263 if (tofArray->GetSize() != fSize){
264 printf("Merging with current entry in list not possible, AliTOFArray in the list has size different from the current one\n");
267 for (Int_t i = 0; i<fSize; i++){
268 Float_t* tempArray = tofArray->GetArray(i);
269 Int_t tempSize = tofArray->GetArraySize(i);
270 Int_t currentSize = GetArraySize(i);
271 Int_t mergeSize = currentSize+tempSize;
272 fArray[i]->Set(mergeSize);
274 for (Int_t j = currentSize; j<mergeSize; j++){
275 SetAt(i,j,tempArray[j-currentSize]);
280 printf("Count = %d \n",count);