]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/EMCAL/AliHLTEMCALMapper.cxx
Coverity
[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 #include "assert.h"
21 #include "AliHLTCaloConstants.h"
22
23 using EMCAL::NXCOLUMNSMOD;
24 using EMCAL::NZROWSMOD;
25 using EMCAL::NMODULES;
26 using EMCAL::NRCUSPERMODULE;
27 using EMCAL::NRCUSPERSECTOR;
28 using EMCAL::MAXHWADDR;
29
30 AliHLTEMCALMapper::AliHLTEMCALMapper(const unsigned long specification ) : AliHLTCaloMapper(specification, "EMCAL")
31 {
32   fCellSize = 6;
33   InitAltroMapping(specification);
34   InitDDLSpecificationMapping();
35   fIsInitializedMapping = true; //CRAP PTH, must check if the initilization actually went ok
36 }
37
38
39 AliHLTEMCALMapper::~AliHLTEMCALMapper()
40 {
41
42 }
43
44
45 void 
46 AliHLTEMCALMapper::GetLocalCoord(const int channelId, Float_t* localCoord) const
47 {
48   localCoord[0] = ( ( Float_t )(channelId&0x3f) - NXCOLUMNSMOD/2)  * fCellSize;
49   localCoord[1] = ( (Float_t)((channelId >> 6)&0x3f) - NZROWSMOD/2) * fCellSize;
50 }
51
52
53 Bool_t 
54 AliHLTEMCALMapper::InitAltroMapping(const unsigned long specification )
55 {
56   char *base =  getenv("ALICE_ROOT");
57   int  nChannels = 0;
58   int  maxaddr = 0; // keep as dummy for now
59   int  tmpHwaddr = 0;
60   int tmpZRow = 0;
61   int tmpXCol = 0;
62   int tmpGain = 0;
63   int res = 0; 
64   
65   if(base !=0)
66     {
67       snprintf(fFilepath,FILEPATHMAXLENGTH,"%s/EMCAL/mapping/%s", base,   DDL2RcuMapFileName( GetDDLFromSpec( specification ) ) ); 
68       snprintf(fFilepath, FILEPATHMAXLENGTH,"%s/EMCAL/mapping/%s", base,   DDL2RcuMapFileName( GetDDLFromSpec( specification ) ) ); 
69
70       FILE *fp = fopen(fFilepath, "r");
71       if(fp != 0)
72         {
73           res = fscanf(fp, "%d\n", &nChannels);
74           res = fscanf(fp, "%d\n", &maxaddr);
75           //      fHw2geomapPtr = new fAltromap[maxaddr +1]; 
76           fHw2geomapPtr = new fAltromap[MAXHWADDR +1];
77         
78           for(int i=0; i< MAXHWADDR + 1 ; i ++) 
79             //for(int i=0; i< maxaddr + 1 ; i ++)
80             {
81               fHw2geomapPtr[i].fXCol = 0;
82               fHw2geomapPtr[i].fZRow = 0;
83               fHw2geomapPtr[i].fGain = 0;
84             }
85           for(int i=0; i<nChannels; i ++)
86             {
87               res = fscanf(fp, "%d %d %d %d\n", &tmpHwaddr, &tmpXCol, &tmpZRow,  &tmpGain);
88               
89               if(tmpGain < 2)
90                 {
91                   if( tmpHwaddr <= MAXHWADDR  )
92                     {
93                       fHw2geomapPtr[tmpHwaddr].fXCol   = (char)tmpXCol;
94                       fHw2geomapPtr[tmpHwaddr].fZRow   = (char)tmpZRow;
95                       fHw2geomapPtr[tmpHwaddr].fGain  =  (char)tmpGain;
96                     }
97                 } 
98             }
99           fIsInitializedMapping = true;   
100           fclose(fp);
101         }
102       else
103         {
104           fIsInitializedMapping = false;          
105         }
106     }
107   else
108     {
109       fIsInitializedMapping = false;
110     }
111     
112     return fIsInitializedMapping;
113 }
114
115
116 void 
117 AliHLTEMCALMapper::InitDDLSpecificationMapping()
118 {
119   fSpecificationMapPtr = new fDDLSpecificationMap[NMODULES*NRCUSPERMODULE];
120   
121   for(Int_t ddl = 0; ddl < NMODULES*NRCUSPERMODULE; ddl++)
122     {
123       fSpecificationMapPtr[ddl].fModId = ddl/( NRCUSPERMODULE );
124     }
125 }
126
127 const char* 
128 AliHLTEMCALMapper::DDL2RcuMapFileName(const int ddlIndex) const //0=4608, 1=4607 etc...
129 {
130   const int rnamelen=256;
131   static char rname[rnamelen];
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   snprintf(rname, rnamelen, "RCU%d%c.data",  tmprcuindex,  tmpSide );
144   //sprintf(rname,"RCU%d%c.data", ddlIndex/NRCUSPERSECTOR, tmpSide );
145   return rname;
146 }
147