]> 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 using EMCAL::MAXCHANNELS; 
30
31 AliHLTEMCALMapper::AliHLTEMCALMapper(const unsigned long specification ) : AliHLTCaloMapper(specification, "EMCAL")
32 {
33   fCellSize = 6;
34   InitAltroMapping(specification);
35   InitDDLSpecificationMapping();
36   fIsInitializedMapping = true; //CRAP PTH, must check if the initilization actually went ok
37 }
38
39
40 AliHLTEMCALMapper::~AliHLTEMCALMapper()
41 {
42
43 }
44
45
46 void 
47 AliHLTEMCALMapper::GetLocalCoord(const int channelId, Float_t* localCoord) const
48 {
49   localCoord[0] = ( ( Float_t )(channelId&0x3f) - NXCOLUMNSMOD/2)  * fCellSize;
50   localCoord[1] = ( (Float_t)((channelId >> 6)&0x3f) - NZROWSMOD/2) * fCellSize;
51 }
52
53
54 Bool_t 
55 AliHLTEMCALMapper::InitAltroMapping(const unsigned long specification )
56 {
57   char *base =  getenv("ALICE_ROOT");
58   int  nChannels = 0;
59   int  maxaddr = 0; // keep as dummy for now
60   int  tmpHwaddr = 0;
61   int tmpZRow = 0;
62   int tmpXCol = 0;
63   int tmpGain = 0;
64   int res = 0; 
65   
66   if(base !=0)
67     {
68       snprintf(fFilepath,FILEPATHMAXLENGTH,"%s/EMCAL/mapping/%s", base,   DDL2RcuMapFileName( GetDDLFromSpec( specification ) ) ); 
69       snprintf(fFilepath, FILEPATHMAXLENGTH,"%s/EMCAL/mapping/%s", base,   DDL2RcuMapFileName( GetDDLFromSpec( specification ) ) ); 
70
71       FILE *fp = fopen(fFilepath, "r");
72       if(fp != 0)
73         {
74           res = fscanf(fp, "%d\n", &nChannels);
75           res = fscanf(fp, "%d\n", &maxaddr);
76           //      fHw2geomapPtr = new fAltromap[maxaddr +1]; 
77           fHw2geomapPtr = new fAltromap[MAXHWADDR +1];
78         
79           for(int i=0; i< MAXHWADDR + 1 ; i ++) 
80             //for(int i=0; i< maxaddr + 1 ; i ++)
81             {
82               fHw2geomapPtr[i].fXCol = 0;
83               fHw2geomapPtr[i].fZRow = 0;
84               fHw2geomapPtr[i].fGain = 0;
85             }
86           // MAXCHANNELS
87           if( nChannels > 0 && nChannels <= MAXCHANNELS )
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                       if( tmpHwaddr <= MAXHWADDR  &&  tmpHwaddr >= 0  )
96                         {
97                           fHw2geomapPtr[tmpHwaddr].fXCol   = (char)tmpXCol;
98                           fHw2geomapPtr[tmpHwaddr].fZRow   = (char)tmpZRow;
99                           fHw2geomapPtr[tmpHwaddr].fGain  =  (char)tmpGain;
100                         }
101                     } 
102                 }
103               fIsInitializedMapping = true;       
104             }
105           else
106             {
107               fIsInitializedMapping = false;       
108             }
109           fclose(fp);
110         }
111       else
112         {
113           fIsInitializedMapping = false;          
114         }
115     }
116   else
117     {
118       fIsInitializedMapping = false;
119     }
120     
121     return fIsInitializedMapping;
122 }
123
124
125 void 
126 AliHLTEMCALMapper::InitDDLSpecificationMapping()
127 {
128   fSpecificationMapPtr = new fDDLSpecificationMap[NMODULES*NRCUSPERMODULE];
129   
130   for(Int_t ddl = 0; ddl < NMODULES*NRCUSPERMODULE; ddl++)
131     {
132       fSpecificationMapPtr[ddl].fModId = ddl/( NRCUSPERMODULE );
133     }
134 }
135
136 const char* 
137 AliHLTEMCALMapper::DDL2RcuMapFileName(const int ddlIndex) const //0=4608, 1=4607 etc...
138 {
139   const int rnamelen=256;
140   static char rname[rnamelen];
141   char tmpSide;
142   
143   if ( ddlIndex%NRCUSPERSECTOR <2)
144     {
145       tmpSide  = 'A';
146     }
147   else
148     {
149       tmpSide  = 'C';
150     }
151   int tmprcuindex = ddlIndex%2;
152   snprintf(rname, rnamelen, "RCU%d%c.data",  tmprcuindex,  tmpSide );
153   //sprintf(rname,"RCU%d%c.data", ddlIndex/NRCUSPERSECTOR, tmpSide );
154   return rname;
155 }
156