+// $Id$
+
/**************************************************************************
* This file is property of and copyright by the Experimental Nuclear *
* Physics Group, Dep. of Physics *
* about the suitability of this software for any purpose. It is *
* provided "as is" without express or implied warranty. *
**************************************************************************/
-#include "AliHLTEMCALMapper.h"
-
-#include "AliHLTEMCALConstants.h"
-
-
-using namespace EmcalHLTConst;
-
-//AliHLTCaloMapper
-
-
-AliHLTEMCALMapper::AliHLTEMCALMapper(const unsigned long specification ) : AliHLTCaloMapper(specification)
+#include "AliHLTEMCALMapper.h"
+#include "assert.h"
+#include "AliHLTCaloConstants.h"
+#include "TString.h"
+
+using EMCAL::NXCOLUMNSMOD;
+using EMCAL::NZROWSMOD;
+using EMCAL::NMODULES;
+using EMCAL::NRCUSPERMODULE;
+using EMCAL::NRCUSPERSECTOR;
+using EMCAL::MAXHWADDR;
+using EMCAL::MAXCHANNELS;
+
+AliHLTEMCALMapper::AliHLTEMCALMapper(const unsigned long specification ) : AliHLTCaloMapper(specification, "EMCAL")
{
+ fCellSize = 6;
InitAltroMapping(specification);
InitDDLSpecificationMapping();
- fIsInitializedMapping = true; //CRAP PTH, must check is the initilization actually went ok
+ fIsInitializedMapping = true; //CRAP PTH, must check if the initilization actually went ok
}
void
+AliHLTEMCALMapper::GetLocalCoord(const int channelId, Float_t* localCoord) const
+{
+ localCoord[0] = ( ( Float_t )(channelId&0x3f) - NXCOLUMNSMOD/2) * fCellSize;
+ localCoord[1] = ( (Float_t)((channelId >> 6)&0x3f) - NZROWSMOD/2) * fCellSize;
+}
+
+
+Bool_t
AliHLTEMCALMapper::InitAltroMapping(const unsigned long specification )
{
- char *base = getenv("ALICE_ROOT");
+ TString base(getenv("ALICE_ROOT"));
int nChannels = 0;
- int maxaddr = 0;
+ int maxaddr = 0; // keep as dummy for now
int tmpHwaddr = 0;
int tmpZRow = 0;
int tmpXCol = 0;
int tmpGain = 0;
int res = 0;
- if(base !=0)
+ if(!base.IsNull())
{
- sprintf(fFilepath, "%s/EMCAL/mapping/%s", base, DDL2RcuMapFileName( GetDDLFromSpec( specification ) ) );
- cout << __FILE__ <<":"<< __LINE__ <<"mapping filename is " << fFilepath << endl;
- // sprintf(fFilepath,"%s/PHOS/mapping/RCU0.data", base);
+ snprintf(fFilepath,FILEPATHMAXLENGTH,"%s/EMCAL/mapping/%s", base.Data(), DDL2RcuMapFileName( GetDDLFromSpec( specification ) ) );
+ snprintf(fFilepath, FILEPATHMAXLENGTH,"%s/EMCAL/mapping/%s", base.Data(), DDL2RcuMapFileName( GetDDLFromSpec( specification ) ) );
+
FILE *fp = fopen(fFilepath, "r");
if(fp != 0)
{
res = fscanf(fp, "%d\n", &nChannels);
res = fscanf(fp, "%d\n", &maxaddr);
- fHw2geomapPtr = new fAltromap[maxaddr +1];
-
- for(int i=0; i< maxaddr + 1 ; i ++)
+ // fHw2geomapPtr = new fAltromap[maxaddr +1];
+ fHw2geomapPtr = new fAltromap[MAXHWADDR +1];
+
+ for(int i=0; i< MAXHWADDR + 1 ; i ++)
+ //for(int i=0; i< maxaddr + 1 ; i ++)
{
fHw2geomapPtr[i].fXCol = 0;
fHw2geomapPtr[i].fZRow = 0;
fHw2geomapPtr[i].fGain = 0;
}
- for(int i=0; i<nChannels; i ++)
+ // MAXCHANNELS
+ if( nChannels > 0 && nChannels <= MAXCHANNELS )
{
- res = fscanf(fp, "%d %d %d %d\n", &tmpHwaddr, &tmpXCol, &tmpZRow, &tmpGain);
-
- // cout << __FILE__ << __LINE__ << " tmpHwaddr = " << tmpHwaddr << ", tmpXCol = " << (int)tmpXCol << ", tmpZRow = "<< (int)tmpZRow << ", tmpGain= "<< (int)tmpGain << endl;
-
- if(tmpGain < 2)
+ for(int i=0; i<nChannels; i ++)
{
- fHw2geomapPtr[tmpHwaddr].fXCol = (char)tmpXCol;
- fHw2geomapPtr[tmpHwaddr].fZRow = (char)tmpZRow;
- fHw2geomapPtr[tmpHwaddr].fGain = (char)tmpGain;
- }
+ res = fscanf(fp, "%d %d %d %d\n", &tmpHwaddr, &tmpXCol, &tmpZRow, &tmpGain);
+
+ if(tmpGain < 2)
+ {
+ if( tmpHwaddr <= MAXHWADDR && tmpHwaddr >= 0 )
+ {
+ fHw2geomapPtr[tmpHwaddr].fXCol = (char)tmpXCol;
+ fHw2geomapPtr[tmpHwaddr].fZRow = (char)tmpZRow;
+ fHw2geomapPtr[tmpHwaddr].fGain = (char)tmpGain;
+ }
+ }
+ }
+ fIsInitializedMapping = true;
+ }
+ else
+ {
+ fIsInitializedMapping = false;
}
- fIsInitializedMapping = true;
fclose(fp);
}
else
{
- cout << __FUNCTION__ << ":"<<__FILE__<<":"<< __LINE__ << "ERROR, could not open mapping file %s" << fFilepath << endl;
fIsInitializedMapping = false;
}
}
{
fIsInitializedMapping = false;
}
+
+ return fIsInitializedMapping;
}
void
AliHLTEMCALMapper::InitDDLSpecificationMapping()
{
- fSpecificationMapPtr = new fDDLSpecificationMap[EmcalHLTConst::NMODULES*EmcalHLTConst::NRCUSPERMODULE];
+ if (fSpecificationMapPtr) delete [] fSpecificationMapPtr;
+ fSpecificationMapPtr = new fDDLSpecificationMap[NMODULES*NRCUSPERMODULE];
- for(Int_t ddl = 0; ddl < EmcalHLTConst::NMODULES*EmcalHLTConst::NRCUSPERMODULE; ddl++)
+ for(Int_t ddl = 0; ddl < NMODULES*NRCUSPERMODULE; ddl++)
{
- fSpecificationMapPtr[ddl].fModId = ddl/EmcalHLTConst::NRCUSPERMODULE;
- fSpecificationMapPtr[ddl].fRcuX = 0;
- fSpecificationMapPtr[ddl].fRcuZ = ddl%2;
- // fSpecificationMapPtr[ddl].fRcuZOffset = NZROWSRCU*(fSpecificationMapPtr[ddl].fRcuZ);
- // fSpecificationMapPtr[ddl].fRcuXOffset = NXCOLUMNSRCU*(fSpecificationMapPtr[ddl].fRcuX);
+ fSpecificationMapPtr[ddl].fModId = ddl/( NRCUSPERMODULE );
}
}
-
-
-//RCU1C.data
-
-
const char*
AliHLTEMCALMapper::DDL2RcuMapFileName(const int ddlIndex) const //0=4608, 1=4607 etc...
{
- static char rname[256];
+ const int rnamelen=256;
+ static char rname[rnamelen];
char tmpSide;
if ( ddlIndex%NRCUSPERSECTOR <2)
{
tmpSide = 'C';
}
-
- sprintf(rname,"RCU%d%c.data", ddlIndex/NRCUSPERSECTOR, tmpSide );
+ int tmprcuindex = ddlIndex%2;
+ snprintf(rname, rnamelen, "RCU%d%c.data", tmprcuindex, tmpSide );
+ //sprintf(rname,"RCU%d%c.data", ddlIndex/NRCUSPERSECTOR, tmpSide );
return rname;
- // rname.fSector = ddlIndex/NRCUSPERSECTOR;
}
-
-/*
-unsigned long
-AliHLTEMCALMapper::GetSpecFromDDLIndex( const int ddlindex )
-{
- return ( (unsigned long)1 << ddlindex ));
-}
-*/
-
-/*
-AliHLTEMCALMapper::GlobalX2ModuleId( const int globalX )
-{
- return globalX/NXCOLUMNSMOD;
-}
-*/
-
- /*
-static const int
-AliHLTEMCALMapper::GlobalZ2ModuleId( const int globalZ )
-{
- return globalZ/NZROWSMOD;
- }
- */
-
-
- /*
- const int
- AliHLTEMCALMapper::Global2ModuleId( const int globalZ, const int globalX )
-{
- int tmpModX =
-
-}
- */