ATLAS Offline Software
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 //
31 template <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 
90  explicit AtlasHitsVector(const AtlasHitsVector<T>& rhs)
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 
109  AtlasHitsVector<T>& operator=(AtlasHitsVector<T>&& rhs) noexcept = default;
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 
162 protected:
163  std::string m_name;
164  std::vector<T> m_hitvector;
165 
166 
167 public:
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 
183 template <class T>
184 void 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.
192 template <class T>
193 const std::type_info* const AtlasHitsVector<T>::s_info = AtlasHitsVector<T>::initHelper();
194 
195 
196 #endif
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
AtlasHitsVector::begin
iterator begin()
Definition: AtlasHitsVector.h:136
AtlasHitsVector::getVector
const std::vector< T > & getVector() const
Definition: AtlasHitsVector.h:126
AtlasHitsVector::operator[]
const T operator[](size_type n) const
Definition: AtlasHitsVector.h:150
AthenaHitsVector.h
AtlasHitsVector::setName
void setName(const std::string &name)
Definition: AtlasHitsVector.h:123
AtlasHitsVector::Insert
void Insert(const T &h)
Definition: AtlasHitsVector.h:72
HitsVectorBase
Definition: AthenaHitsVector.h:38
getMessageSvc.h
singleton-like access to IMessageSvc via open function and helper
python.CaloAddPedShiftConfig.args
args
Definition: CaloAddPedShiftConfig.py:47
AtlasHitsVector::AtlasHitsVector
AtlasHitsVector(const std::string &collectionName="DefaultCollectionName", const unsigned int mySize=100)
Definition: AtlasHitsVector.h:54
AtlasHitsVector::s_info
static const std::type_info *const s_info
Definition: AtlasHitsVector.h:172
AtlasHitsVector::AtlasHitsVector
AtlasHitsVector(const AthenaHitsVector< T > &rhs)
Definition: AtlasHitsVector.h:96
AtlasHitsVector::difference_type
CONT::difference_type difference_type
Definition: AtlasHitsVector.h:46
AtlasHitsVector::const_reference
CONT::const_reference const_reference
Definition: AtlasHitsVector.h:44
AtlasHitsVector::iterator
CONT::iterator iterator
Definition: AtlasHitsVector.h:41
AtlasHitsVector
Definition: AtlasHitsVector.h:32
AtlasHitsVector::AtlasHitsVector
AtlasHitsVector(AtlasHitsVector< T > &&rhs) noexcept=default
dvl_makecontainer
void dvl_makecontainer(size_t nreserve, AtlasHitsVector< T > *&cont)
Construct a new container.
Definition: AtlasHitsVector.h:184
AtlasHitsVector::operator=
AtlasHitsVector< T > & operator=(const AtlasHitsVector< T > &rhs)
Definition: AtlasHitsVector.h:102
DVLInfo.h
Holder to implement conversion copies for DataVector/DataList.
AtlasHitsVector::reserve
void reserve(size_type n)
Definition: AtlasHitsVector.h:157
AtlasHitsVector::Size
int Size() const
Definition: AtlasHitsVector.h:84
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
AtlasHitsVector::~AtlasHitsVector
~AtlasHitsVector() override=default
Args
Definition: test_lwtnn_fastgraph.cxx:12
AtlasHitsVector::initHelper
static const std::type_info * initHelper()
Definition: AtlasHitsVector.h:170
AtlasHitsVector::resize
void resize(size_type n)
Definition: AtlasHitsVector.h:159
AtlasHitsVector::begin
const_iterator begin() const
Definition: AtlasHitsVector.h:130
AtlasHitsVector::CONT
std::vector< T > CONT
Definition: AtlasHitsVector.h:37
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
AtlasHitsVector::const_iterator
CONT::const_iterator const_iterator
Definition: AtlasHitsVector.h:42
AtlasHitsVector::clear
void clear()
Definition: AtlasHitsVector.h:152
AthenaHitsVector::const_iterator
boost::transform_iterator< make_const, typename CONT::const_iterator > const_iterator
Definition: AthenaHitsVector.h:67
AtlasHitsVector::empty
bool empty() const
Definition: AtlasHitsVector.h:128
AtlasHitsVector::AtlasHitsVector
AtlasHitsVector(const AtlasHitsVector< T > &rhs)
Definition: AtlasHitsVector.h:90
AtlasHitsVector::Emplace
void Emplace(Args &&... args)
Definition: AtlasHitsVector.h:80
AtlasHitsVector::const_pointer
CONT::const_pointer const_pointer
Definition: AtlasHitsVector.h:40
AtlasHitsVector::value_type
CONT::value_type value_type
Definition: AtlasHitsVector.h:38
AtlasHitsVector::m_name
std::string m_name
Definition: AtlasHitsVector.h:163
StdJOSetup.msgSvc
msgSvc
Provide convenience handles for various services.
Definition: StdJOSetup.py:36
lumiFormat.i
int i
Definition: lumiFormat.py:85
beamspotman.n
n
Definition: beamspotman.py:727
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
AtlasHitsVector::Name
const std::string & Name() const
Definition: AtlasHitsVector.h:121
AtlasHitsVector::pointer
CONT::pointer pointer
Definition: AtlasHitsVector.h:39
AtlasHitsVector::base_value_type
T base_value_type
Definition: AtlasHitsVector.h:36
AtlasHitsVector::operator=
AtlasHitsVector< T > & operator=(AtlasHitsVector< T > &&rhs) noexcept=default
AtlasHitsVector::reference
CONT::reference reference
Definition: AtlasHitsVector.h:43
AtlasHitsVector::At
T At(unsigned int pos) const
Definition: AtlasHitsVector.h:146
AtlasHitsVector::end
iterator end()
Definition: AtlasHitsVector.h:139
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
AtlasHitsVector::Clear
void Clear()
Definition: AtlasHitsVector.h:66
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:16
h
AthenaHitsVector::Size
int Size() const
Definition: AthenaHitsVector.h:105
AtlasHitsVector::end
const_iterator end() const
Definition: AtlasHitsVector.h:133
DEBUG
#define DEBUG
Definition: page_access.h:11
dq_make_web_display.reference
reference
Definition: dq_make_web_display.py:43
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
AtlasHitsVector::size
size_type size() const
Definition: AtlasHitsVector.h:142
AtlasHitsVector::m_hitvector
std::vector< T > m_hitvector
Definition: AtlasHitsVector.h:164
AthenaHitsVector::end
const_iterator end() const
Definition: AthenaHitsVector.h:152
AtlasHitsVector::operator=
AtlasHitsVector< T > & operator=(const AthenaHitsVector< T > &rhs)
assignment deletes old elements and deep copies the new ones
Definition: AtlasHitsVector.h:113
AthenaHitsVector
Definition: AthenaHitsVector.h:48
DataModel_detail::DVLInfo
Definition: DVLInfo.h:237
AtlasHitsVector::size_type
CONT::size_type size_type
Definition: AtlasHitsVector.h:45
AtlasHitsVector::Insert
void Insert(T &&h)
Definition: AtlasHitsVector.h:76
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35
AthenaHitsVector::begin
const_iterator begin() const
Definition: AthenaHitsVector.h:148
AtlasHitsVector::push_back
void push_back(const T &t)
Definition: AtlasHitsVector.h:144