ATLAS Offline Software
Loading...
Searching...
No Matches
CondAttrListCollection.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
15
16#ifndef DBDATAOBJECTS_CONDATTRLISTCOLLECTION_H
17#define DBDATAOBJECTS_CONDATTRLISTCOLLECTION_H
18
19
20#include "CoralBase/Attribute.h"
21#include "CoralBase/AttributeList.h"
22#include "CoralBase/AttributeListSpecification.h"
23
26#include "GaudiKernel/DataObject.h"
27
28#include <map>
29#include <sstream>
30#include <vector>
31
32
49
50class CondAttrListCollection : public DataObject
51{
52public:
53
54 typedef unsigned int ChanNum;
55 typedef coral::AttributeList AttributeList;
56 typedef std::map<ChanNum, coral::AttributeList> ChanAttrListMap;
57 typedef ChanAttrListMap::value_type ChanAttrListPair;
58 typedef std::map<ChanNum, IOVRange> ChanIOVMap;
59 typedef ChanIOVMap::value_type ChanIOVPair;
60 typedef std::map<ChanNum, std::string> ChanNameMap;
61 typedef ChanNameMap::value_type ChanNamePair;
62 typedef ChanAttrListMap::const_iterator const_iterator;
63 typedef ChanAttrListMap::iterator iterator;
64 typedef ChanAttrListMap::size_type size_type;
65 typedef ChanIOVMap::const_iterator iov_const_iterator;
66 typedef ChanIOVMap::iterator iov_iterator;
67 typedef ChanIOVMap::size_type iov_size_type;
68 typedef ChanNameMap::const_iterator name_const_iterator;
69 typedef ChanNameMap::iterator name_iterator;
70 typedef ChanNameMap::size_type name_size_type;
71
73 explicit CondAttrListCollection(bool hasRunLumiBlockTime);
74
76
77 // copy constructor and assignment operator - have to be explicitly
78 // implemented to control use of the cached AttributeListSpecification
80 // no copy with new Gaudi
82
85
87 const_iterator begin() const;
88 const_iterator end () const;
89
91 size_type size() const;
92
93
96
100
102 iov_size_type iov_size() const;
103
106
110
113
115 ChanNum chanNum(unsigned int index) const;
116
117 bool fixChanNum(ChanNum oldChan, ChanNum newChan);
118
121
123 const IOVRange& iovRange(ChanNum chanNum) const;
124
126 const std::string& chanName(ChanNum chanNum) const;
127
129 const IOVRange& minRange() const;
130
132 bool hasUniqueIOV() const;
133
138
140 void add(ChanNum chanNum, const IOVRange& range);
141
142 // Adding in chan/name pairs
143 void add(ChanNum chanNum,const std::string& name);
144
147 void addNewStart(const IOVTime& start);
148
151 void addNewStop(const IOVTime& stop);
152
156 void resetMinRange();
157
159 void dump() const;
160
162 void dump(std::ostringstream& stream) const;
163
167 bool operator==( const CondAttrListCollection& rhs ) const;
168
172 bool operator!=( const CondAttrListCollection& rhs ) const;
173
179 bool ignoreIOVs = false) const;
180
181
182
183private:
184
189
196 coral::AttributeListSpecification* m_spec;
197};
198
199CLASS_DEF(CondAttrListCollection, 1238547719, 0)
200
201#include "AthenaKernel/CondCont.h"
203
204//<<<<<< INLINE PUBLIC FUNCTIONS >>>>>>
205//<<<<<< INLINE MEMBER FUNCTIONS >>>>>>
206
207
209:
210m_minRange(IOVRange(IOVTime(IOVTime::MINRUN, IOVTime::MINEVENT),
211 IOVTime(IOVTime::MAXRUN, IOVTime::MAXEVENT))),
212 m_hasUniqueIOV(true),
214 m_spec(nullptr)
215{}
216
219 :
220 m_minRange(IOVRange(IOVTime(IOVTime::MINRUN, IOVTime::MINEVENT),
221 IOVTime(IOVTime::MAXRUN, IOVTime::MAXEVENT))),
222 m_hasUniqueIOV(true),
223 m_hasRunLumiBlockTime(hasRunLumiBlockTime),
224 m_spec(nullptr)
225{
229 }
230}
231
235
237 const CondAttrListCollection& rhs) :
238 DataObject::DataObject(rhs),
239 m_iovMap(rhs.m_iovMap),
240 m_nameMap(rhs.m_nameMap),
244 m_spec(nullptr)
245{
246 // members with normal semantics setup in initialisation list
247 // make a new cached AttributeListSpecificaiton and make the payload use it
248 if (!rhs.m_attrMap.empty()) {
249 m_spec=new coral::AttributeListSpecification();
250 const coral::AttributeList& atr1=rhs.m_attrMap.begin()->second;
251 for (const auto& attr : atr1) {
252 const coral::AttributeSpecification& aspec=attr.specification();
253 m_spec->extend(aspec.name(),aspec.typeName());
254 }
255 for (const auto& [chanNum, attrList] : rhs.m_attrMap) {
256 auto newit = m_attrMap.try_emplace(chanNum, *m_spec, true).first;
257 newit->second.fastCopyData(attrList);
258 }
259 }
260}
261
262// no copy with new Gaudi
263// inline CondAttrListCollection& CondAttrListCollection::operator=(
264// const CondAttrListCollection& rhs) {
265// // catch assignment to self - do nothing
266// if (this==&rhs) return *this;
267// // assign base class
268// DataObject::operator=(rhs);
269// // assign members with normal semantics
270// m_attrMap = rhs.m_attrMap;
271// m_iovMap = rhs.m_iovMap;
272// m_nameMap = rhs.m_nameMap;
273// m_minRange = rhs.m_minRange;
274// m_hasUniqueIOV = rhs.m_hasUniqueIOV;
275// m_hasRunLumiBlockTime = rhs.m_hasRunLumiBlockTime;
276// // make a new cache AttributeListSpecification and make the payload map
277// // use it
278// if (m_spec!=0) m_spec->release();
279// if (rhs.m_attrMap.size()>0) {
280// m_spec = new coral::AttributeListSpecification();
281// const coral::AttributeList& atr1 = rhs.m_attrMap.begin()->second;
282// for (coral::AttributeList::const_iterator itr = atr1.begin();itr!=atr1.end();++itr) {
283// const coral::AttributeSpecification& aspec = itr->specification();
284// m_spec->extend(aspec.name(),aspec.typeName());
285// }
286// m_attrMap.clear();
287// const_iterator itr=rhs.m_attrMap.begin();
288// for (; itr != rhs.m_attrMap.end(); ++itr) {
289// m_attrMap[itr->first] = coral::AttributeList(*m_spec,true);
290// m_attrMap[itr->first].fastCopyData(itr->second);
291// }
292// } else {
293// m_spec = 0;
294// }
295// return *this;
296// }
297
304
305
309{
310 return (m_attrMap.begin());
311}
312
315{
316 return (m_attrMap.end());
317}
318
322{
323 return (m_attrMap.size());
324}
325
326
333
337{
338 return (m_iovMap.begin());
339}
340
343{
344 return (m_iovMap.end());
345}
346
350{
351 return (m_iovMap.size());
352}
353
360
364{
365 return (m_nameMap.begin());
366}
367
370{
371 return (m_nameMap.end());
372}
373
377{
378 return (m_nameMap.size());
379}
380
384{
385 if (index < size()) {
386 const_iterator it = begin();
387 unsigned int count = index;
388 while (count > 0) {
389 ++it;
390 --count;
391 }
392 return (it->first);
393 }
394 // otherwise return max
395 else return (0xFFFF);
396}
397
401{
403 if (itr!=m_attrMap.end()) {
404 return itr->second;
405 } else {
406 static const AttributeList attr;
407 return attr;
408 }
409}
410
412inline const IOVRange&
414{
416 if (itr!=m_iovMap.end()) {
417 return itr->second;
418 } else {
419 // Default is the minRange
420 return (m_minRange);
421 }
422}
423
424// find name for channel - empty string for unknonwn/unnamed channels
425inline const std::string& CondAttrListCollection::chanName(ChanNum chanNum) const {
427 if (itr!=m_nameMap.end()) {
428 return itr->second;
429 } else {
430 static const std::string name;
431 return name;
432 }
433}
434
436inline const IOVRange&
438{
439 return (m_minRange);
440}
441
443inline bool
448
450inline bool
452{
453 if (m_attrMap.empty()) {
454 m_spec=new coral::AttributeListSpecification();
455 for (const auto& attr : attributeList) {
456 const coral::AttributeSpecification& aspec=attr.specification();
457 m_spec->extend(aspec.name(),aspec.typeName());
458 }
459 }
460 m_attrMap[chanNum]=coral::AttributeList(*m_spec,true);
461 m_attrMap[chanNum].fastCopyData(attributeList);
462
463 return true;
464}
465
467inline void
469{
470 if (m_attrMap.empty()) {
471 m_spec=new coral::AttributeListSpecification();
472 for (const auto& attr : attributeList) {
473 const coral::AttributeSpecification& aspec=attr.specification();
474 m_spec->extend(aspec.name(),aspec.typeName());
475 }
476 }
477 m_attrMap[chanNum]=coral::AttributeList(*m_spec,true);
479}
480
482inline void
484{
485 m_iovMap[chanNum] = range;
486
487 // Accumulate minRange
488 IOVTime start = m_minRange.start();
489 if (m_minRange.start() < range.start()) start = range.start();
490 IOVTime stop = m_minRange.stop();
491 if (range.stop() < m_minRange.stop()) stop = range.stop();
492 m_minRange = IOVRange(start, stop);
493 if (m_hasUniqueIOV && range != m_minRange)m_hasUniqueIOV = false;
494}
495
497inline void
499{
500 m_nameMap[chanNum] = name;
501}
502
503
506inline void
508{
509 if (start > m_minRange.start()) {
510 m_minRange = IOVRange(start,m_minRange.stop());
511 }
512}
513
516inline void
518{
519 if (stop < m_minRange.stop()) {
520 m_minRange = IOVRange(m_minRange.start(), stop);
521 }
522}
523
527inline void
529{
530 // Reset minRange to max
531 if (m_minRange.start().isTimestamp()) {
533 }
534 else {
537 }
539 iov_const_iterator last1 = iov_end();
540 for (; it1 != last1; ++it1) {
541 const IOVTime& start = (*it1).second.start();
542 const IOVTime& stop = (*it1).second.stop();
543 if (start > m_minRange.start() && stop < m_minRange.stop()) {
544 m_minRange = IOVRange(start, stop);
545 }
546 else if (start > m_minRange.start()) {
547 m_minRange = IOVRange(start,m_minRange.stop());
548 }
549 else if (stop < m_minRange.stop()) {
550 m_minRange = IOVRange(m_minRange.start(), stop);
551 }
552 }
553}
554
555inline void
557{
558 // min range
559 std::cout << "min range: " << m_minRange << std::endl;
560
561 // attribute list
562 for (const auto& [chanNum, attrList] : m_attrMap) {
563 std::cout << "chan, attr: " << chanNum << std::endl;
564 attrList.toOutputStream(std::cout) << std::endl;
565 }
566 // IOVs
567 for (const auto& [chanNum, iov] : m_iovMap) {
568 std::cout << "chan, iov: " << chanNum << std::endl;
569 std::cout << iov << std::endl;
570 }
571 // channel names
572 for (const auto& [chanNum, name] : m_nameMap) {
573 std::cout << "chan, name: " << chanNum << std::endl;
574 std::cout << name << std::endl;
575 }
576
577}
578
579inline void
580CondAttrListCollection::dump(std::ostringstream& stream) const
581{
582 stream << m_minRange << " iov size " << m_iovMap.size() << std::endl;
583 // IOVs
584 for (const auto& [chanNum, iov] : m_iovMap) {
585 stream << "chan, iov: " << chanNum << " " << iov << std::endl;
586 }
587 // Attribute list
588 for (const auto& [chanNum, attrList] : m_attrMap) {
589 stream << "chan, attr: " << chanNum << std::endl;
590 attrList.toOutputStream(stream) << std::endl;
591 }
592 // channel names
593 for (const auto& [chanNum, name] : m_nameMap) {
594 stream << "chan, name: " << chanNum << " " << name << std::endl;
595 }
596}
597
598
599inline
600bool
602{
603
604 // Compare minRange
605 if (m_minRange != rhs.m_minRange) return false;
606 // Rest is in isSameButMinRange
607 return (isSameButMinRange (rhs));
608}
609
610
611
612inline
613bool
615{
616 return (!((*this) == rhs));
617}
618
619inline
620bool
622 bool ignoreIOVs ) const
623{
624
625 // Compare with right hand side
626
627 if(m_hasUniqueIOV != rhs.m_hasUniqueIOV) return false;
628 if(m_hasRunLumiBlockTime != rhs.m_hasRunLumiBlockTime) return false;
629 if (m_attrMap.size() != rhs.m_attrMap.size()) return false;
630 if (m_iovMap.size() != rhs.m_iovMap.size()) return false;
631 if (m_nameMap.size() != rhs.m_nameMap.size()) return false;
632
633 if (!ignoreIOVs) {
634 // Check IOVs
635 auto it1 = m_iovMap.begin();
636 auto it2 = rhs.m_iovMap.begin();
637 auto end1 = m_iovMap.end();
638 for (; it1 != end1; ++it1, ++it2) {
639 if (it1->first != it2->first) return false;
640 if (it1->second != it2->second) return false;
641 }
642 }
643
644 // Check attribute lists
645 auto it3 = m_attrMap.begin();
646 auto it4 = rhs.m_attrMap.begin();
647 auto end3 = m_attrMap.end();
648 for (; it3 != end3; ++it3, ++it4) {
649 if (it3->first != it4->first) return false;
650 if (it3->second != it4->second) return false;
651 }
652
653 // Check names
654 auto it5 = m_nameMap.begin();
655 auto it6 = rhs.m_nameMap.begin();
656 auto end5 = m_nameMap.end();
657 for (; it5 != end5; ++it5, ++it6) {
658 if (it5->first != it6->first) return false;
659 if (it5->second != it6->second) return false;
660 }
661
662 return true;
663}
664
665
666inline bool
668 const ChanNum newChan) {
669 auto attrRet = m_attrMap.emplace(newChan, m_attrMap[oldChan]);
670 // if a new element was inserted, erase the old one
671 if (attrRet.second) m_attrMap.erase(oldChan);
672
673 auto iovRet = m_iovMap.emplace(newChan, m_iovMap[oldChan]);
674 // if a new element was inserted, erase the old one
675 if (iovRet.second) m_iovMap.erase(oldChan);
676
677 auto nameRet = m_nameMap.emplace(newChan, m_nameMap[oldChan]);
678 // if a new element was inserted, erase the old one
679 if (nameRet.second) m_nameMap.erase(oldChan);
680
681 return attrRet.first->first == newChan
682 && iovRet.first->first == newChan
683 && nameRet.first->first == newChan;
684 }
685
686
687
688#endif // DBDATAOBJECTS_CONDATTRLISTCOLLECTION_H
#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
Validity Range object.
This class is a collection of AttributeLists where each one is associated with a channel number.
const AttributeList & attributeList(ChanNum chanNum) const
attribute list for a given channel number
ChanNum chanNum(unsigned int index) const
channel number for index: (index = 0 to size-1)
const_iterator end() const
void addNewStart(const IOVTime &start)
Add new start time to minRange - make sure that start is >= to new start.
ChanNameMap::size_type name_size_type
name_const_iterator name_begin() const
Access to Chan/Name pairs via iterators.
name_size_type name_size() const
number of Chan/Name pairs
bool operator!=(const CondAttrListCollection &rhs) const
Comparison operator.
std::map< ChanNum, std::string > ChanNameMap
ChanIOVMap::value_type ChanIOVPair
ChanIOVMap::iterator iov_iterator
bool add(ChanNum chanNum, const AttributeList &attributeList)
Adding in chan/attrList pairs.
bool hasUniqueIOV() const
Check whether there is a unique IOV for all channels.
const_iterator begin() const
Access to Chan/AttributeList pairs via iterators.
bool isSameButMinRange(const CondAttrListCollection &rhs, bool ignoreIOVs=false) const
Equal operator which ignores minRange.
iov_const_iterator iov_end() const
coral::AttributeListSpecification * m_spec
ChanNameMap::value_type ChanNamePair
iov_const_iterator iov_begin() const
Access to Chan/IOV pairs via iterators.
void addNewStop(const IOVTime &stop)
Add new stop time to minRange - make sure that stop is <= to new stop.
void dump() const
Dump our contents to std::cout.
ChanAttrListMap::size_type size_type
std::map< ChanNum, IOVRange > ChanIOVMap
CondAttrListCollection & operator=(const CondAttrListCollection &rhs)=delete
ChanIOVMap::size_type iov_size_type
CondAttrListCollection(bool hasRunLumiBlockTime)
Constructor with specification for type of time: run/lumiBlock or timestamp.
const std::string & chanName(ChanNum chanNum) const
find name for particular channel
bool fixChanNum(ChanNum oldChan, ChanNum newChan)
void resetMinRange()
Reset minRange according to the IOVs of the contained channels.
const IOVRange & minRange() const
Current minimal IOVRange.
name_const_iterator name_end() const
name_const_iterator chanNamePair(ChanNum chanNum) const
Access to Chan/Name pairs via channel number: returns map iterator.
size_type size() const
number of Chan/AttributeList pairs
ChanAttrListMap::iterator iterator
ChanNameMap::iterator name_iterator
iov_const_iterator chanIOVPair(ChanNum chanNum) const
Access to Chan/IOV pairs via channel number: returns map iterator.
ChanAttrListMap::value_type ChanAttrListPair
ChanAttrListMap::const_iterator const_iterator
void addShared(ChanNum chanNum, const AttributeList &attributeList)
Adding in chan/attrList pairs with shared data.
ChanNameMap::const_iterator name_const_iterator
iov_size_type iov_size() const
number of Chan/IOV pairs
bool operator==(const CondAttrListCollection &rhs) const
Equal operator.
ChanIOVMap::const_iterator iov_const_iterator
const_iterator chanAttrListPair(ChanNum chanNum) const
Access to Chan/AttributeList pairs via channel number: returns map iterator.
std::map< ChanNum, coral::AttributeList > ChanAttrListMap
coral::AttributeList AttributeList
const IOVRange & iovRange(ChanNum chanNum) const
IOVRange list for a given channel number.
CondAttrListCollection()
Default constructor - we hide it to prevent clients from using it - forcing them to specify the type ...
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 uint32_t MAXRUN
Definition IOVTime.h:48
static constexpr uint32_t MINEVENT
Definition IOVTime.h:50
static constexpr uint64_t MINTIMESTAMP
Definition IOVTime.h:56
static constexpr uint32_t MAXEVENT
Definition IOVTime.h:51
static constexpr uint32_t MINRUN
Definition IOVTime.h:44
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:146
Definition index.py:1