]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/EMCAL/AliHLTEMCALMapper.cxx
Refactoring of handling of constants.
[u/mrichter/AliRoot.git] / HLT / EMCAL / AliHLTEMCALMapper.cxx
1 /**************************************************************************
2  * This file is property of and copyright by the Experimental Nuclear     *
3  * Physics Group, Dep. of Physics                                         *
4  * University of Oslo, Norway, 2007                                       *
5  *                                                                        *
6  * Author: Per Thomas Hille <perthi@fys.uio.no> for the ALICE HLT Project.*
7  * Contributors are mentioned in the code where appropriate.              *
8  * Please report bugs to perthi@fys.uio.no                                *
9  *                                                                        *
10  * Permission to use, copy, modify and distribute this software and its   *
11  * documentation strictly for non-commercial purposes is hereby granted   *
12  * without fee, provided that the above copyright notice appears in all   *
13  * copies and that both the copyright notice and this permission notice   *
14  * appear in the supporting documentation. The authors make no claims     *
15  * about the suitability of this software for any purpose. It is          *
16  * provided "as is" without express or implied warranty.                  *
17  **************************************************************************/
18
19 #include "AliHLTEMCALMapper.h"
20
21 //#include "AliHLTEMCALConstant.h"
22 // #include "AliHLTCaloConstant.h"
23
24 #include "assert.h"
25
26 //using namespace EmcalHLTConst;
27
28 #include "AliHLTCaloConstants.h"
29
30 using EMCAL::NXCOLUMNSMOD;
31 using EMCAL::NZROWSMOD;
32 using EMCAL::NMODULES;
33 using EMCAL::NRCUSPERMODULE;
34 using EMCAL::NRCUSPERSECTOR;
35
36 AliHLTEMCALMapper::AliHLTEMCALMapper(const unsigned long specification ) : AliHLTCaloMapper(specification, "EMCAL")
37 {
38   fCellSize = 6;
39   InitAltroMapping(specification);
40   InitDDLSpecificationMapping();
41   fIsInitializedMapping = true; //CRAP PTH, must check if the initilization actually went ok
42 }
43
44
45 AliHLTEMCALMapper::~AliHLTEMCALMapper()
46 {
47
48 }
49   
50
51 void 
52 AliHLTEMCALMapper::GetLocalCoord(const int channelId, Float_t* localCoord) const
53 {
54   localCoord[0] = ( ( Float_t )(channelId&0x3f) - NXCOLUMNSMOD/2)  * fCellSize;
55   localCoord[1] = ( (Float_t)((channelId >> 6)&0x3f) - NZROWSMOD/2) * fCellSize;
56 }
57
58
59 Bool_t 
60 AliHLTEMCALMapper::InitAltroMapping(const unsigned long specification )
61 {
62   char *base =  getenv("ALICE_ROOT");
63   int  nChannels = 0;
64   int  maxaddr = 0;
65   int  tmpHwaddr = 0;
66   int tmpZRow = 0;
67   int tmpXCol = 0;
68   int tmpGain = 0;
69   int res = 0; 
70   
71   if(base !=0)
72     {
73       sprintf(fFilepath, "%s/EMCAL/mapping/%s", base,   DDL2RcuMapFileName( GetDDLFromSpec( specification ) ) ); 
74       sprintf(fFilepath, "%s/EMCAL/mapping/%s", base,   DDL2RcuMapFileName( GetDDLFromSpec( specification ) ) ); 
75
76       FILE *fp = fopen(fFilepath, "r");
77       if(fp != 0)
78         {
79           res = fscanf(fp, "%d\n", &nChannels);
80           res = fscanf(fp, "%d\n", &maxaddr);
81           fHw2geomapPtr = new fAltromap[maxaddr +1]; 
82
83           for(int i=0; i< maxaddr + 1 ; i ++)
84             {
85               fHw2geomapPtr[i].fXCol = 0;
86               fHw2geomapPtr[i].fZRow = 0;
87               fHw2geomapPtr[i].fGain = 0;
88             }
89           for(int i=0; i<nChannels; i ++)
90             {
91               res = fscanf(fp, "%d %d %d %d\n", &tmpHwaddr, &tmpXCol, &tmpZRow,  &tmpGain);
92               
93               if(tmpGain < 2)
94                 {
95                   fHw2geomapPtr[tmpHwaddr].fXCol   = (char)tmpXCol;
96                   fHw2geomapPtr[tmpHwaddr].fZRow   = (char)tmpZRow;
97                   fHw2geomapPtr[tmpHwaddr].fGain  =  (char)tmpGain;
98                 } 
99             }
100           fIsInitializedMapping = true;   
101           fclose(fp);
102         }
103       else
104         {
105           fIsInitializedMapping = false;          
106         }
107     }
108   else
109     {
110       fIsInitializedMapping = false;
111     }
112     
113     return fIsInitializedMapping;
114 }
115
116
117 void 
118 AliHLTEMCALMapper::InitDDLSpecificationMapping()
119 {
120   fSpecificationMapPtr = new fDDLSpecificationMap[NMODULES*NRCUSPERMODULE];
121   
122   for(Int_t ddl = 0; ddl < NMODULES*NRCUSPERMODULE; ddl++)
123     {
124       fSpecificationMapPtr[ddl].fModId = ddl/( NRCUSPERMODULE );
125     }
126 }
127
128 const char* 
129 AliHLTEMCALMapper::DDL2RcuMapFileName(const int ddlIndex) const //0=4608, 1=4607 etc...
130 {
131   static char rname[256];
132   char tmpSide;
133   
134   if ( ddlIndex%NRCUSPERSECTOR <2)
135     {
136       tmpSide  = 'A';
137     }
138   else
139     {
140       tmpSide  = 'C';
141     }
142   int tmprcuindex = ddlIndex%2;
143   sprintf(rname,"RCU%d%c.data",  tmprcuindex,  tmpSide );
144   //sprintf(rname,"RCU%d%c.data", ddlIndex/NRCUSPERSECTOR, tmpSide );
145   return rname;
146 }
147