ATLAS Offline Software
ArrayStore.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef TRTCONDITIONSDATA_ARRAYSTORE_H
6 #define TRTCONDITIONSDATA_ARRAYSTORE_H
7 /********************************************************************
8 
9 NAME:
10 PACKAGE:
11 
12 AUTHORS: Jorgen Beck Hansen
13 CREATED: 1/8/05
14 
15 PURPOSE: Access and manipulate an indexed storage
16 
17 
18 ********************************************************************/
19 
20 // INCLUDE HEADER FILES:
21 
22 #include <vector>
23 #include <map>
24 #include <string>
25 #include <iostream>
26 
31 template <typename IdType = int, typename StorageType = std::vector<float> >
32 class ArrayStore{
33 public:
34 
35  typedef std::less<IdType> lessp;
36  typedef std::map<IdType,int,lessp> BufferMap;
37  typedef typename BufferMap::const_iterator map_citr;
38  typedef typename BufferMap::iterator map_itr;
39 
42  ArrayStore(const std::string& tag);
44  virtual ~ArrayStore();
45 
47  const std::string& tag() const;
49  int numberOfIDs();
51  const StorageType& operator[](const IdType& ident) const;
53  bool sharedID(const IdType& ident);
55  bool existID(const IdType& ident);
57  void dbg() const;
59  map_citr cbegin() const;
60  map_citr cend() const;
61 
63  StorageType& operator[](const IdType& ident);
65  void share(const IdType& ident, const IdType& referenceIdent);
67  void push_back(const IdType& ident, const StorageType& value);
69  void removeID(const IdType& ident);
71  void clear();
73  void cleanUp();
77 
78 private:
79 
80 std::string m_tag;
82 std::vector<StorageType> m_buf;
83 
84 };
85 
86 // inline methods
87 template <typename IdType, typename StorageType>
88 inline ArrayStore<IdType, StorageType>::ArrayStore() : m_tag("Undefined") { }
89 
90 template <typename IdType, typename StorageType>
91 inline ArrayStore<IdType, StorageType>::ArrayStore(const std::string& tag) : m_tag(tag) { }
92 
93 template <typename IdType, typename StorageType>
95 
96 template <typename IdType, typename StorageType>
97 inline void ArrayStore<IdType, StorageType>::clear() {m_bufmap.clear(); m_buf.clear(); }
98 
99 template <typename IdType, typename StorageType>
100 inline void ArrayStore<IdType, StorageType>::push_back(const IdType& ident, const StorageType& value){
101  m_buf.push_back(value);
102  m_bufmap[ident]= m_buf.size()-1;
103 }
104 
105 template <typename IdType, typename StorageType>
106 inline int ArrayStore<IdType, StorageType>::numberOfIDs() { return m_bufmap.size(); }
107 
108 template <typename IdType, typename StorageType>
109 inline void ArrayStore<IdType, StorageType>::removeID(const IdType& ident) { m_bufmap.erase(ident); }
110 
111 template <typename IdType, typename StorageType>
112 inline bool ArrayStore<IdType, StorageType>::existID(const IdType& ident) { return m_bufmap.find(ident)!=m_bufmap.end(); }
113 
114 template <typename IdType, typename StorageType>
115 inline bool ArrayStore<IdType, StorageType>::sharedID(const IdType& ident) { return existID(ident)? m_bufmap.find(ident)->second <0 : false; }
116 
117 template <typename IdType, typename StorageType>
118 inline void ArrayStore<IdType, StorageType>::dbg() const {std::cout << "dbg:" << m_bufmap.size() << " " << m_buf.size() << std::endl;}
119 
120 template <typename IdType, typename StorageType>
121 inline const StorageType& ArrayStore<IdType, StorageType>::operator[](const IdType& ident) const {return m_buf[std::abs(m_bufmap.find(ident)->second)]; }
122 
123 template <typename IdType, typename StorageType>
124 inline StorageType& ArrayStore<IdType, StorageType>::operator[](const IdType& ident) {return m_buf[std::abs(m_bufmap[ident])]; }
125 
126 template <typename IdType, typename StorageType>
127 inline void ArrayStore<IdType, StorageType>::share(const IdType& ident, const IdType& referenceIdent) {
128  if (existID(referenceIdent)){
129  m_bufmap[ident] = -std::abs(m_bufmap[referenceIdent]);
130  m_bufmap[referenceIdent] = -std::abs(m_bufmap[referenceIdent]);
131  }
132 }
133 
134 template <typename IdType, typename StorageType>
135 inline const std::string& ArrayStore<IdType, StorageType>::tag() const {return m_tag;}
136 
137 template <typename IdType, typename StorageType>
139 
140 template <typename IdType, typename StorageType>
142 
143 template <typename IdType, typename StorageType>
144 inline typename ArrayStore<IdType, StorageType>::map_citr ArrayStore<IdType, StorageType>::cbegin() const { return m_bufmap.begin(); }
145 
146 template <typename IdType, typename StorageType>
148 
149 #ifndef TRTCONDITIONSDATA_ARRAYSTORE_ICC
150 #define TRTCONDITIONSDATA_ARRAYSTORE_ICC
151 
152 template <typename IdType, typename StorageType>
154  std::multimap<int,IdType> indexmap;
155 
156  map_citr itr=m_bufmap.begin();
157  for (;itr!=m_bufmap.end();++itr)
158  indexmap.insert(std::pair<int,IdType>(std::abs(itr->second),itr->first));
159  std::vector<StorageType> tmp(m_buf);
160  dbg();
161  this->clear();
162  int i(-tmp.size());
163  for (;i<(int)tmp.size();i++){
164  bool first(true);
165  IdType shared_id;
167  for ( pos=indexmap.lower_bound(i); pos!=indexmap.upper_bound(i); ++pos){
168  if (first){
169  first=false;
170  shared_id=pos->second;
171  this->push_back(shared_id,tmp[std::abs(i)]);
172  } else
173  this->share(pos->second,shared_id);
174  }
175  }
176 }
177 #endif
178 
179 #endif
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
ArrayStore::map_citr
BufferMap::const_iterator map_citr
Definition: ArrayStore.h:37
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
ArrayStore::dbg
void dbg() const
print method
Definition: ArrayStore.h:118
ArrayStore::removeID
void removeID(const IdType &ident)
remove index
Definition: ArrayStore.h:109
ArrayStore::end
map_itr end()
Definition: ArrayStore.h:141
ArrayStore::share
void share(const IdType &ident, const IdType &referenceIdent)
makes index ident share data with referenceIdent
Definition: ArrayStore.h:127
ArrayStore::tag
const std::string & tag() const
Tag accessor.
Definition: ArrayStore.h:135
athena.value
value
Definition: athena.py:124
ArrayStore
Definition: ArrayStore.h:32
ArrayStore::~ArrayStore
virtual ~ArrayStore()
destructor
Definition: ArrayStore.h:94
ArrayStore::numberOfIDs
int numberOfIDs()
Size accessor.
Definition: ArrayStore.h:106
ArrayStore::push_back
void push_back(const IdType &ident, const StorageType &value)
makes new index
Definition: ArrayStore.h:100
ArrayStore::map_itr
BufferMap::iterator map_itr
Definition: ArrayStore.h:38
SH::Meta::dbg
std::string dbg(const Meta &obj, unsigned verbosity=0)
the debugging info of this object
Definition: Meta.cxx:28
ArrayStore::lessp
std::less< IdType > lessp
Definition: ArrayStore.h:35
ArrayStore::existID
bool existID(const IdType &ident)
returns flag for index existing in the std::map
Definition: ArrayStore.h:112
ArrayStore::cbegin
map_citr cbegin() const
begin/end const iterators
Definition: ArrayStore.h:144
ArrayStore::ArrayStore
ArrayStore(const std::string &tag)
Definition: ArrayStore.h:91
ArrayStore::operator[]
const StorageType & operator[](const IdType &ident) const
Overload [] const access.
Definition: ArrayStore.h:121
ArrayStore::operator[]
StorageType & operator[](const IdType &ident)
Overload [] modifier.
Definition: ArrayStore.h:124
lumiFormat.i
int i
Definition: lumiFormat.py:85
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
ArrayStore::ArrayStore
ArrayStore()
constructors, optionally with a tag
Definition: ArrayStore.h:88
ArrayStore::cend
map_citr cend() const
Definition: ArrayStore.h:147
ArrayStore::m_tag
std::string m_tag
The tag std::string.
Definition: ArrayStore.h:80
ArrayStore::clear
void clear()
remove all indices
Definition: ArrayStore.h:97
ArrayStore::m_bufmap
BufferMap m_bufmap
The std::map.
Definition: ArrayStore.h:81
ArrayStore::m_buf
std::vector< StorageType > m_buf
The object stored in each second element.
Definition: ArrayStore.h:82
TRT::Hit::ident
@ ident
Definition: HitInfo.h:77
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
ArrayStore::cleanUp
void cleanUp()
remove data with no index pointing to it
Definition: ArrayStore.h:153
VKalVrtAthena::varHolder_detail::clear
void clear(T &var)
Definition: NtupleVars.h:48
ArrayStore::sharedID
bool sharedID(const IdType &ident)
returns flag for index sharing data
Definition: ArrayStore.h:115
ArrayStore::BufferMap
std::map< IdType, int, lessp > BufferMap
Definition: ArrayStore.h:36
DeMoScan.first
bool first
Definition: DeMoScan.py:536
CaloCondBlobAlgs_fillNoiseFromASCII.tag
string tag
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:24
ArrayStore::begin
map_itr begin()
begin/end iterators
Definition: ArrayStore.h:138