]>
Commit | Line | Data |
---|---|---|
bf000c32 | 1 | //____________________________________________________________________ |
d389af40 | 2 | // |
3 | // $Id$ | |
4 | // | |
5 | // Script to make a class derived from AliFMDMap. | |
6 | // | |
7 | #ifndef __CINT__ | |
8 | #include <fstream> | |
9 | #include <TString.h> | |
10 | #include <TDatime.h> | |
11 | #include <TSystem.h> | |
12 | #include <iostream> | |
13 | using namespace std; | |
14 | #endif | |
15 | ||
16 | void MakeMap(const Char_t* type="Int_t", const Char_t* name=0) | |
17 | { | |
18 | TString base; | |
19 | TString ttype(type); | |
20 | if (ttype.EndsWith("_t")) { | |
21 | Ssiz_t undert = ttype.Index("_t"); | |
22 | ttype.Remove(undert); | |
23 | } | |
24 | if (!name) | |
25 | base = Form("AliFMD%sMap", ttype.Data()); | |
26 | else | |
27 | base = name; | |
28 | ||
29 | cout << "Base name is " << base << endl; | |
30 | ||
31 | TString decl_name(Form("%s.h", base.Data())); | |
32 | TString impl_name(Form("%s.cxx", base.Data())); | |
33 | ofstream decl(decl_name.Data()); | |
34 | ofstream impl(impl_name.Data()); | |
35 | ||
36 | if (!decl) { | |
37 | cerr << "Cannot open declaration file " << decl_name << endl; | |
38 | return; | |
39 | } | |
40 | if (!impl) { | |
41 | cerr << "Cannot open implementation file " << impl_name << endl; | |
42 | return; | |
43 | } | |
44 | ||
45 | TDatime now; | |
46 | cout << "The time is now " << now.AsString() << endl; | |
47 | UserGroup_t* uinfo = gSystem->GetUserInfo(); | |
48 | TString uname(uinfo->fRealName); | |
49 | Ssiz_t comma = uname.Index(","); | |
50 | if (comma != kNPOS) uname.Remove(comma); | |
51 | cout << "User's name is " << uname << endl; | |
52 | TString guard(base); | |
53 | guard.Append("_h"); | |
54 | guard.ToUpper(); | |
55 | ||
56 | cout << "Writing declaration file " << decl_name << " ... " | |
57 | << flush; | |
58 | decl << "#ifndef " << guard << "\n"; | |
59 | decl << "#define " << guard << "\n"; | |
60 | decl << "/* Copyright (c) " << now.GetYear() ; | |
61 | decl << ", ALICE Experiment @ CERN.\n" ; | |
62 | decl << " * All rights reserved\n"; | |
63 | decl << " * See " << impl_name << " for full copyright notice\n"; | |
64 | decl << " * \n" ; | |
65 | decl << " * Created " << now.AsString() << " by " << uname << "\n"; | |
66 | decl << " */\n"; | |
67 | decl << "/* $Id$ */\n"; | |
68 | decl << "//__________________________________________________________\n"; | |
69 | decl << "// \n"; | |
70 | decl << "// Map of " << type << " for each FMD strip\n" ; | |
71 | decl << "// \n"; | |
72 | decl << "#ifndef ALIFMDMAP_H\n"; | |
73 | decl << "# include <AliFMDMap.h>\n"; | |
74 | decl << "#endif\n\n"; | |
75 | decl << "class " << base << " : public AliFMDMap\n"; | |
76 | decl << "{\n"; | |
77 | decl << "public:\n"; | |
78 | decl << " " << base << "(const " << base << "& other);\n"; | |
79 | decl << " " << base << "(size_t maxDet = kMaxDetectors,\n"; | |
80 | decl << " size_t maxRing = kMaxRings,\n"; | |
81 | decl << " size_t maxSec = kMaxSectors,\n"; | |
82 | decl << " size_t maxStr = kMaxStrips);\n"; | |
83 | decl << " virtual ~" << base << "() { delete [] fData; }\n"; | |
84 | decl << " " << base << "& operator=(const " << base << "& other);\n"; | |
85 | decl << " virtual void Clear(const " << type << "& v=" << type << "());\n"; | |
86 | decl << " virtual " << type << "& operator()(UShort_t det,\n"; | |
87 | decl << " Char_t ring,\n"; | |
88 | decl << " UShort_t sec,\n"; | |
89 | decl << " UShort_t str);\n"; | |
90 | decl << " virtual const " << type << "& operator()(UShort_t det,\n"; | |
91 | decl << " Char_t ring,\n"; | |
92 | decl << " UShort_t sec,\n"; | |
93 | decl << " UShort_t str) const;\n"; | |
94 | decl << "protected:\n"; | |
95 | decl << " " << type << "* fData; // The Data\n"; | |
96 | decl << " ClassDef(" << base << ",1) // Map of " << type ; | |
97 | decl << " data per strip\n" ; | |
98 | decl << "};\n\n"; | |
99 | decl << "#endif\n"; | |
100 | decl << "//__________________________________________________________\n"; | |
101 | decl << "// \n"; | |
102 | decl << "// Local Variables:\n"; | |
103 | decl << "// mode: C++\n"; | |
104 | decl << "// End:\n"; | |
105 | decl << "//" << endl;; | |
106 | decl.close(); | |
107 | cout << "done" << endl; | |
108 | ||
109 | cout << "Writing implementation file " << impl_name << " ... " | |
110 | << flush; | |
111 | impl << "/**************************************************************\n"; | |
112 | impl << " * Copyright(c) 1998-1999, ALICE Experiment at CERN. *\n"; | |
113 | impl << " * All rights reserved. *\n"; | |
114 | impl << " * *\n"; | |
115 | impl << " * Author: The ALICE Off-line Project. *\n"; | |
116 | impl << " * Contributors are mentioned in the code where appropriate. *\n"; | |
117 | impl << " * *\n"; | |
118 | impl << " * Permission to use, copy, modify and distribute this *\n"; | |
119 | impl << " * software and its documentation strictly for non-commercial *\n"; | |
120 | impl << " * purposes is hereby granted without fee, provided that the *\n"; | |
121 | impl << " * above copyright notice appears in all copies and that both *\n"; | |
122 | impl << " * the copyright notice and this permission notice appear in *\n"; | |
123 | impl << " * the supporting documentation. The authors make no claims *\n"; | |
124 | impl << " * about the suitability of this software for any purpose. It *\n"; | |
125 | impl << " * is provided \"as is\" without express or implied warranty. *\n"; | |
126 | impl << " **************************************************************/\n"; | |
127 | impl << "/* $Id$ */\n"; | |
128 | impl << "//__________________________________________________________\n"; | |
129 | impl << "// \n"; | |
130 | impl << "// Map of per strip " << type << " information\n"; | |
131 | impl << "// \n"; | |
132 | impl << "// Created " << now.AsString() << " by " << uname << "\n"; | |
133 | impl << "// \n"; | |
134 | impl << "#include \"" << decl_name << "\"\t//" << guard << "\n"; | |
135 | impl << "//__________________________________________________________\n"; | |
136 | impl << "ClassImp(" << base << ");\n"; | |
137 | impl << "//__________________________________________________________\n"; | |
138 | impl << base << "::" << base << "(const " << base << "& other)\n"; | |
139 | impl << " : AliFMDMap(other.fMaxDetectors,\n"; | |
140 | impl << " other.fMaxRings,\n"; | |
141 | impl << " other.fMaxSectors,\n"; | |
142 | impl << " other.fMaxStrips),\n"; | |
143 | impl << " fData(0)\n"; | |
144 | impl << "{\n"; | |
145 | impl << " // Copy constructor\n"; | |
146 | impl << " fData = new " << type << "[fMaxDetectors * fMaxRings "; | |
147 | impl << "* fMaxSectors * fMaxStrips];\n" ; | |
148 | impl << " for (size_t i = 0; i < fMaxDetectors * fMaxRings "; | |
149 | impl << "* fMaxSectors * fMaxStrips; i++)\n"; | |
150 | impl << " fData[i] = other.fData[i];\n"; | |
151 | impl << "}\n\n"; | |
152 | impl << "//__________________________________________________________\n"; | |
153 | impl << base << "::" << base << "(size_t maxDet,\n"; | |
154 | impl << " size_t maxRing,\n"; | |
155 | impl << " size_t maxSec,\n"; | |
156 | impl << " size_t maxStr)\n"; | |
157 | impl << " : AliFMDMap(maxDet, maxRing, maxSec, maxStr),\n"; | |
158 | impl << " fData(0)\n"; | |
159 | impl << "{\n"; | |
160 | impl << " // Constructor.\n"; | |
161 | impl << " // Parameters:\n"; | |
162 | impl << " //\tmaxDet\tMaximum number of detectors\n"; | |
163 | impl << " //\tmaxRing\tMaximum number of rings per detector\n"; | |
164 | impl << " //\tmaxSec\tMaximum number of sectors per ring\n"; | |
165 | impl << " //\tmaxStr\tMaximum number of strips per sector\n"; | |
166 | impl << " fData = new " << type << "[fMaxDetectors * fMaxRings "; | |
167 | impl << "* fMaxSectors * fMaxStrips];\n" ; | |
168 | impl << " Clear();\n"; | |
169 | impl << "}\n\n"; | |
170 | impl << "//__________________________________________________________\n"; | |
171 | impl << base << "&\n"; | |
172 | impl << base << "::operator=(const " << base << "& other)\n"; | |
173 | impl << "{\n"; | |
174 | impl << " // Assignment operator \n"; | |
175 | impl << " fMaxDetectors = other.fMaxDetectors;\n"; | |
176 | impl << " fMaxRings = other.fMaxRings;\n"; | |
177 | impl << " fMaxSectors = other.fMaxSectors;\n"; | |
178 | impl << " fMaxStrips = other.fMaxStrips;\n"; | |
179 | impl << " if (fData) delete [] fData;\n"; | |
180 | impl << " fData = new " << type << "[fMaxDetectors * fMaxRings "; | |
181 | impl << "* fMaxSectors * fMaxStrips];\n" ; | |
182 | impl << " for (size_t i = 0; i < fMaxDetectors * fMaxRings "; | |
183 | impl << "* fMaxSectors * fMaxStrips; i++)\n"; | |
184 | impl << " fData[i] = other.fData[i];\n"; | |
185 | impl << "}\n\n" ; | |
186 | impl << "//__________________________________________________________\n"; | |
187 | impl << "void\n"; | |
188 | impl << base << "::Clear(const " << type << "& val)\n"; | |
189 | impl << "{\n"; | |
190 | impl << " // Reset map to val\n"; | |
191 | impl << " for (size_t i = 0; i < fMaxDetectors * fMaxRings "; | |
192 | impl << "* fMaxSectors * fMaxStrips; i++)\n"; | |
193 | impl << " fData[i] = val;\n"; | |
194 | impl << "}\n\n" ; | |
195 | impl << "//__________________________________________________________\n"; | |
196 | impl << type << "&\n"; | |
197 | impl << base << "::operator()(UShort_t det, Char_t ring, UShort_t sec, " ; | |
198 | impl << "UShort_t str)\n" ; | |
199 | impl << "{\n" ; | |
200 | impl << " // Get data\n"; | |
201 | impl << " // Parameters:\n"; | |
202 | impl << " //\tdet\tDetector #\n"; | |
203 | impl << " //\tring\tRing ID\n"; | |
204 | impl << " //\tsec\tSector #\n"; | |
205 | impl << " //\tstr\tStrip #\n" ; | |
206 | impl << " // Returns appropriate data\n"; | |
207 | impl << " return fData[CalcIndex(det, ring, sec, str)];\n"; | |
208 | impl << "}\n\n"; | |
209 | impl << "//__________________________________________________________\n"; | |
210 | impl << "const " << type << "&\n"; | |
211 | impl << base << "::operator()(UShort_t det, Char_t ring, UShort_t sec, " ; | |
212 | impl << "UShort_t str) const\n" ; | |
213 | impl << "{\n" ; | |
214 | impl << " // Get data\n"; | |
215 | impl << " // Parameters:\n"; | |
216 | impl << " //\tdet\tDetector #\n"; | |
217 | impl << " //\tring\tRing ID\n"; | |
218 | impl << " //\tsec\tSector #\n"; | |
219 | impl << " //\tstr\tStrip #\n" ; | |
220 | impl << " // Returns appropriate data\n"; | |
221 | impl << " return fData[CalcIndex(det, ring, sec, str)];\n"; | |
222 | impl << "}\n\n"; | |
223 | impl << "//__________________________________________________________\n"; | |
224 | impl << "// \n"; | |
225 | impl << "// EOF\n"; | |
226 | impl << "// \n"; | |
227 | impl << endl; | |
228 | impl.close(); | |
229 | cout << "done" << endl; | |
230 | } | |
231 | ||
232 | ||
233 | ||
234 | ||
235 | #ifndef __CINT__ | |
236 | int main() | |
237 | { | |
238 | makemap(); | |
239 | return 0; | |
240 | } | |
241 | #endif | |
a1f80595 | 242 | |
243 | //____________________________________________________________________ | |
244 | // | |
245 | // EOF | |
246 | // |