Containers definition
[u/mrichter/AliRoot.git] / CONTAINERS / AliClassInfo.cxx
CommitLineData
08edbb90 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*/
19///////////////////////////////////////////////////////////////////////////////
20// //
21// AliClassInfo //
22// //
23//Defined to make unified interface to primitive types (in Root described by //
24// TDataType) and TClass. //
25// Additional virtual function (comparing to ROOT TClass) neccesary //
26// for AliContainers //
27// virtual void CTORBuffer(void * pointer, UInt_t size=1) //
28// should construct buffer of size =size objects at position pointer //
29// virtual void DTORBuffer(void * pointer, UInt_t size=1) //
30// should destruct buffer of size =size objects at position pointer //
31// virtual void StreamBuffer(TBuffer& b, const void *object, UInt_t size) //
32// stream buffer of objects `
33//Begin_Html
34//<img src="../gif/AliClassInfo.gif">
35//End_Html
36// //
37// //
38///////////////////////////////////////////////////////////////////////////////
39
40
41#include "AliClassInfo.h"
42#include "TMath.h"
43#include "TClass.h"
44
45#include "TROOT.h"
46#include "iostream.h"
47
48ClassImp(AliClassInfo)
49
50
51TList AliClassInfo::fgList; // list of loaded class
52
53AliClassInfo * AliClassInfo::FindClassInfo(const char * name)
54{
55 //
56 TIter next(&fgList);
57 TString sname(name);
58 AliClassInfo * info;
59 while ((info = (AliClassInfo *) next()))
60 if (info->GetName()==sname) return info;
61 return 0;
62}
63
64
65
66AliClassInfo * AliClassInfo::GenerClassInfo(const char * classname)
67{
68 //
69 // Set class information fClassInfo according class name
70 //
71 char name[100];
72 AliClassInfo *info=0;
73 sprintf(name,"AliClassType%s",classname);
74 info = AliClassInfo::FindClassInfo(classname);
75 if (info) return info;
76 //
77 if ( (!info) && (gROOT->GetType(classname),kTRUE)){
78 //if data type information exist
79 char line[100];
80 // sprintf(line,"(*((AliClassInfo**)%p))= new AliDataType(\"%s\");",
81 // &info,classname);
82 sprintf(line,"new AliDataType(\"%s\");",
83 classname);
84
85 //cout<<line<<"\n";
86 gROOT->ProcessLine(line);
87 info = AliClassInfo::FindClassInfo(classname);
88 }
89 if (info) return info;
90
91 TClass * cl = gROOT->GetClass(classname);
92 // if exist root class information
93 if ( (!info) && (gROOT->GetClass(classname))){ //is it class?
94 char chinter[1000];
95 sprintf(chinter,"%s.C",classname);
96 GenerClassInfoCode(classname,kTRUE,cl->GetDeclFileName(),chinter);
97 info = AliClassInfo::FindClassInfo(classname);
98 }
99 if (!info){
100 TClass * cl = new TClass(classname,0);
101 if (cl->Size()>0){ //if root information doesn't exist
102 //but exist cint information
103 char chinclude[1000];
104 sprintf(chinclude,"%s.h",classname);
105 char chinter[1000];
106 sprintf(chinter,"%s.C",classname);
107 GenerClassInfoCode(classname,kTRUE,chinclude,chinter);
108 }
109 }
110
111 return info;
112}
113
114
115
116void AliClassInfo::GenerClassInfoCode(const char * clname, Bool_t load,
117 const char *incpath, const char *outfile)
118{
119
120 // gener temporary file - name
121
122 FILE *fout = fopen(outfile,"w");
123 if (!clname){
124 cerr<<"Class not specified\n";
125 return ;
126 }
127 char buff[1000];
128 const char *pchar =incpath;
129 //replace with /0
130 char * pchar2 =buff;
131 fprintf(fout,"#include \"AliClassInfo.h\"\n");
132
133 if (incpath==0) {}
134 else{
135 // proces headers - header separated by
136 pchar =incpath;
137 pchar2 =buff;
138 //
139 while (*pchar==' ') pchar++;
140 while (*pchar) {
141 if (*pchar!=' ') *pchar2++ = *pchar;
142 else
143 if (*(pchar2-1)!=0) *pchar2++=0;
144 pchar++;
145 }
146 *pchar2=0;
147 Int_t index = pchar2-buff;
148 for (Int_t i=0;i<index;i++)
149 if ( (i==0) ||(buff[i-1]==0))
150 fprintf(fout,"#include \"%s\"\n",&buff[i]);
151 }
152 //process classes
153 pchar =clname;
154 pchar2 =buff;
155 while (*pchar==' ') pchar++;
156 while (*pchar) {
157 if (*pchar!=' ') *pchar2++ = *pchar;
158 else
159 if (*(pchar2-1)!=0) *pchar2++=0;
160 pchar++;
161 }
162 *pchar2=0;
163 Int_t index = pchar2-buff;
164 for (Int_t i=0;i<index;i++)
165 if ( (i==0) ||(buff[i-1]==0))
166 GenerClassInterface(&buff[i],fout);
167
168 fclose(fout);
169 //
170
171 if (load) {
172 char line[100];
173 // gSystem->Rename("/tmp/root_tmpinterinter"
174 sprintf(line,".L %s+",outfile);
175 cout<<line<<"\nGenerating class Interface \n";
176 cout<<line<<"\n*****************************\n";
177 gROOT->ProcessLine(line);
178 cout<<line<<"\n*****************************\n";
179 cout<<line<<"\nClass Interface generated \n";
180 }
181}
182
183
184
185Bool_t AliClassInfo::GenerClassInterface(const char * clname, FILE * fout)
186{
187 // TClass * cl = gROOT->GetClass("AliLHit",kTRUE);
188 fprintf(fout,"\n/************************************************/\n");
189 fprintf(fout,"/* Automaticaly generated interface for class \n");
190 fprintf(fout," %s \n",clname);
191 fprintf(fout,"**************************************************/\n");
192 fprintf(fout,"\n\n");
193 //constructor
194 fprintf(fout,"class AliClass%s : public AliClassInfo {\n",clname);
195 fprintf(fout,"public:\n");
196 fprintf(fout,"\tAliClass%s(){\n",clname);
197 fprintf(fout,"\t SetName(\"%s\");\n",clname);
198 fprintf(fout,"\t SetTitle(\"Interface for %s class \");\n",clname);
199 fprintf(fout,"\t fgList.Add(this);\n");
200 fprintf(fout,"\t fSize = sizeof(%s);\n\t}\n",clname);
201 //
202 fprintf(fout,"\tconst char * GetClassName(){ return \"%s\";}\n",clname);
203 //
204 fprintf(fout,"\tvirtual TClass* GetClass(){return %s::Class();}\n",clname);
205 //placement constructor interface
206 fprintf(fout,"\tvoid CTORBuffer(void * pointer, UInt_t size=1)\n\t{\n");
207 fprintf(fout,"\t %s * last = &((%s*)pointer)[size];\n",clname,clname);
208 fprintf(fout,"\t %s * p = (%s*)pointer;\n",clname,clname);
209 fprintf(fout,"\t while (p!=last) new (p++)%s;\n\t}\n",clname);
210 //placement destructor interface
211 fprintf(fout,"\tvoid DTORBuffer(void * pointer, UInt_t size=1)\n\t{\n");
212 fprintf(fout,"\t %s * last = &((%s*)pointer)[size];\n",clname,clname);
213 fprintf(fout,"\t %s * p = (%s*)pointer;\n",clname,clname);
214 fprintf(fout,"\t while (p!=last) (p++)->~%s();\n\t}\n",clname);
215 //streamer interface
216 fprintf(fout,"\tvoid StreamBuffer(TBuffer &b,const void * pointer, UInt_t size=1)\n\t{\n");
217 fprintf(fout,"\t for (UInt_t i=0;i<size;i++) ((%s*)pointer)[i].Streamer(b);\n\t}\n",clname);
218 //
219 fprintf(fout,"\t void ObjectDump(void *p) {((%s*)p)->Dump();}\n",clname);
220 fprintf(fout,"};\n");
221 //make instance of the class
222 fprintf(fout,"AliClass%s galiclass____%s; \n",clname,clname);
223 return kTRUE;
224}
225
226
227
228
229
230
231
232
233