ATLAS Offline Software
Loading...
Searching...
No Matches
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
9NAME: FloatArrayStore
10PACKAGE: TRT_ConditionsData
11
12AUTHORS: Jorgen Beck Hansen, Peter Hansen
13CREATED: 1/8/05
14
15PURPOSE: 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"
29
35public:
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
86private:
87
88 std::string m_tag;
91
92};
93
94CLASS_DEF(FloatArrayStore,170308771,1)
95
96// inline methods
97inline FloatArrayStore::FloatArrayStore() : m_tag("Undefined") { }
98
99inline 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
113inline 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
121inline 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
131inline void FloatArrayStore::removeID(const Identifier& ident)
132{ m_bufmap.erase(ident); }
133
134inline bool FloatArrayStore::existID(const Identifier& ident) const
135{ return m_bufmap.find(ident)!=m_bufmap.end(); }
136
137inline bool FloatArrayStore::sharedID(const Identifier& ident) const { return existID(ident)? m_bufmap.find(ident)->second <0 : false; }
138
139inline const std::vector<float>& FloatArrayStore::operator[]
140(const Identifier& ident) const
141{return m_buf[std::abs(m_bufmap.find(ident)->second)]; }
142
143inline 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
154inline 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
167std::ostream& operator<<(std::ostream& os, const FloatArrayStore& store) ;
168std::istream& operator>>(std::istream& is, FloatArrayStore& store) ;
169
170#endif
macros to associate a CLID to a type
#define CLASS_DEF(NAME, CID, VERSION)
associate a clid and a version to a type eg
std::ostream & operator<<(std::ostream &os, const FloatArrayStore &store)
std::istream & operator>>(std::istream &is, FloatArrayStore &store)
class FloatArrayStore Access and manipulate an indexed storage of float vectors
bool sharedID(const Identifier &ident) const
returns flag for index sharing data
const Buffer & buffer() const
return stored vector
map_citr cbegin() const
begin/end const iterators
int numberOfIDs() const
Size accessor.
void cleanUp()
remove data with no index pointing to it
FloatArrayStore & operator=(FloatArrayStore &&other)
move assignment
std::vector< std::vector< float > > Buffer
const std::vector< float > & operator[](const Identifier &ident) const
Overload [] const access.
void share(const Identifier &ident, const Identifier &referenceIdent)
makes index ident share data with referenceIdent
BufferMap::const_iterator map_citr
std::string m_tag
The tag std::string.
void clear()
remove all
BufferMap m_bufmap
The std::map.
map_citr begin() const
begin/end iterators
std::map< Identifier, int, lessp > BufferMap
FloatArrayStore()
constructors, optionally with a tag
bool existID(const Identifier &ident) const
returns flag for index existing in the std::map
void push_back(const Identifier &ident, const std::vector< float > &value)
makes new indices
map_citr end() const
void removeID(const Identifier &ident)
remove new index
virtual ~FloatArrayStore()
destructor
map_citr cend() const
void dbg() const
print method
std::less< Identifier > lessp
const std::string & tag() const
Tag accessor.
Buffer m_buf
The std::vector<float> stored in each second element.
Definition index.py:1