ATLAS Offline Software
Loading...
Searching...
No Matches
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
18
19class MsgStream;
20
21namespace Trk {
22
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),
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
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};
102
104MsgStream& operator<<(MsgStream& sl, const ElementTable& etab);
105std::ostream& operator<<(std::ostream& sl, const ElementTable& etab);
106} // namespace Trk
107
108CLASS_DEF(Trk::ElementTable, 247342244, 1)
109
110#endif
macros to associate a CLID to a type
#define CLASS_DEF(NAME, CID, VERSION)
associate a clid and a version to a type eg
@ Material
bool contains(unsigned int Z) const
quick check
void addElement(const Material &mat, const std::string &mname="")
Add material to the Table - if the elment is already filled ignore.
ElementTable()
Empty constructor.
size_t size() const
Print the table size.
void addElement(std::unique_ptr< Material > mat, const std::string &mname)
Version that takes ownership of a pointer.
ElementTable & operator+=(const ElementTable &et)
Adding two tables : add table entries from another table.
ElementTable & operator=(const ElementTable &et)
Assignment operator.
const Material * element(unsigned int Z) const
Get the material.
const std::string & elementName(unsigned int Z) const
Get the element name.
~ElementTable()
Destructor.
ElementTable(const ElementTable &et)
Empty constructor.
std::vector< std::string > m_names
std::vector< Material * > m_table
A common object to be contained by.
Definition Material.h:117
STL class.
Ensure that the ATLAS eigen extensions are properly loaded.
MsgStream & operator<<(MsgStream &sl, const AlignModule &alignModule)
overload of << operator for MsgStream for debug output
STL namespace.
Extra patterns decribing particle interation process.