ATLAS Offline Software
ElementTable.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // ElementTable.h, (c) ATLAS Detector software
8 
9 #ifndef TRKGEOMETRY_ELEMENTTABLE_H
10 #define TRKGEOMETRY_ELEMENTTABLE_H
11 
12 #include <climits>
13 #include <memory>
14 #include <vector>
15 
16 #include "AthenaKernel/CLASS_DEF.h"
17 #include "TrkGeometry/Material.h"
18 
19 class MsgStream;
20 
21 namespace Trk {
22 
24 class ElementTable {
25  public:
28  : m_table(static_cast<size_t>(UCHAR_MAX), (Material*)nullptr),
29  m_names(static_cast<size_t>(UCHAR_MAX), std::string("None")) {}
30 
33  : m_table(static_cast<size_t>(UCHAR_MAX), (Material*)nullptr),
34  m_names(et.m_names) {
35  for (size_t im = 0; im < et.m_table.size(); ++im) {
36  if (et.m_table[im]) m_table[im] = new Trk::Material(*et.m_table[im]);
37  }
38  }
39 
41  ~ElementTable();
42 
45  if (this != &et) {
46  // clear first, then copy
47  auto elIter = m_table.begin();
48  for (; elIter != m_table.end(); delete (*elIter), ++elIter)
49  ;
50  m_names = et.m_names;
51  for (size_t im = 0; im < et.m_table.size(); ++im) {
52  m_table[im] = nullptr;
53  if (et.m_table[im]) m_table[im] = new Trk::Material(*et.m_table[im]);
54  }
55  }
56  return (*this);
57  }
58 
61  for (size_t ie = 0; ie < size_t(UCHAR_MAX); ++ie) {
62  if (et.element(ie)) {
63  addElement(*et.element(ie), et.elementName(ie));
64  }
65  }
66  return (*this);
67  }
68 
71  const Material* element(unsigned int Z) const { return m_table[Z]; }
73  const std::string& elementName(unsigned int Z) const { return m_names[Z]; }
75  void addElement(const Material& mat, const std::string& mname = "") {
76  unsigned int Zint = (unsigned int)mat.Z;
77  if (!m_table[Zint]) {
78  m_table[Zint] = new Material(mat);
79  m_names[Zint] = mname;
80  }
81  }
82 
84  void addElement(std::unique_ptr<Material> mat, const std::string& mname) {
85  unsigned int Zint = (unsigned int)mat->Z;
86  if (!m_table[Zint]) {
87  m_table[Zint] = mat.release();
88  m_names[Zint] = mname;
89  }
90  }
91 
93  bool contains(unsigned int Z) const { return bool(element(Z)); }
94 
96  size_t size() const { return m_table.size(); }
97 
98  private:
99  std::vector<Material*> m_table;
100  std::vector<std::string> m_names;
101 };
104 MsgStream& operator<<(MsgStream& sl, const ElementTable& etab);
105 std::ostream& operator<<(std::ostream& sl, const ElementTable& etab);
106 } // namespace Trk
107 
108 CLASS_DEF(Trk::ElementTable, 247342244, 1)
109 
110 #endif
et
Extra patterns decribing particle interation process.
Trk::ElementTable::elementName
const std::string & elementName(unsigned int Z) const
Get the element name.
Definition: ElementTable.h:73
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
Trk::ElementTable::m_table
std::vector< Material * > m_table
Definition: ElementTable.h:99
mat
GeoMaterial * mat
Definition: LArDetectorConstructionTBEC.cxx:53
Trk::ElementTable::addElement
void addElement(std::unique_ptr< Material > mat, const std::string &mname)
Version that takes ownership of a pointer.
Definition: ElementTable.h:84
Trk::ElementTable::m_names
std::vector< std::string > m_names
Definition: ElementTable.h:100
Trk::ElementTable::contains
bool contains(unsigned int Z) const
quick check
Definition: ElementTable.h:93
python.atlas_oh.im
im
Definition: atlas_oh.py:167
Trk::ElementTable::element
const Material * element(unsigned int Z) const
Get the material.
Definition: ElementTable.h:71
PlotCalibFromCool.ie
ie
Definition: PlotCalibFromCool.py:420
Trk::ElementTable::operator+=
ElementTable & operator+=(const ElementTable &et)
Adding two tables : add table entries from another table.
Definition: ElementTable.h:60
Trk::ElementTable::operator=
ElementTable & operator=(const ElementTable &et)
Assignment operator.
Definition: ElementTable.h:44
Trk::ElementTable::ElementTable
ElementTable()
Empty constructor.
Definition: ElementTable.h:27
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
Trk::ElementTable
Definition: ElementTable.h:24
Trk::operator<<
MsgStream & operator<<(MsgStream &sl, const AlignModule &alignModule)
overload of << operator for MsgStream for debug output
Definition: AlignModule.cxx:204
CLASS_DEF
#define CLASS_DEF(NAME, CID, VERSION)
associate a clid and a version to a type eg
Definition: Control/AthenaKernel/AthenaKernel/CLASS_DEF.h:64
if
if(febId1==febId2)
Definition: LArRodBlockPhysicsV0.cxx:569
Trk::Material
Definition: Material.h:116
xAOD::bool
setBGCode setTAP setLVL2ErrorBits bool
Definition: TrigDecision_v1.cxx:60
Material
@ Material
Definition: MaterialTypes.h:8
CLASS_DEF.h
macros to associate a CLID to a type
Trk::ElementTable::~ElementTable
~ElementTable()
Destructor.
Definition: ElementTable.cxx:15
Material.h
Trk::ElementTable::size
size_t size() const
Print the table size.
Definition: ElementTable.h:96
Trk::ElementTable::addElement
void addElement(const Material &mat, const std::string &mname="")
Add material to the Table - if the elment is already filled ignore.
Definition: ElementTable.h:75
Trk::ElementTable::ElementTable
ElementTable(const ElementTable &et)
Empty constructor.
Definition: ElementTable.h:32