Removing class AliMUONTrackK
[u/mrichter/AliRoot.git] / MUON / MUONGenerateBusPatch.C
CommitLineData
36903978 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
9cf33953 16// $Id$
17
18#if !defined(__CINT__) || defined(__MAKECINT__)
19// ROOT includes
20#include <Riostream.h>
21#include <TROOT.h>
22#include <TSystem.h>
23#include <TString.h>
24
25// MUON includes
26#include "AliMpBusPatch.h"
27
28#endif
29
30// Generates buspatch id and DDL id for given detection element id
31// station 1 & 2 assuming 24 buspatches per quadrant
32// station345, reading from DetElemIdToSlatType.dat file and calculates
33// the number of bus patches per slat (and also number of Translator and Bridge Boards).
34// Generates an output file DetElemIdToBusPatch.dat.out, preserve from overwriting
35// (Ch. Finck, July 05)
36// (Nov. 05, added DDL)
37// (June 06, correction for St123)
38// (Feb. 07, add 1st manu list for St12 (starting on NB !) and new ddl sharing for station 3)
39
36903978 40
41void MUONGenerateBusPatch()
42{
6e96542a 43
36903978 44 TString dirPath2 = gSystem->Getenv("ALICE_ROOT");
45 dirPath2 += "/MUON/mapping/data/";
46
47 TString dirPath1 = dirPath2 + "station345/";
48
49 TString infile = dirPath1 + "DetElemIdToSlatType.dat";
50 TString outfile = dirPath2 + "DetElemIdToBusPatch.dat.out";
51
52 ifstream in(infile, ios::in);
53 ofstream out(outfile, ios::out);
54 char line[80];
55 char nameSlat[82];
56 Int_t idDE;
57 Int_t i;
58 Int_t cursor = 0;
9cf33953 59 Int_t begin[900];
60 Int_t end[900];
36903978 61 Int_t nbBusPatch;
36903978 62 Int_t nbTB = 0;
63 Int_t nbBB = 0;
64 Int_t idSt12[] = {100, 101, 102, 103,
65 200, 201, 202, 203,
66 300, 301, 302, 303,
67 400, 401, 402, 403};
68
f2bc136f 69 Char_t manuListSt1[]
70 = " 1,27,53,79,105,131,157,183,201,214,224,232,1025,1051,1077,1103,1129,1155,1181,1207,1225,1238,1249,1257";
71
72 Char_t manuListSt2[]
73 = " 1,27,53,79,105,131,157,183,201,214,226,246,1025,1051,1077,1103,1129,1155,1181,1207,1225,1238,1251,1269";
74
75 Int_t idCh5swp1 = 5; // 1/4 chamber for DDL on horizontal
76 Int_t idCh5swp2 = 10; // 1/4 chamber for DDL on horizontal
77 Int_t idCh5swp3 = 14; // 1/4 chamber for DDL on horizontal
78
79 Int_t idCh6swp1 = 5; // 1/4 chamber for DDL on horizontal
80 Int_t idCh6swp2 = 9; // 1/4 chamber for DDL on horizontal
81 Int_t idCh6swp3 = 14; // 1/4 chamber for DDL on horizontal
42c7b335 82
36903978 83 Int_t idSt45swp1 = 7; // half chamber for DDL in vertical cutting twice the official numbering
84 Int_t idSt45swp2 = 20;
85
86 Int_t iDDL = 0;
87 // station 1 & 2
0a69c1eb 88 nbBusPatch = 24;
f2bc136f 89 Int_t nbHalfBusPatch = nbBusPatch/2;
36903978 90 cout << "#DE BusPatch DDL SlatName" << endl;
f2bc136f 91 out << "#DE BusPatch DDL 1st manu in buspatch" << endl;
36903978 92
93 for (Int_t j = 0; j < 16; j++) {
94
95 idDE = idSt12[j];
96 if (idDE % 100 == 0) {
42c7b335 97 iDDL++;
6e96542a 98 begin[cursor] = AliMpBusPatch::GetGlobalBusID(0, iDDL-1);
36903978 99 cout << "# Chamber " << idDE/100 << endl;
100 out << "# Chamber " << idDE/100 << endl;
101 }
42c7b335 102 if (idDE % 100 == 1) {
103 iDDL++;
6e96542a 104 begin[cursor] = AliMpBusPatch::GetGlobalBusID(0, iDDL-1);
42c7b335 105 }
f2bc136f 106
42c7b335 107 if (idDE % 100 == 3) {
108 iDDL--;
6e96542a 109 begin[cursor] = AliMpBusPatch::GetGlobalBusID(0, iDDL-1) + nbBusPatch;
42c7b335 110 }
f2bc136f 111
36903978 112 end[cursor] = begin[cursor] + nbBusPatch - 1;
9cf33953 113 ++cursor; // it seems that vec[++i] does not work in Cint
114 begin[cursor] = end[cursor-1] + 1;
36903978 115
f2bc136f 116 cout << idDE << " " << begin[cursor-1] + nbHalfBusPatch << "-" <<end[cursor-1] << ";" <<
117 begin[cursor-1] << "-" << end[cursor-1] - nbHalfBusPatch << " " << iDDL-1 << endl;
118
119 if (idDE < 300 )
120 out << idDE << " " << begin[cursor-1] + nbHalfBusPatch << "-" <<end[cursor-1] << ";" <<
121 begin[cursor-1] << "-" << end[cursor-1] - nbHalfBusPatch << " " << iDDL-1 <<
122 manuListSt1 << endl;
123 else
124 out << idDE << " " << begin[cursor-1] + nbHalfBusPatch << "-" <<end[cursor-1] << ";" <<
125 begin[cursor-1] << "-" << end[cursor-1] - nbHalfBusPatch << " " << iDDL-1 <<
126 manuListSt2 << endl;
42c7b335 127 if (idDE % 100 == 3) iDDL++;
128
36903978 129 }
130
131 // station 345
132 nbBusPatch = 0;
42c7b335 133 Int_t nbBusSt3Tot1 = 0;
134 Int_t nbBusSt3Tot2 = 0;
135 Int_t nbBusSt3Tot3 = 0;
136 Int_t nbBusSt3Tot4 = 0;
137
138 Int_t nbBusSt3Swap1 = 0;
139 Int_t nbBusSt3Swap2 = 0;
140 Int_t nbBusSt3Swap3 = 0;
141 Int_t nbBusSt3Swap4 = 0;
142
143 Int_t iDDLSt3Swap1 = 0;
144 Int_t iDDLSt3Swap2 = 0;
145 Int_t iDDLSt3Swap3 = 0;
42c7b335 146
147 Int_t nbBusSt45Tot = 0;
148 Int_t nbBusSt45Swap = 0;
149
f2bc136f 150 Int_t nbBus500 = 4; // number of buspatch in DE 500
151 Int_t nbDDL500 = 11; // DDL number for DE 500
152 Int_t offsetBus500 = 13; // number of buspatches in DDL 11 before DE 500
153
42c7b335 154 // reads from file
36903978 155 while ( in.getline(line,80) ) {
156
157 if ( line[0] == '#' || line[0] == '\0' ) continue;
158 i = 0;
159 sscanf(line, "%d %s", &idDE, nameSlat);
160
161 // number of PCB's
162 while(nameSlat[i] < '4' && nameSlat[i] !='0') i++;
163 Int_t len = strlen(nameSlat);
164
165 // number of buspatch
166 if (i == 2 || i == 3)
167 nbBusPatch = 2;
168 else
169 nbBusPatch = 4;
170
171 // calculate the number of TB & BB
172 // R1: 2 bridges more per PCB
173 // R2 & R3: 1 translator more per PCB
174 if (i == 2) nbBB += 2;
175 if (i == 3) nbBB += 4;
176 if (i == 4) nbBB += 4;
177 if (i == 5) nbBB += 6;
178 if (i == 6) nbBB += 8;
179
180 nbTB += nbBusPatch;
08ce37ff 181 if (nameSlat[len-1] == '1') {
42c7b335 182 nbTB += 2;
183 nbBusPatch+=2;
08ce37ff 184 }
0a69c1eb 185 if (nameSlat[len-1] == '2' || nameSlat[len-1] == '3') {
36903978 186 nbTB += 1;
0a69c1eb 187 nbBusPatch++;
188 }
42c7b335 189
190 // station 3
191 // for buspatch length reasons, one ddl connects one 1/4 of two chambers
192 // really messy isn't it ?
f2bc136f 193 // much more with the new DDL sharing for station 3
42c7b335 194
195 if (idDE < 700 ) {
196
f2bc136f 197 if (idDE == 501) {
42c7b335 198 iDDL++;
6e96542a 199 begin[cursor] = AliMpBusPatch::GetGlobalBusID(0, iDDL-1);
42c7b335 200 nbBusSt3Tot1 = 0;
201
202 }
203 if (idDE % 100 == 0) {
204 cout << "# Chamber " << idDE/100 << endl;
205 out << "# Chamber " << idDE/100 << endl;
206 }
207
f2bc136f 208 // taking into account that idDE = 500 is connected to ddl = 11;
209 if (idDE == 500) {
210 cout << idDE << " " << AliMpBusPatch::GetGlobalBusID(offsetBus500, nbDDL500)<<"-"
211 << AliMpBusPatch::GetGlobalBusID(offsetBus500, nbDDL500) + nbBus500 -1
212 << " " << nbDDL500 << " " <<nameSlat <<endl;
213
214 out << idDE << " " << AliMpBusPatch::GetGlobalBusID(offsetBus500, nbDDL500)<<"-"
215 << AliMpBusPatch::GetGlobalBusID(offsetBus500, nbDDL500) + nbBus500 -1
216 << " " << nbDDL500 <<endl;
217 continue;
218 }
42c7b335 219 nbBusSt3Tot1 += nbBusPatch;
220
221 // second 1/4 for chamber 5
f2bc136f 222 if (idDE == 500+idCh5swp1) {
42c7b335 223 iDDLSt3Swap1 = iDDL++;
6e96542a 224 begin[cursor] = AliMpBusPatch::GetGlobalBusID(0, iDDL-1);
42c7b335 225 nbBusSt3Swap1 = nbBusSt3Tot1 - nbBusPatch;
226 nbBusSt3Tot1 = 0;
227 nbBusSt3Tot2 = 0;
228 }
229
230 // first 1/4 chamber 6
231 if (idDE == 600) {
232 iDDL = iDDLSt3Swap1;
6e96542a 233 begin[cursor] = AliMpBusPatch::GetGlobalBusID(nbBusSt3Swap1, iDDL-1);
42c7b335 234 }
235 // third 1/4 for chamber 5
f2bc136f 236 if (idDE == 500+idCh5swp2) {
42c7b335 237 iDDL = iDDLSt3Swap1+1;
238 iDDLSt3Swap2 = iDDL++;
6e96542a 239 begin[cursor] = AliMpBusPatch::GetGlobalBusID(0, iDDL-1);
42c7b335 240 nbBusSt3Swap2 = nbBusSt3Tot2;
241 nbBusSt3Tot2 = 0;
242 nbBusSt3Tot3 = 0;
243 }
244 nbBusSt3Tot2 += nbBusPatch;
245
246 // second 1/4 chamber 6
f2bc136f 247 if (idDE == 600 +idCh6swp1) {
42c7b335 248 iDDL = iDDLSt3Swap2;
6e96542a 249 begin[cursor] = AliMpBusPatch::GetGlobalBusID(nbBusSt3Swap2, iDDL-1);
42c7b335 250 }
251
252 // fourth 1/4 chamber 5
f2bc136f 253 if (idDE == 500+idCh5swp3) {
42c7b335 254 iDDL = iDDLSt3Swap2+1;
255 iDDLSt3Swap3 = iDDL++;
6e96542a 256 begin[cursor] = AliMpBusPatch::GetGlobalBusID(0, iDDL-1);
42c7b335 257 nbBusSt3Swap3 = nbBusSt3Tot3;
258 nbBusSt3Tot2 = 0;
259 nbBusSt3Tot3 = 0;
260 nbBusSt3Tot4 = 0;
261 }
262 nbBusSt3Tot3 += nbBusPatch;
263
264 //third 1/4 chamber 6
265 if (idDE == 600)
266 nbBusSt3Swap4 = nbBusSt3Tot4;
267
f2bc136f 268 if (idDE == 600 +idCh6swp2) {
42c7b335 269 iDDL = iDDLSt3Swap3;
6e96542a 270 begin[cursor] = AliMpBusPatch::GetGlobalBusID(nbBusSt3Swap3, iDDL-1);
42c7b335 271 nbBusSt3Tot4 += nbBusPatch;
272 }
273 nbBusSt3Tot4 += nbBusPatch;
274
275 // fourth 1/4 chamber 6
f2bc136f 276 if (idDE == 600 +idCh6swp3) {
42c7b335 277 iDDL = iDDLSt3Swap3+1;
f2bc136f 278 begin[cursor] = AliMpBusPatch::GetGlobalBusID(nbBusSt3Swap4 + nbBus500, iDDL-1);
42c7b335 279 }
280
281 end[cursor] = begin[cursor] + nbBusPatch - 1;
9cf33953 282 ++cursor;
283 begin[cursor] = end[cursor-1] + 1;
42c7b335 284
285 cout << idDE << " " << begin[cursor-1]<<"-"<<end[cursor-1] << " " << iDDL-1 << " " <<nameSlat <<endl;
286 out << idDE << " " << begin[cursor-1]<<"-"<<end[cursor-1] <<" " << iDDL-1 <<endl;
287 }
288
289 // station 4 & 5
290 // back to normal one ddl connects one 1/2 chamber
291 // finally !
292 if (idDE == 700) {
293 iDDL = ((idDE-1)/100)*2;
294 }
295 if (idDE >= 700) {
296
36903978 297 if (idDE % 100 == 0) {
42c7b335 298 nbBusSt45Tot = 0;
36903978 299 iDDL++;
300 if (idDE >=800)
301 iDDL++;
6e96542a 302 begin[cursor] = AliMpBusPatch::GetGlobalBusID(0, iDDL-1);
36903978 303 cout << "# Chamber " << idDE/100 << endl;
304 out << "# Chamber " << idDE/100 << endl;
305 }
36903978 306
42c7b335 307 nbBusSt45Tot += nbBusPatch;
36903978 308
42c7b335 309 if (idDE == 700+idSt45swp1 || idDE == 800+idSt45swp1 || idDE == 900+idSt45swp1 || idDE == 1000+idSt45swp1 ) {
310 iDDL++;
6e96542a 311 begin[cursor] = AliMpBusPatch::GetGlobalBusID(0, iDDL-1);
42c7b335 312 nbBusSt45Swap = nbBusSt45Tot - nbBusPatch;
313 nbBusSt45Tot = 0;
314 }
315 if (idDE == 700+idSt45swp2 || idDE == 800+idSt45swp2 || idDE == 900+idSt45swp2 || idDE == 1000+idSt45swp2 ) {
36903978 316 iDDL--;
6e96542a 317 begin[cursor] = AliMpBusPatch::GetGlobalBusID(nbBusSt45Swap, iDDL-1);
42c7b335 318 }
9cf33953 319
42c7b335 320 end[cursor] = begin[cursor] + nbBusPatch - 1;
9cf33953 321 ++cursor;
322 begin[cursor] = end[cursor-1] + 1;
36903978 323
42c7b335 324 cout << idDE << " " << begin[cursor-1]<<"-"<<end[cursor-1] << " " << iDDL-1 << " " <<nameSlat <<endl;
325 out << idDE << " " << begin[cursor-1]<<"-"<<end[cursor-1] <<" " << iDDL-1 <<endl;
326 }
36903978 327
36903978 328 }
329 printf(" Slat: number of TB %d and BB %d\n", nbTB, nbBB);
330 in.close();
331 out.close();
332}