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