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