]> git.uio.no Git - u/mrichter/AliRoot.git/blob - CONTAINERS/AliObjectArray.cxx
Transition to NewIO
[u/mrichter/AliRoot.git] / CONTAINERS / AliObjectArray.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 ///////////////////////////////////////////////////////////////////////////////
19 //                                                                           //
20 //  AliObjectArray                                                           //
21 //                                                                           // 
22 //AliObjectArray is an array of clone (identical) objects.                   //
23 //In comparison with the TClonesArray objects in this array don't need       //
24 //to derive from TObject. They also don't need RTTI - type information.      // 
25 //                                                                           //
26 //Objects type information is stored in object fClassInfo (instance of       //
27 //the AliClassInfo).                                                         //
28 //Objects in array are stored sequentialy in buffers. Buffer is standart C++ //
29 //array of objects. Buffers size is equal for all of the buffers. If we specify
30 //fBufferSize==0 objects are stored in one big standart C++ array.
31 //
32 //  Origin:  Marian Ivanov, Uni. of Bratislava, ivanov@fmph.uniba.sk // 
33 //
34 //Begin_Html 
35 /*
36 <img src="../gif/AliObjectArray.gif">
37 */
38 ///////////////////////////////////////////////////////////////////////////////
39
40
41 #include "AliObjectArray.h"
42
43 ClassImp(AliObjectArray) 
44
45 AliObjectArray::AliObjectArray():AliMemArray()
46
47   //
48   //default constructor
49   //
50   fClassInfo = 0;
51 }
52
53 AliObjectArray::AliObjectArray(const char * classname, Int_t buffersize):AliMemArray()
54 {
55   //
56   // AliObject array constructor 
57   // Set class information  fClassInfo according specified type and set the array size -size
58   // Buufer size fBufferSize 
59   fClassInfo = 0;
60   fBufferSize = buffersize;
61   SetClass(classname);
62 }
63
64 AliObjectArray::AliObjectArray(const AliObjectArray &arr):
65   AliMemArray(arr)
66 {  
67   //
68   //
69   *((AliMemArray*)this) = *((AliMemArray*)&arr);
70   fClassInfo = arr.GetClassInfo();
71 }
72
73
74 AliObjectArray & AliObjectArray::operator=(const AliObjectArray &arr)
75 {  
76   //
77   //
78   *((AliMemArray*)this) = *((AliMemArray*)&arr);
79   fClassInfo = arr.GetClassInfo();
80   return (*this);
81 }
82
83 AliObjectArray::~AliObjectArray()  
84 {
85   //
86   //default destructor
87   Delete();  
88 }
89
90 Bool_t AliObjectArray::SetClass(const char * classname) 
91 {
92   //
93   // Set class information fClassInfo  according class name
94   //  
95   Delete();
96   
97   fClassInfo = AliClassInfo::GenerClassInfo(classname);
98   fObjectSize = fClassInfo->Size();
99   return (fClassInfo!=0);  
100 }
101
102 void   AliObjectArray::Dump(Int_t i)
103 {
104   //dump object at position i 
105   if (At(i)) fClassInfo->ObjectDump(At(i));
106   else printf("index %d - out of range\n",i);
107 }
108
109 void AliObjectArray::Streamer(TBuffer& R__b) 
110 {
111   //
112   //Stream of the AliVector2D
113   //
114   TString s; 
115   if (R__b.IsReading()) {
116     Version_t R__v = R__b.ReadVersion(); if (R__v) { }
117     TObject::Streamer(R__b); 
118     s.Streamer(R__b);  //read class info
119     if (s!=" ") SetClass(s.Data());
120     else fClassInfo=0;
121     R__b >> fBufferSize;
122     R__b >> fObjectSize;
123     Int_t size;
124     R__b >> size;
125     Resize(size); 
126     if (fSize>0){
127       if (fBufferSize==0) fClassInfo->StreamBuffer(R__b, GetArray(), fSize);
128       else
129         for (UInt_t i=0;i<GetNBuffers();i++)
130           fClassInfo->StreamBuffer(R__b, GetRow(i), fBufferSize);
131     }   
132   } else {
133     R__b.WriteVersion(AliObjectArray::IsA());
134     TObject::Streamer(R__b);     
135     if (fClassInfo) s = fClassInfo->GetClassName();
136     else s=" ";
137     s.Streamer(R__b);
138     R__b << fBufferSize;
139     R__b << fObjectSize;
140     R__b << fSize;
141    
142     if (fSize>0){
143       if (fBufferSize==0) fClassInfo->StreamBuffer(R__b, GetArray(), fSize);
144       else
145         for (UInt_t i=0;i<GetNBuffers();i++)
146           fClassInfo->StreamBuffer(R__b, GetRow(i), fBufferSize);
147     }
148   }
149 }
150
151
152
153
154