ATLAS Offline Software
Loading...
Searching...
No Matches
AtlasHitsVector.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3*/
4
5//
6// Templated class for the Hit collections in athena
7// There is a bunch of ifdef __CINT__ to make this class
8// intelligible to AthenaRoot and work out a persistency mechanism
9//
10
11
12#ifndef AtlasHitsVector_H
13#define AtlasHitsVector_H
14//
15//
16// vector class
17#include <vector>
20
21//
22// Gaudi includes, not provided to rootcint
23#ifndef __CINT__
24#include "GaudiKernel/ISvcLocator.h"
26#include "GaudiKernel/MsgStream.h"
27#include "GaudiKernel/IMessageSvc.h"
28#endif
29
30//
31template <typename T>
33 public:
34 //
35 // additional typedef
36 typedef T base_value_type;
37 typedef std::vector<T> CONT;
38 typedef typename CONT::value_type value_type;
39 typedef typename CONT::pointer pointer;
40 typedef typename CONT::const_pointer const_pointer;
41 typedef typename CONT::iterator iterator;
42 typedef typename CONT::const_iterator const_iterator;
43 typedef typename CONT::reference reference;
44 typedef typename CONT::const_reference const_reference;
45 typedef typename CONT::size_type size_type;
46 typedef typename CONT::difference_type difference_type;
47 //
48 // default constructor for rootcint
49#ifdef __CINT__
50 AtlasHitsVector( ) {}
51 //
52 // methods not provided to rootcint
53#else
54 AtlasHitsVector(const std::string& collectionName="DefaultCollectionName", const unsigned int mySize=100)
55 {
56 IMessageSvc* msgSvc(Athena::getMessageSvc());
57 MsgStream log(msgSvc, "AtlasHitsVector");
58 log << MSG::DEBUG << " initialized AtlasHitVector " << collectionName << endmsg;
59
60 m_name = collectionName;
61 m_hitvector.reserve(mySize);
62 }
63
64 ~AtlasHitsVector() override = default;
65
66 void Clear()
67 {
68 m_hitvector.clear();
69 std::vector<T>().swap(m_hitvector);
70 }
71
72 void Insert(const T& h)
73 {
74 m_hitvector.push_back(h);
75 }
76 void Insert(T&& h)
77 {
78 m_hitvector.push_back( std::move(h) );
79 }
80 template <class... Args> void Emplace(Args&&... args)
81 {
82 m_hitvector.emplace_back( std::forward<Args>(args)... );
83 }
84 int Size() const
85 {
86 return size();
87 }
88#endif // __CINT__
89
91 : m_hitvector(rhs.m_hitvector) {}
92
93 AtlasHitsVector(AtlasHitsVector<T>&& rhs) noexcept = default;
94
95 // Conversion
96 explicit AtlasHitsVector(const AthenaHitsVector<T>& rhs) {
97 m_hitvector.reserve(rhs.Size());
98 typename AthenaHitsVector<T>::const_iterator i(rhs.begin()), e(rhs.end());
99 while (i != e) {m_hitvector.push_back( T( (**i) ) ); ++i;}
100 }
101
103 if (this != &rhs) {
105 }
106 return *this;
107 }
108
110
112 // Assignment from the AthenaHitsVector form
114 this->Clear();
115 m_hitvector.reserve(rhs.Size());
116 typename AthenaHitsVector<T>::const_iterator i(rhs.begin()), e(rhs.end());
117 while (i != e) {m_hitvector.push_back( T( (**i) ) ); ++i;}
118 return *this;
119 }
120
121 const std::string& Name() const {return m_name;}
122
123 void setName(const std::string& name) {m_name = name;}
124 //
125 // vector methods.
126 const std::vector<T>& getVector() const {return m_hitvector;}
127
128 bool empty() const { return m_hitvector.empty(); }
129
131 { return m_hitvector.begin(); }
132
134 { return m_hitvector.end(); }
135
137 { return m_hitvector.begin(); }
138
140 { return m_hitvector.end(); }
141
142 size_type size() const { return m_hitvector.size(); }
143
144 void push_back(const T& t ) { m_hitvector.push_back(t);}
145
146 T At(unsigned int pos) const {
147 return m_hitvector.at(pos);
148 }
149
150 const T operator[] (size_type n) const {return m_hitvector[n];}
151
152 void clear() {
153 m_hitvector.clear();
154 std::vector<T>().swap(m_hitvector);
155 }
156
157 void reserve (size_type n) { m_hitvector.reserve (n); }
158
159 void resize (size_type n) { m_hitvector.resize (n); }
160
161
162protected:
163 std::string m_name;
164 std::vector<T> m_hitvector;
165
166
167public:
168 // Used to ensure that the DVLInfo gets registered
169 // when the dictionary for this class is loaded.
170 static const std::type_info* initHelper()
172 static const std::type_info* const s_info;
173};
174
183template <class T>
184void dvl_makecontainer (size_t nreserve, AtlasHitsVector<T>*& cont)
185{
186 cont = new AtlasHitsVector<T> ("", nreserve);
187}
188
189
190// Ensure that the DVLInfo gets registered
191// when the dictionary for this class is loaded.
192template <class T>
194
195
196#endif
#define endmsg
void dvl_makecontainer(size_t nreserve, AtlasHitsVector< T > *&cont)
Construct a new container.
Holder to implement conversion copies for DataVector/DataList.
Header file for AthHistogramAlgorithm.
boost::transform_iterator< make_const, typename CONT::const_iterator > const_iterator
const_iterator end() const
const_iterator begin() const
std::vector< AFP_SiDigi > m_hitvector
AtlasHitsVector(const AthenaHitsVector< T > &rhs)
CONT::const_pointer const_pointer
std::vector< AFP_SiDigi > CONT
const T operator[](size_type n) const
bool empty() const
void Insert(const T &h)
AtlasHitsVector(const std::string &collectionName="DefaultCollectionName", const unsigned int mySize=100)
AtlasHitsVector(AtlasHitsVector< T > &&rhs) noexcept=default
CONT::const_iterator const_iterator
void push_back(const T &t)
CONT::difference_type difference_type
AtlasHitsVector< T > & operator=(const AthenaHitsVector< T > &rhs)
assignment deletes old elements and deep copies the new ones
CONT::const_reference const_reference
~AtlasHitsVector() override=default
void Insert(T &&h)
void setName(const std::string &name)
const_iterator begin() const
AtlasHitsVector< T > & operator=(AtlasHitsVector< T > &&rhs) noexcept=default
AtlasHitsVector(const AtlasHitsVector< T > &rhs)
void resize(size_type n)
static const std::type_info *const s_info
void Emplace(Args &&... args)
void reserve(size_type n)
size_type size() const
const_iterator end() const
const std::string & Name() const
AtlasHitsVector< T > & operator=(const AtlasHitsVector< T > &rhs)
const std::vector< T > & getVector() const
T At(unsigned int pos) const
static const std::type_info * initHelper()
singleton-like access to IMessageSvc via open function and helper
IMessageSvc * getMessageSvc(bool quiet=false)