Project
Loading...
Searching...
No Matches
PixelMapper.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
16#include <TSystem.h>
17
18#include <fairlogger/Logger.h>
20
21using namespace o2::focal;
22
23PixelMapper::PixelMapper(PixelMapper::MappingType_t mappingtype) : mMappingType(mappingtype)
24{
25 switch (mappingtype) {
27 mMappingFile = Form("%s/share/Detectors/FOC/files/mapping_ib.data", gSystem->Getenv("O2_ROOT"));
28 break;
30 mMappingFile = Form("%s/share/Detectors/FOC/files/mapping_ob.data", gSystem->Getenv("O2_ROOT"));
31 default:
32 break;
33 };
34
35 if (mMappingFile.length()) {
36 init();
37 }
38}
39
40void PixelMapper::init()
41{
42 if (gSystem->AccessPathName(mMappingFile.data())) {
43 throw MappingNotSetException();
44 }
45 LOG(debug) << "Reading pixel mapping from file: " << mMappingFile;
46 mMapping.clear();
47 std::ifstream reader(mMappingFile);
48 std::string buffer;
49 while (std::getline(reader, buffer)) {
50 auto delimiter = buffer.find("//");
51 std::string data = buffer;
52 if (delimiter == 0) {
53 // whole line commented out
54 continue;
55 }
56 if (delimiter != std::string::npos) {
57 data = buffer.substr(0, delimiter);
58 }
59 LOG(debug) << "Processing line: " << data;
60 std::stringstream decoder(data);
61 std::string linebuffer;
62 std::vector<int> identifiers;
63 while (std::getline(decoder, linebuffer, ',')) {
64 identifiers.push_back(std::stoi(linebuffer));
65 }
66 if (identifiers.size() < 8) {
67 LOG(error) << "Chip coordinates not fully defined (" << data << "), skipping ...";
68 }
69 ChipIdentifier nextIdentifier;
70 nextIdentifier.mFEEID = identifiers[0];
71 nextIdentifier.mLaneID = identifiers[1];
72 nextIdentifier.mChipID = identifiers[2];
73 ChipPosition nextPosition;
74 nextPosition.mLayer = identifiers[3];
75 nextPosition.mColumn = identifiers[4];
76 nextPosition.mRow = identifiers[5];
77 nextPosition.mInvertColumn = (identifiers[6] == 1 ? true : false);
78 nextPosition.mInvertRow = (identifiers[7] == 1 ? true : false);
79 LOG(debug) << "Inserting chip: (FEE " << nextIdentifier.mFEEID << ", Lane " << nextIdentifier.mLaneID << ", Chip " << nextIdentifier.mChipID << ") -> (Layer " << nextPosition.mLayer << ", Col " << nextPosition.mColumn << ", Row " << nextPosition.mRow << ", Inv Col " << (nextPosition.mInvertColumn ? "yes" : "no") << ", Inv Row " << (nextPosition.mInvertRow ? "yes" : "no") << ")";
80 if (mMapping.find(nextIdentifier) != mMapping.end()) {
81 LOG(error) << "Chip with FEE" << nextIdentifier.mFEEID << ", Lane " << nextIdentifier.mLaneID << ", Chip " << nextIdentifier.mChipID << " already present, not overwriting ...";
82 continue;
83 }
84 mMapping.insert({nextIdentifier, nextPosition});
85 if (nextPosition.mRow + 1 > mNumberOfRows) {
86 mNumberOfRows = nextPosition.mRow + 1;
87 }
88 if (nextPosition.mColumn + 1 > mNumberOfColumns) {
89 mNumberOfColumns = nextPosition.mColumn + 1;
90 }
91 }
92 LOG(info) << "Pixel Mapper: Found " << mMapping.size() << " chips, in " << mNumberOfColumns << " colums and " << mNumberOfRows << " rows";
93 reader.close();
94}
95
96PixelMapper::ChipPosition PixelMapper::getPosition(unsigned int feeID, unsigned int laneID, unsigned int chipID) const
97{
98 auto cardindex = feeID & 0x00FF;
99 checkInitialized();
100 ChipIdentifier identifier{cardindex, laneID, chipID};
101 auto found = mMapping.find(identifier);
102 if (found == mMapping.end()) {
103 throw InvalidChipException(identifier);
104 }
105 return found->second;
106}
107
108void PixelMapper::checkInitialized() const
109{
110 if (!mMapping.size()) {
111 throw UninitException();
112 }
113}
114
116{
117 stream << mMessage;
118}
119
121{
122 stream << what();
123}
124
126{
127 stream << what();
128}
129
130std::ostream& o2::focal::operator<<(std::ostream& stream, const PixelMapper::InvalidChipException& error)
131{
132 error.print(stream);
133 return stream;
134}
135
136std::ostream& o2::focal::operator<<(std::ostream& stream, const PixelMapper::UninitException& error)
137{
138 error.print(stream);
139 return stream;
140}
141
142std::ostream& o2::focal::operator<<(std::ostream& stream, const PixelMapper::MappingNotSetException& error)
143{
144 error.print(stream);
145 return stream;
146}
std::ostringstream debug
void print(std::ostream &stream) const
void print(std::ostream &stream) const
void print(std::ostream &stream) const
ChipPosition getPosition(unsigned int feeID, unsigned int laneID, unsigned int chipID) const
PixelMapper(MappingType_t mappingtype)
GLuint buffer
Definition glcorearb.h:655
GLboolean * data
Definition glcorearb.h:298
GLuint GLuint stream
Definition glcorearb.h:1806
std::ostream & operator<<(std::ostream &in, const IndexExceptionEvent &error)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"