ATLAS Offline Software
PackedLinkImpl.icc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration.
3  */
4 /**
5  * @file AthContainers/PackedLinkImpl.icc
6  * @author scott snyder <snyder@bnl.gov>
7  * @date Oct, 2023
8  * @brief Definition of PackedLink type.
9  */
10 
11 
12 namespace SG {
13 
14 
15 /**
16  * @brief Default constructor.
17  *
18  * Initialize a null link.
19  */
20 inline
21 PackedLinkBase::PackedLinkBase()
22  : m_packed (0)
23 {
24 }
25 
26 
27 /**
28  * @brief Constructor.
29  * @param collection The index of the collection in the @c DataLink vector,
30  * @param index The index of the element within the collection.
31  */
32 inline
33 PackedLinkBase::PackedLinkBase (unsigned int collection, unsigned int index) :
34  m_packed ((collection << INDEX_NBITS) + index)
35 {
36  assert (index <= INDEX_MAX);
37  assert (collection <= COLLECTION_MAX);
38 }
39 
40 
41 /**
42  * @brief Comparison.
43  * @param other The link with which to compare.
44  */
45 inline
46 bool PackedLinkBase::operator== (const PackedLinkBase& other) const
47 {
48  return m_packed == other.m_packed;
49 }
50 
51 
52 /**
53  * @brief Unpack the collection index from the link.
54  */
55 inline
56 unsigned int PackedLinkBase::collection() const
57 {
58  return m_packed >> INDEX_NBITS;
59 }
60 
61 
62 /**
63  * @brief Unpack the element index from the link.
64  */
65 inline
66 unsigned int PackedLinkBase::index() const
67 {
68  return (m_packed & INDEX_MAX);
69 }
70 
71 
72 /**
73  * @brief Set the collection index;
74  * @param collection The index of the collection in the @c DataLink vector,
75  */
76 inline
77 void PackedLinkBase::setCollection (unsigned int collection)
78 {
79  assert (collection <= COLLECTION_MAX);
80  m_packed = (m_packed & INDEX_MAX) | (collection << INDEX_NBITS);
81 }
82 
83 
84 /**
85  * @brief Set the element index;
86  * @param index The index of the element within the collection.
87  */
88 inline
89 void PackedLinkBase::setIndex (unsigned int index)
90 {
91  assert (index <= INDEX_MAX);
92  m_packed = (m_packed & (COLLECTION_MAX << INDEX_NBITS)) | index;
93 }
94 
95 
96 } // namespace SG