Skip to content

Commit 4bc341d

Browse files
mfasDashahor02
authored andcommitted
[FOCAL-9] Port mapping for pads from QC
Mapping pad channel to position on pad layer
1 parent 0884452 commit 4bc341d

4 files changed

Lines changed: 183 additions & 0 deletions

File tree

Detectors/FOCAL/reconstruction/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ o2_add_library(FOCALReconstruction
1313
SOURCES src/PadWord.cxx
1414
src/PadData.cxx
1515
src/PadDecoder.cxx
16+
src/PadMapper.cxx
1617
PUBLIC_LINK_LIBRARIES O2::Headers
1718
AliceO2::InfoLogger
1819
Microsoft.GSL::GSL)
@@ -21,6 +22,7 @@ o2_target_root_dictionary(
2122
FOCALReconstruction
2223
HEADERS include/FOCALReconstruction/PadData.h
2324
include/FOCALReconstruction/PadDecoder.h
25+
include/FOCALReconstruction/PadMapper.h
2426
)
2527

2628
o2_add_executable(rawreader-pad-rootify
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
#ifndef ALICEO2_FOCAL_PADMAPPER_H
12+
#define ALICEO2_FOCAL_PADMAPPER_H
13+
14+
#include <array>
15+
#include <exception>
16+
#include <iosfwd>
17+
#include <string>
18+
#include <tuple>
19+
20+
namespace o2::focal
21+
{
22+
23+
class PadMapper
24+
{
25+
public:
26+
static constexpr std::size_t NCOLUMN = 8;
27+
static constexpr std::size_t NROW = 9;
28+
static constexpr std::size_t NCHANNELS = NCOLUMN * NROW;
29+
30+
class PositionException : public std::exception
31+
{
32+
public:
33+
PositionException(unsigned int column, unsigned int row) : mColumn(column), mRow(row), mMessage()
34+
{
35+
mMessage = "Invalid pad position: col (" + std::to_string(mColumn) + "), row (" + std::to_string(mRow);
36+
}
37+
~PositionException() noexcept final = default;
38+
39+
const char* what() const noexcept final
40+
{
41+
return mMessage.data();
42+
}
43+
44+
unsigned int getColumn() const noexcept { return mColumn; }
45+
unsigned int getRow() const noexcept { return mRow; }
46+
void print(std::ostream& stream) const;
47+
48+
private:
49+
unsigned int mColumn;
50+
unsigned int mRow;
51+
std::string mMessage;
52+
};
53+
54+
class ChannelIDException : public std::exception
55+
{
56+
public:
57+
ChannelIDException(unsigned int channelID) : mChannelID(channelID), mMessage()
58+
{
59+
mMessage = "Invalid channelID: " + std::to_string(mChannelID);
60+
}
61+
~ChannelIDException() noexcept final = default;
62+
63+
const char* what() const noexcept final
64+
{
65+
return mMessage.data();
66+
}
67+
68+
unsigned int getChannelID() const { return mChannelID; }
69+
void print(std::ostream& stream) const;
70+
71+
private:
72+
unsigned int mChannelID;
73+
std::string mMessage;
74+
};
75+
PadMapper();
76+
~PadMapper() = default;
77+
78+
std::tuple<unsigned int, unsigned int> getRowColFromChannelID(unsigned int channelID) const;
79+
unsigned int getRow(unsigned int channelID) const;
80+
unsigned int getColumn(unsigned int channelID) const;
81+
82+
unsigned int getChannelID(unsigned int col, unsigned int row) const;
83+
84+
private:
85+
static constexpr unsigned int mMapping[NCOLUMN][NROW] = { // map of channels in XY
86+
{43, 41, 53, 49, 58, 54, 66, 68, 69},
87+
{39, 37, 47, 51, 56, 62, 60, 64, 70},
88+
{38, 42, 45, 46, 50, 59, 55, 65, 71},
89+
{44, 40, 36, 48, 52, 61, 57, 67, 63},
90+
{8, 4, 0, 14, 16, 19, 23, 31, 27},
91+
{2, 6, 11, 10, 17, 21, 25, 33, 35},
92+
{1, 3, 9, 15, 22, 24, 26, 28, 34},
93+
{7, 5, 12, 13, 18, 20, 29, 30, 32}};
94+
95+
void initInverseMapping();
96+
97+
std::array<std::tuple<unsigned int, unsigned int>, NCHANNELS> mInverseMapping; ///< Inverse mapping (Channel ID -> Col/Row)
98+
};
99+
100+
std::ostream& operator<<(std::ostream& stream, const PadMapper::PositionException& except);
101+
std::ostream& operator<<(std::ostream& stream, const PadMapper::ChannelIDException& except);
102+
103+
} // namespace o2::focal
104+
105+
#endif // ALICEO2_FOCAL_PADMAPPER_H

Detectors/FOCAL/reconstruction/src/FOCALReconstructionLinkDef.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@
1919
#pragma link C++ class o2::focal::ASICContainer + ;
2020
#pragma link C++ class o2::focal::PadData + ;
2121
#pragma link C++ class o2::focal::PadDecoder + ;
22+
#pragma link C++ class o2::focal::PadMapper + ;
2223
#endif
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
12+
#include <iostream>
13+
#include <FOCALReconstruction/PadMapper.h>
14+
15+
using namespace o2::focal;
16+
17+
PadMapper::PadMapper()
18+
{
19+
initInverseMapping();
20+
}
21+
22+
std::tuple<unsigned int, unsigned int> PadMapper::getRowColFromChannelID(unsigned int channelID) const
23+
{
24+
if (channelID >= NCHANNELS) {
25+
throw ChannelIDException(channelID);
26+
}
27+
return mInverseMapping[channelID];
28+
}
29+
unsigned int PadMapper::getRow(unsigned int channelID) const
30+
{
31+
return std::get<1>(getRowColFromChannelID(channelID));
32+
}
33+
unsigned int PadMapper::getColumn(unsigned int channelID) const
34+
{
35+
return std::get<0>(getRowColFromChannelID(channelID));
36+
}
37+
38+
unsigned int PadMapper::getChannelID(unsigned int col, unsigned int row) const
39+
{
40+
if (col >= NCOLUMN || row >= NROW) {
41+
throw PositionException(col, row);
42+
}
43+
return mMapping[col][row];
44+
}
45+
46+
void PadMapper::initInverseMapping()
47+
{
48+
for (unsigned int icol = 0; icol < NCOLUMN; icol++) {
49+
for (unsigned int irow = 0; irow < NROW; irow++) {
50+
mInverseMapping[mMapping[icol][irow]] = std::make_tuple(icol, irow);
51+
}
52+
}
53+
}
54+
55+
void PadMapper::ChannelIDException::print(std::ostream& stream) const
56+
{
57+
stream << mMessage;
58+
}
59+
60+
void PadMapper::PositionException::print(std::ostream& stream) const
61+
{
62+
stream << mMessage;
63+
}
64+
65+
std::ostream& o2::focal::operator<<(std::ostream& stream, const PadMapper::ChannelIDException& except)
66+
{
67+
except.print(stream);
68+
return stream;
69+
}
70+
71+
std::ostream& o2::focal::operator<<(std::ostream& stream, const PadMapper::PositionException& except)
72+
{
73+
except.print(stream);
74+
return stream;
75+
}

0 commit comments

Comments
 (0)