]> git.uio.no Git - u/mrichter/AliRoot.git/blob - CONTAINERS/TArrayOfArray.cxx
More exact rounding function, but also much slower.
[u/mrichter/AliRoot.git] / CONTAINERS / TArrayOfArray.cxx
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
16 /*
17 $Log$
18 Revision 1.1  2000/11/01 16:01:26  kowal2
19 Classes for handling the new hits structures
20
21 */
22 #include "TArrayOfArray.h"
23 #include "iostream.h"
24
25
26
27
28 ClassImp(TArrayOfArray)
29 ClassImp(TArrayOfArrayVStack)
30 ClassImp(TArrayOfArrayVList)
31  
32
33 TArrayOfArrayVStack::TArrayOfArrayVStack()
34
35   fIndex = 0;
36   fArray = 0;
37 }     
38   
39 TArrayOfArrayVStack::TArrayOfArrayVStack(const char *classname)
40 {
41   fIndex = 0;
42   fArray = 0;
43   SetClass(classname);
44
45
46   
47 TArrayOfArrayVStack::~TArrayOfArrayVStack()  
48 {
49   if (fIndex) delete fIndex;
50   if (fArray) delete fArray;
51
52
53 Bool_t TArrayOfArrayVStack::SetClass(const char * classname)
54 {
55   //
56   //set class
57   if (fIndex==0) fIndex = new AliObjectArray("Int_t");
58   if (fArray==0) fArray = new AliObjectArray;
59   else fArray->Delete();
60   return fArray->SetClass(classname);
61 }
62
63
64 void  TArrayOfArrayVStack::Clear(Option_t *)
65 {
66   //
67   // clear contents
68   if (fIndex) fIndex->Clear();
69   if (fArray) fArray->Clear();
70   //if (fIndex) fIndex->Resize(0);
71   //if (fArray) fArray->Resize(0);
72   
73 }
74
75 void * TArrayOfArrayVStack::At(UInt_t index0, UInt_t index1)
76 {
77   //get pointer to the object
78   if ( (fIndex!=0) && (index0+1<fIndex->GetSize()) 
79        && ((*((UInt_t*)(fIndex->Unchecked1DAt(index0+1)))
80             >(*((UInt_t*)(fIndex->Unchecked1DAt(index0)))+index1)) ) )
81     return Unchecked1DAt(index0,index1);
82   else 
83     return 0;
84 }
85 void  TArrayOfArrayVStack::Dump(UInt_t index0, UInt_t index1)
86 {
87   void * p = At(index0,index1);
88   if ( (p) && fArray->GetClassInfo()) fArray->GetClassInfo()->ObjectDump(p); 
89   else{    
90     printf("Index %d,%d out of range\n",index0,index1);
91     cout<<flush;
92   }
93   
94 }
95
96 Int_t TArrayOfArrayVStack::Resize(Int_t index, UInt_t newsize)
97
98   //expand array with index index to newsize
99   if (index<0) index = fIndex->GetSize()-2;
100   if  ((UInt_t)index==(fIndex->GetSize()-2)){
101     Int_t arrindex = *((Int_t*)(fIndex->At(index)));
102     fArray->Resize(arrindex+newsize);
103     *(Int_t*)(fIndex->At(index+1)) = arrindex+newsize;        
104   }
105   else{
106     cout<<"out\n"; 
107   }
108   return 0;
109 }
110
111 UInt_t TArrayOfArrayVStack::Push(UInt_t size)
112 {
113   //make new array with size  - return starting index
114   if ( (fIndex==0) || (fArray==0)) return 0;
115   UInt_t index1 = fIndex->GetSize(); 
116   UInt_t indexa = fArray->GetSize();
117   fArray->Resize(indexa+size);
118   if (index1==0) { 
119     fIndex->Resize(2);
120     (*(Int_t*)fIndex->Unchecked1DAt(0))=0;
121     (*(Int_t*)fIndex->Unchecked1DAt(1))=size;
122     return 0;
123   }
124   else{
125     fIndex->Resize(index1+1);
126     (*(Int_t*)fIndex->Unchecked1DAt(index1))=indexa+size;
127   }
128   return index1-1;
129 }
130
131 Int_t TArrayOfArrayVStack::ArraySize(UInt_t index)
132 {
133   //size if subarray with index index
134   if ( (fIndex) && fIndex->GetSize()>index+1) 
135     return (*(Int_t*)fIndex->Unchecked1DAt(index+1))-(*(Int_t*)fIndex->Unchecked1DAt(index));
136   else 
137     return 0;
138 }