]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - RAW/AliAltroMapping.cxx
updated
[u/mrichter/AliRoot.git] / RAW / AliAltroMapping.cxx
index 54bc0d00befaa193012b5c725c37080cfd06af1f..749e157fe1dd6c5c15dd2d9467590707124db298 100644 (file)
 
 // This class handles the mapping of the Altro channels
 // The mapping is read from an external mapping files
-// The class is used by TPC,PHOS and FMD
+// The class is used as a base class by TPC,PHOS and FMD
 // Author: C.Cheshkov
 
 #include "AliAltroMapping.h"
 #include "AliLog.h"
 #include <Riostream.h>
-//#include <stdlib.h>
 
 
 ClassImp(AliAltroMapping)
 
+//_____________________________________________________________________________
+AliAltroMapping::AliAltroMapping():
+  fIn(NULL),
+  fNumberOfChannels(0),
+  fMaxHWAddress(0),
+  fMappingSize(0),
+  fMapping(NULL)
+{
+  // Default constructor
+}
+
 //_____________________________________________________________________________
 AliAltroMapping::AliAltroMapping(const char *mappingFile):
+  fIn(NULL),
   fNumberOfChannels(0),
-  fMaxHWAdress(0),
-  fMinPadRow(0),
-  fMaxPadRow(0),
-  fMaxPad(0),
-  fMapping(NULL),
-  fInvMapping(NULL)
+  fMaxHWAddress(0),
+  fMappingSize(0),
+  fMapping(NULL)
 {
   // Constructor
   // Reads the mapping from an external file
   if (mappingFile)
-    ReadMapping(mappingFile);
+    OpenMappingFile(mappingFile);
   else
     AliFatal("Mapping file not specified !");
 }
@@ -48,180 +56,45 @@ AliAltroMapping::AliAltroMapping(const char *mappingFile):
 AliAltroMapping::~AliAltroMapping()
 {
   // destructor
-  if (fMapping) {
-    for (Int_t i = 0; i <= fMaxHWAdress; i++) delete [] fMapping[i];
-    delete [] fMapping;
-  }
-
-  if (fInvMapping) {
-    for (Int_t i = 0; i <= (fMaxPadRow - fMinPadRow); i++)
-      delete [] fInvMapping[i];
-    delete [] fInvMapping;
-  }
-
-}
-
-//_____________________________________________________________________________
-AliAltroMapping::AliAltroMapping(const AliAltroMapping& mapping):
-  TObject(mapping),
-  fNumberOfChannels(mapping.fNumberOfChannels),
-  fMaxHWAdress(mapping.fMaxHWAdress),
-  fMinPadRow(mapping.fMinPadRow),
-  fMaxPadRow(mapping.fMaxPadRow),
-  fMaxPad(mapping.fMaxPad),
-  fMapping(mapping.fMapping),
-  fInvMapping(mapping.fInvMapping)
-{
-// Copy Constructor
+  CloseMappingFile();
 
-  Fatal("AliAltroMapping", "copy constructor not implemented");
+  if (fMapping) delete [] fMapping;
 }
 
 //_____________________________________________________________________________
-AliAltroMapping& AliAltroMapping::operator = (const AliAltroMapping& /*mapping*/)
-{
-//Assigment operator
-
-  Fatal("operator =", "assignment operator not implemented");
-  return *this;
-}
-
-//_____________________________________________________________________________
-Bool_t AliAltroMapping::ReadMapping(const char *mappingFile)
+Bool_t AliAltroMapping::OpenMappingFile(const char *mappingFile)
 {
   // Initalizes the ALTRO mapping from a file
   // Look at the TPC module for the format of
   // the mapping file
-  ifstream in(mappingFile);
-  if (!in) {
+  fIn = new ifstream(mappingFile);
+  if (!*fIn) {
     AliFatal(Form("Missing mapping file (%s) !",mappingFile));
+    CloseMappingFile();
     return kFALSE;
   }
-  if (!(in >> fNumberOfChannels)) {
+  if (!(*fIn >> fNumberOfChannels)) {
     AliFatal(Form("Syntax of the mapping file is wrong (%s) !",mappingFile));
+    CloseMappingFile();
     return kFALSE;
   }
-  if (!(in >> fMaxHWAdress)) {
+  if (!(*fIn >> fMaxHWAddress)) {
     AliFatal(Form("Syntax of the mapping file is wrong (%s) !",mappingFile));
+    CloseMappingFile();
     return kFALSE;
   }
-//   if (!(in >> fMinPadRow >> fMaxPadRow)) {
-//     AliFatal(Form("Syntax of the mapping file is wrong (%s) !",mappingFile));
-//     return kFALSE;
-//   }
-//   if (!(in >> fMaxPad)) {
-//     AliFatal(Form("Syntax of the mapping file is wrong (%s) !",mappingFile));
-//     return kFALSE;
-//   }
-
-  fMinPadRow = 0x7fffffff;
-  fMaxPadRow = 0;
-  fMaxPad = 0;
-  fMapping = new Short_t*[fMaxHWAdress+1];
-  for (Int_t i = 0; i <= fMaxHWAdress; i++) {
-    fMapping[i] = new Short_t[2];
-    fMapping[i][0] = fMapping[i][1] = -1;
-  }
-  for(Int_t i = 0; i < fNumberOfChannels ; i++) { //5504 is size of irorc mapping at ther moment only for irorc
-    Int_t hwAdress;
-    if (!(in >> hwAdress)) {
-      AliFatal(Form("Syntax of the mapping file is wrong (%s) !",mappingFile));
-      return kFALSE;
-    }
-    if (hwAdress > fMaxHWAdress) {
-      AliFatal(Form("Hardware (ALTRO) adress (%d) outside the range (0 -> %d) !",hwAdress,fMaxHWAdress));
-      return kFALSE;
-    }
-    Int_t padrow,pad;
-    if (!(in >> padrow >> pad)) {
-      AliFatal(Form("Syntax of the mapping file is wrong (%s) !",mappingFile));
-      return kFALSE;
-    }
-    fMapping[hwAdress][0] = padrow;
-    fMapping[hwAdress][1] = pad;
-
-    if (padrow > fMaxPadRow) fMaxPadRow = padrow;
-    if (padrow < fMinPadRow) fMinPadRow = padrow;
-    if (pad > fMaxPad) fMaxPad = pad;
-  }
 
-  fInvMapping = new Short_t*[fMaxPadRow - fMinPadRow + 1];
-  for (Int_t i = 0; i <= (fMaxPadRow - fMinPadRow); i++) {
-    fInvMapping[i] = new Short_t[fMaxPad + 1];
-    for (Int_t j = 0; j <= fMaxPad; j++) fInvMapping[i][j] = -1;
-  }
-
-  for(Int_t i = 0; i <= fMaxHWAdress; i++) {
-    Int_t padrow = fMapping[i][0];
-    Int_t pad = fMapping[i][1];
-    if(padrow != -1 && pad != -1)
-      fInvMapping[padrow-fMinPadRow][pad] = i;
-  }
-
-  in.close();
   return kTRUE;
 }
 
 //_____________________________________________________________________________
-Int_t AliAltroMapping::GetHWAdress(Int_t padrow, Int_t pad) const
+void AliAltroMapping::CloseMappingFile()
 {
-  // Get the content of the mapping array
-  // return -1 in case there is no hardware
-  // adress defined for these pad-row and pad
-  if (!fInvMapping) {
-    AliWarning("Mapping array was not initalized correctly !");
-    return -1;
-  }
-  if (padrow < fMinPadRow || padrow > fMaxPadRow) {
-    AliWarning(Form("Index of pad-row (%d) outside the range (%d -> %d) !",padrow,fMinPadRow,fMaxPadRow));
-    return -1;
-  }
-  if (pad > fMaxPad) {
-    AliWarning(Form("Index of pad (%d) outside the range (0 -> %d) !",pad,fMaxPad));
-    return -1;
+  // Closes the external mapping
+  // file
+  if (fIn) {
+    fIn->close();
+    delete fIn;
+    fIn = NULL;
   }
-  Int_t hwAdress = fInvMapping[padrow-fMinPadRow][pad];
-  if (hwAdress == -1)
-    AliWarning(Form("Hardware (ALTRO) adress is not defined for these pad-row (%d) and pad (%d) !",padrow,pad));
-
-  return hwAdress;
-}
-
-//_____________________________________________________________________________
-Int_t AliAltroMapping::GetPadRow(Int_t hwAdress) const
-{
-  if (!fMapping) {
-    AliWarning("Mapping array was not initalized correctly !");
-    return -1;
-  }
-  if (hwAdress > fMaxHWAdress) {
-    AliWarning(Form("Hardware (ALTRO) adress (%d) outside the range (0 -> %d) !",hwAdress,fMaxHWAdress));
-    return -1;
-  }
-  Int_t padrow = fMapping[hwAdress][0];
-  if (padrow == -1)
-    AliWarning(Form("Hardware (ALTRO) adress (%d) is not defined !",hwAdress));
-
-  return padrow;
-}
-
-//_____________________________________________________________________________
-Int_t AliAltroMapping::GetPad(Int_t hwAdress) const
-{
-  if (!fMapping) {
-    AliWarning("Mapping array was not initalized correctly !");
-    return -1;
-  }
-  if (hwAdress > fMaxHWAdress) {
-    AliWarning(Form("Hardware (ALTRO) adress (%d) outside the range (0 -> %d) !",hwAdress,fMaxHWAdress));
-    return -1;
-  }
-  Int_t pad = fMapping[hwAdress][1];
-  if (pad == -1)
-    AliWarning(Form("Hardware (ALTRO) adress (%d) is not defined !",hwAdress));
-
-  return pad;
 }