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