#include "AliFMDAltroMapping.h" // ALIFMDALTROMAPPING_H
#include "AliFMDParameters.h"
#include "AliLog.h"
+#include <iostream>
+#include <iomanip>
//____________________________________________________________________
ClassImp(AliFMDAltroMapping)
}
//_____________________________________________________________________________
-void
-AliFMDAltroMapping::DeleteMappingArrays()
+Bool_t
+AliFMDAltroMapping::CreateInvMapping()
{
- // Clear map in memory
+ // Create inverse mapping - not used
+ return kTRUE;
}
//____________________________________________________________________
AliFMDAltroMapping::Hardware2Detector(UInt_t ddl, UInt_t addr,
UShort_t& det, Char_t& ring,
UShort_t& sec, UShort_t& str) const
+{
+ // Translate a hardware address to detector coordinates.
+ //
+ // See also Hardware2Detector that accepts 4 inputs
+ UInt_t board = (addr >> 7) & 0x1F;
+ UInt_t altro = (addr >> 4) & 0x7;
+ UInt_t chan = (addr & 0xf);
+ return Hardware2Detector(ddl, board, altro, chan, det, ring, sec, str);
+}
+
+//____________________________________________________________________
+Bool_t
+AliFMDAltroMapping::Hardware2Detector(UInt_t ddl, UInt_t board,
+ UInt_t altro, UInt_t chan,
+ UShort_t& det, Char_t& ring,
+ UShort_t& sec, UShort_t& str) const
{
// Translate a hardware address to detector coordinates.
// The detector is simply
// +-------------+----------+----------+
//
// The board number identifier among other things the ring. There's
- // up to 4 boards per DDL, and the two first (0 and 1) corresponds
- // to the inner rings, while the two last (2 and 3) corresponds to
+ // up to 4 boards per DDL, and the two first (0 and 16) corresponds
+ // to the inner rings, while the two last (1 and 17) corresponds to
// the outer rings.
//
// The board number and ALTRO number together identifies the sensor,
// return the first strip in the given range.
//
det = ddl + 1;
- UInt_t board = (addr >> 7) & 0x1F;
- UInt_t altro = (addr >> 4) & 0x7;
- UInt_t chan = (addr & 0xf);
- if (board > 3) {
- AliError(Form("Invalid board address %d for the FMD", board));
- return kFALSE;
- }
- if (altro > 2) {
- AliError(Form("Invalid ALTRO address %d for the FMD digitizer %d",
- altro, board));
- return kFALSE;
+ ring = (board % 2) == 0 ? 'I' : 'O';
+ switch (ring) {
+ case 'i':
+ case 'I':
+ sec = ((board / 16) * 10 + (altro < 1 ? 0 : altro < 2 ? 4 : 6)
+ + 2 * (chan / 8) + chan % 2);
+ str = ((chan % 8) / 2) * 128;
+ break;
+ case 'o':
+ case 'O':
+ sec = ((board / 16) * 20 + (altro < 1 ? 0 : altro < 2 ? 8 : 12)
+ + 2 * (chan / 4) + chan % 2);
+ str = ((chan % 4) / 2) * 128;
+ break;
}
- ring = (board > 1 ? 'O' : 'I');
- UInt_t nsen = (ring == 'I' ? 10 : 20);
- UInt_t nsa = (ring == 'I' ? 2 : 4); // Sensors per ALTRO
- UInt_t ncs = (ring == 'I' ? 8 : 4); // Channels per sensor
- UInt_t sen = (board % 2) * nsen / 2; // Base for half-ring
- sen += chan / ncs + (altro == 0 ? 0 :
- altro == 1 ? nsa : UInt_t(1.5 * nsa));
- sec = 2 * sen + (chan % 2);
- str = (chan % ncs) / 2 * 128;
return kTRUE;
}
//____________________________________________________________________
Bool_t
-AliFMDAltroMapping::Detector2Hardware(UShort_t det, Char_t ring,
- UShort_t sec, UShort_t str,
- UInt_t& ddl, UInt_t& addr) const
+AliFMDAltroMapping::Detector2Hardware(UShort_t det, Char_t ring,
+ UShort_t sec, UShort_t str,
+ UInt_t& ddl, UInt_t& board,
+ UInt_t& altro, UInt_t& chan) const
{
// Translate detector coordinates to a hardware address.
// The ddl is simply
// +-------------+----------+----------+
//
// The board number is given by the ring and sector. The inner
- // rings board 0 and 1, while the outer are 2 and 3. Which of these
+ // rings board 0 and 16, while the outer are 1 and 17. Which of these
// depends on the sector. The map is
//
// Ring I, sector 0- 9 -> board 0
- // Ring I, sector 10-19 -> board 1
- // Ring O, sector 0-19 -> board 2
- // Ring O, sector 20-39 -> board 3
+ // Ring I, sector 10-19 -> board 16
+ // Ring O, sector 0-19 -> board 1
+ // Ring O, sector 20-39 -> board 17
//
// There are 3 ALTRO's per board. The ALTRO number is given by the
// sector number. For the inner rings, these are given by
// give us a unique hardware address
//
ddl = (det - 1);
- UInt_t nsen = (ring == 'I' ? 10 : 20);
- UInt_t nsa = (ring == 'I' ? 2 : 4); // Sensors per ALTRO
- UInt_t ncs = (ring == 'I' ? 8 : 4); // Channels per sensor
- UInt_t bbase = (ring == 'I' ? 0 : 2);
- UInt_t board = bbase + sec / nsen;
- UInt_t lsec = (sec - (board - bbase) * nsen); // Local sec in half-ring
- UInt_t altro = (lsec < 2 * nsa ? 0 : (lsec < 3 * nsa ? 1 : 2));
- UInt_t sbase = (altro == 0 ? 0 : altro == 1 ? 2 * nsa : 3 * nsa);
- UInt_t chan = (sec % 2) + (lsec-sbase) / 2 * ncs + 2 * (str / 128);
- AliDebug(40, Form("\n"
- " chan = (%d %% 2) + (%d-%d) / %d * %d + 2 * %d / 128\n"
- " = %d + %d + %d = %d",
- sec, lsec, sbase, 2, ncs, str,
- (sec % 2), (lsec - sbase) / 2 * ncs,
- 2 * (str / 128), chan));
- addr = chan + (altro << 4) + (board << 7);
-
+ UInt_t tmp = 0;
+ switch (ring) {
+ case 'I':
+ case 'i':
+ board = (sec / 10) * 16;
+ altro = (sec % 10) < 4 ? 0 : (sec % 10) < 6 ? 1 : 2;
+ tmp = (sec % 10) - (altro == 0 ? 0 : altro == 1 ? 4 : 6);
+ chan = 2 * (str / 128) + (sec % 2) + ((tmp / 2) % 2) * 8;
+ break;
+ case 'O':
+ case 'o':
+ board = (sec / 20) * 16 + 1;
+ altro = (sec % 20) < 8 ? 0 : (sec % 20) < 12 ? 1 : 2;
+ tmp = (sec % 20) - (altro == 0 ? 0 : altro == 1 ? 8 : 12);
+ chan = 2 * (str / 128) + (sec % 2) + ((tmp / 2) % 4) * 4;
+ break;
+ }
+ return kTRUE;
+}
+
+//____________________________________________________________________
+Bool_t
+AliFMDAltroMapping::Detector2Hardware(UShort_t det, Char_t ring,
+ UShort_t sec, UShort_t str,
+ UInt_t& ddl, UInt_t& addr) const
+{
+ // Translate detector coordinates to a hardware address.
+ //
+ // See also Detector2Hardware that returns 4 parameters.
+ UInt_t board = 0;
+ UInt_t altro = 0;
+ UInt_t chan = 0;
+ if (!Detector2Hardware(det,ring,sec,str,ddl,board,altro,chan)) return kFALSE;
+ addr = chan + (altro << 4) + (board << 7);
return kTRUE;
}
//____________________________________________________________________
Int_t
-AliFMDAltroMapping::GetHWAddress(Int_t sec, Int_t str, Int_t ring) const
+AliFMDAltroMapping::GetHWAddress(Int_t sec, Int_t str, Int_t ring)
{
// Return hardware address corresponding to sector sec, strip str,
// and ring ring. Mapping from TPC to FMD coordinates are
return Int_t(ring);
}
+//____________________________________________________________________
+void
+AliFMDAltroMapping::Print(Option_t* option) const
+{
+ TString opt(option);
+ opt.ToLower();
+ UInt_t ddl, board, chip, chan, addr;
+ UShort_t det, sec, str;
+ Char_t rng;
+
+ if (opt.Contains("hw") || opt.Contains("hardware")) {
+ std::cout << " DDL | Board | Chip | Chan | Address | Detector\n"
+ << "=====+=======+======+======+=========+==============="
+ << std::endl;
+ for (ddl = 0; ddl <= 2; ddl++) {
+ Int_t boards[] = { 0, 16, (ddl == 0 ? 32 : 1), 17, 32};
+ Int_t* ptr = boards;
+ while ((board = *(ptr++)) < 32) {
+ for (chip = 0; chip <= 2; chip++) {
+ UInt_t nchan = (chip == 1 ? 8 : 16);
+ for (chan = 0; chan < nchan; chan++) {
+ Hardware2Detector(ddl, board, chip, chan, det, rng, sec, str);
+ addr = ((board & 0x1f) << 7) | ((chip & 0x7) << 4) | (chan & 0xf);
+ std::cout << " "
+ << std::setw(3) << ddl << " | "
+ << std::setfill('0') << std::hex << " 0x"
+ << std::setw(2) << board << " | 0x"
+ << std::setw(1) << chip << " | 0x"
+ << std::setw(1) << chan << " | 0x"
+ << std::setw(3) << addr << " | "
+ << std::setfill(' ') << std::dec << " FMD"
+ << std::setw(1) << det << rng << "["
+ << std::setw(2) << sec << "," << std::setw(3) << str
+ << "]" << std::endl;
+ } // for chan ...
+ if (chip == 2 && *ptr >= 32) continue;
+ std::cout << " + + + + + "
+ << std::endl;
+ } // for chip ...
+ } // while board
+ std::cout << "-----+-------+------+------+---------+---------------"
+ << std::endl;
+ } // for ddl ...
+ } // if hw
+ if (opt.Contains("det")) {
+ std::cout << " Detector | DDL | Board | Chip | Chan | Address\n"
+ << "===============+=====+=======+======+======+========"
+ << std::endl;
+ for (det = 1; det <= 3; det++) {
+ Char_t rings[] = { 'I', (det == 1 ? '\0' : 'O'),'\0' };
+ Char_t* ptr = rings;
+ while ((rng = *(ptr++)) != '\0') {
+ UShort_t nsec = (rng == 'I' ? 20 : 40);
+ UShort_t nstr = (rng == 'I' ? 512 : 256);
+ for (sec = 0; sec < nsec; sec++) {
+ for (str = 0; str < nstr; str += 128) {
+ ddl = board = chip = chan;
+ Detector2Hardware(det,rng,sec,str,ddl,board,chip,chan);
+ addr = ((board & 0x1f) << 7) | ((chip & 0x7) << 4) | (chan & 0xf);
+ std::cout << std::setfill(' ') << std::dec << " FMD"
+ << std::setw(1) << det << rng << "["
+ << std::setw(2) << sec << ","
+ << std::setw(3) << str << "] | "
+ << std::setw(3) << ddl << " | 0x"
+ << std::setfill('0') << std::hex
+ << std::setw(2) << board << " | 0x"
+ << std::setw(1) << chip << " | 0x"
+ << std::setw(1) << chan << " | 0x"
+ << std::setw(3) << addr << std::endl;
+ } // for str ...
+ } // for sec ...
+ if (*ptr == '\0') continue;
+ std::cout << " + + + + + "
+ << std::endl;
+ } // while rng ...
+ std::cout << "---------------+-----+-------+------+------+--------"
+ << std::endl;
+
+ } // for det ...
+ } // if det
+}
+
//_____________________________________________________________________________
//
// EOF