]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/macros/Mapping/WriteMapping.C
New PHOS mapping is uploaded:
[u/mrichter/AliRoot.git] / PHOS / macros / Mapping / WriteMapping.C
CommitLineData
8a89bc69 1WriteMapping()
2{
3 // Create the RCU mapping files for PHOS
4 // The geometrical mapping within one FEE card is read
5 // from the file CSP2ALTRO.dat prepared manually beforehand.
6 //
7 // The hardware address of the FEE channels is a 12-bit word formed
8 // from the branch number, FEE number, ALTRO chip number and ALTRO channel
9 // as follows:
10 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
11 // |0|0|0|0| | | | |
12 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
13 // ^ FEE chip channel
14 // branch
15 //
16 // Max address: 1 1110 100 1111 = 3919
17 //
18 // Author: Yuri Kharlov
b7999bf2 19 // Date : 29 October 2009
20 // $Id$
21
8a89bc69 22
23 char string[128];
24 UInt_t xcell,zcell,csp,altro,chanHG,chanLG;
0e0944b2 25 UInt_t hwAddress, maxHWAddress[4], nHWaddress[4];
26 const char *FEEmapping[2] = {"CSP2ALTRO_new.dat", "CSP2ALTRO_old.dat"};
27 Int_t map=0;
28
29 for (Int_t module=0; module<5; module++) {
30 printf("\n\n====> Mapping file is created for the module %d\n",module);
31 if (module <4) map=0;
32 else if (module==4) map=1;
33 FILE *fd = fopen(FEEmapping[map],"r");
34 if (fd != 0)
35 printf("Input file %s is opened successfully\n",FEEmapping[map]);
36 else {
37 printf("Cannot open the input file %s\n",FEEmapping[map]);
38 return -1;
8a89bc69 39 }
0e0944b2 40
41 FILE *fRCU[4];
42
8a89bc69 43 for (Int_t iRCU=0; iRCU<4; iRCU++) {
0e0944b2 44 TString rcuFileName = Form("Mod%dRCU%d.data.unsorted",module,iRCU);
45 fRCU[iRCU] = fopen(rcuFileName.Data(),"w");
46 maxHWAddress[iRCU]=0;
47 nHWaddress[iRCU]=0;
48 }
49
50 while (fgets(string,128,fd)) {
51 if (string[0]=='*') {
52 continue;
53 }
54 sscanf(string,"%d %d %d %d %d %d",
55 &xcell,&zcell,&csp,&altro,&chanHG,&chanLG);
56 for (Int_t iRCU=0; iRCU<4; iRCU++) {
57 for (Int_t iBranch=0; iBranch<2; iBranch++) {
58 for (Int_t iFEE=1; iFEE<=14; iFEE++) {
59 // High gain
60 hwAddress = chanHG | (altro<<4) | (iFEE<<7) | (iBranch<<11);
61 if (hwAddress > maxHWAddress[iRCU]) maxHWAddress[iRCU]=hwAddress;
62 nHWaddress[iRCU]++;
63 fprintf(fRCU[iRCU],"%4d %4d %4d %4d\n",
64 hwAddress,
65 xcell+iRCU*16,
b7999bf2 66 zcell+27+(1-2*iBranch)+(iFEE-1)*2*(1-2*iBranch),1);
0e0944b2 67 // Low gain
68 hwAddress = chanLG | (altro<<4) | (iFEE<<7) | (iBranch<<11);
69 if (hwAddress > maxHWAddress[iRCU]) maxHWAddress[iRCU]=hwAddress;
70 nHWaddress[iRCU]++;
71 fprintf(fRCU[iRCU],"%4d %4d %4d %4d\n",
72 hwAddress,
73 xcell+iRCU*16,
b7999bf2 74 zcell+27+(1-2*iBranch)+(iFEE-1)*2*(1-2*iBranch),0);
0e0944b2 75 }
8a89bc69 76 }
77 }
78 }
0e0944b2 79 printf("End of input file\n");
80 fclose(fd);
8a89bc69 81
0e0944b2 82 for (Int_t iRCU=0; iRCU<4; iRCU++) {
83 fclose(fRCU[iRCU]);
8a89bc69 84 }
0e0944b2 85
86 // Post-process the RCU mapping files
87
88 for (Int_t iRCU=0; iRCU<4; iRCU++) {
89
90 // Add the number of channels and maximum HW address
91
92 TString rcuFileName = Form("Mod%dRCU%d.data",module,iRCU);
93 fRCU[iRCU] = fopen(rcuFileName.Data(),"w");
94 fprintf(fRCU[iRCU],"%d\n%d\n",nHWaddress[iRCU]+256,maxHWAddress[iRCU]);
95
96 // TRU mapping
97
98 for (int i=0; i<128; i++) {
99 fprintf(fRCU[iRCU],"%4d %4d %4d %4d\n",i,iRCU,i,2);
100 }
101 for (int i=0; i<128; i++) {
102 fprintf(fRCU[iRCU],"%4d %4d %4d %4d\n",i+2048,iRCU,i+2048,2);
103 }
104 fclose(fRCU[iRCU]);
105
106 // Sort HW addresses
107
108 TString cmd = Form("sort -n Mod%dRCU%d.data.unsorted >> %s",
109 module,iRCU,rcuFileName.Data());
110 gSystem->Exec(cmd);
111
112 cmd = Form("rm -f Mod%dRCU%d.data.unsorted", module,iRCU);
113 gSystem->Exec(cmd);
114
115 printf("RCU mapping file %s is created\n",rcuFileName.Data());
8a89bc69 116 }
8a89bc69 117 }
8a89bc69 118}