Project
Loading...
Searching...
No Matches
Mapper.cxx
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
12#include <fstream>
13#include <iostream>
14#include <sstream>
15#include <TSystem.h>
16#include "EMCALBase/Mapper.h"
17
18using namespace o2::emcal;
19
20Mapper::Mapper(const std::string_view filename) : mMapping(),
21 mInverseMapping()
22{
23 init(filename); // will throw exceptions in case the initialization from file failed
24}
25
26void Mapper::setMapping(const std::string_view inputfile)
27{
28 mMapping.clear();
29 mInverseMapping.clear();
30 mInitStatus = false;
31 init(inputfile);
32}
33
34void Mapper::init(const std::string_view filename)
35{
36 std::ifstream reader(filename.data());
37 std::string tmp;
38
39 int maxHardwareAddress(-1);
40 try {
41 std::getline(reader, tmp); // max. number of entries - no longer needed
42 std::getline(reader, tmp);
43 maxHardwareAddress = std::stoi(tmp);
44 } catch (std::invalid_argument& e) {
45 throw FileFormatException(e.what());
46 } catch (std::out_of_range& e) {
47 throw FileFormatException(e.what());
48 } catch (std::iostream::failure& e) {
49 throw FileFormatException(e.what());
50 }
51
52 // loop over channels
53 int address, row, col, caloflag;
54 while (getline(reader, tmp)) {
55 std::stringstream addressmapping(tmp);
56
57 try {
58 addressmapping >> address >> row >> col >> caloflag;
59 } catch (std::iostream::failure& e) {
60 throw FileFormatException(e.what());
61 }
62
63 if (address > maxHardwareAddress) {
64 throw AddressRangeException(address, maxHardwareAddress);
65 }
66
67 auto chantype = o2::emcal::intToChannelType(caloflag);
68
69 mMapping.insert(std::pair<int, ChannelID>(static_cast<unsigned int>(address), {uint8_t(row), uint8_t(col), chantype}));
70 mInverseMapping.insert(std::pair<ChannelID, int>({uint8_t(row), uint8_t(col), chantype}, static_cast<unsigned int>(address)));
71 }
72
73 mInitStatus = true;
74}
75
76Mapper::ChannelID Mapper::getChannelID(unsigned int hardawareaddress) const
77{
78 if (!mInitStatus) {
79 throw InitStatusException();
80 }
81 auto res = mMapping.find(hardawareaddress);
82 if (res == mMapping.end()) {
83 throw AddressNotFoundException(hardawareaddress);
84 }
85 return res->second;
86}
87
88unsigned int Mapper::getHardwareAddress(uint8_t row, uint8_t col, ChannelType_t channeltype) const
89{
90 if (!mInitStatus) {
91 throw InitStatusException();
92 }
93 ChannelID channelToFind{row, col, channeltype};
94 auto found = mInverseMapping.find(channelToFind);
95 if (found == mInverseMapping.end()) {
96 throw ChannelNotFoundException(channelToFind);
97 }
98 return found->second;
99}
100
102{
103 const std::array<char, 2> SIDES = {{'A', 'C'}};
104 const unsigned int NDDL = 2;
105 for (unsigned int iside = 0; iside < 2; iside++) {
106 for (unsigned int iddl = 0; iddl < NDDL; iddl++) {
107 mMappings[iside * NDDL + iddl].setMapping(Form("%s/share/Detectors/EMC/files/RCU%d%c.data", gSystem->Getenv("O2_ROOT"), iddl, SIDES[iside]));
108 }
109 }
110}
111
113{
114 if (ddl >= 40) {
116 }
117 const unsigned int NDDLSM = 2, NSIDES = 2;
118 unsigned int ddlInSM = ddl % NDDLSM,
119 sideID = (ddl / NDDLSM) % NSIDES;
120 unsigned int mappingIndex = sideID * NDDLSM + ddlInSM;
121 if (mappingIndex < 0 || mappingIndex >= mMappings.size()) {
122 std::cout << "Access to invalid mapping position for ddl " << ddl << std::endl;
124 }
125 return mMappings[mappingIndex];
126}
127
128int MappingHandler::getFEEForChannelInDDL(unsigned int ddl, unsigned int channelFEC, unsigned int branch)
129{
130 if (ddl >= 40) {
132 }
133 int ddlInSupermodule = ddl % 2;
134 int fecID = ddlInSupermodule ? 20 : 0;
135 if (branch) {
136 fecID += 10;
137 }
138 fecID += channelFEC;
139 return fecID;
140}
141
142std::ostream& o2::emcal::operator<<(std::ostream& stream, const Mapper::ChannelID& channel)
143{
144 stream << "Row " << static_cast<int>(channel.mRow) << ", Column " << static_cast<int>(channel.mColumn) << ", type " << o2::emcal::channelTypeToString(channel.mChannelType);
145 return stream;
146}
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 First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char e
uint32_t col
Definition RawData.h:4
uint32_t res
Definition RawData.h:0
Error handling requests for unknown hardware addresses.
Definition Mapper.h:85
Exception handling invalid channel ID.
Definition Mapper.h:153
Error handling requests to not properly initialized mapping object.
Definition Mapper.h:214
ALTRO mapping for calorimeters.
Definition Mapper.h:43
Mapper()=default
Default constructor.
void setMapping(const std::string_view inputfile)
Initialize with new.
Definition Mapper.cxx:26
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
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()
Constructor.
Definition Mapper.cxx:101
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
std::string channelTypeToString(ChannelType_t chantype)
Create string representation of the channel type object.
Definition Constants.cxx:20
ChannelType_t intToChannelType(int chantype)
Convert integer number to channel type object.
Definition Constants.cxx:55
ChannelType_t
Type of a raw data channel.
Definition Constants.h:33
std::string filename()
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
std::vector< int > row