LCOV - code coverage report
Current view: top level - RAW/RAWDatabase - AliCaloAltroMapping.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 98 132 74.2 %
Date: 2016-06-14 17:26:59 Functions: 14 14 100.0 %

          Line data    Source code
       1             : /**************************************************************************
       2             :  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
       3             :  *                                                                        *
       4             :  * Author: The ALICE Off-line Project.                                    *
       5             :  * Contributors are mentioned in the code where appropriate.              *
       6             :  *                                                                        *
       7             :  * Permission to use, copy, modify and distribute this software and its   *
       8             :  * documentation strictly for non-commercial purposes is hereby granted   *
       9             :  * without fee, provided that the above copyright notice appears in all   *
      10             :  * copies and that both the copyright notice and this permission notice   *
      11             :  * appear in the supporting documentation. The authors make no claims     *
      12             :  * about the suitability of this software for any purpose. It is          *
      13             :  * provided "as is" without express or implied warranty.                  *
      14             :  **************************************************************************/
      15             : /* $Id$ */
      16             : 
      17             : // This class handles the mapping of the Altro channels in the PHOS/EMCAL
      18             : // The mapping is read from an external mapping files
      19             : // Author: C.Cheshkov
      20             : 
      21             : /// Exported from PHOS to be used also by EMCAL
      22             : /// November 2006 Gustavo Conesa Balbastre
      23             : 
      24             : #include "AliCaloAltroMapping.h"
      25             : #include "AliLog.h"
      26             : #include <Riostream.h>
      27             : //#include <stdlib.h>
      28             : 
      29             : 
      30         128 : ClassImp(AliCaloAltroMapping)
      31             : 
      32             : //_____________________________________________________________________________
      33             : AliCaloAltroMapping::AliCaloAltroMapping():
      34          72 :   AliAltroMapping(),
      35          72 :   fMinRow(0),
      36          72 :   fMaxRow(0),
      37          72 :   fMinCol(0),
      38          72 :   fMaxCol(0),
      39          72 :   fInvMappingLow(NULL),
      40          72 :   fInvMappingHigh(NULL)
      41         360 : {
      42             :   // Default constructor
      43         144 : }
      44             : 
      45             : //_____________________________________________________________________________
      46             : AliCaloAltroMapping::AliCaloAltroMapping(const char *mappingFile):
      47          80 :   AliAltroMapping(mappingFile),
      48          80 :   fMinRow(0),
      49          80 :   fMaxRow(0),
      50          80 :   fMinCol(0),
      51          80 :   fMaxCol(0),
      52          80 :   fInvMappingLow(NULL),
      53          80 :   fInvMappingHigh(NULL)
      54         400 : {
      55             :   // Constructor
      56          80 :   ReadMapping();
      57          80 :   CloseMappingFile();
      58         160 : }
      59             : 
      60             : //_____________________________________________________________________________
      61             : AliCaloAltroMapping::~AliCaloAltroMapping()
      62         480 : {
      63             :   // destructor
      64             :   // Deletes the arrays which have been
      65             :   // allocated during the reading of the
      66             :   // mapping file
      67          80 :   if (fInvMappingLow) delete [] fInvMappingLow;
      68             : 
      69          80 :   if (fInvMappingHigh) delete [] fInvMappingHigh;
      70         240 : }
      71             : 
      72             : //_____________________________________________________________________________
      73             : Bool_t AliCaloAltroMapping::ReadMapping()
      74             : {
      75             :   // Initalizes the ALTRO mapping from a file
      76             :   // Look at the Calo module for the format of
      77             :   // the mapping file
      78         160 :   if (!fIn) {
      79           0 :     AliFatal("Mapping file has not been opened !");
      80           0 :     return kFALSE;
      81             :   }
      82             : 
      83          80 :   fMinRow = 0x7fffffff;
      84          80 :   fMaxRow = 0;
      85          80 :   fMinCol = 0x7fffffff;
      86          80 :   fMaxCol = 0;
      87          80 :   fMappingSize = 3*(fMaxHWAddress+1);
      88          80 :   fMapping = new Short_t[fMappingSize];
      89      627360 :   for (Int_t i = 0; i <= fMaxHWAddress; i++) {
      90      313600 :     fMapping[3*i] = fMapping[3*i+1] = fMapping[3*i+2] = -1;
      91             :   }
      92             :  
      93      327920 :   for(Int_t i = 0; i < fNumberOfChannels ; i++) { // 1792 = 2*896 channels connected to each RCU
      94      163840 :     Int_t hwAddress;
      95      163840 :     if (!(*fIn >> hwAddress)) {
      96           0 :       AliFatal("Syntax of the mapping file is wrong !");
      97           0 :       return kFALSE;
      98             :     }
      99      163840 :     if (hwAddress > fMaxHWAddress) {
     100           0 :       AliFatal(Form("Hardware (ALTRO) adress (%d) outside the range (0 -> %d) !",hwAddress,fMaxHWAddress));
     101           0 :       return kFALSE;
     102             :     }
     103      163840 :     Int_t row,col,caloFlag;
     104      163840 :     if (!(*fIn >> row >> col >> caloFlag)) {
     105           0 :       AliFatal("Syntax of the mapping file is wrong !");
     106           0 :       return kFALSE;
     107             :     }
     108             : 
     109      163840 :     if (caloFlag < 0 || caloFlag > 3) {
     110           0 :       AliFatal(Form("Wrong CaloFlag value found (%d)! Should be 0 ,1, 2 or 3 !",caloFlag));
     111           0 :       return kFALSE;
     112             :     }
     113             :  
     114      163840 :     fMapping[3*hwAddress] = row;
     115      163840 :     fMapping[3*hwAddress+1] = col;
     116      163840 :     fMapping[3*hwAddress+2] = caloFlag;
     117             : 
     118      164220 :     if (row > fMaxRow) fMaxRow = row;
     119      163920 :     if (row < fMinRow) fMinRow = row;
     120      184240 :     if (col > fMaxCol) fMaxCol = col;
     121      163920 :     if (col < fMinCol) fMinCol = col;
     122             : 
     123      491520 :   }
     124             : 
     125          80 :   return kTRUE;
     126          80 : }
     127             : 
     128             : //_____________________________________________________________________________
     129             : Bool_t AliCaloAltroMapping::CreateInvMapping()
     130             : {
     131             :   // Create the inverse mapping
     132             :   // needed for the simulation of
     133             :   // raw data
     134          30 :   if (fInvMappingLow) return kTRUE;
     135             : 
     136          15 :   if (!fMapping) {
     137           0 :     AliWarning("Mapping array was not initalized correctly ! Impossible to create the inverse mapping !");
     138           0 :     return kFALSE;
     139             :   }
     140             : 
     141          15 :   Int_t nRows = fMaxRow - fMinRow + 1;
     142          15 :   Int_t nCols = fMaxCol - fMinCol + 1;
     143          15 :   Int_t invMappingSize = nRows*nCols;
     144             : 
     145          15 :   fInvMappingLow  = new Short_t[invMappingSize];
     146          15 :   fInvMappingHigh = new Short_t[invMappingSize];
     147         992 :   for (Int_t i = 0; i < nRows; i++) {
     148     1766594 :     for (Int_t j = 0; j < nCols; j++) {
     149      882816 :       fInvMappingLow[nCols*i+j]  = -1;
     150      882816 :       fInvMappingHigh[nCols*i+j] = -1;
     151             :     }
     152             :   }
     153      112510 :   for(Int_t i = 0; i <= fMaxHWAddress; i++) {
     154       56240 :     Int_t row = fMapping[3*i];
     155       56240 :     Int_t col = fMapping[3*i+1];
     156       56240 :     Int_t caloFlag = fMapping[3*i+2];
     157       56240 :     if(row != -1 && col != -1) {
     158       28000 :       if (caloFlag == 0)
     159       12160 :         fInvMappingLow[nCols*(row-fMinRow)+(col-fMinCol)] = i;
     160       28000 :       if (caloFlag == 1)
     161       12160 :         fInvMappingHigh[nCols*(row-fMinRow)+(col-fMinCol)] = i;
     162             :     }
     163             :   }
     164             : 
     165             :   return kTRUE;
     166          15 : }
     167             : 
     168             : //_____________________________________________________________________________
     169             : Int_t AliCaloAltroMapping::GetHWAddress(Int_t row, Int_t col, Int_t caloFlag)
     170             : {
     171             :   // Get the content of the mapping array
     172             :   // return -1 in case there is no hardware
     173             :   // adress defined for these row-column-caloFlag
     174         621 :   if (!fInvMappingLow || !fInvMappingHigh) {
     175          15 :     if (!CreateInvMapping()) return -1;
     176             :   }
     177         424 :   if (row < fMinRow || row > fMaxRow) {
     178           0 :     AliWarning(Form("Index of row (%d) outside the range (%d -> %d) !",row,fMinRow,fMaxRow));
     179           0 :     return -1;
     180             :   }
     181         424 :   if (col < fMinCol || col > fMaxCol) {
     182           0 :     AliWarning(Form("Index of column (%d) outside the range (%d -> %d) !",col,fMinCol,fMaxCol));
     183           0 :     return -1;
     184             :   }
     185         212 :   if (caloFlag < 0 || caloFlag > 3) {
     186           0 :     AliWarning(Form("Invalid caloFlag (%d)! Should be 0, 1, 2 or 3 !",caloFlag));
     187           0 :     return -1;
     188             :   }
     189             :   Int_t hwAddress = -1;
     190         212 :   if (caloFlag == 0)
     191          46 :     hwAddress = fInvMappingLow[(fMaxCol - fMinCol + 1)*(row-fMinRow)+(col-fMinCol)];
     192         212 :   if (caloFlag == 1)
     193         166 :     hwAddress = fInvMappingHigh[(fMaxCol - fMinCol + 1)*(row-fMinRow)+(col-fMinCol)];
     194             : 
     195         212 :   if (hwAddress == -1)
     196           0 :     AliWarning(Form("Hardware (ALTRO) adress is not defined for these row (%d), column (%d) and caloFlag (%d) !",row,col,caloFlag));
     197             : 
     198             :   return hwAddress;
     199         212 : }
     200             : 
     201             : //_____________________________________________________________________________
     202             : Int_t AliCaloAltroMapping::GetPadRow(Int_t hwAddress) const
     203             : {
     204             :   // Return the row index
     205             :   // Note the difference w.r.t to the base class notation
     206         790 :   if (!fMapping) {
     207           0 :     AliWarning("Mapping array was not initalized correctly !");
     208           0 :     return -1;
     209             :   }
     210         395 :   if (hwAddress > fMaxHWAddress) {
     211           0 :     AliWarning(Form("Hardware (ALTRO) adress (%d) outside the range (0 -> %d) !",hwAddress,fMaxHWAddress));
     212           0 :     return -1;
     213             :   }
     214         395 :   Int_t row = fMapping[3*hwAddress];
     215         395 :   if (row == -1)
     216           0 :     AliWarning(Form("Hardware (ALTRO) adress (%d) is not defined !",hwAddress));
     217             : 
     218             :   return row;
     219         395 : }
     220             : 
     221             : //_____________________________________________________________________________
     222             : Int_t AliCaloAltroMapping::GetPad(Int_t hwAddress) const
     223             : {
     224             :   // Return the column index
     225             :   // Note the difference w.r.t to the base class notation
     226         790 :   if (!fMapping) {
     227           0 :     AliWarning("Mapping array was not initalized correctly !");
     228           0 :     return -1;
     229             :   }
     230         395 :   if (hwAddress > fMaxHWAddress) {
     231           0 :     AliWarning(Form("Hardware (ALTRO) adress (%d) outside the range (0 -> %d) !",hwAddress,fMaxHWAddress));
     232           0 :     return -1;
     233             :   }
     234         395 :   Int_t col = fMapping[3*hwAddress+1];
     235         395 :   if (col == -1)
     236           0 :     AliWarning(Form("Hardware (ALTRO) adress (%d) is not defined !",hwAddress));
     237             : 
     238             :   return col;
     239         395 : }
     240             : 
     241             : //_____________________________________________________________________________
     242             : Int_t AliCaloAltroMapping::GetSector(Int_t hwAddress) const
     243             : {
     244             :   // Return the caloFlag factor (0/1)
     245             :   // Note the difference w.r.t to the base class notation
     246         790 :   if (!fMapping) {
     247           0 :     AliWarning("Mapping array was not initalized correctly !");
     248           0 :     return -1;
     249             :   }
     250         395 :   if (hwAddress > fMaxHWAddress) {
     251           0 :     AliWarning(Form("Hardware (ALTRO) adress (%d) outside the range (0 -> %d) !",hwAddress,fMaxHWAddress));
     252           0 :     return -1;
     253             :   }
     254         395 :   Int_t caloFlag = fMapping[3*hwAddress+2];
     255         395 :   if (caloFlag == -1)
     256           0 :     AliWarning(Form("Hardware (ALTRO) adress (%d) is not defined !",hwAddress));
     257             : 
     258             :   return caloFlag;
     259         395 : }

Generated by: LCOV version 1.11