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