15 declareInterface<IeFEXFPGATowerIdProvider>(
this);
22 if (setAddress(csvpath) == StatusCode::FAILURE) {
23 ATH_MSG_WARNING(
"tower_fpga_efex_map.csv missing or invalid. Swiching to hard-coded mapping.");
25 return StatusCode::SUCCESS;
30 for (
auto each : m_alltowers) {
34 for (
auto each : m_towerrankingcache) {
43 if (inputaddress.empty()) {
45 return StatusCode::FAILURE;
48 m_csvaddress = inputaddress;
49 if (loadcsv() == StatusCode::FAILURE) {
51 return StatusCode::FAILURE;
53 m_towerrankingcache = std::vector<std::vector<int>*>(96,
nullptr);
55 for (
int efex{ 0 }; efex < 24; efex++) {
56 for (
int fpga{ 0 }; fpga < 4; fpga++) {
57 if (rankTowerinFPGA(getFPGAIndex(efex, fpga)) == StatusCode::FAILURE) {
59 return StatusCode::FAILURE;
63 return StatusCode::SUCCESS;
67 int FPGAindex{ getFPGAIndex(eFEXID, FPGAID) };
68 if (m_towerrankingcache[FPGAindex]) {
71 for (
int i{ 0 };
i < 10;
i++) {
72 for (
int j{ 0 }; j < 6; j++) {
73 towerlist[
i][j] = (*m_towerrankingcache[FPGAindex]).at(vectorindex++);
79 for (
int i{ 0 };
i < 10;
i++) {
80 for (
int j{ 0 }; j < 6; j++) {
85 return StatusCode::FAILURE;
87 return StatusCode::SUCCESS;
91 int FPGA0index{ getFPGAIndex(eFEXID, 0) };
92 int FPGA1index{ getFPGAIndex(eFEXID, 1) };
93 int FPGA2index{ getFPGAIndex(eFEXID, 2) };
94 int FPGA3index{ getFPGAIndex(eFEXID, 3) };
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;
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 std::vector<int>*
output =
new std::vector<int>;
179 for (
int i{ 0 };
i < 10;
i++) {
180 for (
int j{ 0 }; j < 6; j++) {
184 m_towerrankingcache[FPGAindex] =
output;
186 return StatusCode::SUCCESS;
192 std::unordered_map<int, std::vector<towerinfo>*>::const_iterator haskey = m_alltowers.find(FPGAindex);
193 if (haskey == m_alltowers.end()) {
202 std::string eachline;
203 std::ifstream myfile(m_csvaddress);
204 if (myfile.is_open()) {
205 while (std::getline(myfile, eachline)) {
207 std::string::size_type ipos = eachline.find(
"#");
208 if (ipos!=std::string::npos) eachline.resize(ipos);
211 if (std::all_of(eachline.begin(), eachline.end(), ::isspace)) {
216 auto validchar = [](
char ch) {
return (::isspace(
ch) || ::isdigit(
ch) ||
ch==
','); };
217 if (!std::all_of(eachline.begin(), eachline.end(), validchar)) {
223 std::stringstream eachline_stream(eachline);
224 std::vector<int> numbers_in_eachline;
225 while (eachline_stream.good()) {
226 std::string tem_string;
227 std::getline(eachline_stream, tem_string,
',');
229 numbers_in_eachline.push_back(std::stoi(tem_string));
233 return StatusCode::FAILURE;
239 if (numbers_in_eachline.size() != 5) {
241 return StatusCode::FAILURE;
244 if (numbers_in_eachline[3] < 0 || numbers_in_eachline[4] < 0) {
247 return StatusCode::FAILURE;
249 int FPGAindex = getFPGAIndex(numbers_in_eachline[0], numbers_in_eachline[1]);
251 if (FPGAindex == -1) {
253 return StatusCode::FAILURE;
256 tem_towerinfo.
eTowerID = numbers_in_eachline[2];
261 if (
int(numbers_in_eachline[2] / 100000) % 2 != 0) {
266 tem_towerinfo.
eTowerEta = etasign * (numbers_in_eachline[3]);
267 tem_towerinfo.
eTowerPhi = numbers_in_eachline[4];
272 if (hasFPGA(FPGAindex)) {
273 m_alltowers[FPGAindex]->push_back(tem_towerinfo);
275 std::vector<towerinfo>* FPGAinfovector =
new std::vector<towerinfo>;
276 FPGAinfovector->push_back(tem_towerinfo);
277 m_alltowers[FPGAindex] = FPGAinfovector;
283 return StatusCode::FAILURE;
285 return StatusCode::SUCCESS;
293 if (FPGAid < 0 or FPGAid > 3) {
296 if (eFEXid < 0 or FPGAid > 23) {
299 return eFEXid * 4 + FPGAid;