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