Project
Loading...
Searching...
No Matches
testMapper.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#define BOOST_TEST_MODULE Test EMCAL Base
12#define BOOST_TEST_MAIN
13#define BOOST_TEST_DYN_LINK
14#include <boost/test/unit_test.hpp>
15#include <fmt/format.h>
17#include "EMCALBase/Mapper.h"
18#include <array>
19#include <iostream>
20#include <fstream>
21#include <vector>
22#include "RStringView.h"
23
24struct refchannel {
26 int mRow;
27 int mCol;
30};
31
32std::vector<refchannel> loadReferenceMapping(const std::string_view filename);
33
42{
43
44 const char* aliceO2env = std::getenv("O2_ROOT");
45 std::string inputDir = " ";
46 if (aliceO2env) {
47 inputDir = aliceO2env;
48 }
49 inputDir += "/share/Detectors/EMC/files/";
50
51 std::vector<char> sides = {'A', 'C'};
52 for (auto side : sides) {
53 for (int iddl = 0; iddl < 2; iddl++) {
54 std::string mappingbase = fmt::format("RCU{}{}.data", iddl, side);
55 std::cout << "Test mapping " << mappingbase << std::endl;
56 std::string mappingfile = inputDir + mappingbase;
57 o2::emcal::Mapper testmapper(mappingfile);
58
59 // Load reference mapping (same file)
60 auto refmapping = loadReferenceMapping(mappingfile);
61
62 // test mapping of channel
63 for (const auto& chan : refmapping) {
64 BOOST_CHECK_EQUAL(chan.mRow, testmapper.getRow(chan.mAddress));
65 BOOST_CHECK_EQUAL(chan.mCol, testmapper.getColumn(chan.mAddress));
66 BOOST_CHECK_EQUAL(o2::emcal::intToChannelType(chan.mCellType), testmapper.getChannelType(chan.mAddress));
67 if (!chan.mAmbiguous) {
68 // Skip channels in inverse mapping for which two hardware adresses are registered
69 // (feature of the odd DDL mappings)
70 BOOST_CHECK_EQUAL(chan.mAddress, testmapper.getHardwareAddress(chan.mRow, chan.mCol, o2::emcal::intToChannelType(chan.mCellType))); // test of inverse mapping
71 }
72 }
73 if (mappingbase == "RCU0A.data") {
74 // test of the error handling:
75 // Hardware address outside range
76 BOOST_CHECK_EXCEPTION(testmapper.getRow(4000), o2::emcal::Mapper::AddressNotFoundException, [](o2::emcal::Mapper::AddressNotFoundException const& e) { return e.getAddress() == 4000; });
77 // Row, and column out of range
78 BOOST_CHECK_EXCEPTION(testmapper.getHardwareAddress(16, 0, o2::emcal::ChannelType_t::HIGH_GAIN), o2::emcal::Mapper::ChannelNotFoundException, [](o2::emcal::Mapper::ChannelNotFoundException const& e) { return e.getChannel().mRow == 16; });
79 BOOST_CHECK_EXCEPTION(testmapper.getHardwareAddress(0, 128, o2::emcal::ChannelType_t::TRU), o2::emcal::Mapper::ChannelNotFoundException, [](o2::emcal::Mapper::ChannelNotFoundException const& e) { return e.getChannel().mColumn == 128; });
80 }
81 }
82 }
83}
84
88std::vector<refchannel> loadReferenceMapping(const std::string_view mappingfile)
89{
90 std::vector<refchannel> mapping;
91 std::ifstream in(mappingfile.data());
92 std::string tmpstr;
93 // skip first two lines (header)
94 std::getline(in, tmpstr);
95 std::getline(in, tmpstr);
96 int address, row, col, caloflag;
97 int nline = 0;
98 while (std::getline(in, tmpstr)) {
99 std::stringstream addressdecoder(tmpstr);
100 addressdecoder >> address >> row >> col >> caloflag;
101 // check whether the col/row is already registered with a different hardware address
102 // Odd-DDLs have several TRU channels listed with different hardware addresses
103 // In such cases the inverse mapping cannot be tested reliably due to ambiguity and
104 // must be skipped.
105 auto channelPresent = std::find_if(mapping.begin(), mapping.end(), [row, col, caloflag](const refchannel& test) {
106 return row == test.mRow && col == test.mCol && caloflag == test.mCellType;
107 });
108 bool ambiguous = false;
109 if (channelPresent != mapping.end()) {
110 ambiguous = true;
111 channelPresent->mAmbiguous = ambiguous;
112 }
113 mapping.push_back({address, row, col, caloflag, ambiguous});
114 }
115
116 return mapping;
117}
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 side
Definition RawData.h:0
uint32_t col
Definition RawData.h:4
Error handling requests for unknown hardware addresses.
Definition Mapper.h:85
Exception handling invalid channel ID.
Definition Mapper.h:153
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
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
unsigned int getHardwareAddress(uint8_t row, uint8_t col, ChannelType_t channeltype) const
Get the hardware address for a channel.
Definition Mapper.cxx:88
GLuint GLuint64EXT address
Definition glcorearb.h:5846
ChannelType_t intToChannelType(int chantype)
Convert integer number to channel type object.
Definition Constants.cxx:55
@ TRU
TRU channel.
Definition Constants.h:36
@ HIGH_GAIN
High gain channel.
Definition Constants.h:35
FIXME: do not use data model tables.
std::string filename()
BOOST_AUTO_TEST_CASE(Mapper_test)
std::vector< refchannel > loadReferenceMapping(const std::string_view filename)
Load reference mapping from mapping file.
BOOST_CHECK_EQUAL(triggersD.size(), triggers.size())
std::vector< int > row