ATLAS Offline Software
Loading...
Searching...
No Matches
columnar::TestUtils::LinkColumnVector Class Referencefinal

#include <ColumnReaderBranch.h>

Collaboration diagram for columnar::TestUtils::LinkColumnVector:

Public Types

using CM = ColumnarModeArray

Public Member Functions

 ~LinkColumnVector () noexcept
std::vector< std::string > connect (const ColumnInfo &columnInfo, const std::unordered_map< std::string, const std::vector< ColumnarOffsetType > * > &offsetColumns, const std::unordered_map< std::string, ColumnInfo > &requestedColumns)
void clear ()
void checkOffsets (unsigned eventIndex)
template<typename T>
void addLink (const ElementLink< T > &element, unsigned eventIndex)
void addEmptyLink ()
void addSplitLink (std::size_t linkIndex, SG::sgkey_t linkKey, unsigned eventIndex)
std::size_t size () const noexcept
const CM::LinkIndexType * data () const noexcept
auto begin () const noexcept
auto end () const noexcept
const std::vector< typename CM::LinkKeyType > & keysColumn (std::size_t index) const

Private Member Functions

void addTarget (const std::string &name, const std::unordered_map< std::string, const std::vector< ColumnarOffsetType > * > &offsetColumns, std::uint32_t clid=0)

Private Attributes

std::vector< typename CM::LinkIndexType > m_columnData
std::string m_columnName
std::vector< std::string > m_targetNames
std::vector< SG::sgkey_t > m_targetKeys
std::vector< const std::vector< ColumnarOffsetType > * > m_targetOffsetColumns
std::vector< std::vector< typename CM::LinkKeyType > > m_keysColumns
std::unordered_map< SG::sgkey_t, std::unordered_set< std::size_t > > m_unknownKeysAllowedTargets

Detailed Description

Definition at line 32 of file ColumnReaderBranch.h.

Member Typedef Documentation

◆ CM

Public Members

Definition at line 38 of file ColumnReaderBranch.h.

Constructor & Destructor Documentation

◆ ~LinkColumnVector()

columnar::TestUtils::LinkColumnVector::~LinkColumnVector ( )
inlinenoexcept

Definition at line 40 of file ColumnReaderBranch.h.

41 {
42 if (!m_unknownKeysAllowedTargets.empty())
43 {
44 std::cout << "found unknown keys for " << m_columnName << ":";
45 for (auto& [key, allowedSet] : m_unknownKeysAllowedTargets)
46 {
47 std::cout << " " << std::hex << key << std::dec << " (allowed targets:";
48 for (auto index : allowedSet)
49 std::cout << " " << m_targetNames.at(index);
50 std::cout << ")";
51 }
52 }
53 }
std::vector< std::string > m_targetNames
std::unordered_map< SG::sgkey_t, std::unordered_set< std::size_t > > m_unknownKeysAllowedTargets

Member Function Documentation

◆ addEmptyLink()

void columnar::TestUtils::LinkColumnVector::addEmptyLink ( )
inline

Definition at line 107 of file ColumnReaderBranch.h.

108 {
110 }
std::vector< typename CM::LinkIndexType > m_columnData
constexpr ColumnarOffsetType invalidObjectIndex
the value for an invalid element index

◆ addLink()

template<typename T>
void columnar::TestUtils::LinkColumnVector::addLink ( const ElementLink< T > & element,
unsigned eventIndex )
inline

Definition at line 96 of file ColumnReaderBranch.h.

97 {
98 if (element.isDefault())
99 {
100 addEmptyLink();
101 return;
102 }
103
104 addSplitLink (element.index(), element.key(), eventIndex);
105 }
bool isDefault() const
Test to see if this link is in the default state.
void addSplitLink(std::size_t linkIndex, SG::sgkey_t linkKey, unsigned eventIndex)

◆ addSplitLink()

void columnar::TestUtils::LinkColumnVector::addSplitLink ( std::size_t linkIndex,
SG::sgkey_t linkKey,
unsigned eventIndex )
inline

Definition at line 112 of file ColumnReaderBranch.h.

113 {
114 if (linkIndex == 0 && linkKey == 0)
115 {
116 addEmptyLink();
117 return;
118 }
119
120 unsigned targetIndex = 0u;
121 while (targetIndex < m_targetKeys.size() && m_targetKeys.at(targetIndex) != linkKey)
122 ++ targetIndex;
123
124 // We didn't find the key, so we try to figure out which of the
125 // targets it could be. The idea is that you wouldn't rely on
126 // this for real tests, but that you then go and fill in those
127 // keys in the central lookup table. It will always record and
128 // report, that means if there is a variant link with extra
129 // targets you didn't declare you will get a diagnostic. This
130 // may be overly cautious, but it gives an extra diagnostic if
131 // maybe you missed a target.
132 if (targetIndex == m_targetKeys.size())
133 {
134 if (!m_unknownKeysAllowedTargets.contains (linkKey))
135 {
136 auto& allowedSet = m_unknownKeysAllowedTargets[linkKey];
137 for (std::size_t i = 0; i < m_targetKeys.size(); ++ i)
138 {
139 if (m_targetKeys.at(i) == 0)
140 allowedSet.insert(i);
141 }
142 }
143 auto& allowedSet = m_unknownKeysAllowedTargets[linkKey];
144 for (auto iter = allowedSet.begin(); iter != allowedSet.end();)
145 {
146 auto index = *iter;
147 auto& targetOffsetColumn = *m_targetOffsetColumns.at(index);
148 if (eventIndex + 1 >= targetOffsetColumn.size())
149 throw std::runtime_error ("target offset column not yet filled for: " + m_targetNames.at(index));
150 if (targetOffsetColumn.at(eventIndex) + linkIndex >= targetOffsetColumn.at(eventIndex + 1))
151 iter = allowedSet.erase(iter);
152 else
153 ++ iter;
154 }
155 // Not quite sure whether it is safer to use or not use one of
156 // the targets from the allowed set in this case. In general
157 // tools are expected to handle invalid links gracefully,
158 // worst case they throw an exception when trying to access
159 // it. So what I came up with is that for variant links we
160 // assume it invalid, but for non-variant links the tool
161 // expects exactly one target and we either found it or throw
162 // an exception.
163 if (m_keysColumns.empty())
164 {
165 if (allowedSet.size() == 1 && m_targetKeys.at(*allowedSet.begin()) == 0 && m_unknownKeysAllowedTargets.size() == 1)
166 targetIndex = *allowedSet.begin();
167 else
168 {
169 std::ostringstream error;
170 error << "target key mismatch: read sgkey " << std::hex << linkKey << std::dec;
171 error << " for column " << m_columnName << " with element index " << linkIndex << " targeting " << m_targetNames.at(0);
172 if (m_targetKeys.at(0) != 0u)
173 {
174 error << ", expected sgkey " << std::hex << m_targetKeys.at(0) << std::dec;
175 } else if (m_unknownKeysAllowedTargets.size() > 1)
176 {
177 error << ", alternate key found for non-variant link:";
178 for (auto& [key, allowedSet] : m_unknownKeysAllowedTargets)
179 {
180 if (key != linkKey)
181 error << " " << std::hex << key << std::dec;
182 }
183 } else
184 {
185 error << ", no expected sgkey configured but the maximum allowed index for the target is " << m_targetOffsetColumns.at(0)->at(eventIndex + 1) - m_targetOffsetColumns.at(0)->at(eventIndex) - 1;
186 }
187 throw std::runtime_error (std::move (error).str());
188 }
189 }
190 }
191
192 if (targetIndex == m_targetKeys.size())
193 {
194 // this creates a link with an unknown key, which the user
195 // will ignore
196 m_columnData.push_back (CM::mergeLinkKeyIndex (0xff, linkIndex));
197 return;
198 }
199
200 auto& targetOffsetColumn = *m_targetOffsetColumns.at(targetIndex);
201 if (eventIndex + 1 >= targetOffsetColumn.size())
202 throw std::runtime_error ("target offset column not yet filled for: " + m_targetNames.at(targetIndex));
203 auto myLinkIndex = linkIndex + targetOffsetColumn.at(eventIndex);
204 if (myLinkIndex >= targetOffsetColumn.at(eventIndex + 1))
205 throw std::runtime_error ("index out of range for link: " + m_columnName + " with element index " + std::to_string(linkIndex) + " targeting " + m_targetNames.at(targetIndex) + " with offset " + std::to_string(targetOffsetColumn.at(eventIndex)) + " and next offset " + std::to_string(targetOffsetColumn.at(eventIndex + 1)));
206
207 m_columnData.push_back (CM::mergeLinkKeyIndex (targetIndex, myLinkIndex));
208 }
std::vector< SG::sgkey_t > m_targetKeys
std::vector< const std::vector< ColumnarOffsetType > * > m_targetOffsetColumns
std::vector< std::vector< typename CM::LinkKeyType > > m_keysColumns
str index
Definition DeMoScan.py:362
@ u
Enums for curvilinear frames.
Definition ParamDefs.h:77
static LinkIndexType mergeLinkKeyIndex(LinkIndexType key, LinkIndexType index)
merge a key and index value into a link value

◆ addTarget()

void columnar::TestUtils::LinkColumnVector::addTarget ( const std::string & name,
const std::unordered_map< std::string, const std::vector< ColumnarOffsetType > * > & offsetColumns,
std::uint32_t clid = 0 )
inlineprivate

Definition at line 250 of file ColumnReaderBranch.h.

251 {
252 unsigned targetIndex = 0;
253 while (targetIndex < m_targetNames.size() && m_targetNames.at(targetIndex) != name)
254 ++ targetIndex;
255 if (targetIndex == m_targetNames.size())
256 {
257 m_targetNames.push_back(name);
258 if (auto offsetIter = offsetColumns.find (name); offsetIter != offsetColumns.end())
259 m_targetOffsetColumns.push_back (offsetIter->second);
260 else
261 throw std::runtime_error ("missing offset column: " + name);
262 if (clid != 0)
263 m_targetKeys.push_back (computeSgKey (name, clid));
264 else if (auto keyIter = knownSgKeys.find (name); keyIter != knownSgKeys.end())
265 m_targetKeys.push_back (keyIter->second);
266 else
267 m_targetKeys.push_back (0);
268 }
269 if (!m_keysColumns.empty())
270 m_keysColumns.back().push_back (targetIndex);
271 }
const std::unordered_map< std::string, SG::sgkey_t > knownSgKeys
lookup table from container name to its sgkey hash
Definition KnownSgKeys.h:32
SG::sgkey_t computeSgKey(const std::string &name, std::uint32_t clid)
compute the StoreGate hashed key for a container

◆ begin()

auto columnar::TestUtils::LinkColumnVector::begin ( ) const
inlinenodiscardnoexcept

Definition at line 220 of file ColumnReaderBranch.h.

220{ return m_columnData.begin(); }

◆ checkOffsets()

void columnar::TestUtils::LinkColumnVector::checkOffsets ( unsigned eventIndex)
inline

Definition at line 85 of file ColumnReaderBranch.h.

86 {
87 for (std::size_t i = 0; i < m_targetNames.size(); ++ i)
88 {
89 auto& targetOffsetColumn = *m_targetOffsetColumns.at(i);
90 if (eventIndex + 1 >= targetOffsetColumn.size())
91 throw std::runtime_error ("target offset column not yet filled for: " + m_targetNames.at(i) + " when checking link column " + m_columnName);
92 }
93 }

◆ clear()

void columnar::TestUtils::LinkColumnVector::clear ( )
inline

Definition at line 80 of file ColumnReaderBranch.h.

81 {
82 m_columnData.clear();
83 }

◆ connect()

std::vector< std::string > columnar::TestUtils::LinkColumnVector::connect ( const ColumnInfo & columnInfo,
const std::unordered_map< std::string, const std::vector< ColumnarOffsetType > * > & offsetColumns,
const std::unordered_map< std::string, ColumnInfo > & requestedColumns )
inlinenodiscard

Definition at line 55 of file ColumnReaderBranch.h.

56 {
57 m_columnName = columnInfo.name;
58 std::vector<std::string> keyColumnNames;
59 if (!columnInfo.soleLinkTargetName.empty())
60 {
61 addTarget (columnInfo.soleLinkTargetName, offsetColumns, columnInfo.soleLinkTargetClid);
62 } else
63 {
64 for (auto& [requestedName, requestedInfo] : requestedColumns)
65 {
66 if (requestedInfo.keyColumnForVariantLink == m_columnName)
67 {
68 keyColumnNames.push_back (requestedName);
69 m_keysColumns.emplace_back();
70 for (const auto& targetName : requestedInfo.variantLinkTargetNames)
71 addTarget (targetName, offsetColumns);
72 }
73 }
74 if (m_keysColumns.empty())
75 throw std::runtime_error ("no key column found for variant link: " + m_columnName);
76 }
77 return keyColumnNames;
78 }
void addTarget(const std::string &name, const std::unordered_map< std::string, const std::vector< ColumnarOffsetType > * > &offsetColumns, std::uint32_t clid=0)

◆ data()

const CM::LinkIndexType * columnar::TestUtils::LinkColumnVector::data ( ) const
inlinenodiscardnoexcept

Definition at line 215 of file ColumnReaderBranch.h.

216 {
217 return m_columnData.data();
218 }

◆ end()

auto columnar::TestUtils::LinkColumnVector::end ( ) const
inlinenodiscardnoexcept

Definition at line 221 of file ColumnReaderBranch.h.

221{ return m_columnData.end(); }

◆ keysColumn()

const std::vector< typename CM::LinkKeyType > & columnar::TestUtils::LinkColumnVector::keysColumn ( std::size_t index) const
inlinenodiscard

Definition at line 223 of file ColumnReaderBranch.h.

224 {
225 return m_keysColumns.at(index);
226 }

◆ size()

std::size_t columnar::TestUtils::LinkColumnVector::size ( ) const
inlinenodiscardnoexcept

Definition at line 210 of file ColumnReaderBranch.h.

211 {
212 return m_columnData.size();
213 }

Member Data Documentation

◆ m_columnData

std::vector<typename CM::LinkIndexType> columnar::TestUtils::LinkColumnVector::m_columnData
private

Private Members

Definition at line 234 of file ColumnReaderBranch.h.

◆ m_columnName

std::string columnar::TestUtils::LinkColumnVector::m_columnName
private

Definition at line 236 of file ColumnReaderBranch.h.

◆ m_keysColumns

std::vector<std::vector<typename CM::LinkKeyType> > columnar::TestUtils::LinkColumnVector::m_keysColumns
private

Definition at line 244 of file ColumnReaderBranch.h.

◆ m_targetKeys

std::vector<SG::sgkey_t> columnar::TestUtils::LinkColumnVector::m_targetKeys
private

Definition at line 239 of file ColumnReaderBranch.h.

◆ m_targetNames

std::vector<std::string> columnar::TestUtils::LinkColumnVector::m_targetNames
private

Definition at line 238 of file ColumnReaderBranch.h.

◆ m_targetOffsetColumns

std::vector<const std::vector<ColumnarOffsetType>*> columnar::TestUtils::LinkColumnVector::m_targetOffsetColumns
private

Definition at line 240 of file ColumnReaderBranch.h.

◆ m_unknownKeysAllowedTargets

std::unordered_map<SG::sgkey_t,std::unordered_set<std::size_t> > columnar::TestUtils::LinkColumnVector::m_unknownKeysAllowedTargets
private

Definition at line 246 of file ColumnReaderBranch.h.


The documentation for this class was generated from the following file: