9#include "GaudiKernel/EventContext.h"
19 ISvcLocator* pSvcLocator)
30 return StatusCode::SUCCESS;
37 if (
m_done.load(std::memory_order_acquire)) {
38 return StatusCode::SUCCESS;
41 bool expected =
false;
42 if (!
m_done.compare_exchange_strong(expected,
true, std::memory_order_acq_rel)) {
43 return StatusCode::SUCCESS;
51 return StatusCode::FAILURE;
55 const std::pair< Identifier, int> w_and_fe_id =
waferId(row);
57 const std::string waferId_str =
id.get_identifier32().getString();
63 std::string
x = waferId_str.substr(0, waferId_str.length() - 2 );
70 int fe = w_and_fe_id.second;
71 std::bitset<32> febits = std::bitset<32>(fe);
75 output << waferId_str <<
"\t"
77 << b.to_string() <<
"\t"
78 << febits.to_string() <<
"\t"
85 std::stringstream
res;
86 res << std::hex << std::uppercase << b.to_ulong();
89 output << b.to_ulong() <<
"\n";
94 return StatusCode::SUCCESS;
99 if (resolvedCsv.empty()) {
101 return StatusCode::FAILURE;
105 std::ifstream input(resolvedCsv);
108 return StatusCode::FAILURE;
115 bool firstLine =
true;
116 while (std::getline(input, line)) {
125 const std::vector<std::string> fields =
splitCsvLine(line);
126 if (fields.size() < 3) {
132 row.spChain =
trim(fields[0]);
133 row.md =
trim(fields[1]);
134 row.fe = std::stoi(
trim(fields[2]));
136 m_rows.push_back(std::move(row));
140 return StatusCode::SUCCESS;
145 <<
", module " << row.md <<
", FE " << row.fe);
148 std::vector<std::string> spChain_cur =
parseSPChain(row.spChain);
154 int fe_n =
feID(spChain_cur, row.fe );
160 const auto begin = input.find_first_not_of(
" \t\r\n");
161 if (begin == std::string::npos) {
165 const auto end = input.find_last_not_of(
" \t\r\n");
166 return input.substr(begin, end - begin + 1);
170 std::vector<std::string> fields;
171 std::stringstream
ss(line);
174 while (std::getline(
ss, field,
',')) {
175 fields.push_back(field);
182 std::vector<std::string> elements;
183 std::stringstream
ss(spChain);
186 while (std::getline(
ss, element,
'-')) {
187 elements.push_back(element);
196 if (spchain[1] ==
"IS" &&
197 (spchain[2] ==
"L0" || spchain[2] ==
"L1") &&
198 spchain.at(3)[0] !=
'R') {
201 else if (spchain[1] ==
"OB" &&
202 (spchain[2] ==
"L2" || spchain[2] ==
"L3" ||
203 spchain[2] ==
"L4") &&
204 (spchain.at(3)[0] ==
'B')) {
209 std::string sideAC = spchain[4];
210 if(sideAC !=
"A" && sideAC !=
"C"){
213 int side = (sideAC ==
"A")? 1 : -1;
221 return spchain.at(2)[1] -
'0';
224 if (spchain[2] ==
"L01" &&
225 (spchain.at(5) ==
"SP1" || spchain.at(5) ==
"SP3")) {
228 else if (spchain[2] ==
"L01" &&
229 (spchain.at(5) ==
"SP2" || spchain.at(5) ==
"SP4")) {
232 else if(spchain[1] ==
"OB" && (spchain[2] ==
"L2" ||
233 spchain[2] ==
"L3" ||
234 spchain[2] ==
"L4") ){
235 return (2* ((spchain.at(2))[1] -
'0') - 1);
237 else if(spchain[1] ==
"IS" && spchain[2] ==
"L05"){
240 else if(spchain[1] ==
"IS" && spchain[2] ==
"L1"){
243 else if(spchain[1] ==
"EC"){
244 return 2* (spchain.at(2)[1]-
'0');
259 std::string phi_str = (spchain.at(3)).substr(1,2);
260 if(ld == 0 || ld ==1 ){
261 return std::stoi(phi_str) - 1;
264 int phi = std::stoi(phi_str) - 1 ;
265 phi = (mod[2] ==
'T') ? 2*
phi + 1 : 2*
phi;
270 if (spchain[2] ==
"L01" &&
271 (spchain.at(5) ==
"SP1" || spchain.at(5) ==
"SP3")) {
272 std::string sp_str(1, (spchain.at(5)[2]));
274 return 6 * (stoi(mod) - 1 ) + 2 * (fe - 1);
276 else if(sp_str ==
"3"){
277 return 6 * (stoi(mod) - 1 ) + 2 * (fe - 1) + 1;
284 else if (spchain[2] ==
"L01" &&
285 (spchain.at(5) ==
"SP2" || spchain.at(5) ==
"SP4")) {
287 std::string sp_str(1, spchain.at(5)[2]);
289 return 2 * (stoi(mod) - 1 ) ;
291 else if(sp_str ==
"4"){
292 return 2 * (stoi(mod) - 1 ) + 1;
300 else if(ld == 3 || ld == 5 || ld ==7){
301 std::string phi_str = mod.substr(3,2);
302 int phi = std::stoi(phi_str);
306 return 6 * (stoi(mod) - 1 ) + 2 * (fe - 1);
309 std::string sp_str(1, spchain.at(5)[2]);
311 return 2 * (stoi(mod) - 1 ) ;
313 else if(sp_str ==
"2"){
314 return 2 * (stoi(mod) - 1 ) + 1;
318 else if(ld == 4 || ld == 6 || ld ==8){
319 std::string phi_str = mod.substr(2,2);
320 int phi = std::stoi(phi_str);
335 int side = (spchain[4] ==
"A") ? 1 : -1;
339 return side * (3 * (std::stoi(mod) -1) + fe );
342 return side * std::stoi(mod);
345 std::string eta_str(1, mod[4]);
346 int eta = std::stoi(eta_str);
356 if(spchain[2] ==
"L01"){
357 std::string eta_str = (spchain.at(3)).substr(1,2);
358 return std::stoi(eta_str);
360 else if(ld == 3 || ld == 5 || ld ==7){
361 std::string eta_str = (spchain.at(3)).substr(1,2);
362 return std::stoi(eta_str) - 1 ;
365 std::string eta_str = (spchain.at(3)).substr(1,2);
366 return std::stoi(eta_str) - 1;
369 std::string eta_str = (spchain.at(3)).substr(1,2);
370 return std::stoi(eta_str) + 14 ;
372 else if(ld == 4 || ld == 6 || ld ==8){
373 std::string eta_str = (spchain.at(3)).substr(1,2);
374 return std::stoi(eta_str) - 1 ;
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
std::pair< std::vector< unsigned int >, bool > res
This is an Identifier helper class for the Pixel subdetector.
const ServiceHandle< StoreGateSvc > & detStore() const
bool msgLvl(const MSG::Level lvl) const
An algorithm that can be simultaneously executed in multiple threads.
virtual StatusCode initialize() override
virtual StatusCode execute(const EventContext &ctx) const override
static std::string trim(const std::string &input)
std::atomic< bool > m_done
static std::vector< std::string > splitCsvLine(const std::string &line)
const PixelID * m_pixIdHelper
std::vector< CsvRow > m_rows
int phi_module(const std::vector< std::string > &spchain, const std::string &mod, int fe) const
Gaudi::Property< std::string > m_outputFile
static std::vector< std::string > parseSPChain(const std::string &spChain)
int feID(const std::vector< std::string > &spchain, int fe) const
Gaudi::Property< std::string > m_csvFile
int barrel_ec(const std::vector< std::string > &spchain) const
std::pair< Identifier, int > waferId(const CsvRow &row) const
int eta_module(const std::vector< std::string > &spchain, const std::string &mod, int fe) const
ITkPixelCsvWaferIdAlg(const std::string &name, ISvcLocator *pSvcLocator)
int layer_disk(const std::vector< std::string > &spchain) const
static std::string find_file(const std::string &logical_file_name, const std::string &search_path)