ATLAS Offline Software
Public Member Functions | Private Types | Private Attributes | List of all members
pix::PixelMapping Class Reference

#include <PixelMapping.h>

Collaboration diagram for pix::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  result.first = name;
48  result.second = coords;
49  return result;
50  };
51  while (std::getline(fs, line)){
52  //hash at start indicates comment, do nothing
53  if (line[0] == '#') continue;
54  std::smatch m;
55  bool matched = std::regex_match(line, m, re);
56  if (not matched){
57  std::cout<<"line in unexpected format:\n"<<line<<std::endl;
58  continue;
59  }
60  const auto& [ptr, Ok]=m_internalMap.insert(dissectMatch(m));
61  if (not Ok){
62  std::cout<<"repeated entry:\n"<<line<<std::endl;
63  }
64  }
65  fs.close();
66  }

Member Function Documentation

◆ contains()

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

Definition at line 97 of file PixelMapping.cxx.

97  {
98  return (m_internalMap.find(geographicalID) != m_internalMap.end());
99  }

◆ getID()

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

Definition at line 86 of file PixelMapping.cxx.

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

◆ mapping()

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

Definition at line 70 of file PixelMapping.cxx.

70  {
71  auto pName = m_internalMap.find(geographicalID);
72  if (pName == m_internalMap.end()){
73  std::cout<<"id "<<geographicalID<<" not found in mapping"<<std::endl;
74  return;
75  }
76  const auto & coordinates = pName->second;
77  *hashID = coordinates[0];
78  *bec = coordinates[1];
79  *layer = coordinates[2];
80  *phimod = coordinates[3];
81  *etamod = coordinates[4];
82  return;
83  }

◆ nModules()

int pix::PixelMapping::nModules ( ) const

Definition at line 102 of file PixelMapping.cxx.

102  {
103  return m_internalMap.size();
104  }

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:
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
checkFileSG.line
line
Definition: checkFileSG.py:75
get_generator_info.result
result
Definition: get_generator_info.py:21
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
ParticleGun_SamplingFraction.bec
int bec
Definition: ParticleGun_SamplingFraction.py:89
dbg::ptr
void * ptr(T *p)
Definition: SGImplSvc.cxx:74
PrepareReferenceFile.regex
regex
Definition: PrepareReferenceFile.py:43
CaloSwCorrections.etamod
def etamod(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:206
lumiFormat.i
int i
Definition: lumiFormat.py:85
CaloSwCorrections.phimod
def phimod(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:203
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
python.ElectronD3PDObject.matched
matched
Definition: ElectronD3PDObject.py:138
re
const boost::regex re(r_e)
Herwig7_QED_EvtGen_ll.fs
dictionary fs
Definition: Herwig7_QED_EvtGen_ll.py:17
pix::PixelMapping::m_internalMap
std::unordered_map< std::string, Coordinates > m_internalMap
Definition: PixelMapping.h:33
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
pix::PixelMapping::Coordinates
std::array< int, 5 > Coordinates
Definition: PixelMapping.h:32