ATLAS Offline Software
Loading...
Searching...
No Matches
TokenIterator.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "TokenIterator.h"
10
11#include "GaudiKernel/StatusCode.h"
12
13#include <exception>
14
16 const std::string& containerName) :
17 m_container( nullptr ), m_refToken ( nullptr )
18{
19 DbDatabase dbH( fileDescriptor.dbc()->handle() );
20 if ( dbH.isValid() ) {
21 m_refToken = new Token(dbH.cntToken(containerName));
22 m_container = new DbContainer(m_refToken->technology());
23 }
24 if( !dbH.isValid() || !m_container->open(dbH, m_refToken->contID(), 0, m_refToken->technology(), Io::READ).isSuccess() ) {
25 throw std::runtime_error( "Selection from " + fileDescriptor.PFN() + "(" + containerName + ") failed (APR: \" TokenIterator::TokenIterator() \" from \" PersistencySvc \")" );
26 }
27}
28
30{
31 delete m_container; m_container = nullptr;
32 m_refToken->release(); m_refToken = nullptr;
33}
34
35
36Token*
38{
39 Token::OID_t linkH(m_refToken->oid());
40 if( !m_container->next(linkH).isSuccess() ) return nullptr;
41 m_refToken->oid() = linkH;
42 m_refToken->addRef();
43 return m_refToken;
44}
45
46
47std::size_t
49{
50 return m_container->size();
51}
52
53
54bool
55pool::TokenIterator::seek(std::size_t position)
56{
57 if( position >= size() ) return false;
58 // go to position-1, so that the next call to next() will return the Token at <position>
59 m_refToken->oid().second = int(position-1);
60 return true;
61}
size_t size() const
Number of registered mappings.
This class provides a token that identifies in a unique way objects on the persistent storage.
Definition Token.h:22
DbDatabaseObj * handle()
Access object identifier.
Description: Definition of the object describing a database container Handle managing a DbContainerOb...
Definition DbContainer.h:48
Description: Handle managing a DbDatabaseObj, a generic Database object.
Definition DbDatabase.h:54
const Token * cntToken(const std::string &cntName)
Access local container token (if container exists).
bool isValid() const
Validity check (Objy like).
DbConnection * dbc()
Access to file descriptor (READ).
const std::string & PFN() const
Access to physical file name (READ).
virtual Token * next() override final
Advances tne iterator and returns a pointer to next token.
virtual std::size_t size() override final
Return the size of the collection.
DbContainer * m_container
virtual bool seek(std::size_t position) override final
Seek to a given position in the collection.
TokenIterator(FileDescriptor &fileDescriptor, const std::string &containerName)
Constructor taking as argument the file descriptor, the container name.