Project
Loading...
Searching...
No Matches
PixelMapper.h
Go to the documentation of this file.
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_PIXELMAPPER_H
12#define ALICEO2_FOCAL_PIXELMAPPER_H
13
14#include <cstdio>
15#include <array>
16#include <exception>
17#include <iosfwd>
18#include <string>
19#include <unordered_map>
20#include <boost/container_hash/hash.hpp>
22#include <Rtypes.h>
23
24namespace o2::focal
25{
26
28{
29 public:
30 enum class MappingType_t {
34 };
35
37 unsigned int mFEEID;
38 unsigned int mLaneID;
39 unsigned int mChipID;
40
41 bool operator==(const ChipIdentifier& other) const { return mFEEID == other.mFEEID && mLaneID == other.mLaneID && mChipID == other.mChipID; }
42 };
43 struct ChipPosition {
44 unsigned int mColumn;
45 unsigned int mRow;
46 unsigned int mLayer;
49
50 bool operator==(const ChipPosition& other) const { return mLayer == other.mLayer && mColumn == other.mColumn && mRow == other.mRow; }
51 };
53
57 size_t operator()(const ChipIdentifier& s) const
58 {
59 std::size_t seed = 0;
60 boost::hash_combine(seed, s.mFEEID);
61 boost::hash_combine(seed, s.mChipID);
62 boost::hash_combine(seed, s.mLaneID);
63 return seed;
64 }
65 };
66
67 class InvalidChipException : public std::exception
68 {
69 public:
70 InvalidChipException(PixelMapper::ChipIdentifier& identifier) : mIdentifier(identifier), mMessage()
71 {
72 mMessage = "Invalid chip identifier: FEE " + std::to_string(mIdentifier.mFEEID) + ", lane " + std::to_string(mIdentifier.mLaneID) + ", chip " + std::to_string(mIdentifier.mChipID);
73 }
74 ~InvalidChipException() noexcept final = default;
75
76 const char* what() const noexcept final { return mMessage.data(); }
77 const PixelMapper::ChipIdentifier& getIdentifier() const { return mIdentifier; }
78 unsigned int getLane() const noexcept { return mIdentifier.mLaneID; }
79 unsigned int getChipID() const noexcept { return mIdentifier.mChipID; }
80 unsigned int getFEEID() const noexcept { return mIdentifier.mFEEID; }
81 void print(std::ostream& stream) const;
82
83 private:
85 std::string mMessage;
86 };
87
88 class UninitException : public std::exception
89 {
90 public:
91 UninitException() = default;
92 ~UninitException() noexcept final = default;
93
94 const char* what() const noexcept final { return "Mapping is not initalized"; }
95 void print(std::ostream& stream) const;
96 };
97
98 class MappingNotSetException : public std::exception
99 {
100 public:
102 ~MappingNotSetException() noexcept final = default;
103 const char* what() const noexcept final { return "Mapping file not set"; }
104 void print(std::ostream& stream) const;
105 };
106
107 PixelMapper(MappingType_t mappingtype);
108 ~PixelMapper() = default;
109
110 ChipPosition getPosition(unsigned int feeID, unsigned int laneID, unsigned int chipID) const;
111 ChipPosition getPosition(unsigned int feeID, const PixelChip& chip) const
112 {
113 return getPosition(feeID, chip.mLaneID, chip.mChipID);
114 };
115
116 int getNumberOfColumns() const { return mNumberOfColumns; }
117 int getNumberOfRows() const { return mNumberOfRows; }
118 MappingType_t getMappingType() const { return mMappingType; }
119
120 void setMappingFile(const std::string_view mappingfile, MappingType_t mappingtype)
121 {
122 mMappingFile = mappingfile;
123 mMappingType = mappingtype;
124 init();
125 }
126
127 private:
128 void checkInitialized() const;
129 void init();
130 std::unordered_map<ChipIdentifier, ChipPosition, ChipIdentifierHasher> mMapping;
131 std::string mMappingFile;
133 int mNumberOfColumns = 0;
134 int mNumberOfRows = 0;
135
136 ClassDefNV(PixelMapper, 1);
137};
138
139std::ostream& operator<<(std::ostream& stream, const PixelMapper::InvalidChipException& error);
140std::ostream& operator<<(std::ostream& stream, const PixelMapper::UninitException& error);
141std::ostream& operator<<(std::ostream& stream, const PixelMapper::MappingNotSetException& error);
142
143} // namespace o2::focal
144
145#endif // ALICEO2_FOCAL_PixelMapper_H
void print() const
unsigned int getFEEID() const noexcept
Definition PixelMapper.h:80
unsigned int getLane() const noexcept
Definition PixelMapper.h:78
InvalidChipException(PixelMapper::ChipIdentifier &identifier)
Definition PixelMapper.h:70
const PixelMapper::ChipIdentifier & getIdentifier() const
Definition PixelMapper.h:77
const char * what() const noexcept final
Definition PixelMapper.h:76
unsigned int getChipID() const noexcept
Definition PixelMapper.h:79
~InvalidChipException() noexcept final=default
const char * what() const noexcept final
~MappingNotSetException() noexcept final=default
~UninitException() noexcept final=default
const char * what() const noexcept final
Definition PixelMapper.h:94
ChipPosition getPosition(unsigned int feeID, unsigned int laneID, unsigned int chipID) const
int getNumberOfColumns() const
void setMappingFile(const std::string_view mappingfile, MappingType_t mappingtype)
ChipPosition getPosition(unsigned int feeID, const PixelChip &chip) const
MappingType_t getMappingType() const
int getNumberOfRows() const
GLuint GLuint stream
Definition glcorearb.h:1806
std::ostream & operator<<(std::ostream &in, const IndexExceptionEvent &error)
std::string to_string(gsl::span< T, Size > span)
Definition common.h:52
size_t operator()(const ChipIdentifier &s) const
Functor implementation.
Definition PixelMapper.h:57
bool operator==(const ChipIdentifier &other) const
Definition PixelMapper.h:41
bool operator==(const ChipPosition &other) const
Definition PixelMapper.h:50
VectorOfTObjectPtrs other