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;
35 if (inputaddress.empty()) {
37 return StatusCode::FAILURE;
41 if (
loadcsv() == StatusCode::FAILURE) {
43 return StatusCode::FAILURE;
48 for (
int efex{ 0 }; efex < 24; efex++) {
49 for (
int fpga{ 0 }; fpga < 4; fpga++) {
52 return StatusCode::FAILURE;
56 return StatusCode::SUCCESS;
61 if (FPGAindex<0)
return StatusCode::FAILURE;
65 for (
int i{ 0 }; i < 10; i++) {
66 for (
int j{ 0 }; j < 6; j++) {
73 for (
int i{ 0 }; i < 10; i++) {
74 for (
int j{ 0 }; j < 6; j++) {
79 return StatusCode::FAILURE;
81 return StatusCode::SUCCESS;
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;
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++) {
117 for (
int i{ 0 }; i < 10; i++) {
119 for (
int j{ 2 }; j < 4; j++) {
127 for (
int i{ 0 }; i < 10; i++) {
128 for (
int j{ 0 }; j < 6; j++) {
135 for (
int i{ 0 }; i < 10; i++) {
137 for (
int j{ 2 }; j < 6; j++) {
141 return StatusCode::SUCCESS;
153 if (FPGAindex < 0)
return StatusCode::FAILURE;
156 std::vector<std::pair<int, int>> rankingmap;
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);
187 return StatusCode::SUCCESS;
199 std::string eachline;
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];
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;
#define ATH_MSG_WARNING(x)
StatusCode loadcsv()
load the mapping info in the csv file
bool hasFPGA(int) const
check if an FPGA exists in the csv file
std::vector< std::unique_ptr< std::vector< int > > > m_towerrankingcache
Ordered tower Ids in each FPGAs. The index is the index of the FPGA.
StatusCode initialize()
initialize the tool
bool m_hascsvfile
if the csv file is valid
StatusCode rankTowerinFPGA(int FPGAindex)
rank the tower ids in an FPGA This function determines the order of towers in an FPGA.
int getFPGAIndex(int eFEXid, int FPGAid) const
determine the index of an FPGA
std::unordered_map< int, std::unique_ptr< std::vector< towerinfo > > > m_alltowers
Unordered tower Ids in each FPGAs. The index is the index of the FPGA.
StatusCode getRankedTowerIDinFPGA(int eFEXID, int FPGAID, int(&towerlist)[10][6]) const
obtain ordered tower IDs in an FPGA
bool ifhaveinputfile() const
StatusCode getRankedTowerIDineFEX(int eFEXID, int(&towerlist)[10][18]) const
obtain ordered tower IDs in an eFEX
std::string m_csvaddress
path to the input csv file
~eFEXFPGATowerIdProvider()
Destructor.
eFEXFPGATowerIdProvider(const std::string &type, const std::string &name, const IInterface *parent)
Constructor.
StatusCode setAddress(const std::string &inputaddress)
set path to the csv file and load
static std::string find_file(const std::string &logical_file_name, const std::string &search_path)
Provide tower-FPGA mapping.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
Sturcture defines the id, eta and phi position of a tower.
int eTowerEta
tower Eta index
int eTowerPhi
tower Phi index