ATLAS Offline Software
Loading...
Searching...
No Matches
L0Muon::TgcL0GoodMagMap Class Reference

Immutable sparse GoodMag map loaded from ASCII. More...

#include <TgcL0GoodMagMap.h>

Collaboration diagram for L0Muon::TgcL0GoodMagMap:

Public Member Functions

bool isGood (int etaBin, int phiFoldBin) const
 Return false for a masked or out-of-range calibration bin.
const std::string & version () const
unsigned int etaBins () const
unsigned int phiBinsPerFold () const
std::size_t poorBinCount () const

Static Public Member Functions

static std::unique_ptr< TgcL0GoodMagMaploadAscii (const std::string &calibrationPath, std::string &error)

Private Member Functions

 TgcL0GoodMagMap ()=default

Private Attributes

std::string m_version {}
unsigned int m_etaBins {0U}
unsigned int m_phiBinsPerFold {0U}
std::vector< bool > m_poorBins {}
std::size_t m_poorBinCount {0U}

Detailed Description

Immutable sparse GoodMag map loaded from ASCII.

Definition at line 15 of file TgcL0GoodMagMap.h.

Constructor & Destructor Documentation

◆ TgcL0GoodMagMap()

L0Muon::TgcL0GoodMagMap::TgcL0GoodMagMap ( )
privatedefault

Member Function Documentation

◆ etaBins()

unsigned int L0Muon::TgcL0GoodMagMap::etaBins ( ) const
inline

Definition at line 24 of file TgcL0GoodMagMap.h.

24{ return m_etaBins; }

◆ isGood()

bool L0Muon::TgcL0GoodMagMap::isGood ( int etaBin,
int phiFoldBin ) const

Return false for a masked or out-of-range calibration bin.

Definition at line 164 of file TgcL0GoodMagMap.cxx.

165 {
166 if (etaBin < 0 || phiFoldBin < 0 ||
167 etaBin >= static_cast<int>(m_etaBins) ||
168 phiFoldBin >= static_cast<int>(m_phiBinsPerFold)) {
169 return false;
170 }
171 const std::size_t index = static_cast<std::size_t>(etaBin) *
173 static_cast<std::size_t>(phiFoldBin);
174 return !m_poorBins[index];
175}
std::vector< bool > m_poorBins
str index
Definition DeMoScan.py:362
setSAddress setEtaMS setDirPhiMS setDirZMS setBarrelRadius setEndcapAlpha setEndcapRadius setInterceptInner setEtaMap etaBin

◆ loadAscii()

std::unique_ptr< TgcL0GoodMagMap > L0Muon::TgcL0GoodMagMap::loadAscii ( const std::string & calibrationPath,
std::string & error )
static

Definition at line 39 of file TgcL0GoodMagMap.cxx.

40 {
41 error.clear();
42 std::ifstream input{calibrationPath};
43 if (!input) {
44 error = "cannot open ASCII GoodMag map: " + calibrationPath;
45 return nullptr;
46 }
47
48 auto map = std::unique_ptr<TgcL0GoodMagMap>{new TgcL0GoodMagMap};
49 unsigned int schemaVersion = 0U;
50 bool schemaVersionSeen = false;
51 bool payloadVersionSeen = false;
52 bool etaBinsSeen = false;
53 bool phiBinsSeen = false;
54 bool mapRecordsStarted = false;
55 std::string line;
56 std::size_t lineNumber = 0U;
57 while (std::getline(input, line)) {
58 ++lineNumber;
59 if (line.empty() || line[0] == '#') continue;
60 if (hasEmptyCsvField(line)) {
61 error = "empty CSV field at line " + std::to_string(lineNumber);
62 return nullptr;
63 }
64 const auto fields = CxxUtils::tokenize(line, ',');
65 if (fields.empty()) continue;
66 const std::string& record = fields[0];
67 if (record == "META") {
68 if (mapRecordsStarted) {
69 error = "META row after map records at line " +
70 std::to_string(lineNumber);
71 return nullptr;
72 }
73 if (fields.size() != 3U) {
74 error = "invalid META row at line " + std::to_string(lineNumber);
75 return nullptr;
76 }
77 const std::string& key = fields[1];
78 if (key == "schemaVersion") {
79 if (schemaVersionSeen ||
80 !parseUnsignedInteger(fields[2], schemaVersion)) {
81 error = "invalid or duplicate schemaVersion";
82 return nullptr;
83 }
84 schemaVersionSeen = true;
85 } else if (key == "payloadVersion") {
86 if (payloadVersionSeen || fields[2].empty()) {
87 error = "invalid or duplicate payloadVersion";
88 return nullptr;
89 }
90 map->m_version = fields[2];
91 payloadVersionSeen = true;
92 } else if (key == "etaBins") {
93 if (etaBinsSeen ||
94 !parseUnsignedInteger(fields[2], map->m_etaBins)) {
95 error = "invalid or duplicate etaBins";
96 return nullptr;
97 }
98 etaBinsSeen = true;
99 } else if (key == "phiBinsPerFold") {
100 if (phiBinsSeen ||
101 !parseUnsignedInteger(fields[2], map->m_phiBinsPerFold)) {
102 error = "invalid or duplicate phiBinsPerFold";
103 return nullptr;
104 }
105 phiBinsSeen = true;
106 } else {
107 error = "unknown metadata key at line " +
108 std::to_string(lineNumber) + ": " + key;
109 return nullptr;
110 }
111 continue;
112 }
113
114 mapRecordsStarted = true;
115 if (record != "POOR") {
116 error = "unknown map record at line " + std::to_string(lineNumber) +
117 ": " + record;
118 return nullptr;
119 }
120 if (fields.size() != 3U || map->m_etaBins == 0U ||
121 map->m_phiBinsPerFold == 0U) {
122 error = "invalid POOR row at line " + std::to_string(lineNumber);
123 return nullptr;
124 }
125 int etaBin = -1;
126 int phiFoldBin = -1;
127 if (!parseInteger(fields[1], etaBin) ||
128 !parseInteger(fields[2], phiFoldBin) || etaBin < 0 ||
129 phiFoldBin < 0 || etaBin >= static_cast<int>(map->m_etaBins) ||
130 phiFoldBin >= static_cast<int>(map->m_phiBinsPerFold)) {
131 error = "invalid map bin at line " + std::to_string(lineNumber);
132 return nullptr;
133 }
134 if (map->m_poorBins.empty()) {
135 const std::size_t count = static_cast<std::size_t>(map->m_etaBins) *
136 map->m_phiBinsPerFold;
137 map->m_poorBins.assign(count, false);
138 }
139 const std::size_t index = static_cast<std::size_t>(etaBin) *
140 map->m_phiBinsPerFold +
141 static_cast<std::size_t>(phiFoldBin);
142 if (map->m_poorBins[index]) {
143 error = "duplicate POOR bin at line " + std::to_string(lineNumber);
144 return nullptr;
145 }
146 map->m_poorBins[index] = true;
147 ++map->m_poorBinCount;
148 }
149
150 if (!schemaVersionSeen || schemaVersion != 1U || !payloadVersionSeen ||
151 !etaBinsSeen || !phiBinsSeen || map->m_etaBins == 0U ||
152 map->m_phiBinsPerFold == 0U) {
153 error = "incomplete or unsupported ASCII GoodMag metadata";
154 return nullptr;
155 }
156 if (map->m_poorBins.empty()) {
157 const std::size_t count = static_cast<std::size_t>(map->m_etaBins) *
158 map->m_phiBinsPerFold;
159 map->m_poorBins.assign(count, false);
160 }
161 return map;
162}
static const Attributes_t empty
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:148
std::vector< std::string > tokenize(std::string_view the_str, std::string_view delimiters)
Splits the string into smaller substrings.

◆ phiBinsPerFold()

unsigned int L0Muon::TgcL0GoodMagMap::phiBinsPerFold ( ) const
inline

Definition at line 25 of file TgcL0GoodMagMap.h.

25{ return m_phiBinsPerFold; }

◆ poorBinCount()

std::size_t L0Muon::TgcL0GoodMagMap::poorBinCount ( ) const
inline

Definition at line 26 of file TgcL0GoodMagMap.h.

26{ return m_poorBinCount; }

◆ version()

const std::string & L0Muon::TgcL0GoodMagMap::version ( ) const
inline

Definition at line 23 of file TgcL0GoodMagMap.h.

23{ return m_version; }

Member Data Documentation

◆ m_etaBins

unsigned int L0Muon::TgcL0GoodMagMap::m_etaBins {0U}
private

Definition at line 32 of file TgcL0GoodMagMap.h.

32{0U};

◆ m_phiBinsPerFold

unsigned int L0Muon::TgcL0GoodMagMap::m_phiBinsPerFold {0U}
private

Definition at line 33 of file TgcL0GoodMagMap.h.

33{0U};

◆ m_poorBinCount

std::size_t L0Muon::TgcL0GoodMagMap::m_poorBinCount {0U}
private

Definition at line 35 of file TgcL0GoodMagMap.h.

35{0U};

◆ m_poorBins

std::vector<bool> L0Muon::TgcL0GoodMagMap::m_poorBins {}
private

Definition at line 34 of file TgcL0GoodMagMap.h.

34{};

◆ m_version

std::string L0Muon::TgcL0GoodMagMap::m_version {}
private

Definition at line 31 of file TgcL0GoodMagMap.h.

31{};

The documentation for this class was generated from the following files: