14 declareInterface<IeFEXSuperCellTowerIdProvider>(
this);
25 if (setAddress(csvpath) == StatusCode::FAILURE) {
26 ATH_MSG_WARNING(
"sc_tower_map.csv missing or invalid. Swiching to hard-coded mapping.");
28 return StatusCode::SUCCESS;
33 if (inputaddress.empty()) {
35 return StatusCode::FAILURE;
39 m_csvaddress = inputaddress;
40 if ( loadcsv() == StatusCode::FAILURE) {
42 return StatusCode::FAILURE;
44 return StatusCode::SUCCESS;
49 auto mapentry = m_SuperCelltoTowerIdmap.find(scid);
51 if (mapentry != m_SuperCelltoTowerIdmap.end()) {
52 towerinfo towerinfo_tem = mapentry->second;
54 slot = towerinfo_tem.
slot;
55 issplit = towerinfo_tem.
isSplit;
64 return StatusCode::SUCCESS;
69 auto haskey = m_SuperCelltoTowerIdmap.find(scid);
70 if (haskey == m_SuperCelltoTowerIdmap.end()) {
84 std::ifstream myfile(m_csvaddress);
85 if (myfile.is_open()) {
86 while (std::getline(myfile, eachline)) {
89 std::string::size_type ipos = eachline.find(
"#");
90 if (ipos!=std::string::npos) eachline.resize(ipos);
93 if (std::all_of(eachline.begin(), eachline.end(), ::isspace)) {
98 std::stringstream eachline_stream(eachline);
99 int each_etowerid{ -1 }, each_slot{ -1 };
100 bool eachisSplit{
false };
101 std::string each_scid =
"";
103 while (eachline_stream.good()) {
105 int number_in_eachline;
106 std::string tem_string;
107 std::getline(eachline_stream, tem_string,
',');
112 if (
i == 1 ||
i == 3 ||
i == 4) {
114 number_in_eachline = std::stoi(tem_string);
117 ATH_MSG_ERROR(
"Invalid input in " << m_csvaddress <<
". Unable to convert " << tem_string <<
" to int.");
118 return StatusCode::FAILURE;
121 each_etowerid = number_in_eachline;
123 each_slot = number_in_eachline;
126 if (number_in_eachline != 0 && number_in_eachline != 1) {
127 ATH_MSG_ERROR(
"Invalid input in " << m_csvaddress <<
". Unable to reader the fourth column.");
128 return StatusCode::FAILURE;
130 eachisSplit = number_in_eachline;
134 each_scid = tem_string;
137 ATH_MSG_ERROR(
"Invalid input in " << m_csvaddress <<
". Too many columns.");
138 return StatusCode::FAILURE;
143 if (each_etowerid > 601599 || each_etowerid < 100000) {
144 ATH_MSG_ERROR(
"Invalid eTower ID in " << m_csvaddress <<
".");
145 return StatusCode::FAILURE;
148 if (each_slot > 13 || each_slot < 0) {
149 ATH_MSG_ERROR(
"Invalid slot number in " << m_csvaddress <<
".");
150 return StatusCode::FAILURE;
153 if (each_scid.find(
"0x") == std::string::npos) {
154 ATH_MSG_ERROR(
"Invalid SuperCell ID in " << m_csvaddress <<
".");
155 return StatusCode::FAILURE;
158 each_towerinfo.
eTowerID = each_etowerid;
159 each_towerinfo.
slot = each_slot;
160 each_towerinfo.
isSplit = eachisSplit;
161 uint64_t scid_uint64 = strtoull(each_scid.c_str(),
nullptr, 16);
163 m_SuperCelltoTowerIdmap[scid_uint64] = each_towerinfo;
165 ATH_MSG_ERROR(
"Invalid SuperCell ID in " << m_csvaddress <<
".");
166 return StatusCode::FAILURE;
172 ATH_MSG_ERROR(
"eFEXFPGATowerIdProvider: Unable to open" << m_csvaddress <<
".");
173 return StatusCode::FAILURE;
175 return StatusCode::SUCCESS;