Project
Loading...
Searching...
No Matches
Mapper.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 __O2_EMCAL_MAPPER_H__
12#define __O2_EMCAL_MAPPER_H__
13
14#include <array>
15#include <cstdint>
16#include <exception>
17#include <functional>
18#include <iosfwd>
19#include <unordered_map>
20#include <sstream>
21#include <string>
22#include <boost/container_hash/hash.hpp>
23
24#include "fmt/format.h"
25#include "RStringView.h"
26#include "Rtypes.h"
28
29namespace o2
30{
31
32namespace emcal
33{
34
42class Mapper
43{
44 public:
47 struct ChannelID {
51
52 bool operator==(const ChannelID& other) const
53 {
54 return mRow == other.mRow && mColumn == other.mColumn && mChannelType == other.mChannelType;
55 }
56 friend std::ostream& operator<<(std::ostream& stream, const Mapper::ChannelID& channel);
57 };
58
62
66 size_t operator()(const ChannelID& s) const
67 {
68 std::size_t seed = 0;
69 boost::hash_combine(seed, s.mRow);
70 boost::hash_combine(seed, s.mColumn);
71 boost::hash_combine(seed, o2::emcal::channelTypeToInt(s.mChannelType));
72 return seed;
73 /*
74 size_t h1 = std::hash<int>()(s.mRow);
75 size_t h2 = std::hash<int>()(s.mColumn);
76 size_t h3 = std::hash<int>()(o2::emcal::channelTypeToInt(s.mChannelType));
77 return ((h1 ^ (h2 << 1)) >> 1) ^ (h3 << 1);
78 */
79 }
80 };
81
84 class AddressNotFoundException : public std::exception
85 {
86 public:
90 mAddress(address),
91 mMessage()
92 {
93 std::stringstream msgbuilder;
94 msgbuilder << "Hardware address " << address << "(0x" << std::hex << address << std::dec << ") not found";
95 mMessage = msgbuilder.str();
96 }
97
99 ~AddressNotFoundException() noexcept override = default;
100
103 const char* what() const noexcept override { return mMessage.data(); }
104
107 int getAddress() const noexcept { return mAddress; }
108
109 private:
110 int mAddress;
111 std::string mMessage;
112 };
113
116 class AddressRangeException : public std::exception
117 {
118 public:
122 AddressRangeException(int address, int maxaddress) : exception(),
123 mAddress(address),
124 mMaxAddress(maxaddress),
125 mMessage("Hardware (ALTRO) address (" + std::to_string(mAddress) + " outside the range (0 -> " + std::to_string(mMaxAddress) + ") !")
126 {
127 }
128
130 ~AddressRangeException() noexcept override = default;
131
134 const char* what() const noexcept override { return mMessage.data(); }
135
138 int getAddress() const noexcept { return mAddress; }
139
142 int getMaxAddress() const noexcept { return mMaxAddress; }
143
144 private:
145 int mAddress;
146 int mMaxAddress;
147 std::string mMessage;
148 };
149
152 class ChannelNotFoundException : public std::exception
153 {
154 public:
158 mChannelID(id),
159 mMessage()
160 {
161 std::stringstream msgbuilder;
162 msgbuilder << "Channel with " << mChannelID << " not found.";
163 mMessage = msgbuilder.str();
164 }
165
167 ~ChannelNotFoundException() noexcept override = default;
168
171 const char* what() const noexcept override
172 {
173 return mMessage.data();
174 }
175
178 const ChannelID& getChannel() const { return mChannelID; }
179
180 private:
181 ChannelID mChannelID;
182 std::string mMessage;
183 };
184
187 class FileFormatException : public std::exception
188 {
189 public:
192 FileFormatException(const std::string_view errormessage) : std::exception(),
193 mMessage(std::string("Failure reading input file: ") + errormessage.data())
194 {
195 }
196
198 ~FileFormatException() noexcept override = default;
199
202 const char* what() const noexcept override
203 {
204 return mMessage.data();
205 }
206
207 private:
208 std::string mMessage;
209 };
210
213 class InitStatusException : public std::exception
214 {
215 public:
218
220 ~InitStatusException() noexcept override = default;
221
224 const char* what() const noexcept override { return "Mapping not properly initialized"; }
225 };
226
228 Mapper() = default;
229
235 Mapper(const std::string_view inputfile);
236
238 ~Mapper() = default;
239
244 ChannelID getChannelID(unsigned int hardawareaddress) const;
245
250 uint8_t getRow(unsigned int hardawareaddress) const
251 {
252 return getChannelID(hardawareaddress).mRow;
253 }
254
259 uint8_t getColumn(unsigned int hardawareaddress) const
260 {
261 return getChannelID(hardawareaddress).mColumn;
262 }
263
268 ChannelType_t getChannelType(unsigned int hardawareaddress) const
269 {
270 return getChannelID(hardawareaddress).mChannelType;
271 }
272
279 unsigned int getHardwareAddress(uint8_t row, uint8_t col, ChannelType_t channeltype) const;
280
286 void setMapping(const std::string_view inputfile);
287
288 private:
294 void init(const std::string_view inputfile);
295
296 std::unordered_map<unsigned int, ChannelID> mMapping;
297 std::unordered_map<ChannelID, unsigned int, ChannelIDHasher> mInverseMapping;
298 bool mInitStatus = false;
299
300 ClassDefNV(Mapper, 1);
301};
302
313{
314 public:
320 class DDLInvalid final : public std::exception
321 {
322 public:
323 DDLInvalid(int ddlID) : mDDL(ddlID) { mMessage = fmt::format("DDL {0} not existing for EMCAL", mDDL); };
324
326 ~DDLInvalid() noexcept final = default;
327
330 const char* what() const noexcept final { return mMessage.data(); }
331
334 int getDDDL() const { return mDDL; }
335
336 private:
337 std::string mMessage;
338 int mDDL;
339 };
340
343
345 ~MappingHandler() = default;
346
351 Mapper& getMappingForDDL(unsigned int ddl);
352
357 int getFEEForChannelInDDL(unsigned int dll, unsigned int channelFEC, unsigned int branch);
358
359 private:
360 std::array<Mapper, 4> mMappings;
361
362 ClassDefNV(MappingHandler, 1);
363};
364
369std::ostream& operator<<(std::ostream& stream, const Mapper::ChannelID& channel);
370
371} // namespace emcal
372
373} // namespace o2
374
375#endif //__O2_EMCAL_MAPPER_H__
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error s
uint32_t col
Definition RawData.h:4
Error handling requests for unknown hardware addresses.
Definition Mapper.h:85
const char * what() const noexcept override
Access to error message.
Definition Mapper.h:103
~AddressNotFoundException() noexcept override=default
Destructor.
AddressNotFoundException(int address)
Constructor initializing the exception.
Definition Mapper.h:89
int getAddress() const noexcept
Access to hardware address raising the exception.
Definition Mapper.h:107
int getAddress() const noexcept
Access to hardware address raising the exception.
Definition Mapper.h:138
int getMaxAddress() const noexcept
Access to max hardware address in mapping.
Definition Mapper.h:142
~AddressRangeException() noexcept override=default
Destructor.
const char * what() const noexcept override
Access to error message of the exception.
Definition Mapper.h:134
AddressRangeException(int address, int maxaddress)
Constructor initializing the exception.
Definition Mapper.h:122
Exception handling invalid channel ID.
Definition Mapper.h:153
const char * what() const noexcept override
Access to error message of the exception.
Definition Mapper.h:171
const ChannelID & getChannel() const
Access to channel ID raising the exception.
Definition Mapper.h:178
~ChannelNotFoundException() noexcept override=default
Destructor.
ChannelNotFoundException(ChannelID id)
Constructor initializing the exception.
Definition Mapper.h:157
Error handling for invalid file format.
Definition Mapper.h:188
~FileFormatException() noexcept override=default
Destructor.
FileFormatException(const std::string_view errormessage)
Constructor initializing exception.
Definition Mapper.h:192
const char * what() const noexcept override
Access to error message of the exception.
Definition Mapper.h:202
Error handling requests to not properly initialized mapping object.
Definition Mapper.h:214
const char * what() const noexcept override
Access to error message of the exception.
Definition Mapper.h:224
~InitStatusException() noexcept override=default
Destructor.
InitStatusException()=default
Constructor.
ALTRO mapping for calorimeters.
Definition Mapper.h:43
uint8_t getRow(unsigned int hardawareaddress) const
Get channel row for a given hardware address.
Definition Mapper.h:250
~Mapper()=default
Destructor.
Mapper()=default
Default constructor.
void setMapping(const std::string_view inputfile)
Initialize with new.
Definition Mapper.cxx:26
ChannelType_t getChannelType(unsigned int hardawareaddress) const
Get channel type for a given hardware address.
Definition Mapper.h:268
uint8_t getColumn(unsigned int hardawareaddress) const
Get channel column for a given hardware address.
Definition Mapper.h:259
ChannelID getChannelID(unsigned int hardawareaddress) const
Get channel ID params for a given hardware address.
Definition Mapper.cxx:76
unsigned int getHardwareAddress(uint8_t row, uint8_t col, ChannelType_t channeltype) const
Get the hardware address for a channel.
Definition Mapper.cxx:88
Error handling for invalid DDL IDs (not in range for EMCAL)
Definition Mapper.h:321
~DDLInvalid() noexcept final=default
Destructor.
const char * what() const noexcept final
Access to the error message of the exception.
Definition Mapper.h:330
int getDDDL() const
Access to DDL ID responsible for the exception.
Definition Mapper.h:334
Handler providing the correct mapping for the given DDL.
Definition Mapper.h:313
int getFEEForChannelInDDL(unsigned int dll, unsigned int channelFEC, unsigned int branch)
Get FEC index for channel based on DDL and information in the channel header.
Definition Mapper.cxx:128
Mapper & getMappingForDDL(unsigned int ddl)
Get Mapping for given DDL.
Definition Mapper.cxx:112
~MappingHandler()=default
Destructor.
MappingHandler()
Constructor.
Definition Mapper.cxx:101
GLsizei const GLchar *const * string
Definition glcorearb.h:809
GLuint GLuint64EXT address
Definition glcorearb.h:5846
GLuint GLuint stream
Definition glcorearb.h:1806
std::ostream & operator<<(std::ostream &stream, const Cell &cell)
Stream operator for EMCAL cell.
Definition Cell.cxx:366
ChannelType_t
Type of a raw data channel.
Definition Constants.h:33
int channelTypeToInt(ChannelType_t chantype)
integer representation of the channel type object
Definition Constants.cxx:40
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::string to_string(gsl::span< T, Size > span)
Definition common.h:52
Hash functor for channel ID.
Definition Mapper.h:61
size_t operator()(const ChannelID &s) const
Functor implementation.
Definition Mapper.h:66
Mapped information of a channel.
Definition Mapper.h:47
uint8_t mColumn
Column of the channel in module.
Definition Mapper.h:49
ChannelType_t mChannelType
Type of the channel (see o2::emcal::ChannelType for channel type definitions)
Definition Mapper.h:50
uint8_t mRow
Row of the channel in module.
Definition Mapper.h:48
friend std::ostream & operator<<(std::ostream &stream, const Mapper::ChannelID &channel)
stream operator for Mapper::Channel
bool operator==(const ChannelID &other) const
Definition Mapper.h:52
VectorOfTObjectPtrs other
std::vector< int > row