]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/MUONGenerateBusPatch.C
Useful macros for the shifter
[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
e54bf126 30/// \ingroup macros
31/// \file MUONGenerateBusPatch.C
32/// \brief Generates buspatch id and DDL id for given detection element id
33///
34/// - station 1 & 2 assuming 24 buspatches per quadrant
35/// - station345, reading from DetElemIdToSlatType.dat file and calculates
36/// the number of bus patches per slat (and also number of Translator and Bridge Boards).
37/// Generates an output file DetElemIdToBusPatch.dat.out, preserve from overwriting
38///
39/// List of changes:
40/// - July 05, first version
41/// - Nov. 05, added DDL
42/// - June 06, correction for St123
43/// - Feb. 07, add 1st manu list for St12 (starting on NB !) and new ddl sharing for station 3)
44/// - June. 07, new numbering of station 345, and buspatch starts at 1)
45///
46/// \author Ch. Finck, July 05
9cf33953 47
36903978 48
49void MUONGenerateBusPatch()
50{
6e96542a 51
36903978 52 TString dirPath2 = gSystem->Getenv("ALICE_ROOT");
53 dirPath2 += "/MUON/mapping/data/";
54
55 TString dirPath1 = dirPath2 + "station345/";
56
57 TString infile = dirPath1 + "DetElemIdToSlatType.dat";
58 TString outfile = dirPath2 + "DetElemIdToBusPatch.dat.out";
59
60 ifstream in(infile, ios::in);
61 ofstream out(outfile, ios::out);
62 char line[80];
63 char nameSlat[82];
64 Int_t idDE;
65 Int_t i;
66 Int_t cursor = 0;
9cf33953 67 Int_t begin[900];
68 Int_t end[900];
36903978 69 Int_t nbBusPatch;
36903978 70 Int_t nbTB = 0;
71 Int_t nbBB = 0;
72 Int_t idSt12[] = {100, 101, 102, 103,
73 200, 201, 202, 203,
74 300, 301, 302, 303,
75 400, 401, 402, 403};
76
f2bc136f 77 Char_t manuListSt1[]
78 = " 1,27,53,79,105,131,157,183,201,214,224,232,1025,1051,1077,1103,1129,1155,1181,1207,1225,1238,1249,1257";
79
80 Char_t manuListSt2[]
81 = " 1,27,53,79,105,131,157,183,201,214,226,246,1025,1051,1077,1103,1129,1155,1181,1207,1225,1238,1251,1269";
82
f2bc136f 83
36903978 84
85 Int_t iDDL = 0;
86 // station 1 & 2
0a69c1eb 87 nbBusPatch = 24;
f2bc136f 88 Int_t nbHalfBusPatch = nbBusPatch/2;
36903978 89 cout << "#DE BusPatch DDL SlatName" << endl;
f2bc136f 90 out << "#DE BusPatch DDL 1st manu in buspatch" << endl;
36903978 91
92 for (Int_t j = 0; j < 16; j++) {
93
94 idDE = idSt12[j];
95 if (idDE % 100 == 0) {
42c7b335 96 iDDL++;
fc8c4a6f 97 begin[cursor] = AliMpBusPatch::GetGlobalBusID(1, iDDL-1);
36903978 98 cout << "# Chamber " << idDE/100 << endl;
99 out << "# Chamber " << idDE/100 << endl;
100 }
42c7b335 101 if (idDE % 100 == 1) {
102 iDDL++;
fc8c4a6f 103 begin[cursor] = AliMpBusPatch::GetGlobalBusID(1, iDDL-1);
42c7b335 104 }
f2bc136f 105
42c7b335 106 if (idDE % 100 == 3) {
107 iDDL--;
fc8c4a6f 108 begin[cursor] = AliMpBusPatch::GetGlobalBusID(1, iDDL-1) + nbBusPatch;
42c7b335 109 }
f2bc136f 110
36903978 111 end[cursor] = begin[cursor] + nbBusPatch - 1;
9cf33953 112 ++cursor; // it seems that vec[++i] does not work in Cint
113 begin[cursor] = end[cursor-1] + 1;
36903978 114
f2bc136f 115 cout << idDE << " " << begin[cursor-1] + nbHalfBusPatch << "-" <<end[cursor-1] << ";" <<
116 begin[cursor-1] << "-" << end[cursor-1] - nbHalfBusPatch << " " << iDDL-1 << endl;
117
118 if (idDE < 300 )
119 out << idDE << " " << begin[cursor-1] + nbHalfBusPatch << "-" <<end[cursor-1] << ";" <<
120 begin[cursor-1] << "-" << end[cursor-1] - nbHalfBusPatch << " " << iDDL-1 <<
121 manuListSt1 << endl;
122 else
123 out << idDE << " " << begin[cursor-1] + nbHalfBusPatch << "-" <<end[cursor-1] << ";" <<
124 begin[cursor-1] << "-" << end[cursor-1] - nbHalfBusPatch << " " << iDDL-1 <<
125 manuListSt2 << endl;
42c7b335 126 if (idDE % 100 == 3) iDDL++;
127
36903978 128 }
129
130 // station 345
131 nbBusPatch = 0;
fc8c4a6f 132 Int_t idCh5swp1 = 501; // 1/4 chamber for DDL on horizontal
133 Int_t idCh5swp2 = 505; // 1/4 chamber for DDL on horizontal
134 Int_t idCh5swp3 = 510; // 1/4 chamber for DDL on horizontal
135 Int_t idCh5swp4 = 514; // 1/4 chamber for DDL on horizontal
136
137 Int_t idCh6swp1 = 600; // 1/4 chamber for DDL on horizontal
138 Int_t idCh6swp2 = 605; // 1/4 chamber for DDL on horizontal
139 Int_t idCh6swp3 = 609; // 1/4 chamber for DDL on horizontal
140 Int_t idCh6swp4 = 614; // 1/4 chamber for DDL on horizontal
42c7b335 141
fc8c4a6f 142 Int_t idSt45swp1 = 7; // half chamber for DDL in vertical cutting twice the official numbering
143 Int_t idSt45swp2 = 20;
144
145 Int_t offsetBusCh5swp1 = 13; // number of buspatches between DE 501-504
146 Int_t offsetBusCh5swp2 = 17; // number of buspatches before DE 510
42c7b335 147
fc8c4a6f 148 Int_t offsetBusCh6swp1 = 17; // number of buspatches before DE 600-604
149 Int_t offsetBusCh6swp2 = 13; // number of buspatches between DE 614-617
42c7b335 150
fc8c4a6f 151 Int_t offsetBusSt4 = 25; // number of buspatches before DE 700-800
152 Int_t offsetBusSt4swp = 46; // number of buspatches between 801-806 (701-706)
42c7b335 153
fc8c4a6f 154 Int_t offsetBusSt5 = 27; // number of buspatches before DE 900-1000
155 Int_t offsetBusSt5swp = 50; // number of buspatches between 901-906 (1001-1006)
f2bc136f 156
42c7b335 157 // reads from file
36903978 158 while ( in.getline(line,80) ) {
159
160 if ( line[0] == '#' || line[0] == '\0' ) continue;
161 i = 0;
162 sscanf(line, "%d %s", &idDE, nameSlat);
163
164 // number of PCB's
165 while(nameSlat[i] < '4' && nameSlat[i] !='0') i++;
166 Int_t len = strlen(nameSlat);
167
168 // number of buspatch
169 if (i == 2 || i == 3)
170 nbBusPatch = 2;
171 else
172 nbBusPatch = 4;
173
174 // calculate the number of TB & BB
175 // R1: 2 bridges more per PCB
176 // R2 & R3: 1 translator more per PCB
177 if (i == 2) nbBB += 2;
178 if (i == 3) nbBB += 4;
179 if (i == 4) nbBB += 4;
180 if (i == 5) nbBB += 6;
181 if (i == 6) nbBB += 8;
182
183 nbTB += nbBusPatch;
08ce37ff 184 if (nameSlat[len-1] == '1') {
42c7b335 185 nbTB += 2;
186 nbBusPatch+=2;
08ce37ff 187 }
0a69c1eb 188 if (nameSlat[len-1] == '2' || nameSlat[len-1] == '3') {
36903978 189 nbTB += 1;
0a69c1eb 190 nbBusPatch++;
191 }
42c7b335 192
193 // station 3
194 // for buspatch length reasons, one ddl connects one 1/4 of two chambers
195 // really messy isn't it ?
f2bc136f 196 // much more with the new DDL sharing for station 3
42c7b335 197
198 if (idDE < 700 ) {
fc8c4a6f 199
42c7b335 200 if (idDE % 100 == 0) {
201 cout << "# Chamber " << idDE/100 << endl;
202 out << "# Chamber " << idDE/100 << endl;
203 }
204
fc8c4a6f 205 // chamber 5
206 if (idDE == 500 ) {
207 iDDL = (idDE/100)*2+2;
208 begin[cursor] = AliMpBusPatch::GetGlobalBusID(1, iDDL-1);
209
210 end[cursor] = begin[cursor] + nbBusPatch - 1;
211 ++cursor;
212 begin[cursor] = end[cursor-1] + 1;
213
214 cout << idDE << " " << begin[cursor-1]<<"-"<<end[cursor-1] << " " << iDDL-1 << " " <<nameSlat <<endl;
215 out << idDE << " " << begin[cursor-1]<<"-"<<end[cursor-1] <<" " << iDDL-1 <<endl;
f2bc136f 216 }
fc8c4a6f 217
218 if (idDE >= idCh5swp1 && idDE < idCh5swp2) {
219
220 if ( idDE == idCh5swp1) {
221 iDDL = (idDE/100)*2 ;
222 begin[cursor] = AliMpBusPatch::GetGlobalBusID(offsetBusCh5swp1, iDDL-1);
223 }
224
225 end[cursor] = begin[cursor] - nbBusPatch + 1;
226 ++cursor;
227 begin[cursor] = end[cursor-1] - 1;
228
229 cout << idDE << " " << end[cursor-1]<<"-"<<begin[cursor-1] << " " << iDDL-1 << " " <<nameSlat <<endl;
230 out << idDE << " " << end[cursor-1]<<"-"<<begin[cursor-1] <<" " << iDDL-1 <<endl;
42c7b335 231 }
232
fc8c4a6f 233 if (idDE >= idCh5swp2 && idDE < idCh5swp3) {
234
235 if (idDE == idCh5swp2) {
236 iDDL = (idDE/100)*2-1;
237 begin[cursor] = AliMpBusPatch::GetGlobalBusID(1, iDDL-1);
238 }
239
240 end[cursor] = begin[cursor] + nbBusPatch - 1;
241 ++cursor;
242 begin[cursor] = end[cursor-1] + 1;
243
244 cout << idDE << " " << begin[cursor-1]<<"-"<<end[cursor-1] << " " << iDDL-1 << " " <<nameSlat <<endl;
245 out << idDE << " " << begin[cursor-1]<<"-"<<end[cursor-1] <<" " << iDDL-1 <<endl;
42c7b335 246 }
fc8c4a6f 247
248 if (idDE >= idCh5swp3 && idDE < idCh5swp4) {
249
250 if (idDE == idCh5swp3) {
251 iDDL = (idDE/100)*2+1;
252 begin[cursor] = AliMpBusPatch::GetGlobalBusID(1, iDDL-1);
253 }
254
255 end[cursor] = begin[cursor] + nbBusPatch - 1;
256 ++cursor;
257 begin[cursor] = end[cursor-1] + 1;
258
259 cout << idDE << " " << begin[cursor-1]<<"-"<<end[cursor-1] << " " << iDDL-1 << " " <<nameSlat <<endl;
260 out << idDE << " " << begin[cursor-1]<<"-"<<end[cursor-1] <<" " << iDDL-1 <<endl;
42c7b335 261 }
42c7b335 262
fc8c4a6f 263 if (idDE >= idCh5swp4 && idDE < 600) {
264
265 if ( idDE == idCh5swp4) {
266 iDDL = (idDE/100)*2+2 ;
267 begin[cursor] = AliMpBusPatch::GetGlobalBusID(offsetBusCh5swp2, iDDL-1);
268 }
269
270 end[cursor] = begin[cursor] - nbBusPatch + 1;
271 ++cursor;
272 begin[cursor] = end[cursor-1] - 1;
273
274 cout << idDE << " " << end[cursor-1]<<"-"<<begin[cursor-1] << " " << iDDL-1 << " " <<nameSlat <<endl;
275 out << idDE << " " << end[cursor-1]<<"-"<<begin[cursor-1] <<" " << iDDL-1 <<endl;
42c7b335 276 }
fc8c4a6f 277
278 // chamber 6
279 if (idDE >= idCh6swp1 && idDE < idCh6swp2) {
280
281 if ( idDE == idCh6swp1) {
282 iDDL = (idDE/100)*2-2 ;
283 begin[cursor] = AliMpBusPatch::GetGlobalBusID(offsetBusCh5swp1+offsetBusCh6swp1, iDDL-1);
284 }
285
286 end[cursor] = begin[cursor] - nbBusPatch + 1;
287 ++cursor;
288 begin[cursor] = end[cursor-1] - 1;
289
290 cout << idDE << " " << end[cursor-1]<<"-"<<begin[cursor-1] << " " << iDDL-1 << " " <<nameSlat <<endl;
291 out << idDE << " " << end[cursor-1]<<"-"<<begin[cursor-1] <<" " << iDDL-1 <<endl;
42c7b335 292 }
42c7b335 293
fc8c4a6f 294 if (idDE >= idCh6swp2 && idDE < idCh6swp3) {
295
296 if (idDE == idCh6swp2) {
297 iDDL = (idDE/100)*2-3;
298 begin[cursor] = AliMpBusPatch::GetGlobalBusID(offsetBusCh5swp2+1, iDDL-1);
299 }
300
301 end[cursor] = begin[cursor] + nbBusPatch - 1;
302 ++cursor;
303 begin[cursor] = end[cursor-1] + 1;
42c7b335 304
fc8c4a6f 305 cout << idDE << " " << begin[cursor-1]<<"-"<<end[cursor-1] << " " << iDDL-1 << " " <<nameSlat <<endl;
306 out << idDE << " " << begin[cursor-1]<<"-"<<end[cursor-1] <<" " << iDDL-1 <<endl;
42c7b335 307 }
42c7b335 308
fc8c4a6f 309 if (idDE >= idCh6swp3 && idDE < idCh6swp4) {
310
311 if (idDE == idCh6swp3) {
312 iDDL = (idDE/100)*2-1;
313 begin[cursor] = AliMpBusPatch::GetGlobalBusID(offsetBusCh5swp1+1, iDDL-1);
314 }
315
316 end[cursor] = begin[cursor] + nbBusPatch - 1;
317 ++cursor;
318 begin[cursor] = end[cursor-1] + 1;
319
320 cout << idDE << " " << begin[cursor-1]<<"-"<<end[cursor-1] << " " << iDDL-1 << " " <<nameSlat <<endl;
321 out << idDE << " " << begin[cursor-1]<<"-"<<end[cursor-1] <<" " << iDDL-1 <<endl;
42c7b335 322 }
323
fc8c4a6f 324 if (idDE >= idCh6swp4 && idDE < 700) {
325
326 if ( idDE == idCh6swp4) {
327 iDDL = (idDE/100)*2 ;
328 begin[cursor] = AliMpBusPatch::GetGlobalBusID(offsetBusCh5swp2+offsetBusCh6swp2, iDDL-1);
329 }
330
331 end[cursor] = begin[cursor] - nbBusPatch + 1;
332 ++cursor;
333 begin[cursor] = end[cursor-1] - 1;
334
335 cout << idDE << " " << end[cursor-1]<<"-"<<begin[cursor-1] << " " << iDDL-1 << " " <<nameSlat <<endl;
336 out << idDE << " " << end[cursor-1]<<"-"<<begin[cursor-1] <<" " << iDDL-1 <<endl;
337 }
42c7b335 338
42c7b335 339 }
fc8c4a6f 340
42c7b335 341 // station 4 & 5
342 // back to normal one ddl connects one 1/2 chamber
343 // finally !
fc8c4a6f 344
42c7b335 345 if (idDE >= 700) {
346
fc8c4a6f 347 if (idDE % 100 == 0) {
348 cout << "# Chamber " << idDE/100 << endl;
349 out << "# Chamber " << idDE/100 << endl;
42c7b335 350 }
fc8c4a6f 351
352 if ((idDE % 100) >= idSt45swp1 && (idDE % 100) < idSt45swp2) {
353 if ((idDE % 100) == idSt45swp1) {
354 iDDL = (idDE/100)*2-1;
355 begin[cursor] = AliMpBusPatch::GetGlobalBusID(1, iDDL-1);
356 }
357 end[cursor] = begin[cursor] + nbBusPatch - 1;
358 ++cursor;
359 begin[cursor] = end[cursor-1] + 1;
360
361 cout << idDE << " " << begin[cursor-1]<<"-"<<end[cursor-1] << " " << iDDL-1 << " " <<nameSlat <<endl;
362 out << idDE << " " << begin[cursor-1]<<"-"<<end[cursor-1] <<" " << iDDL-1 <<endl;
42c7b335 363 }
9cf33953 364
fc8c4a6f 365 if (idDE % 100 >= idSt45swp2) {
36903978 366
fc8c4a6f 367 if ((idDE % 100) == idSt45swp2 ) {
368 iDDL = (idDE/100)*2 ;
369 if (idDE/100 == 7 || idDE/100 == 8)
370 begin[cursor] = AliMpBusPatch::GetGlobalBusID(offsetBusSt4swp, iDDL-1);
371 else
372 begin[cursor] = AliMpBusPatch::GetGlobalBusID(offsetBusSt5swp, iDDL-1);
373
374 }
375 end[cursor] = begin[cursor] - nbBusPatch + 1;
376 ++cursor;
377 begin[cursor] = end[cursor-1] - 1;
378
379 cout << idDE << " " << end[cursor-1]<<"-"<<begin[cursor-1] << " " << iDDL-1 << " " <<nameSlat <<endl;
380 out << idDE << " " << end[cursor-1]<<"-"<<begin[cursor-1] <<" " << iDDL-1 <<endl;
381 }
382
383 if ((idDE % 100) >= 0 && (idDE % 100) < idSt45swp1) {
384
385 if ((idDE % 100) == 0 ) {
386 iDDL = (idDE/100)*2;
387 if (idDE/100 == 7 || idDE/100 == 8)
388 begin[cursor] = AliMpBusPatch::GetGlobalBusID(offsetBusSt4, iDDL-1);
389 else
390 begin[cursor] = AliMpBusPatch::GetGlobalBusID(offsetBusSt5, iDDL-1);
391
392 }
393 end[cursor] = begin[cursor] - nbBusPatch + 1;
394 ++cursor;
395 begin[cursor] = end[cursor-1] - 1;
396
397 cout << idDE << " " << end[cursor-1]<<"-"<<begin[cursor-1] << " " << iDDL-1 << " " <<nameSlat <<endl;
398 out << idDE << " " << end[cursor-1]<<"-"<<begin[cursor-1] <<" " << iDDL-1 <<endl;
399 }
400
42c7b335 401 }
36903978 402
36903978 403 }
404 printf(" Slat: number of TB %d and BB %d\n", nbTB, nbBB);
405 in.close();
406 out.close();
407}