ATLAS Offline Software
Loading...
Searching...
No Matches
CondAttrListVec.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
17
18#ifndef DBDATAOBJECTS_CONDATTRLISTVEC_H
19#define DBDATAOBJECTS_CONDATTRLISTVEC_H
20
21
22#include "CoralBase/Attribute.h"
23#include "CoralBase/AttributeList.h"
24#include "CoralBase/AttributeListSpecification.h"
28#include "GaudiKernel/DataObject.h"
29
30class CondAttrListVec : public DataObject
31{
32 public:
33 typedef std::pair<unsigned int,coral::AttributeList> AttrListPair;
34 typedef std::vector<AttrListPair> AttrListVec;
35 typedef std::vector<coral::AttributeList>::const_iterator AttrListDataIter;
36 typedef AttrListVec::const_iterator const_iterator;
37 typedef AttrListVec::size_type size_type;
38 typedef std::map<unsigned int,IOVRange> AttrListIOVMap;
39 typedef AttrListIOVMap::const_iterator iov_const_iterator;
40 typedef AttrListIOVMap::size_type iov_size_type;
41 typedef std::map<unsigned int, std::vector<const coral::AttributeList*> >
43
44 struct Index
45 {
47 std::vector<unsigned int> m_indexchan;
48 };
49
50 // constructor with specification of type of time: run/event or timestamp
51 explicit CondAttrListVec(bool runevent);
52 // constructor with specification of type and initial size
53 CondAttrListVec(bool runevent, size_type nelm);
54 // destructor to release specification
56 // copy constructor and assignment operator - have to be explicitly
57 // implemented to control use of the cachced AttributeListSpecification
59 // no copy operator with new Gaudi
61
62 // access to iterate over channel/AttributeList pairs
63 const_iterator begin() const;
64 const_iterator end() const;
65 // number of channel/AttributeList pairs
66 size_type size() const;
67
68 // access to channel/IOVRange map associated with AttributeList data
71 // find IOV associated with channel
72 iov_const_iterator iovRange(const unsigned int channel) const;
73 // number of IOV ranges stored
74 size_type iov_size() const;
75
76 // minimal IOVRange and uniqueness
77 const IOVRange& minRange() const;
78 bool hasUniqueIOV() const;
79
80 // adding new data - specify IOV range, channel and start/end of
81 // AttributeLists
82 void add(const IOVRange& range,const unsigned int chan,
83 AttrListDataIter data_begin,AttrListDataIter data_end);
84
85 // adding new data sliced out of a vector of AttributeLists
86 // specify IOV range, channel, vector and start/end offsets
87 void addSlice(const IOVRange& range,const unsigned int chan,
88 const std::vector<coral::AttributeList>& data,
89 const unsigned int datastart,const unsigned int dataend);
90
91 // add new stop time to minRange - make sure minRange is <=stop
92 void addNewStop(const IOVTime& stop);
93
94 // indexing function - return vector of unique channel IDs
95 const std::vector<unsigned int>& channelIDs() const;
96
97 // return true if a particular channel ID exists in the data
98 bool hasChannel(const int chan) const;
99
100 // return vector of pointers to attribute lists
101 // that are associated with given channel
102 // requesting a channel which does not exist may give an exception
103 const std::vector<const coral::AttributeList*>&
104 attrListVec(const int chan) const;
105
106 private:
107 // hide default constructor - force client to specify type
109
115 coral::AttributeListSpecification* m_spec;
116 // indexing variables
118
119 const Index& index() const;
120};
121
122CLASS_DEF( CondAttrListVec , 55403898 , 1)
123
124#include "AthenaKernel/CondCont.h"
126
127inline CondAttrListVec::CondAttrListVec(bool runevent) :
128 m_minrange(IOVRange(IOVTime(IOVTime::MINRUN, IOVTime::MINEVENT),
129 IOVTime(IOVTime::MAXRUN, IOVTime::MAXEVENT))),
130 m_uniqueiov(true),m_runevent(runevent),m_spec(nullptr) {
133}
134
135inline CondAttrListVec::CondAttrListVec(bool runevent, size_type nelm) :
136 m_minrange(IOVRange(IOVTime(IOVTime::MINRUN, IOVTime::MINEVENT),
137 IOVTime(IOVTime::MAXRUN, IOVTime::MAXEVENT))),
138 m_uniqueiov(true),m_runevent(runevent),m_spec(nullptr) {
141 m_data.reserve(nelm);
142}
143
144
146 if (m_spec) m_spec->release();
147}
148
150 DataObject::DataObject(rhs),
151 m_iovmap(rhs.m_iovmap),
155 m_spec(nullptr)
156{
157 // members with normal semantics setup in initialisation list
158 // make a new cached AttributeListSpecification and make the payload use it
159 if (!rhs.m_data.empty()) {
160 m_spec=new coral::AttributeListSpecification();
161 const coral::AttributeList& atr1=rhs.m_data.begin()->second;
162 for (const auto& attr : atr1) {
163 const coral::AttributeSpecification& aspec=attr.specification();
164 m_spec->extend(aspec.name(),aspec.typeName());
165 }
166 for (const auto& [chan, attrList] : rhs.m_data) {
167 m_data.push_back(AttrListPair(chan,
168 coral::AttributeList(*m_spec,true)));
169 (m_data.back().second).fastCopyData(attrList);
170 }
171 }
172}
173
174// no copy operator with new Gaudi
175// inline CondAttrListVec& CondAttrListVec::operator=(const CondAttrListVec& rhs) {
176// // catch assignment to self - do nothing
177// if (this==&rhs) return *this;
178// // assign base class
179// DataObject::operator=(rhs);
180// // assign members with normal semantics
181// m_iovmap=rhs.m_iovmap;
182// m_minrange=rhs.m_minrange;
183// m_uniqueiov=rhs.m_uniqueiov;
184// m_runevent=rhs.m_runevent;
185// m_indexed=false;
186// // make a new cache AttributeListSpecification and make the payload map
187// // use it
188// if (m_spec!=0) m_spec->release();
189// if (rhs.m_data.size()>0) {
190// m_spec=new coral::AttributeListSpecification();
191// const coral::AttributeList& atr1=rhs.m_data.begin()->second;
192// for (coral::AttributeList::const_iterator itr=atr1.begin();itr!=atr1.end();
193// ++itr) {
194// const coral::AttributeSpecification& aspec=itr->specification();
195// m_spec->extend(aspec.name(),aspec.typeName());
196// }
197// m_data.clear();
198// for (const_iterator itr=rhs.m_data.begin();itr!=rhs.m_data.end();++itr) {
199// m_data.push_back(AttrListPair(itr->first,
200// coral::AttributeList(*m_spec,true)));
201// (m_data.back().second).fastCopyData(itr->second);
202// }
203// } else {
204// m_spec=0;
205// }
206// return *this;
207// }
208
211
214
216{ return m_data.size(); }
217
220
223
225CondAttrListVec::iovRange(const unsigned int channel) const
226{ return m_iovmap.find(channel); }
227
230
232{ return m_minrange; }
233
235{return m_uniqueiov; }
236
237
238inline void CondAttrListVec::add(const IOVRange& range,
239 const unsigned int chan,
240 AttrListDataIter data_begin, AttrListDataIter data_end) {
241 //invalidate index
242 m_index.reset();
243 // set minimum range correctly
244 IOVTime start=m_minrange.start();
245 if (m_minrange.start()<range.start()) start=range.start();
246 IOVTime stop = m_minrange.stop();
247 if (range.stop()<m_minrange.stop()) stop=range.stop();
248 m_minrange=IOVRange(start,stop);
249 if (m_uniqueiov && range!=m_minrange) m_uniqueiov=false;
250 // store attributeList if needed
251 if (!m_spec && data_begin!=data_end) {
252 m_spec=new coral::AttributeListSpecification();
253 for (const auto& attr : *data_begin) {
254 const coral::AttributeSpecification& aspec=attr.specification();
255 m_spec->extend(aspec.name(),aspec.typeName());
256 }
257 }
258 // copy in data
259 for (AttrListDataIter itr=data_begin;itr!=data_end;++itr) {
260 m_data.push_back(AttrListPair(chan,coral::AttributeList(*m_spec,true)));
261 (m_data.back().second).fastCopyData(*itr);
262 }
263 m_iovmap[chan]=range;
264}
265
267 (const IOVRange& range,
268 const unsigned int chan,
269 const std::vector<coral::AttributeList>& data,
270 const unsigned int datastart,const unsigned int dataend)
271{
272 // invalidate index
273 m_index.reset();
274 // set minimum range correctly
275 IOVTime start=m_minrange.start();
276 if (m_minrange.start()<range.start()) start=range.start();
277 IOVTime stop = m_minrange.stop();
278 if (range.stop()<m_minrange.stop()) stop=range.stop();
279 m_minrange=IOVRange(start,stop);
280 if (m_uniqueiov && range!=m_minrange) m_uniqueiov=false;
281 // store attributeList if needed
282 if (!m_spec && datastart!=dataend) {
283 m_spec=new coral::AttributeListSpecification();
284 const coral::AttributeList& atr0=data[datastart];
285 for (const auto& attr : atr0) {
286 const coral::AttributeSpecification& aspec=attr.specification();
287 m_spec->extend(aspec.name(),aspec.typeName());
288 }
289 }
290 // copy in data
291 for (unsigned int i=datastart;i<dataend;++i) {
292 m_data.push_back(AttrListPair(chan,coral::AttributeList(*m_spec,true)));
293 (m_data.back().second).merge(data[i]);
294 }
295 m_iovmap[chan]=range;
296}
297
298inline void CondAttrListVec::addNewStop(const IOVTime& stop) {
299 if (stop<m_minrange.stop()) m_minrange=IOVRange(m_minrange.start(),stop);
300}
301
302inline const std::vector<unsigned int>& CondAttrListVec::channelIDs() const {
303 return index().m_indexchan;
304}
305
306inline bool CondAttrListVec::hasChannel(const int chan) const {
308 return (m.find(chan)!=m.end());
309}
310
311inline const std::vector<const coral::AttributeList*>&
312CondAttrListVec::attrListVec(const int chan) const
313{
315 AttrListCVMap::const_iterator it = m.find (chan);
316 if (it != m.end()) {
317 return it->second;
318 }
319 static const std::vector<const coral::AttributeList*> dum;
320 return dum;
321}
322
323inline
325{
326 if (!m_index.isValid()) {
327 Index index;
328
329 // loop over all the elements, build vector of AttributeList for each channel
330 // and a vector of all the channels
331 for (const AttrListPair& p : m_data) {
332 unsigned int chan=p.first;
333 AttrListCVMap::iterator clist=index.m_indexchanvec.find(chan);
334 if (clist==index.m_indexchanvec.end()) {
335 // channel not seen before, create a new entry in map and vector
336 std::pair<AttrListCVMap::iterator,bool> res=
337 index.m_indexchanvec.insert(AttrListCVMap::value_type(chan,
338 std::vector<const coral::AttributeList*>()));
339 clist=res.first;
340 index.m_indexchan.push_back(chan);
341 }
342 clist->second.push_back(&(p.second));
343 }
344
345 m_index.set (std::move (index));
346 }
347 return *m_index.ptr();
348}
349
350#endif // DBDATAOBJECTS_CONDATTRLISTVEC_H
Cached value with atomic update.
#define CONDCONT_DEF(...)
Definition CondCont.h:1413
macros to associate a CLID to a type
#define CLASS_DEF(NAME, CID, VERSION)
associate a clid and a version to a type eg
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
Validity Range object.
std::pair< std::vector< unsigned int >, bool > res
std::vector< coral::AttributeList >::const_iterator AttrListDataIter
iov_const_iterator iov_begin() const
CxxUtils::CachedValue< Index > m_index
bool hasUniqueIOV() const
AttrListVec::const_iterator const_iterator
void addSlice(const IOVRange &range, const unsigned int chan, const std::vector< coral::AttributeList > &data, const unsigned int datastart, const unsigned int dataend)
AttrListIOVMap::size_type iov_size_type
const_iterator end() const
const_iterator begin() const
size_type size() const
AttrListIOVMap::const_iterator iov_const_iterator
std::map< unsigned int, std::vector< const coral::AttributeList * > > AttrListCVMap
void addNewStop(const IOVTime &stop)
const Index & index() const
std::map< unsigned int, IOVRange > AttrListIOVMap
coral::AttributeListSpecification * m_spec
AttrListIOVMap m_iovmap
AttrListVec::size_type size_type
CondAttrListVec & operator=(const CondAttrListVec &rhs)=delete
iov_const_iterator iovRange(const unsigned int channel) const
const std::vector< unsigned int > & channelIDs() const
std::vector< AttrListPair > AttrListVec
std::pair< unsigned int, coral::AttributeList > AttrListPair
const std::vector< const coral::AttributeList * > & attrListVec(const int chan) const
size_type iov_size() const
bool hasChannel(const int chan) const
CondAttrListVec(bool runevent)
iov_const_iterator iov_end() const
const IOVRange & minRange() const
void add(const IOVRange &range, const unsigned int chan, AttrListDataIter data_begin, AttrListDataIter data_end)
Cached value with atomic update.
Definition CachedValue.h:55
Validity Range object.
Definition IOVRange.h:30
Basic time unit for IOVSvc.
Definition IOVTime.h:33
static constexpr uint64_t MAXTIMESTAMP
Definition IOVTime.h:58
static constexpr uint64_t MINTIMESTAMP
Definition IOVTime.h:56
Definition index.py:1
AttrListCVMap m_indexchanvec
std::vector< unsigned int > m_indexchan