LCOV - code coverage report
Current view: top level - TOF/TOFbase - AliTOFArray.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 126 0.8 %
Date: 2016-06-14 17:26:59 Functions: 1 18 5.6 %

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

Generated by: LCOV version 1.11