ATLAS Offline Software
FloatArrayStore.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 #ifndef TRTCONDITIONSDATA_FLOATARRAYSTORE_H
6 #define TRTCONDITIONSDATA_FLOATARRAYSTORE_H
7 /********************************************************************
8 
9 NAME: FloatArrayStore
10 PACKAGE: TRT_ConditionsData
11 
12 AUTHORS: Jorgen Beck Hansen, Peter Hansen
13 CREATED: 1/8/05
14 
15 PURPOSE: Access and manipulate an indexed storage
16 
17 ********************************************************************/
18 
19 // INCLUDE HEADER FILES:
20 
21 #include <vector>
22 #include <map>
23 #include <string>
24 #include <functional> //for std::less
25 #include <iosfwd> // fwd declaration for io classes
26 #include <cmath> //std::abs
27 #include "Identifier/Identifier.h"
28 #include "AthenaKernel/CLASS_DEF.h"
29 
35 public:
36 
37  typedef std::less<Identifier> lessp;
38  typedef std::map<Identifier,int,lessp> BufferMap;
39  typedef BufferMap::const_iterator map_citr;
40  typedef std::vector< std::vector<float> > Buffer;
41 
44  FloatArrayStore(const std::string& tag);
46  virtual ~FloatArrayStore();
49 
51  const std::string& tag() const;
53  int numberOfIDs() const;
55  const std::vector<float>& operator[](const Identifier& ident) const;
57  bool sharedID(const Identifier& ident) const;
59  bool existID(const Identifier& ident) const;
61  void dbg() const;
63  map_citr cbegin() const;
64  map_citr cend() const;
65 
67  std::vector<float>& operator[](const Identifier& ident);
69  void share(const Identifier& ident, const Identifier& referenceIdent);
71  void push_back(const Identifier& ident, const std::vector<float>& value);
72  void push_back(const std::vector<Identifier>& identvec, const std::vector<float>& value);
74  void removeID(const Identifier& ident);
76  void clear();
78  void cleanUp();
80  map_citr begin() const;
81  map_citr end() const;
83  const Buffer& buffer() const { return m_buf ; }
84 
85 
86 private:
87 
88  std::string m_tag;
90  Buffer m_buf;
91 
92 };
93 
94 CLASS_DEF(FloatArrayStore,170308771,1)
95 
96 // inline methods
97 inline FloatArrayStore::FloatArrayStore() : m_tag("Undefined") { }
98 
99 inline FloatArrayStore::FloatArrayStore(const std::string& tag) : m_tag(tag) { }
100 
102  if (this!=&other){
103  m_tag=std::move(other.m_tag);
104  m_bufmap = other.m_bufmap;//can't std::move a map, the keys are const
105  m_buf=std::move(other.m_buf);
106  }
107  return *this;
108 }
109 
110 
112 
113 inline void FloatArrayStore::clear() {m_bufmap.clear(); m_buf.clear(); }
114 
116  (const Identifier& ident, const std::vector<float>& value){
117  m_buf.push_back(value);
118  m_bufmap[ident]= m_buf.size()-1;
119 }
120 
121 inline void FloatArrayStore::push_back(const std::vector<Identifier>& identvec, const std::vector<float>& value){
122  m_buf.push_back(value);
123  size_t index = m_buf.size()-1;
124  for(std::vector<Identifier>::const_iterator it = identvec.begin() ; it != identvec.end(); ++it)
125  m_bufmap[*it] = index ;
126 }
127 
129 { return m_bufmap.size(); }
130 
132 { m_bufmap.erase(ident); }
133 
134 inline bool FloatArrayStore::existID(const Identifier& ident) const
135 { return m_bufmap.find(ident)!=m_bufmap.end(); }
136 
137 inline bool FloatArrayStore::sharedID(const Identifier& ident) const { return existID(ident)? m_bufmap.find(ident)->second <0 : false; }
138 
139 inline const std::vector<float>& FloatArrayStore::operator[]
140 (const Identifier& ident) const
141 {return m_buf[std::abs(m_bufmap.find(ident)->second)]; }
142 
143 inline std::vector<float>& FloatArrayStore::operator[](const Identifier& ident)
144  {return m_buf[std::abs(m_bufmap[ident])]; }
145 
147 (const Identifier& ident, const Identifier& referenceIdent) {
148  if (existID(referenceIdent)){
149  m_bufmap[ident] = -std::abs(m_bufmap[referenceIdent]);
150  m_bufmap[referenceIdent] = -std::abs(m_bufmap[referenceIdent]);
151  }
152 }
153 
154 inline const std::string& FloatArrayStore::tag() const {return m_tag;}
155 
157  FloatArrayStore::begin() const { return m_bufmap.begin(); }
158 
160  FloatArrayStore::end() const { return m_bufmap.end(); }
161 
163  FloatArrayStore::cbegin() const { return m_bufmap.begin(); }
164 
166 
167 std::ostream& operator<<(std::ostream& os, const FloatArrayStore& store) ;
168 std::istream& operator>>(std::istream& is, FloatArrayStore& store) ;
169 
170 #endif
FloatArrayStore::m_tag
std::string m_tag
The tag std::string.
Definition: FloatArrayStore.h:98
SGTest::store
TestStore store
Definition: TestStore.cxx:23
FloatArrayStore::cend
map_citr cend() const
Definition: FloatArrayStore.h:165
FloatArrayStore::numberOfIDs
int numberOfIDs() const
Size accessor.
Definition: FloatArrayStore.h:128
Undefined
@ Undefined
Definition: MaterialTypes.h:8
FloatArrayStore::removeID
void removeID(const Identifier &ident)
remove new index
Definition: FloatArrayStore.h:131
FloatArrayStore::begin
map_citr begin() const
begin/end iterators
Definition: FloatArrayStore.h:157
FloatArrayStore::share
void share(const Identifier &ident, const Identifier &referenceIdent)
makes index ident share data with referenceIdent
Definition: FloatArrayStore.h:147
index
Definition: index.py:1
FloatArrayStore::tag
const std::string & tag() const
Tag accessor.
Definition: FloatArrayStore.h:154
skel.it
it
Definition: skel.GENtoEVGEN.py:396
athena.value
value
Definition: athena.py:124
FloatArrayStore::~FloatArrayStore
virtual ~FloatArrayStore()
destructor
Definition: FloatArrayStore.h:111
FloatArrayStore::m_buf
Buffer m_buf
The std::vector<float> stored in each second element.
Definition: FloatArrayStore.h:100
FloatArrayStore::dbg
void dbg() const
print method
Definition: FloatArrayStore.cxx:34
FloatArrayStore::operator=
FloatArrayStore & operator=(FloatArrayStore &&other)
move assignment
Definition: FloatArrayStore.h:101
FloatArrayStore::FloatArrayStore
FloatArrayStore()
constructors, optionally with a tag
Definition: FloatArrayStore.h:97
operator>>
std::istream & operator>>(std::istream &is, FloatArrayStore &store)
Definition: FloatArrayStore.cxx:64
operator<<
std::ostream & operator<<(std::ostream &os, const FloatArrayStore &store)
Definition: FloatArrayStore.cxx:39
FloatArrayStore::buffer
const Buffer & buffer() const
return stored vector
Definition: FloatArrayStore.h:93
FloatArrayStore::operator[]
const std::vector< float > & operator[](const Identifier &ident) const
Overload [] const access.
Definition: FloatArrayStore.h:140
FloatArrayStore::end
map_citr end() const
Definition: FloatArrayStore.h:160
FloatArrayStore::Buffer
std::vector< std::vector< float > > Buffer
Definition: FloatArrayStore.h:50
FloatArrayStore::existID
bool existID(const Identifier &ident) const
returns flag for index existing in the std::map
Definition: FloatArrayStore.h:134
FloatArrayStore::cbegin
map_citr cbegin() const
begin/end const iterators
Definition: FloatArrayStore.h:163
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
FloatArrayStore::lessp
std::less< Identifier > lessp
Definition: FloatArrayStore.h:47
FloatArrayStore::sharedID
bool sharedID(const Identifier &ident) const
returns flag for index sharing data
Definition: FloatArrayStore.h:137
FloatArrayStore::cleanUp
void cleanUp()
remove data with no index pointing to it
Definition: FloatArrayStore.cxx:9
FloatArrayStore::map_citr
BufferMap::const_iterator map_citr
Definition: FloatArrayStore.h:49
Buffer
Definition: trigbs_orderedMerge.cxx:114
FloatArrayStore::BufferMap
std::map< Identifier, int, lessp > BufferMap
Definition: FloatArrayStore.h:48
TRT::Hit::ident
@ ident
Definition: HitInfo.h:77
FloatArrayStore::m_bufmap
BufferMap m_bufmap
The std::map.
Definition: FloatArrayStore.h:99
DeMoScan.index
string index
Definition: DeMoScan.py:364
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
CLASS_DEF
#define CLASS_DEF(NAME, CID, VERSION)
associate a clid and a version to a type eg
Definition: Control/AthenaKernel/AthenaKernel/CLASS_DEF.h:64
FloatArrayStore::clear
void clear()
remove all
Definition: FloatArrayStore.h:113
CaloCondBlobAlgs_fillNoiseFromASCII.tag
string tag
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:24
FloatArrayStore
class FloatArrayStore Access and manipulate an indexed storage of float vectors
Definition: FloatArrayStore.h:34
CLASS_DEF.h
macros to associate a CLID to a type
FloatArrayStore::push_back
void push_back(const Identifier &ident, const std::vector< float > &value)
makes new indices
Definition: FloatArrayStore.h:116
Identifier
Definition: IdentifierFieldParser.cxx:14