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