ATLAS Offline Software
CondAttrListVec.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 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  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  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(0) {
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(0) {
141  m_data.reserve(nelm);
142 }
143 
144 
146  if (m_spec!=0) 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(0)
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.size()>0) {
160  m_spec=new coral::AttributeListSpecification();
161  const coral::AttributeList& atr1=rhs.m_data.begin()->second;
162  for (coral::AttributeList::const_iterator itr=atr1.begin();itr!=atr1.end();
163  ++itr) {
164  const coral::AttributeSpecification& aspec=itr->specification();
165  m_spec->extend(aspec.name(),aspec.typeName());
166  }
167  for (const_iterator itr=rhs.m_data.begin();itr!=rhs.m_data.end();++itr) {
168  m_data.push_back(AttrListPair(itr->first,
169  coral::AttributeList(*m_spec,true)));
170  (m_data.back().second).fastCopyData(itr->second);
171  }
172  }
173 }
174 
175 // no copy operator with new Gaudi
176 // inline CondAttrListVec& CondAttrListVec::operator=(const CondAttrListVec& rhs) {
177 // // catch assignment to self - do nothing
178 // if (this==&rhs) return *this;
179 // // assign base class
180 // DataObject::operator=(rhs);
181 // // assign members with normal semantics
182 // m_iovmap=rhs.m_iovmap;
183 // m_minrange=rhs.m_minrange;
184 // m_uniqueiov=rhs.m_uniqueiov;
185 // m_runevent=rhs.m_runevent;
186 // m_indexed=false;
187 // // make a new cache AttributeListSpecification and make the payload map
188 // // use it
189 // if (m_spec!=0) m_spec->release();
190 // if (rhs.m_data.size()>0) {
191 // m_spec=new coral::AttributeListSpecification();
192 // const coral::AttributeList& atr1=rhs.m_data.begin()->second;
193 // for (coral::AttributeList::const_iterator itr=atr1.begin();itr!=atr1.end();
194 // ++itr) {
195 // const coral::AttributeSpecification& aspec=itr->specification();
196 // m_spec->extend(aspec.name(),aspec.typeName());
197 // }
198 // m_data.clear();
199 // for (const_iterator itr=rhs.m_data.begin();itr!=rhs.m_data.end();++itr) {
200 // m_data.push_back(AttrListPair(itr->first,
201 // coral::AttributeList(*m_spec,true)));
202 // (m_data.back().second).fastCopyData(itr->second);
203 // }
204 // } else {
205 // m_spec=0;
206 // }
207 // return *this;
208 // }
209 
211 { return m_data.begin(); }
212 
214 { return m_data.end(); }
215 
217 { return m_data.size(); }
218 
220 { return m_iovmap.begin(); }
221 
223 { return m_iovmap.end(); }
224 
226 CondAttrListVec::iovRange(const unsigned int channel) const
227 { return m_iovmap.find(channel); }
228 
230 { return m_iovmap.size(); }
231 
233 { return m_minrange; }
234 
235 inline bool CondAttrListVec::hasUniqueIOV() const
236 {return m_uniqueiov; }
237 
238 
240  const unsigned int chan,
241  AttrListDataIter data_begin, AttrListDataIter data_end) {
242  //invalidate index
243  m_index.reset();
244  // set minimum range correctly
246  if (m_minrange.start()<range.start()) start=range.start();
248  if (range.stop()<m_minrange.stop()) stop=range.stop();
250  if (m_uniqueiov && range!=m_minrange) m_uniqueiov=false;
251  // store attributeList if needed
252  if (m_spec==0 && data_begin!=data_end) {
253  m_spec=new coral::AttributeListSpecification();
254  for (coral::AttributeList::const_iterator itr=data_begin->begin();itr!=data_begin->end();++itr) {
255  const coral::AttributeSpecification& aspec=itr->specification();
256  m_spec->extend(aspec.name(),aspec.typeName());
257  }
258  }
259  // copy in data
260  for (AttrListDataIter itr=data_begin;itr!=data_end;++itr) {
262  (m_data.back().second).fastCopyData(*itr);
263  }
265 }
266 
268  (const IOVRange& range,
269  const unsigned int chan,
270  const std::vector<coral::AttributeList>& data,
271  const unsigned int datastart,const unsigned int dataend)
272 {
273  // invalidate index
274  m_index.reset();
275  // set minimum range correctly
277  if (m_minrange.start()<range.start()) start=range.start();
279  if (range.stop()<m_minrange.stop()) stop=range.stop();
281  if (m_uniqueiov && range!=m_minrange) m_uniqueiov=false;
282  // store attributeList if needed
283  if (m_spec==0 && datastart!=dataend) {
284  m_spec=new coral::AttributeListSpecification();
285  const coral::AttributeList& atr0=data[datastart];
286  for (coral::AttributeList::const_iterator itr=atr0.begin();
287  itr!=atr0.end();++itr) {
288  const coral::AttributeSpecification& aspec=itr->specification();
289  m_spec->extend(aspec.name(),aspec.typeName());
290  }
291  }
292  // copy in data
293  for (unsigned int i=datastart;i<dataend;++i) {
295  (m_data.back().second).merge(data[i]);
296  }
298 }
299 
302 }
303 
304 inline const std::vector<unsigned int>& CondAttrListVec::channelIDs() const {
305  return index().m_indexchan;
306 }
307 
308 inline bool CondAttrListVec::hasChannel(const int chan) const {
309  const AttrListCVMap& m = index().m_indexchanvec;
310  return (m.find(chan)!=m.end());
311 }
312 
313 inline const std::vector<const coral::AttributeList*>&
315 {
316  const AttrListCVMap& m = index().m_indexchanvec;
317  AttrListCVMap::const_iterator it = m.find (chan);
318  if (it != m.end()) {
319  return it->second;
320  }
321  static const std::vector<const coral::AttributeList*> dum;
322  return dum;
323 }
324 
325 inline
327 {
328  if (!m_index.isValid()) {
329  Index index;
330 
331  // loop over all the elements, build vector of AttributeList for each channel
332  // and a vector of all the channels
333  for (const AttrListPair& p : m_data) {
334  unsigned int chan=p.first;
335  AttrListCVMap::iterator clist=index.m_indexchanvec.find(chan);
336  if (clist==index.m_indexchanvec.end()) {
337  // channel not seen before, create a new entry in map and vector
338  std::pair<AttrListCVMap::iterator,bool> res=
339  index.m_indexchanvec.insert(AttrListCVMap::value_type(chan,
340  std::vector<const coral::AttributeList*>()));
341  clist=res.first;
342  index.m_indexchan.push_back(chan);
343  }
344  clist->second.push_back(&(p.second));
345  }
346 
347  m_index.set (std::move (index));
348  }
349  return *m_index.ptr();
350 }
351 
352 #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:229
IOVRange
Validity Range object. Holds two IOVTimes (start and stop)
Definition: IOVRange.h:30
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
CondAttrListVec::add
void add(const IOVRange &range, const unsigned int chan, AttrListDataIter data_begin, AttrListDataIter data_end)
Definition: CondAttrListVec.h:239
plotting.yearwise_efficiency.channel
channel
Definition: yearwise_efficiency.py:28
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:304
CondAttrListVec::Index
Definition: CondAttrListVec.h:45
mergePhysValFiles.start
start
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:14
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:423
CondAttrListVec::hasUniqueIOV
bool hasUniqueIOV() const
Definition: CondAttrListVec.h:235
PixelModuleFeMask_create_db.stop
int stop
Definition: PixelModuleFeMask_create_db.py:76
python.PyKernel.AttributeList
AttributeList
Definition: PyKernel.py:36
CondAttrListVec::minRange
IOVRange minRange() const
Definition: CondAttrListVec.h:232
CondAttrListVec::size_type
AttrListVec::size_type size_type
Definition: CondAttrListVec.h:37
CondAttrListVec::size
size_type size() const
Definition: CondAttrListVec.h:216
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:226
CondAttrListVec::index
const Index & index() const
Definition: CondAttrListVec.h:326
IOVTime
Basic time unit for IOVSvc. Hold time as a combination of run and event numbers.
Definition: IOVTime.h:33
CondAttrListVec
Definition: CondAttrListVec.h:31
lumiFormat.i
int i
Definition: lumiFormat.py:92
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:14
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:195
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:314
CondAttrListVec::iov_end
iov_const_iterator iov_end() const
Definition: CondAttrListVec.h:222
CondAttrListVec::end
const_iterator end() const
Definition: CondAttrListVec.h:213
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:300
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:308
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:210
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
python.utility.LHE.merge
def merge(input_file_pattern, output_file)
Merge many input LHE files into a single output file.
Definition: LHE.py:17
CondAttrListVec::iov_begin
iov_const_iterator iov_begin() const
Definition: CondAttrListVec.h:219
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:268
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::iov_const_iterator
AttrListIOVMap::const_iterator iov_const_iterator
Definition: CondAttrListVec.h:39