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