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