temp = 0x2AA;
FillBuffer(temp);
temp = 0xA << 6;
- temp |= (wordsNumber >> 4);
+ temp |= ((wordsNumber & 0x3FF) >> 4);
FillBuffer(temp);
temp = (wordsNumber << 6) & 0x3FF;
temp |= (0xA << 2);
- Short_t hwAdress = fMapping->GetHWAdress(rowNumber,padNumber);
+ Short_t hwAdress = fMapping->GetHWAdress(rowNumber,padNumber,secNumber);
if (hwAdress == -1)
AliFatal(Form("No hardware (ALTRO) adress found for these pad-row (%d) and pad (%d) indeces !",rowNumber,padNumber));
}
//_____________________________________________________________________________
-Bool_t AliAltroBuffer::ReadTrailer(Int_t& wordsNumber, Int_t& padNumber,
- Int_t& rowNumber, Int_t& secNumber)
+Bool_t AliAltroBuffer::ReadDummyTrailer(Int_t& wordsNumber, Int_t& padNumber,
+ Int_t& rowNumber, Int_t& secNumber)
{
-//Read a trailer of 40 bits in the forward reading mode
+//Read a dummy trailer of 40 bits in the forward reading mode
wordsNumber = GetNext();
if (wordsNumber == -1) return kFALSE;
return kTRUE;
}
+//_____________________________________________________________________________
+Bool_t AliAltroBuffer::ReadTrailer(Int_t& wordsNumber, Int_t& padNumber,
+ Int_t& rowNumber, Int_t& secNumber)
+{
+//Read a trailer of 40 bits in the forward reading mode
+ if (!fMapping) {
+ AliError("No ALTRO mapping information is loaded! Reading a dummy trailer!");
+ return ReadDummyTrailer(wordsNumber,padNumber,
+ rowNumber,secNumber);
+ }
+
+ Int_t temp = GetNext();
+ if (temp != 0x2AA)
+ AliFatal(Form("Incorrect trailer found ! Expecting 0x2AA but found %x !",temp));
+
+ temp = GetNext();
+ if ((temp >> 6) != 0xA)
+ AliFatal(Form("Incorrect trailer found ! Expecting 0xA but found %x !",temp >> 6));
+ wordsNumber = (temp << 4) & 0x3FF;
+
+ temp = GetNext();
+ wordsNumber |= (temp >> 6);
+ if ((temp & 0xF) != 0xA)
+ AliFatal(Form("Incorrect trailer found ! Expecting second 0xA but found %x !",temp >> 6));
+ Int_t hwAdress = (temp & 0x3) << 10;
+
+ temp = GetNext();
+ hwAdress |= temp;
+
+ rowNumber = fMapping->GetPadRow(hwAdress);
+ padNumber = fMapping->GetPad(hwAdress);
+ secNumber = fMapping->GetSector(hwAdress);
+ return kTRUE;
+}
+
//_____________________________________________________________________________
Bool_t AliAltroBuffer::ReadTrailerBackward(Int_t& wordsNumber,
Int_t& padNumber,
// 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"
//_____________________________________________________________________________
AliAltroMapping::AliAltroMapping(const char *mappingFile):
+ fIn(NULL),
fNumberOfChannels(0),
- fMaxHWAdress(0),
- fMinPadRow(0),
- fMaxPadRow(0),
- fMaxPad(0),
- fMapping(NULL),
- fInvMapping(NULL)
+ fMaxHWAdress(0)
{
// Constructor
// Reads the mapping from an external file
if (mappingFile)
- ReadMapping(mappingFile);
+ OpenMappingFile(mappingFile);
else
AliFatal("Mapping file not specified !");
}
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),
+ fIn(mapping.fIn),
fNumberOfChannels(mapping.fNumberOfChannels),
- fMaxHWAdress(mapping.fMaxHWAdress),
- fMinPadRow(mapping.fMinPadRow),
- fMaxPadRow(mapping.fMaxPadRow),
- fMaxPad(mapping.fMaxPad),
- fMapping(mapping.fMapping),
- fInvMapping(mapping.fInvMapping)
+ fMaxHWAdress(mapping.fMaxHWAdress)
{
// Copy Constructor
}
//_____________________________________________________________________________
-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));
return kFALSE;
}
- if (!(in >> fNumberOfChannels)) {
+ if (!(*fIn >> fNumberOfChannels)) {
AliFatal(Form("Syntax of the mapping file is wrong (%s) !",mappingFile));
return kFALSE;
}
- if (!(in >> fMaxHWAdress)) {
+ if (!(*fIn >> fMaxHWAdress)) {
AliFatal(Form("Syntax of the mapping file is wrong (%s) !",mappingFile));
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
+Bool_t 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;
+ // Closes the external mapping
+ // file
+ if (fIn) {
+ fIn->close();
+ fIn = NULL;
}
- 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;
- }
- 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;
+ return kTRUE;
}
AliAltroMapping(const AliAltroMapping& mapping);
AliAltroMapping& operator = (const AliAltroMapping& mapping);
- Int_t GetHWAdress(Int_t padrow, Int_t pad) const;
- Int_t GetPadRow(Int_t hwAdress) const;
- Int_t GetPad(Int_t hwAdress) const;
-
- private:
- Bool_t ReadMapping(const char *mappingFile);
-
+ virtual Int_t GetHWAdress(Int_t padrow, Int_t pad, Int_t sector) const = 0;
+ virtual Int_t GetPadRow(Int_t hwAdress) const = 0;
+ virtual Int_t GetPad(Int_t hwAdress) const = 0;
+ virtual Int_t GetSector(Int_t hwAdress) const = 0;
+
+ protected:
+ Bool_t OpenMappingFile(const char *mappingFile);
+ Bool_t CloseMappingFile();
+ virtual Bool_t ReadMapping() = 0;
+ virtual void DeleteMappingArrays() = 0;
+
+ ifstream *fIn; // External mapping file
Int_t fNumberOfChannels; // Number of ALTRO channels
Int_t fMaxHWAdress; // Maximum HW adress
- Int_t fMinPadRow; // Minimum Index of pad-row
- Int_t fMaxPadRow; // Maximum Index of pad-row
- Int_t fMaxPad; // Maximum Index of pad inside row
- Short_t **fMapping; // Array which connects hardware adresses to pad and pad-row indeces
- Short_t **fInvMapping; // Inverse of fMapping
ClassDef(AliAltroMapping,0) // Altro mapping handler class
};