23.05.2014 Views

Athena Developer Guide

Athena Developer Guide

Athena Developer Guide

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Athena</strong><br />

Chapter 7 Accessing data Version/Issue: 2.0.0<br />

Smart references and Smart reference vectors are declared inside a class as:<br />

#include "GaudiKernel/SmartRef.h"<br />

#include "GaudiKernel/SmartRefVector.h"<br />

class MCParticle {<br />

private:<br />

/// Smart reference to origin vertex<br />

SmartRef m_originMCVertex;<br />

/// Vector of smart references to decay vertices<br />

SmartRefVector m_decayMCVertices;<br />

public:<br />

/// Access the origin Vertex<br />

/// Note: When the smart reference is converted to MCVertex* the object<br />

/// will be loaded from the persistent medium.<br />

MCVertex* originMCVertex() { return m_originMCVertex; }<br />

}<br />

The syntax of usage of smart references is identical to plain C++ pointers. The Algorithm only sees a<br />

pointer to the MCVertex object:<br />

#include "GaudiKernel/SmartDataPtr.h"<br />

// Use a SmartDataPtr to get the MC particles from the event store<br />

SmartDataPtr particles(eventSvc(),"/Event/MC/MCParticles");<br />

MCParticleVector::const_iterator iter;<br />

// Loop over the particles to access the MCVertex via the SmartRef<br />

for( iter = particles->begin(); iter != particles->end(); iter++ ) {<br />

MCVertex* originVtx = (*iter)->originMCVertex();<br />

if( 0 != originVtx ) {<br />

std::cout

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!