15 declareInterface<eFEXFPGATowerIdProvider>(
this);
21 if (setAddress(csvpath) == StatusCode::FAILURE) {
22 ATH_MSG_WARNING(
"tower_fpga_efex_map.csv missing or invalid. Swiching to hard-coded mapping.");
24 return StatusCode::SUCCESS;
30 m_towerrankingcache.clear();
35 if (inputaddress.empty()) {
37 return StatusCode::FAILURE;
40 m_csvaddress = inputaddress;
41 if (loadcsv() == StatusCode::FAILURE) {
43 return StatusCode::FAILURE;
45 m_towerrankingcache.clear();
46 m_towerrankingcache.resize(96);
48 for (
int efex{ 0 }; efex < 24; efex++) {
49 for (
int fpga{ 0 }; fpga < 4; fpga++) {
50 if (rankTowerinFPGA(getFPGAIndex(efex, fpga)) == StatusCode::FAILURE) {
52 return StatusCode::FAILURE;
56 return StatusCode::SUCCESS;
60 int FPGAindex{ getFPGAIndex(eFEXID, FPGAID) };
61 if (FPGAindex<0)
return StatusCode::FAILURE;
62 if (m_towerrankingcache[FPGAindex]) {
65 for (
int i{ 0 };
i < 10;
i++) {
66 for (
int j{ 0 }; j < 6; j++) {
67 towerlist[
i][j] = (*m_towerrankingcache[FPGAindex]).at(vectorindex++);
73 for (
int i{ 0 };
i < 10;
i++) {
74 for (
int j{ 0 }; j < 6; j++) {
79 return StatusCode::FAILURE;
81 return StatusCode::SUCCESS;
85 int FPGA0index{ getFPGAIndex(eFEXID, 0) };
86 int FPGA1index{ getFPGAIndex(eFEXID, 1) };
87 int FPGA2index{ getFPGAIndex(eFEXID, 2) };
88 int FPGA3index{ getFPGAIndex(eFEXID, 3) };
90 auto is_negative = [](
int val){
return val<0;};
91 if (std::ranges::any_of(std::initializer_list{FPGA0index, FPGA1index, FPGA2index, FPGA3index}, is_negative)){
92 return StatusCode::FAILURE;
96 if (!m_towerrankingcache[FPGA0index] || !m_towerrankingcache[FPGA1index] ||
97 !m_towerrankingcache[FPGA2index] || !m_towerrankingcache[FPGA3index]) {
98 for (
int i{ 0 };
i < 10;
i++) {
99 for (
int j{ 0 }; j < 18; j++) {
104 return StatusCode::FAILURE;
108 int vectorindex{ 0 };
109 for (
int i{ 0 };
i < 10;
i++) {
110 for (
int j{ 0 }; j < 6; j++) {
111 towerlist[
i][j] = (*m_towerrankingcache[FPGA0index]).at(vectorindex++);
117 for (
int i{ 0 };
i < 10;
i++) {
119 for (
int j{ 2 }; j < 4; j++) {
120 towerlist[
i][j + 4] = (*m_towerrankingcache[FPGA1index]).at(vectorindex++);
127 for (
int i{ 0 };
i < 10;
i++) {
128 for (
int j{ 0 }; j < 6; j++) {
129 towerlist[
i][j + 8] = (*m_towerrankingcache[FPGA2index]).at(vectorindex++);
135 for (
int i{ 0 };
i < 10;
i++) {
137 for (
int j{ 2 }; j < 6; j++) {
138 towerlist[
i][j + 12] = (*m_towerrankingcache[FPGA3index]).at(vectorindex++);
141 return StatusCode::SUCCESS;
153 if (FPGAindex < 0)
return StatusCode::FAILURE;
155 if (!m_towerrankingcache[FPGAindex]) {
156 std::vector<std::pair<int, int>> rankingmap;
158 for (
auto each : *m_alltowers[FPGAindex]) {
159 if (each.eTowerPhi < 3 && each.eTowerPhi > -1 && FPGAindex >= getFPGAIndex(21, 0)) {
160 rankingmap.push_back(std::pair<int, int>(-each.eTowerEta - (90 + each.eTowerPhi) * 100, each.eTowerID));
162 rankingmap.push_back(std::pair<int, int>(-each.eTowerEta - each.eTowerPhi * 100, each.eTowerID));
166 if (rankingmap.size() != 60) {
167 return StatusCode::FAILURE;
169 std::sort(rankingmap.begin(), rankingmap.end(),
170 [](std::pair<int, int>
a, std::pair<int, int>
b) {
172 if (a.first == b.first) {
173 return (a.second < b.second);
175 return (
a.first >
b.first);
177 auto output = std::make_unique<std::vector<int>>();
180 for (
int i{ 0 };
i < 10;
i++) {
181 for (
int j{ 0 }; j < 6; j++) {
182 output->push_back(rankingmap[vectorindex++].
second);
185 m_towerrankingcache[FPGAindex] = std::move(output);
187 return StatusCode::SUCCESS;
193 return m_alltowers.contains(FPGAindex);
199 std::string eachline;
200 std::ifstream myfile(m_csvaddress);
201 if (myfile.is_open()) {
202 while (std::getline(myfile, eachline)) {
204 std::string::size_type ipos = eachline.find(
"#");
205 if (ipos!=std::string::npos) eachline.resize(ipos);
208 if (std::all_of(eachline.begin(), eachline.end(), ::isspace)) {
213 auto validchar = [](
char ch) {
return (::isspace(
ch) || ::isdigit(
ch) ||
ch==
','); };
214 if (!std::all_of(eachline.begin(), eachline.end(), validchar)) {
220 std::stringstream eachline_stream(eachline);
221 std::vector<int> numbers_in_eachline;
222 while (eachline_stream.good()) {
223 std::string tem_string;
224 std::getline(eachline_stream, tem_string,
',');
226 numbers_in_eachline.push_back(std::stoi(tem_string));
230 return StatusCode::FAILURE;
236 if (numbers_in_eachline.size() != 5) {
238 return StatusCode::FAILURE;
241 if (numbers_in_eachline[3] < 0 || numbers_in_eachline[4] < 0) {
244 return StatusCode::FAILURE;
246 int FPGAindex = getFPGAIndex(numbers_in_eachline[0], numbers_in_eachline[1]);
248 if (FPGAindex == -1) {
250 return StatusCode::FAILURE;
253 tem_towerinfo.
eTowerID = numbers_in_eachline[2];
258 if (
int(numbers_in_eachline[2] / 100000) % 2 != 0) {
263 tem_towerinfo.
eTowerEta = etasign * (numbers_in_eachline[3]);
264 tem_towerinfo.
eTowerPhi = numbers_in_eachline[4];
269 if (hasFPGA(FPGAindex)) {
270 m_alltowers[FPGAindex]->push_back(tem_towerinfo);
272 m_alltowers[FPGAindex] = std::make_unique<std::vector<towerinfo>>(std::vector{tem_towerinfo});
278 return StatusCode::FAILURE;
280 return StatusCode::SUCCESS;
288 if (FPGAid < 0 or FPGAid > 3) {
291 if (eFEXid < 0 or FPGAid > 23) {
294 return eFEXid * 4 + FPGAid;