23 fs.open(csvFilename.c_str());
24 if (not
fs.is_open()){
25 const std::string
msg =
"Failed to open the mapping file: " + csvFilename;
26 throw std::runtime_error(
msg);
30 std::regex
re(R
"delim(^(.*), (\d+), (-?\d+), (\d+), (\d+), (-?\d+)$)delim");
31 auto dissectMatch=[](
const std::smatch & m)->std::pair<std::string, Coordinates>{
32 static constexpr size_t expectedSize(7);
33 static constexpr size_t coordStart(2);
34 std::pair<std::string, PixelMapping::Coordinates>
result{};
35 if (m.size()!=expectedSize)
return result;
36 const std::string name = m[1];
39 for (
size_t i(0); i!=coords.size();++i){
41 coords[i] = std::stoi(m.str(i+coordStart));
42 }
catch (std::invalid_argument &e){
43 const std::string
msg =
"PixelMapping: Line of csv file in unexpected format, \n"+ std::string(m[0]);
44 throw std::runtime_error(
msg);
47 return {name, coords};
49 while (std::getline(
fs, line)){
51 if (line[0] ==
'#')
continue;
53 bool matched = std::regex_match(line, m,
re);
55 std::cout<<
"line in unexpected format:\n"<<line<<std::endl;
60 std::cout<<
"repeated entry:\n"<<line<<std::endl;
68 PixelMapping::mapping(
const std::string & geographicalID,
int *hashID,
int *bec,
int *layer,
int *phimod,
int *etamod)
const{
71 std::cout<<
"id "<<geographicalID<<
" not found in mapping"<<std::endl;
74 const auto & coordinates = pName->second;
75 *hashID = coordinates[0];
76 *bec = coordinates[1];
77 *layer = coordinates[2];
78 *phimod = coordinates[3];
79 *etamod = coordinates[4];