ATLAS Offline Software
Loading...
Searching...
No Matches
columnar::TestUtils::LinkColumnVector Class Referencefinal
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::LinkIndexTypedata () 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)

Private Attributes

std::vector< typename CM::LinkIndexTypem_columnData
std::string m_columnName
std::vector< std::string > m_targetNames
std::vector< SG::sgkey_tm_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 299 of file ColumnarPhysliteTest.cxx.

Member Typedef Documentation

◆ CM

Constructor & Destructor Documentation

◆ ~LinkColumnVector()

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

Definition at line 307 of file ColumnarPhysliteTest.cxx.

308 {
309 if (!m_unknownKeysAllowedTargets.empty())
310 {
311 std::cout << "found unknown keys for " << m_columnName << ":";
312 for (auto& [key, allowedSet] : m_unknownKeysAllowedTargets)
313 {
314 std::cout << " " << std::hex << key << std::dec << " (allowed targets:";
315 for (auto index : allowedSet)
316 std::cout << " " << m_targetNames.at(index);
317 std::cout << ")";
318 }
319 }
320 }
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 374 of file ColumnarPhysliteTest.cxx.

375 {
377 }
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 363 of file ColumnarPhysliteTest.cxx.

364 {
365 if (element.isDefault())
366 {
367 addEmptyLink();
368 return;
369 }
370
371 addSplitLink (element.index(), element.key(), eventIndex);
372 }
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 379 of file ColumnarPhysliteTest.cxx.

380 {
381 if (linkIndex == 0 && linkKey == 0)
382 {
383 addEmptyLink();
384 return;
385 }
386
387 unsigned targetIndex = 0u;
388 while (targetIndex < m_targetKeys.size() && m_targetKeys.at(targetIndex) != linkKey)
389 ++ targetIndex;
390
391 // We didn't find the key, so we try to figure out which of the
392 // targets it could be. The idea is that you wouldn't rely on
393 // this for real tests, but that you then go and fill in those
394 // keys in the central lookup table. It will always record and
395 // report, that means if there is a variant link with extra
396 // targets you didn't declare you will get a diagnostic. This
397 // may be overly cautious, but it gives an extra diagnostic if
398 // maybe you missed a target.
399 if (targetIndex == m_targetKeys.size())
400 {
401 if (!m_unknownKeysAllowedTargets.contains (linkKey))
402 {
403 auto& allowedSet = m_unknownKeysAllowedTargets[linkKey];
404 for (std::size_t i = 0; i < m_targetKeys.size(); ++ i)
405 {
406 if (m_targetKeys.at(i) == 0)
407 allowedSet.insert(i);
408 }
409 }
410 auto& allowedSet = m_unknownKeysAllowedTargets[linkKey];
411 for (auto iter = allowedSet.begin(); iter != allowedSet.end();)
412 {
413 auto index = *iter;
414 auto& targetOffsetColumn = *m_targetOffsetColumns.at(index);
415 if (eventIndex + 1 >= targetOffsetColumn.size())
416 throw std::runtime_error ("target offset column not yet filled for: " + m_targetNames.at(index));
417 if (targetOffsetColumn.at(eventIndex) + linkIndex >= targetOffsetColumn.at(eventIndex + 1))
418 iter = allowedSet.erase(iter);
419 else
420 ++ iter;
421 }
422 // Not quite sure whether it is safer to use or not use one of
423 // the targets from the allowed set in this case. In general
424 // tools are expected to handle invalid links gracefully,
425 // worst case they throw an exception when trying to access
426 // it. So what I came up with is that for variant links we
427 // assume it invalid, but for non-variant links the tool
428 // expects exactly one target and we either found it or throw
429 // an exception.
430 if (m_keysColumns.empty())
431 {
432 if (allowedSet.size() == 1 && m_targetKeys.at(*allowedSet.begin()) == 0 && m_unknownKeysAllowedTargets.size() == 1)
433 targetIndex = *allowedSet.begin();
434 else
435 {
436 std::ostringstream error;
437 error << "target key mismatch: read sgkey " << std::hex << linkKey << std::dec;
438 error << " for column " << m_columnName << " with element index " << linkIndex << " targeting " << m_targetNames.at(0);
439 if (m_targetKeys.at(0) != 0u)
440 {
441 error << ", expected sgkey " << std::hex << m_targetKeys.at(0) << std::dec;
442 } else if (m_unknownKeysAllowedTargets.size() > 1)
443 {
444 error << ", alternate key found for non-variant link:";
445 for (auto& [key, allowedSet] : m_unknownKeysAllowedTargets)
446 {
447 if (key != linkKey)
448 error << " " << std::hex << key << std::dec;
449 }
450 } else
451 {
452 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;
453 }
454 throw std::runtime_error (std::move (error).str());
455 }
456 }
457 }
458
459 if (targetIndex == m_targetKeys.size())
460 {
461 // this creates a link with an unknown key, which the user
462 // will ignore
463 m_columnData.push_back (CM::mergeLinkKeyIndex (0xff, linkIndex));
464 return;
465 }
466
467 auto& targetOffsetColumn = *m_targetOffsetColumns.at(targetIndex);
468 if (eventIndex + 1 >= targetOffsetColumn.size())
469 throw std::runtime_error ("target offset column not yet filled for: " + m_targetNames.at(targetIndex));
470 auto myLinkIndex = linkIndex + targetOffsetColumn.at(eventIndex);
471 if (myLinkIndex >= targetOffsetColumn.at(eventIndex + 1))
472 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)));
473
474 m_columnData.push_back (CM::mergeLinkKeyIndex (targetIndex, myLinkIndex));
475 }
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
@ linkIndex
link index for multiple track and vertex matches
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 )
inlineprivate

Definition at line 517 of file ColumnarPhysliteTest.cxx.

518 {
519 unsigned targetIndex = 0;
520 while (targetIndex < m_targetNames.size() && m_targetNames.at(targetIndex) != name)
521 ++ targetIndex;
522 if (targetIndex == m_targetNames.size())
523 {
524 m_targetNames.push_back(name);
525 if (auto offsetIter = offsetColumns.find (name); offsetIter != offsetColumns.end())
526 m_targetOffsetColumns.push_back (offsetIter->second);
527 else
528 throw std::runtime_error ("missing offset column: " + name);
529 if (auto keyIter = knownKeys.find (name); keyIter != knownKeys.end())
530 m_targetKeys.push_back (keyIter->second);
531 else
532 m_targetKeys.push_back (0);
533 }
534 if (!m_keysColumns.empty())
535 m_keysColumns.back().push_back (targetIndex);
536 }
const std::unordered_map< std::string, SG::sgkey_t > knownKeys

◆ begin()

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

Definition at line 487 of file ColumnarPhysliteTest.cxx.

487{ return m_columnData.begin(); }

◆ checkOffsets()

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

Definition at line 352 of file ColumnarPhysliteTest.cxx.

353 {
354 for (std::size_t i = 0; i < m_targetNames.size(); ++ i)
355 {
356 auto& targetOffsetColumn = *m_targetOffsetColumns.at(i);
357 if (eventIndex + 1 >= targetOffsetColumn.size())
358 throw std::runtime_error ("target offset column not yet filled for: " + m_targetNames.at(i) + " when checking link column " + m_columnName);
359 }
360 }

◆ clear()

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

Definition at line 347 of file ColumnarPhysliteTest.cxx.

348 {
349 m_columnData.clear();
350 }

◆ 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 322 of file ColumnarPhysliteTest.cxx.

323 {
324 m_columnName = columnInfo.name;
325 std::vector<std::string> keyColumnNames;
326 if (!columnInfo.soleLinkTargetName.empty())
327 {
328 addTarget (columnInfo.soleLinkTargetName, offsetColumns);
329 } else
330 {
331 for (auto& [requestedName, requestedInfo] : requestedColumns)
332 {
333 if (requestedInfo.keyColumnForVariantLink == m_columnName)
334 {
335 keyColumnNames.push_back (requestedName);
336 m_keysColumns.emplace_back();
337 for (const auto& targetName : requestedInfo.variantLinkTargetNames)
338 addTarget (targetName, offsetColumns);
339 }
340 }
341 if (m_keysColumns.empty())
342 throw std::runtime_error ("no key column found for variant link: " + m_columnName);
343 }
344 return keyColumnNames;
345 }
void addTarget(const std::string &name, const std::unordered_map< std::string, const std::vector< ColumnarOffsetType > * > &offsetColumns)

◆ data()

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

Definition at line 482 of file ColumnarPhysliteTest.cxx.

483 {
484 return m_columnData.data();
485 }

◆ end()

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

Definition at line 488 of file ColumnarPhysliteTest.cxx.

488{ return m_columnData.end(); }

◆ keysColumn()

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

Definition at line 490 of file ColumnarPhysliteTest.cxx.

491 {
492 return m_keysColumns.at(index);
493 }

◆ size()

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

Definition at line 477 of file ColumnarPhysliteTest.cxx.

478 {
479 return m_columnData.size();
480 }

Member Data Documentation

◆ m_columnData

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

Private Members

Definition at line 501 of file ColumnarPhysliteTest.cxx.

◆ m_columnName

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

Definition at line 503 of file ColumnarPhysliteTest.cxx.

◆ m_keysColumns

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

Definition at line 511 of file ColumnarPhysliteTest.cxx.

◆ m_targetKeys

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

Definition at line 506 of file ColumnarPhysliteTest.cxx.

◆ m_targetNames

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

Definition at line 505 of file ColumnarPhysliteTest.cxx.

◆ m_targetOffsetColumns

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

Definition at line 507 of file ColumnarPhysliteTest.cxx.

◆ m_unknownKeysAllowedTargets

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

Definition at line 513 of file ColumnarPhysliteTest.cxx.


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