]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/EMCAL/AliHLTEMCALMapper.cxx
bugfix: using correct detector string for the setup of the AliHLTCaloMapper class
[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 #include "AliHLTEMCALMapper.h"
19
20 #include "AliHLTEMCALConstants.h"
21 #include "assert.h"
22
23 using namespace EmcalHLTConst;
24
25
26
27
28 AliHLTEMCALMapper::AliHLTEMCALMapper(const unsigned long specification ) : AliHLTCaloMapper(specification, "EMCAL")
29 {
30   fCellSize = 6;
31   InitAltroMapping(specification);
32   InitDDLSpecificationMapping();
33   fIsInitializedMapping = true; //CRAP PTH, must check is the initilization actually went ok
34 }
35
36
37 AliHLTEMCALMapper::~AliHLTEMCALMapper()
38 {
39
40 }
41   
42
43
44 // channelCoord[0] = (static_cast<Float_t>(channelId&0x3f) - NXCOLUMNSMOD/2)* fCellStep;
45 // channelCoord[1] = (static_cast<Float_t>((channelId >> 6)&0x3f) - NZROWSMOD/2) * fCellStep;
46
47 void 
48 AliHLTEMCALMapper::GetLocalCoord(const int channelId, Float_t* localCoord) const
49 {
50   localCoord[0] = ( ( Float_t )(channelId&0x3f) - NXCOLUMNSMOD/2)  * fCellSize;
51   localCoord[1] = ( (Float_t)((channelId >> 6)&0x3f) - NZROWSMOD/2) * fCellSize;
52 }
53
54
55 void 
56 AliHLTEMCALMapper::InitAltroMapping(const unsigned long specification )
57 {
58   char *base =  getenv("ALICE_ROOT");
59   int  nChannels = 0;
60   int  maxaddr = 0;
61   int  tmpHwaddr = 0;
62   int tmpZRow = 0;
63   int tmpXCol = 0;
64   int tmpGain = 0;
65   int res = 0; 
66   
67   if(base !=0)
68     {
69       //      int tmpddlindex =  GetDDLFromSpec( specification )%2; 
70
71       sprintf(fFilepath, "%s/EMCAL/mapping/%s", base,   DDL2RcuMapFileName( GetDDLFromSpec( specification ) ) ); 
72       sprintf(fFilepath, "%s/EMCAL/mapping/%s", base,   DDL2RcuMapFileName( GetDDLFromSpec( specification ) ) ); 
73
74       //   assert("DDL spec is  %d", GetDDLFromSpec( specification ) );
75      
76       cout << __FILE__ <<":"<< __LINE__ <<"DDL spec is " <<   GetDDLFromSpec( specification )  << endl;
77       cout << __FILE__ <<":"<< __LINE__ <<"mapping filename is " <<  fFilepath << endl;
78         // sprintf(fFilepath,"%s/PHOS/mapping/RCU0.data", base);
79       FILE *fp = fopen(fFilepath, "r");
80       if(fp != 0)
81         {
82           res = fscanf(fp, "%d\n", &nChannels);
83           res = fscanf(fp, "%d\n", &maxaddr);
84           fHw2geomapPtr = new fAltromap[maxaddr +1]; 
85
86           for(int i=0; i< maxaddr + 1 ; i ++)
87             {
88               fHw2geomapPtr[i].fXCol = 0;
89               fHw2geomapPtr[i].fZRow = 0;
90               fHw2geomapPtr[i].fGain = 0;
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               //              cout << __FILE__ << __LINE__ << "  tmpHwaddr  = " << tmpHwaddr << ", tmpXCol = " << (int)tmpXCol <<  ", tmpZRow = "<< (int)tmpZRow <<  ", tmpGain= "<< (int)tmpGain << endl;
97               
98               if(tmpGain < 2)
99                 {
100                   fHw2geomapPtr[tmpHwaddr].fXCol   = (char)tmpXCol;
101                   fHw2geomapPtr[tmpHwaddr].fZRow   = (char)tmpZRow;
102                   fHw2geomapPtr[tmpHwaddr].fGain  =  (char)tmpGain;
103                 } 
104             }
105           fIsInitializedMapping = true;   
106           fclose(fp);
107         }
108       else
109         {
110           cout << __FUNCTION__ << ":"<<__FILE__<<":"<< __LINE__ << "ERROR, could not open mapping file %s" <<  fFilepath << endl;
111           fIsInitializedMapping = false;          
112         }
113     }
114   else
115     {
116       fIsInitializedMapping = false;
117     }
118 }
119
120
121 void 
122 AliHLTEMCALMapper::InitDDLSpecificationMapping()
123 {
124   fSpecificationMapPtr = new fDDLSpecificationMap[EmcalHLTConst::NMODULES*EmcalHLTConst::NRCUSPERMODULE];
125   
126   for(Int_t ddl = 0; ddl < EmcalHLTConst::NMODULES*EmcalHLTConst::NRCUSPERMODULE; ddl++)
127     {
128       fSpecificationMapPtr[ddl].fModId = ddl/(EmcalHLTConst::NRCUSPERMODULE);
129     }
130 }
131
132 const char* 
133 AliHLTEMCALMapper::DDL2RcuMapFileName(const int ddlIndex) const //0=4608, 1=4607 etc...
134 {
135   static char rname[256];
136   char tmpSide;
137   
138   if ( ddlIndex%NRCUSPERSECTOR <2)
139     {
140       tmpSide  = 'A';
141     }
142   else
143     {
144       tmpSide  = 'C';
145     }
146   int tmprcuindex = ddlIndex%2;
147   sprintf(rname,"RCU%d%c.data",  tmprcuindex,  tmpSide );
148   //sprintf(rname,"RCU%d%c.data", ddlIndex/NRCUSPERSECTOR, tmpSide );
149   return rname;
150 }
151