ATLAS Offline Software
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 
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"
25 #include "AthenaKernel/IOVRange.h"
26 #include "AthenaKernel/CLASS_DEF.h"
27 #include "CxxUtils/CachedValue.h"
28 #include "GaudiKernel/DataObject.h"
29 
30 class 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
58  CondAttrListVec(const CondAttrListVec& rhs);
59  // no copy operator with new Gaudi
60  CondAttrListVec& operator=(const CondAttrListVec& rhs) = delete;
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 
122 CLASS_DEF( CondAttrListVec , 55403898 , 1)
123 
124 #include "AthenaKernel/CondCont.h"
126 
127 inline 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 
135 inline 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),
152  m_minrange(rhs.m_minrange),
153  m_uniqueiov(rhs.m_uniqueiov),
154  m_runevent(rhs.m_runevent),
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 
210 { return m_data.begin(); }
211 
213 { return m_data.end(); }
214 
216 { return m_data.size(); }
217 
219 { return m_iovmap.begin(); }
220 
222 { return m_iovmap.end(); }
223 
225 CondAttrListVec::iovRange(const unsigned int channel) const
226 { return m_iovmap.find(channel); }
227 
229 { return m_iovmap.size(); }
230 
231 inline const IOVRange& CondAttrListVec::minRange() const
232 { return m_minrange; }
233 
234 inline bool CondAttrListVec::hasUniqueIOV() const
235 {return m_uniqueiov; }
236 
237 
239  const unsigned int chan,
240  AttrListDataIter data_begin, AttrListDataIter data_end) {
241  //invalidate index
242  m_index.reset();
243  // set minimum range correctly
245  if (m_minrange.start()<range.start()) start=range.start();
247  if (range.stop()<m_minrange.stop()) stop=range.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) {
261  (m_data.back().second).fastCopyData(*itr);
262  }
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
276  if (m_minrange.start()<range.start()) start=range.start();
278  if (range.stop()<m_minrange.stop()) stop=range.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) {
293  (m_data.back().second).merge(data[i]);
294  }
296 }
297 
300 }
301 
302 inline const std::vector<unsigned int>& CondAttrListVec::channelIDs() const {
303  return index().m_indexchan;
304 }
305 
306 inline bool CondAttrListVec::hasChannel(const int chan) const {
307  const AttrListCVMap& m = index().m_indexchanvec;
308  return (m.find(chan)!=m.end());
309 }
310 
311 inline const std::vector<const coral::AttributeList*>&
313 {
314  const AttrListCVMap& m = index().m_indexchanvec;
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 
323 inline
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
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
CondAttrListVec::m_data
AttrListVec m_data
Definition: CondAttrListVec.h:110
CONDCONT_DEF
CONDCONT_DEF(CondAttrListVec, 74272308)
CondAttrListVec::iov_size
size_type iov_size() const
Definition: CondAttrListVec.h:228
IOVRange
Validity Range object. Holds two IOVTimes (start and stop)
Definition: IOVRange.h:30
CondAttrListVec::add
void add(const IOVRange &range, const unsigned int chan, AttrListDataIter data_begin, AttrListDataIter data_end)
Definition: CondAttrListVec.h:238
plotting.yearwise_efficiency.channel
channel
Definition: yearwise_efficiency.py:24
IOVRange.h
Validity Range object. Holds two IOVTime instances (start and stop)
CondAttrListVec::m_uniqueiov
bool m_uniqueiov
Definition: CondAttrListVec.h:113
index
Definition: index.py:1
CondAttrListVec::channelIDs
const std::vector< unsigned int > & channelIDs() const
Definition: CondAttrListVec.h:302
CondAttrListVec::Index
Definition: CondAttrListVec.h:45
mergePhysValFiles.start
start
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:13
python.CaloCondTools.MINRUN
int MINRUN
Definition: CaloCondTools.py:23
IOVRange::start
const IOVTime & start() const
Definition: IOVRange.h:38
skel.it
it
Definition: skel.GENtoEVGEN.py:407
CondAttrListVec::hasUniqueIOV
bool hasUniqueIOV() const
Definition: CondAttrListVec.h:234
PixelModuleFeMask_create_db.stop
int stop
Definition: PixelModuleFeMask_create_db.py:76
python.PyKernel.AttributeList
AttributeList
Definition: PyKernel.py:36
CondAttrListVec::size_type
AttrListVec::size_type size_type
Definition: CondAttrListVec.h:37
CondAttrListVec::size
size_type size() const
Definition: CondAttrListVec.h:215
CondAttrListVec::AttrListVec
std::vector< AttrListPair > AttrListVec
Definition: CondAttrListVec.h:34
IOVRange::stop
const IOVTime & stop() const
Definition: IOVRange.h:39
CondAttrListVec::AttrListPair
std::pair< unsigned int, coral::AttributeList > AttrListPair
Definition: CondAttrListVec.h:33
CondAttrListVec::iovRange
iov_const_iterator iovRange(const unsigned int channel) const
Definition: CondAttrListVec.h:225
CondAttrListVec::index
const Index & index() const
Definition: CondAttrListVec.h:324
IOVTime
Basic time unit for IOVSvc. Hold time as a combination of run and event numbers.
Definition: IOVTime.h:33
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:209
CondAttrListVec
Definition: CondAttrListVec.h:31
lumiFormat.i
int i
Definition: lumiFormat.py:85
ReadCellNoiseFromCool.chan
chan
Definition: ReadCellNoiseFromCool.py:52
CondAttrListVec::m_runevent
bool m_runevent
Definition: CondAttrListVec.h:114
CondAttrListVec::operator=
CondAttrListVec & operator=(const CondAttrListVec &rhs)=delete
res
std::pair< std::vector< unsigned int >, bool > res
Definition: JetGroupProductTest.cxx:11
CxxUtils::CachedValue
Cached value with atomic update.
Definition: CachedValue.h:55
CondAttrListVec::m_minrange
IOVRange m_minrange
Definition: CondAttrListVec.h:112
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:194
IOVTime::MAXTIMESTAMP
static constexpr uint64_t MAXTIMESTAMP
Definition: IOVTime.h:58
CondAttrListVec::AttrListIOVMap
std::map< unsigned int, IOVRange > AttrListIOVMap
Definition: CondAttrListVec.h:38
CondAttrListVec::m_iovmap
AttrListIOVMap m_iovmap
Definition: CondAttrListVec.h:111
CondAttrListVec::attrListVec
const std::vector< const coral::AttributeList * > & attrListVec(const int chan) const
Definition: CondAttrListVec.h:312
CondAttrListVec::iov_end
iov_const_iterator iov_end() const
Definition: CondAttrListVec.h:221
CondAttrListVec::end
const_iterator end() const
Definition: CondAttrListVec.h:212
CondAttrListVec::AttrListCVMap
std::map< unsigned int, std::vector< const coral::AttributeList * > > AttrListCVMap
Definition: CondAttrListVec.h:42
CondAttrListVec::addNewStop
void addNewStop(const IOVTime &stop)
Definition: CondAttrListVec.h:298
CondAttrListVec::m_spec
coral::AttributeListSpecification * m_spec
Definition: CondAttrListVec.h:115
CondAttrListVec::~CondAttrListVec
~CondAttrListVec()
Definition: CondAttrListVec.h:145
CondAttrListVec::m_index
CxxUtils::CachedValue< Index > m_index
Definition: CondAttrListVec.h:117
CachedValue.h
Cached value with atomic update.
CondAttrListVec::const_iterator
AttrListVec::const_iterator const_iterator
Definition: CondAttrListVec.h:36
python.CaloCondTools.MAXRUN
MAXRUN
Definition: CaloCondTools.py:25
CondAttrListVec::hasChannel
bool hasChannel(const int chan) const
Definition: CondAttrListVec.h:306
CondAttrListVec::iov_size_type
AttrListIOVMap::size_type iov_size_type
Definition: CondAttrListVec.h:40
CondAttrListVec::Index::m_indexchanvec
AttrListCVMap m_indexchanvec
Definition: CondAttrListVec.h:46
CondAttrListVec::Index::m_indexchan
std::vector< unsigned int > m_indexchan
Definition: CondAttrListVec.h:47
CondAttrListVec::begin
const_iterator begin() const
Definition: CondAttrListVec.h:209
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:67
python.utility.LHE.merge
def merge(input_file_pattern, output_file)
Merge many input LHE files into a single output file.
Definition: LHE.py:29
CondAttrListVec::iov_begin
iov_const_iterator iov_begin() const
Definition: CondAttrListVec.h:218
IOVTime::MINTIMESTAMP
static constexpr uint64_t MINTIMESTAMP
Definition: IOVTime.h:56
CondAttrListVec::CondAttrListVec
CondAttrListVec()
CondAttrListVec::addSlice
void addSlice(const IOVRange &range, const unsigned int chan, const std::vector< coral::AttributeList > &data, const unsigned int datastart, const unsigned int dataend)
Definition: CondAttrListVec.h:267
CondAttrListVec::AttrListDataIter
std::vector< coral::AttributeList >::const_iterator AttrListDataIter
Definition: CondAttrListVec.h:35
CLASS_DEF.h
macros to associate a CLID to a type
CondAttrListVec::minRange
const IOVRange & minRange() const
Definition: CondAttrListVec.h:231
CondAttrListVec::iov_const_iterator
AttrListIOVMap::const_iterator iov_const_iterator
Definition: CondAttrListVec.h:39
python.SystemOfUnits.m
float m
Definition: SystemOfUnits.py:106