LCOV - code coverage report
Current view: top level - HLT/TPCLib - AliHLTTPCMapping.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 170 0.6 %
Date: 2016-06-14 17:26:59 Functions: 1 12 8.3 %

          Line data    Source code
       1             : // $Id$
       2             : /**************************************************************************
       3             :  * This file is property of and copyright by the ALICE HLT Project        * 
       4             :  * ALICE Experiment at CERN, All rights reserved.                         *
       5             :  *                                                                        *
       6             :  * Primary Authors: Kenneth Aamodt <kenneth@ift.uib.no>                   *
       7             :  *                  for The ALICE HLT Project.                            *
       8             :  *                                                                        *
       9             :  * Permission to use, copy, modify and distribute this software and its   *
      10             :  * documentation strictly for non-commercial purposes is hereby granted   *
      11             :  * without fee, provided that the above copyright notice appears in all   *
      12             :  * copies and that both the copyright notice and this permission notice   *
      13             :  * appear in the supporting documentation. The authors make no claims     *
      14             :  * about the suitability of this software for any purpose. It is          *
      15             :  * provided "as is" without express or implied warranty.                  *
      16             :  **************************************************************************/
      17             : 
      18             : /** @file   AliHLTTPCMapping.cxx
      19             :     @author Kenneth Aamodt
      20             :     @date   
      21             :     @brief  A mapping class for the TPC.
      22             : */
      23             : 
      24             : // see header file for class documentation                                   //
      25             : // or                                                                        //
      26             : // refer to README to build package                                          //
      27             : // or                                                                        //
      28             : // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt                          //
      29             : 
      30             : #include <cassert>
      31             : #include "AliHLTTPCMapping.h"
      32             : #include "AliHLTTPCGeometry.h"
      33             : 
      34             : using namespace std;
      35             : 
      36           6 : ClassImp(AliHLTTPCMapping)
      37             : 
      38           0 : AliHLTTPCMapping::AliHLTTPCMapping(UInt_t patch)
      39             :   :
      40           0 :   fPatch(patch),
      41           0 :   fCurrentRowMapping(NULL),
      42           0 :   fCurrentPadMapping(NULL),
      43           0 :   fNofRows(0),
      44           0 :   fMaxHWAdd(0),
      45           0 :   fRowOffset(0)
      46           0 : {
      47             :   // see header file for class documentation
      48             :   // or
      49             :   // refer to README to build package
      50             :   // or
      51             :   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
      52             : 
      53           0 :   assert(patch<fgkNofPatches);
      54           0 :   if (patch>=fgkNofPatches) {
      55           0 :     HLTFatal("invalid partition number %d, allowed range [0,%d]", patch, fgkNofPatches-1);
      56           0 :     fPatch=0; // just to avoid boundary overflow
      57           0 :     return;
      58             :   }
      59             : 
      60             :   // Get the row offset.
      61             :   // we have several possibilities to count the rows:
      62             :   // - A: absolute number: 0 to 158 over all partitions
      63             :   // - B: sectorwise: 0 to 62 for inner, 0 to 95 for outer sector
      64             :   // - C: within a partition: the mappping class is designed to return the
      65             :   //   mapping within a partition.
      66             :   // The mapping files use scheme B. We have to subtract the first row.
      67             :   // AliHLTTPCGeometry::GetFirstRow returns first row in scheme A.
      68           0 :   fNofRows=AliHLTTPCGeometry::GetNRows(patch);
      69           0 :   fRowOffset=AliHLTTPCGeometry::GetFirstRow(patch);
      70             : 
      71           0 :   if(!fgMappingIsDone[patch]){
      72           0 :     ReadArray(patch, fgkMappingSize[patch], fgRowMapping[patch], fgPadMapping[patch], fgkMappingHwaSize, fgHwaMapping[patch]);
      73           0 :     fgMappingIsDone[patch]=kTRUE;
      74           0 :   }
      75           0 :   fCurrentRowMapping=fgRowMapping[patch];
      76           0 :   fCurrentPadMapping=fgPadMapping[patch];
      77           0 :   fMaxHWAdd=fgkMappingSize[patch];
      78           0 : }
      79             : 
      80             : Bool_t AliHLTTPCMapping::fgMappingIsDone[fgkNofPatches]={
      81             :   kFALSE,
      82             :   kFALSE,
      83             :   kFALSE,
      84             :   kFALSE,
      85             :   kFALSE,
      86             :   kFALSE
      87             : };
      88             : 
      89             : const UInt_t AliHLTTPCMapping::fgkMappingSize[fgkNofPatches]={
      90             :   AliHLTTPCMapping::fgkMapping0Size,
      91             :   AliHLTTPCMapping::fgkMapping1Size,
      92             :   AliHLTTPCMapping::fgkMapping2Size,
      93             :   AliHLTTPCMapping::fgkMapping3Size,
      94             :   AliHLTTPCMapping::fgkMapping4Size,
      95             :   AliHLTTPCMapping::fgkMapping5Size
      96             : };
      97             : 
      98             : UInt_t AliHLTTPCMapping::fgRowMapping0[fgkMapping0Size];
      99             : UInt_t AliHLTTPCMapping::fgPadMapping0[fgkMapping0Size];
     100             : UInt_t AliHLTTPCMapping::fgHwaMapping0[fgkMappingHwaSize];
     101             : UInt_t AliHLTTPCMapping::fgRowMapping1[fgkMapping1Size];
     102             : UInt_t AliHLTTPCMapping::fgPadMapping1[fgkMapping1Size];
     103             : UInt_t AliHLTTPCMapping::fgHwaMapping1[fgkMappingHwaSize];
     104             : UInt_t AliHLTTPCMapping::fgRowMapping2[fgkMapping2Size];
     105             : UInt_t AliHLTTPCMapping::fgPadMapping2[fgkMapping2Size];
     106             : UInt_t AliHLTTPCMapping::fgHwaMapping2[fgkMappingHwaSize];
     107             : UInt_t AliHLTTPCMapping::fgRowMapping3[fgkMapping3Size];
     108             : UInt_t AliHLTTPCMapping::fgPadMapping3[fgkMapping3Size];
     109             : UInt_t AliHLTTPCMapping::fgHwaMapping3[fgkMappingHwaSize];
     110             : UInt_t AliHLTTPCMapping::fgRowMapping4[fgkMapping4Size];
     111             : UInt_t AliHLTTPCMapping::fgPadMapping4[fgkMapping4Size];
     112             : UInt_t AliHLTTPCMapping::fgHwaMapping4[fgkMappingHwaSize];
     113             : UInt_t AliHLTTPCMapping::fgRowMapping5[fgkMapping5Size];
     114             : UInt_t AliHLTTPCMapping::fgPadMapping5[fgkMapping5Size];
     115             : UInt_t AliHLTTPCMapping::fgHwaMapping5[fgkMappingHwaSize];
     116             : 
     117             : UInt_t* AliHLTTPCMapping::fgRowMapping[fgkNofPatches]={
     118             :   AliHLTTPCMapping::fgRowMapping0,
     119             :   AliHLTTPCMapping::fgRowMapping1,
     120             :   AliHLTTPCMapping::fgRowMapping2,
     121             :   AliHLTTPCMapping::fgRowMapping3,
     122             :   AliHLTTPCMapping::fgRowMapping4,
     123             :   AliHLTTPCMapping::fgRowMapping5
     124             : };
     125             : 
     126             : UInt_t* AliHLTTPCMapping::fgPadMapping[fgkNofPatches]={
     127             :   AliHLTTPCMapping::fgPadMapping0,
     128             :   AliHLTTPCMapping::fgPadMapping1,
     129             :   AliHLTTPCMapping::fgPadMapping2,
     130             :   AliHLTTPCMapping::fgPadMapping3,
     131             :   AliHLTTPCMapping::fgPadMapping4,
     132             :   AliHLTTPCMapping::fgPadMapping5
     133             : };
     134             : 
     135             : UInt_t* AliHLTTPCMapping::fgHwaMapping[fgkNofPatches]={
     136             :   AliHLTTPCMapping::fgHwaMapping0,
     137             :   AliHLTTPCMapping::fgHwaMapping1,
     138             :   AliHLTTPCMapping::fgHwaMapping2,
     139             :   AliHLTTPCMapping::fgHwaMapping3,
     140             :   AliHLTTPCMapping::fgHwaMapping4,
     141             :   AliHLTTPCMapping::fgHwaMapping5
     142             : };
     143             : 
     144           0 : AliHLTTPCMapping::~AliHLTTPCMapping(){
     145             :   // see header file for class documentation
     146           0 : }
     147             : 
     148             : void AliHLTTPCMapping::InitializeMap(UInt_t patch)
     149             : {
     150             :   // see header file for class documentation
     151             :   // method is deprecated, just kept as history for a while
     152             : 
     153             :   UInt_t fNRowsToSubtract=0;
     154             :   //The row numbers returned by digit readers used are not from zero always
     155           0 :   switch(patch){
     156             :   case 0:
     157             :     fNRowsToSubtract=0;
     158           0 :     break;
     159             :   case 1:
     160             :     fNRowsToSubtract=30;
     161           0 :     break;
     162             :   case 2:
     163             :     fNRowsToSubtract=0;
     164           0 :     break;
     165             :   case 3:
     166             :     fNRowsToSubtract=27;
     167           0 :     break;
     168             :   case 4:
     169             :     fNRowsToSubtract=54;
     170           0 :     break;
     171             :   case 5:
     172             :     fNRowsToSubtract=76;
     173           0 :     break;
     174             :   }
     175             : 
     176             :   //Making mapping arrays for the given patch
     177           0 :   ifstream inFile;
     178           0 :   TString filename;
     179           0 :   const char* basePath=getenv("ALICE_ROOT");
     180           0 :   if (basePath) {
     181           0 :     filename.Form("%s/TPC/mapping/Patch%d.data", basePath,patch);
     182             :   }
     183           0 :   inFile.open(filename.Data());
     184           0 :   if (!inFile) {
     185           0 :     HLTFatal("Unable to open file: %s      This means no mapping is provided.", filename.Data());
     186             :   }
     187             :   else{
     188           0 :     UInt_t nHWAdd=0;
     189           0 :     if(inFile >> nHWAdd){
     190           0 :       if(inFile >> fMaxHWAdd){
     191           0 :         UInt_t hwAdd=0;
     192           0 :         UInt_t row=0;
     193           0 :         UInt_t pad=0;
     194           0 :         switch(patch){
     195             :         case 0:
     196           0 :           if(fgkMappingSize[patch]<fMaxHWAdd){
     197           0 :             HLTFatal("Max hardware address exceeded for patch %d, max number is %d, number from mapping file is %d.",patch,fgkMappingSize[patch] ,fMaxHWAdd);
     198             :             break;
     199             :           }
     200           0 :           while(inFile>>hwAdd && inFile>>row && inFile>>pad){
     201           0 :             if (hwAdd>fMaxHWAdd) {
     202           0 :               HLTFatal("hardware address exceeds max hwAddress %d, mapping file %s corrupted?", fMaxHWAdd);
     203             :               break;
     204             :             }
     205           0 :             fgRowMapping0[hwAdd]=row-fNRowsToSubtract;
     206           0 :             fgPadMapping0[hwAdd]=pad;
     207             :           }
     208           0 :           fgMappingIsDone[patch]=kTRUE;
     209           0 :           break;
     210             :         case 1:
     211           0 :           if(fgkMappingSize[patch]<fMaxHWAdd){
     212           0 :             HLTFatal("Max hardware address exceeded for patch %d, max number is %d, number from mapping file is %d.",patch,fgkMappingSize[patch] ,fMaxHWAdd);
     213             :             break;
     214             :           }
     215           0 :           while(inFile>>hwAdd && inFile>>row && inFile>>pad){
     216           0 :             if (hwAdd>fMaxHWAdd) {
     217           0 :               HLTFatal("hardware address exceeds max hwAddress %d, mapping file %s corrupted?", fMaxHWAdd);
     218             :               break;
     219             :             }
     220           0 :             fgRowMapping1[hwAdd]=row-fNRowsToSubtract;
     221           0 :             fgPadMapping1[hwAdd]=pad;
     222             :           }
     223           0 :           fgMappingIsDone[patch]=kTRUE;
     224           0 :           break;
     225             :         case 2:
     226           0 :           if(fgkMappingSize[patch]<fMaxHWAdd){
     227           0 :             HLTFatal("Max hardware address exceeded for patch %d, max number is %d number from mapping file is %d.",patch,fgkMappingSize[patch] ,fMaxHWAdd);
     228             :             break;
     229             :           }
     230           0 :           while(inFile>>hwAdd && inFile>>row && inFile>>pad){
     231           0 :             if (hwAdd>fMaxHWAdd) {
     232           0 :               HLTFatal("hardware address exceeds max hwAddress %d, mapping file %s corrupted?", fMaxHWAdd);
     233             :               break;
     234             :             }
     235           0 :             fgRowMapping2[hwAdd]=row-fNRowsToSubtract;
     236           0 :             fgPadMapping2[hwAdd]=pad;
     237             :           }
     238           0 :           fgMappingIsDone[patch]=kTRUE;
     239           0 :           break;
     240             :         case 3:
     241           0 :           if(fgkMappingSize[patch]<fMaxHWAdd){
     242           0 :             HLTFatal("Max hardware address exceeded for patch %d, max number is %d number from mapping file is %d.",patch,fgkMappingSize[patch] ,fMaxHWAdd);
     243             :             break;
     244             :           }
     245           0 :           while(inFile>>hwAdd && inFile>>row && inFile>>pad){
     246           0 :             if (hwAdd>fMaxHWAdd) {
     247           0 :               HLTFatal("hardware address exceeds max hwAddress %d, mapping file %s corrupted?", fMaxHWAdd);
     248             :               break;
     249             :             }
     250           0 :             fgRowMapping3[hwAdd]=row-fNRowsToSubtract;
     251           0 :             fgPadMapping3[hwAdd]=pad;
     252             :           }
     253           0 :           fgMappingIsDone[patch]=kTRUE;
     254           0 :           break;
     255             :         case 4:
     256           0 :           if(fgkMappingSize[patch]<fMaxHWAdd){
     257           0 :             HLTFatal("Max hardware address exceeded for patch %d, max number is %d number from mapping file is %d.",patch,fgkMappingSize[patch] ,fMaxHWAdd);
     258             :             break;
     259             :           }
     260           0 :           while(inFile>>hwAdd && inFile>>row && inFile>>pad){
     261           0 :             if (hwAdd>fMaxHWAdd) {
     262           0 :               HLTFatal("hardware address exceeds max hwAddress %d, mapping file %s corrupted?", fMaxHWAdd);
     263             :               break;
     264             :             }
     265           0 :             fgRowMapping4[hwAdd]=row-fNRowsToSubtract;
     266           0 :             fgPadMapping4[(UInt_t)hwAdd]=(UInt_t)pad;
     267             :           }
     268           0 :           fgMappingIsDone[patch]=kTRUE;
     269           0 :           break;
     270             :         case 5:
     271           0 :           if(fgkMappingSize[patch]<fMaxHWAdd){
     272           0 :             HLTFatal("Max hardware address exceeded for patch %d, max number is %d number from mapping file is %d.",patch,fgkMappingSize[patch] ,fMaxHWAdd);
     273             :             break;
     274             :           }
     275           0 :           while(inFile>>hwAdd && inFile>>row && inFile>>pad){
     276           0 :             if (hwAdd>fMaxHWAdd) {
     277           0 :               HLTFatal("hardware address exceeds max hwAddress %d, mapping file %s corrupted?", fMaxHWAdd);
     278             :               break;
     279             :             }
     280           0 :             fgRowMapping5[hwAdd]=row-fNRowsToSubtract;
     281           0 :             fgPadMapping5[hwAdd]=pad;
     282             :           }
     283           0 :           fgMappingIsDone[patch]=kTRUE;
     284           0 :           break;
     285             :         }
     286           0 :       }
     287             :     }
     288           0 :   }
     289           0 :   inFile.close();
     290           0 : }
     291             : 
     292             : UInt_t AliHLTTPCMapping::GetRow(UInt_t hwadd) const
     293             : {
     294             :   // see header file for class documentation
     295           0 :   assert(fCurrentRowMapping);
     296           0 :   if (!fCurrentRowMapping) return 0;
     297           0 :   if (hwadd>fMaxHWAdd) return 0;
     298           0 :   return fCurrentRowMapping[hwadd];
     299           0 : }
     300             : 
     301             : UInt_t AliHLTTPCMapping::GetPad(UInt_t hwadd) const
     302             : {
     303             :   // see header file for class documentation
     304           0 :   assert(fCurrentPadMapping);
     305           0 :   if (!fCurrentPadMapping) return 0;
     306           0 :   if (hwadd>fMaxHWAdd) return 0;
     307           0 :   return fCurrentPadMapping[hwadd];
     308           0 : }
     309             : 
     310             : UInt_t AliHLTTPCMapping::GetHwAddress(UInt_t row, UInt_t pad) const
     311             : {
     312             :   // see header file for class documentation
     313           0 :   assert(fPatch<fgkNofPatches);
     314           0 :   assert(fgHwaMapping[fPatch]);
     315           0 :   UInt_t hwaIndex=(row<<fgkMappingHwaRowBitShift) + pad;
     316           0 :   if (hwaIndex<fgkMappingHwaSize) {
     317           0 :     return (fgHwaMapping[fPatch])[hwaIndex];
     318             :   }
     319           0 :   return ~((UInt_t)0);
     320           0 : }
     321             : 
     322             : Bool_t AliHLTTPCMapping::ReadArray(UInt_t patch, UInt_t arraySize, UInt_t rowArray[], UInt_t padArray[], UInt_t hwaMappingSize, UInt_t hwaArray[]) const
     323             : {
     324             :   // see header file for class documentation
     325             :   //Making mapping arrays for the given patch
     326             :   Bool_t result=kTRUE;
     327             : 
     328           0 :   assert(rowArray!=NULL || padArray!=NULL || hwaArray!=NULL);
     329           0 :   if (!rowArray || !padArray || !hwaArray) return kFALSE;
     330             : 
     331           0 :   memset(rowArray, -1, arraySize*sizeof(rowArray[0]));
     332           0 :   memset(padArray, -1, arraySize*sizeof(padArray[0]));
     333           0 :   memset(hwaArray, -1, hwaMappingSize*sizeof(padArray[0]));
     334             : 
     335           0 :   ifstream inFile;
     336           0 :   TString filename;
     337           0 :   const char* basePath=getenv("ALICE_ROOT");
     338           0 :   if (basePath) {
     339           0 :     filename.Form("%s/TPC/mapping/Patch%d.data", basePath,patch);
     340             :   }
     341           0 :   inFile.open(filename.Data());
     342           0 :   if (!inFile) {
     343           0 :     HLTFatal("Unable to open file: %s      This means no mapping is provided.", filename.Data());
     344           0 :     return kFALSE;
     345             :   }
     346             : 
     347           0 :   UInt_t nHWAdd=0;
     348           0 :   UInt_t maxHWAdd=0;
     349           0 :   if(inFile >> nHWAdd){
     350           0 :     if(inFile >> maxHWAdd){
     351           0 :       if(arraySize<maxHWAdd){
     352           0 :         HLTFatal("Max hardware address exceeded for patch %d, max number is %d, number from mapping file is %d.",patch, arraySize ,fMaxHWAdd);
     353             :         result=kFALSE;
     354           0 :       }
     355           0 :       UInt_t hwAdd=0;
     356           0 :       UInt_t row=0;
     357           0 :       UInt_t pad=0;
     358           0 :       while(result && inFile>>hwAdd && inFile>>row && inFile>>pad){
     359           0 :         if (hwAdd>maxHWAdd) {
     360           0 :           HLTFatal("hardware address exceeds max hwAddress %d, mapping file %s corrupted?", maxHWAdd);
     361             :           result=kFALSE;
     362           0 :           break;
     363             :         }
     364           0 :         Int_t dummy=0;
     365             :         // AliHLTTPCGeometry::GetFirstRow returns first row in scheme A.
     366             :         // We have to transform to scheme B by AliHLTTPCGeometry::Slice2Sector.
     367           0 :         Int_t offsetSchemeB=0;
     368           0 :         AliHLTTPCGeometry::Slice2Sector(0, fRowOffset, dummy, offsetSchemeB);
     369           0 :         rowArray[hwAdd]=row-offsetSchemeB;
     370           0 :         padArray[hwAdd]=pad;
     371           0 :         UInt_t hwaIndex=(rowArray[hwAdd]<<fgkMappingHwaRowBitShift) + padArray[hwAdd];
     372           0 :         assert(hwaIndex<hwaMappingSize);
     373           0 :         if (hwaIndex<hwaMappingSize) {
     374           0 :           hwaArray[hwaIndex]=hwAdd;
     375           0 :         }
     376           0 :       }
     377           0 :     }
     378             :   }
     379           0 :   inFile.close();
     380           0 :   return result;
     381           0 : }
     382             : 
     383             : Bool_t AliHLTTPCMapping::IsValidHWAddress(UInt_t hwadd) const
     384             : {
     385           0 :   if (hwadd>fMaxHWAdd){
     386           0 :     return kFALSE;
     387             :   }
     388             :   else{
     389           0 :     return kTRUE;
     390             :   }
     391           0 : }

Generated by: LCOV version 1.11