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 {
34 public:
35  //
36  // additional typedef
37  typedef T base_value_type;
38  typedef std::vector<T> CONT;
39  typedef typename CONT::value_type value_type;
40  typedef typename CONT::pointer pointer;
41  typedef typename CONT::const_pointer const_pointer;
42  typedef typename CONT::iterator iterator;
43  typedef typename CONT::const_iterator const_iterator;
44  typedef typename CONT::reference reference;
45  typedef typename CONT::const_reference const_reference;
46  typedef typename CONT::size_type size_type;
47  typedef typename CONT::difference_type difference_type;
48  //
49  // default constructor for rootcint
50 #ifdef __CINT__
51  AtlasHitsVector( ) {}
52  //
53  // methods not provided to rootcint
54 #else
55  AtlasHitsVector(const std::string& collectionName="DefaultCollectionName", const unsigned int mySize=100)
56  {
57  IMessageSvc* msgSvc(Athena::getMessageSvc());
58  MsgStream log(msgSvc, "AtlasHitsVector");
59  log << MSG::DEBUG << " initialized AtlasHitVector " << collectionName << endmsg;
60 
61  m_name = collectionName;
62  m_hitvector.reserve(mySize);
63  }
64 
65  ~AtlasHitsVector () =default;
66 
67  void Clear()
68  {
69  m_hitvector.clear();
70  std::vector<T>().swap(m_hitvector);
71  }
72 
73  void Insert(const T& h)
74  {
75  m_hitvector.push_back(h);
76  }
77  void Insert(T&& h)
78  {
79  m_hitvector.push_back( std::move(h) );
80  }
81  template <class... Args> void Emplace(Args&&... args)
82  {
83  m_hitvector.emplace_back( std::forward<Args>(args)... );
84  }
85  int Size() const
86  {
87  return size();
88  }
89 #endif // __CINT__
90 
91  explicit AtlasHitsVector(const AtlasHitsVector<T>& rhs)
92  : m_hitvector(rhs.m_hitvector) {}
93 
94  AtlasHitsVector(AtlasHitsVector<T>&& rhs) noexcept = default;
95 
96  // Conversion
97  explicit AtlasHitsVector(const AthenaHitsVector<T>& rhs) {
98  m_hitvector.reserve(rhs.Size());
99  typename AthenaHitsVector<T>::const_iterator i(rhs.begin()), e(rhs.end());
100  while (i != e) {m_hitvector.push_back( T( (**i) ) ); ++i;}
101  }
102 
104  if (this != &rhs) {
106  }
107  return *this;
108  }
109 
110  AtlasHitsVector<T>& operator=(AtlasHitsVector<T>&& rhs) noexcept = default;
111 
113  // Assignment from the AthenaHitsVector form
115  this->Clear();
116  m_hitvector.reserve(rhs.Size());
117  typename AthenaHitsVector<T>::const_iterator i(rhs.begin()), e(rhs.end());
118  while (i != e) {m_hitvector.push_back( T( (**i) ) ); ++i;}
119  return *this;
120  }
121 
122  const std::string& Name() const {return m_name;}
123 
124  void setName(const std::string& name) {m_name = name;}
125  //
126  // vector methods.
127  const std::vector<T>& getVector() const {return m_hitvector;}
128 
129  bool empty() const { return m_hitvector.empty(); }
130 
132  { return m_hitvector.begin(); }
133 
135  { return m_hitvector.end(); }
136 
138  { return m_hitvector.begin(); }
139 
141  { return m_hitvector.end(); }
142 
143  size_type size() const { return m_hitvector.size(); }
144 
145  void push_back(const T& t ) { m_hitvector.push_back(t);}
146 
147  T At(unsigned int pos) const {
148  return m_hitvector.at(pos);
149  }
150 
151  const T operator[] (size_type n) const {return m_hitvector[n];}
152 
153  void clear() {
154  m_hitvector.clear();
155  std::vector<T>().swap(m_hitvector);
156  }
157 
158  void reserve (size_type n) { m_hitvector.reserve (n); }
159 
160  void resize (size_type n) { m_hitvector.resize (n); }
161 
162 
163 protected:
164  std::string m_name;
165  std::vector<T> m_hitvector;
166 
167 
168 public:
169  // Used to ensure that the DVLInfo gets registered
170  // when the dictionary for this class is loaded.
171  static const std::type_info* initHelper()
173  static const std::type_info* const s_info;
174 };
175 
176 
185 template <class T>
186 void dvl_makecontainer (size_t nreserve, AtlasHitsVector<T>*& cont)
187 {
188  cont = new AtlasHitsVector<T> ("", nreserve);
189 }
190 
191 
192 // Ensure that the DVLInfo gets registered
193 // when the dictionary for this class is loaded.
194 template <class T>
195 const std::type_info* const AtlasHitsVector<T>::s_info = AtlasHitsVector<T>::initHelper();
196 
197 
198 #endif
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
AtlasHitsVector::begin
iterator begin()
Definition: AtlasHitsVector.h:137
AtlasHitsVector::getVector
const std::vector< T > & getVector() const
Definition: AtlasHitsVector.h:127
AtlasHitsVector::operator[]
const T operator[](size_type n) const
Definition: AtlasHitsVector.h:151
AthenaHitsVector.h
AtlasHitsVector::setName
void setName(const std::string &name)
Definition: AtlasHitsVector.h:124
AtlasHitsVector::Insert
void Insert(const T &h)
Definition: AtlasHitsVector.h:73
getMessageSvc.h
singleton-like access to IMessageSvc via open function and helper
AtlasHitsVector::AtlasHitsVector
AtlasHitsVector(const std::string &collectionName="DefaultCollectionName", const unsigned int mySize=100)
Definition: AtlasHitsVector.h:55
AtlasHitsVector::s_info
static const std::type_info *const s_info
Definition: AtlasHitsVector.h:173
AtlasHitsVector::AtlasHitsVector
AtlasHitsVector(const AthenaHitsVector< T > &rhs)
Definition: AtlasHitsVector.h:97
AtlasHitsVector::difference_type
CONT::difference_type difference_type
Definition: AtlasHitsVector.h:47
AtlasHitsVector::const_reference
CONT::const_reference const_reference
Definition: AtlasHitsVector.h:45
AtlasHitsVector::iterator
CONT::iterator iterator
Definition: AtlasHitsVector.h:42
AtlasHitsVector
Definition: AtlasHitsVector.h:33
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:186
AtlasHitsVector::operator=
AtlasHitsVector< T > & operator=(const AtlasHitsVector< T > &rhs)
Definition: AtlasHitsVector.h:103
DVLInfo.h
Holder to implement conversion copies for DataVector/DataList.
AtlasHitsVector::reserve
void reserve(size_type n)
Definition: AtlasHitsVector.h:158
AtlasHitsVector::Size
int Size() const
Definition: AtlasHitsVector.h:85
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
Args
Definition: test_lwtnn_fastgraph.cxx:12
AtlasHitsVector::initHelper
static const std::type_info * initHelper()
Definition: AtlasHitsVector.h:171
AtlasHitsVector::resize
void resize(size_type n)
Definition: AtlasHitsVector.h:160
AtlasHitsVector::begin
const_iterator begin() const
Definition: AtlasHitsVector.h:131
AtlasHitsVector::CONT
std::vector< T > CONT
Definition: AtlasHitsVector.h:38
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
AtlasHitsVector::const_iterator
CONT::const_iterator const_iterator
Definition: AtlasHitsVector.h:43
AtlasHitsVector::clear
void clear()
Definition: AtlasHitsVector.h:153
AthenaHitsVector::const_iterator
boost::transform_iterator< make_const, typename CONT::const_iterator > const_iterator
Definition: AthenaHitsVector.h:58
AtlasHitsVector::empty
bool empty() const
Definition: AtlasHitsVector.h:129
AtlasHitsVector::AtlasHitsVector
AtlasHitsVector(const AtlasHitsVector< T > &rhs)
Definition: AtlasHitsVector.h:91
AtlasHitsVector::Emplace
void Emplace(Args &&... args)
Definition: AtlasHitsVector.h:81
AtlasHitsVector::const_pointer
CONT::const_pointer const_pointer
Definition: AtlasHitsVector.h:41
AtlasHitsVector::value_type
CONT::value_type value_type
Definition: AtlasHitsVector.h:39
AtlasHitsVector::m_name
std::string m_name
Definition: AtlasHitsVector.h:164
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:731
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
AtlasHitsVector::Name
const std::string & Name() const
Definition: AtlasHitsVector.h:122
AtlasHitsVector::pointer
CONT::pointer pointer
Definition: AtlasHitsVector.h:40
AtlasHitsVector::base_value_type
T base_value_type
Definition: AtlasHitsVector.h:37
AtlasHitsVector::operator=
AtlasHitsVector< T > & operator=(AtlasHitsVector< T > &&rhs) noexcept=default
AtlasHitsVector::reference
CONT::reference reference
Definition: AtlasHitsVector.h:44
AtlasHitsVector::At
T At(unsigned int pos) const
Definition: AtlasHitsVector.h:147
AtlasHitsVector::end
iterator end()
Definition: AtlasHitsVector.h:140
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
AtlasHitsVector::Clear
void Clear()
Definition: AtlasHitsVector.h:67
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
h
AthenaHitsVector::Size
int Size() const
Definition: AthenaHitsVector.h:96
AtlasHitsVector::end
const_iterator end() const
Definition: AtlasHitsVector.h:134
DEBUG
#define DEBUG
Definition: page_access.h:11
dq_make_web_display.reference
reference
Definition: dq_make_web_display.py:44
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
AtlasHitsVector::size
size_type size() const
Definition: AtlasHitsVector.h:143
AtlasHitsVector::m_hitvector
std::vector< T > m_hitvector
Definition: AtlasHitsVector.h:165
AthenaHitsVector::end
const_iterator end() const
Definition: AthenaHitsVector.h:143
AtlasHitsVector::operator=
AtlasHitsVector< T > & operator=(const AthenaHitsVector< T > &rhs)
assignment deletes old elements and deep copies the new ones
Definition: AtlasHitsVector.h:114
AthenaHitsVector
Definition: AthenaHitsVector.h:39
AtlasHitsVector::~AtlasHitsVector
~AtlasHitsVector()=default
DataModel_detail::DVLInfo
Definition: DVLInfo.h:237
AtlasHitsVector::size_type
CONT::size_type size_type
Definition: AtlasHitsVector.h:46
AtlasHitsVector::Insert
void Insert(T &&h)
Definition: AtlasHitsVector.h:77
python.CaloScaleNoiseConfig.args
args
Definition: CaloScaleNoiseConfig.py:80
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35
AthenaHitsVector::begin
const_iterator begin() const
Definition: AthenaHitsVector.h:139
AtlasHitsVector::push_back
void push_back(const T &t)
Definition: AtlasHitsVector.h:145