ATLAS Offline Software
Loading...
Searching...
No Matches
PixelMapping Class Reference

#include <PixelMapping.h>

Collaboration diagram for PixelMapping:

Public Member Functions

 PixelMapping (const std::string &csvFilename)
void mapping (const std::string &geographicalID, int *hashID, int *bec, int *layer, int *phimod, int *etamod) const
int getID (const std::string &geographicalID) const
bool contains (const std::string &geographicalID) const
int nModules () const

Private Types

typedef std::array< int, 5 > Coordinates

Private Attributes

std::unordered_map< std::string, Coordinatesm_internalMap

Detailed Description

Definition at line 18 of file PixelMapping.h.

Member Typedef Documentation

◆ Coordinates

typedef std::array<int,5> pix::PixelMapping::Coordinates
private

Definition at line 32 of file PixelMapping.h.

Constructor & Destructor Documentation

◆ PixelMapping()

pix::PixelMapping::PixelMapping ( const std::string & csvFilename)

Definition at line 18 of file PixelMapping.cxx.

18 {
19 //read in csv file and fill data structures
20 //lines in file are of format 'D2A_B02_S1_M3, 1950, 2, 1, 10, 0'
21 //'#' at start of line denotes a comment or header
22 std::ifstream fs;
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);
27 }
28 std::string line;
29 //string, digits, signed digits, digits, digits, signed digits
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];
37 Coordinates coords{};
38
39 for (size_t i(0); i!=coords.size();++i){
40 try{
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);
45 }
46 }
47 return {name, coords};
48 };
49 while (std::getline(fs, line)){
50 //hash at start indicates comment, do nothing
51 if (line[0] == '#') continue;
52 std::smatch m;
53 bool matched = std::regex_match(line, m, re);
54 if (not matched){
55 std::cout<<"line in unexpected format:\n"<<line<<std::endl;
56 continue;
57 }
58 const auto& [ptr, Ok]=m_internalMap.insert(dissectMatch(m));
59 if (not Ok){
60 std::cout<<"repeated entry:\n"<<line<<std::endl;
61 }
62 }
63 fs.close();
64 }
const boost::regex re(r_e)
static Double_t fs
std::unordered_map< std::string, Coordinates > m_internalMap
std::array< int, 5 > Coordinates
void * ptr(T *p)
Definition SGImplSvc.cxx:74
MsgStream & msg
Definition testRead.cxx:32

Member Function Documentation

◆ contains()

bool pix::PixelMapping::contains ( const std::string & geographicalID) const

Definition at line 95 of file PixelMapping.cxx.

95 {
96 return (m_internalMap.find(geographicalID) != m_internalMap.end());
97 }

◆ getID()

int pix::PixelMapping::getID ( const std::string & geographicalID) const

Definition at line 84 of file PixelMapping.cxx.

84 {
85 auto pName = m_internalMap.find(geographicalID);
86 if (pName == m_internalMap.end()) {
87 std::cout<<"id "<<geographicalID<<" not found in mapping"<<std::endl;
88 return -1;
89 }
90 const auto & coordinates = pName->second;
91 return coordinates[0];
92}

◆ mapping()

void pix::PixelMapping::mapping ( const std::string & geographicalID,
int * hashID,
int * bec,
int * layer,
int * phimod,
int * etamod ) const

Definition at line 68 of file PixelMapping.cxx.

68 {
69 auto pName = m_internalMap.find(geographicalID);
70 if (pName == m_internalMap.end()){
71 std::cout<<"id "<<geographicalID<<" not found in mapping"<<std::endl;
72 return;
73 }
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];
80 return;
81 }
phimod(flags, cells_name, *args, **kw)
etamod(flags, cells_name, *args, **kw)
@ layer
Definition HitInfo.h:79

◆ nModules()

int pix::PixelMapping::nModules ( ) const

Definition at line 100 of file PixelMapping.cxx.

100 {
101 return m_internalMap.size();
102 }

Member Data Documentation

◆ m_internalMap

std::unordered_map<std::string,Coordinates > pix::PixelMapping::m_internalMap
private

Definition at line 33 of file PixelMapping.h.


The documentation for this class was generated from the following files: