ATLAS Offline Software
Loading...
Searching...
No Matches
AthExDevice::EventDataCopyExampleAlg Class Reference

Example for how "device agnostic" event data copies should be done. More...

#include <EventDataCopyExampleAlg.h>

Inheritance diagram for AthExDevice::EventDataCopyExampleAlg:
Collaboration diagram for AthExDevice::EventDataCopyExampleAlg:

Public Member Functions

virtual StatusCode sysInitialize () override
 Override sysInitialize.
virtual bool isClonable () const override
 Specify if the algorithm is clonable.
virtual StatusCode sysExecute (const EventContext &ctx) override
 Execute an algorithm.
virtual const DataObjIDColl & extraOutputDeps () const override
 Return the list of extra output dependencies.
virtual bool filterPassed (const EventContext &ctx) const
 Get filter decision:
virtual void setFilterPassed (bool state, const EventContext &ctx) const
 Set filter decision:
ServiceHandle< StoreGateSvc > & evtStore ()
 The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
const ServiceHandle< StoreGateSvc > & detStore () const
 The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
virtual StatusCode sysStart () override
 Handle START transition.
virtual std::vector< Gaudi::DataHandle * > inputHandles () const override
 Return this algorithm's input handles.
virtual std::vector< Gaudi::DataHandle * > outputHandles () const override
 Return this algorithm's output handles.
Gaudi::Details::PropertyBase & declareProperty (Gaudi::Property< T, V, H > &t)
void updateVHKA (Gaudi::Details::PropertyBase &)
MsgStream & msg () const
bool msgLvl (const MSG::Level lvl) const
Function(s) inherited from @c AthReentrantAlgorithm
virtual StatusCode initialize () override
 Function initialising the algorithm.
virtual StatusCode execute (const EventContext &ctx) const override
 Function executing the algorithm.

Protected Member Functions

void renounceArray (SG::VarHandleKeyArray &handlesArray)
 remove all handles from I/O resolution
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce (T &h)
void extraDeps_update_handler (Gaudi::Details::PropertyBase &ExtraDeps)
 Add StoreName to extra input/output deps as needed.

Private Types

typedef ServiceHandle< StoreGateSvcStoreGateSvc_t

Private Member Functions

Gaudi::Details::PropertyBase & declareGaudiProperty (Gaudi::Property< T, V, H > &hndl, const SG::VarHandleKeyType &)
 specialization for handling Gaudi::Property<SG::VarHandleKey>

Private Attributes

DataObjIDColl m_extendedExtraObjects
 Extra output dependency collection, extended by AthAlgorithmDHUpdate to add symlinks.
StoreGateSvc_t m_evtStore
 Pointer to StoreGate (event store by default).
StoreGateSvc_t m_detStore
 Pointer to StoreGate (detector store by default).
std::vector< SG::VarHandleKeyArray * > m_vhka
bool m_varHandleArraysDeclared
Algorithm properties
SG::ReadHandleKey< xAOD::TrackParticleContainerm_inputKey
 The input container.
SG::WriteHandleKey< DeviceObjectCollection::buffer > m_outputKey
 The output container.
ToolHandle< AthDevice::ICopiesToolm_copies
 The copies tool to use for copying data to/from the device.
ToolHandle< AthDevice::IMemoryResourcesToolm_mrs
 The memory resources tool to use for allocating memory on the device.

Detailed Description

Example for how "device agnostic" event data copies should be done.

Definition at line 24 of file EventDataCopyExampleAlg.h.

Member Typedef Documentation

◆ StoreGateSvc_t

typedef ServiceHandle<StoreGateSvc> AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::StoreGateSvc_t
privateinherited

Definition at line 388 of file AthCommonDataStore.h.

Member Function Documentation

◆ declareGaudiProperty()

Gaudi::Details::PropertyBase & AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::declareGaudiProperty ( Gaudi::Property< T, V, H > & hndl,
const SG::VarHandleKeyType &  )
inlineprivateinherited

specialization for handling Gaudi::Property<SG::VarHandleKey>

Definition at line 156 of file AthCommonDataStore.h.

158 {
160 hndl.value(),
161 hndl.documentation());
162
163 }
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)

◆ declareProperty()

Gaudi::Details::PropertyBase & AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::declareProperty ( Gaudi::Property< T, V, H > & t)
inlineinherited

Definition at line 145 of file AthCommonDataStore.h.

145 {
146 typedef typename SG::HandleClassifier<T>::type htype;
148 }
Gaudi::Details::PropertyBase & declareGaudiProperty(Gaudi::Property< T, V, H > &hndl, const SG::VarHandleKeyType &)
specialization for handling Gaudi::Property<SG::VarHandleKey>

◆ detStore()

const ServiceHandle< StoreGateSvc > & AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::detStore ( ) const
inlineinherited

The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 95 of file AthCommonDataStore.h.

◆ evtStore()

ServiceHandle< StoreGateSvc > & AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::evtStore ( )
inlineinherited

The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 85 of file AthCommonDataStore.h.

◆ execute()

StatusCode AthExDevice::EventDataCopyExampleAlg::execute ( const EventContext & ctx) const
overridevirtual

Function executing the algorithm.

Definition at line 26 of file EventDataCopyExampleAlg.cxx.

26 {
27
28 // Create the StoreGate handles.
29 auto inputHandle = SG::makeHandle(m_inputKey, ctx);
30 auto outputHandle = SG::makeHandle(m_outputKey, ctx);
31
32 // Helper lambda for copying the payload from the input (host) container into
33 // a host-accessible output buffer.
34 auto copyToBuffer = [](const xAOD::TrackParticleContainer& input,
35 DeviceObjectCollection::buffer& output) {
36 assert(input.size() == output.capacity());
37 DeviceObjectCollection::device helper{output};
38 for (size_t i = 0; i < input.size(); ++i) {
39 const xAOD::TrackParticle* inputObj = input.at(i);
40 DeviceObject outputObj = helper.at(i);
41 outputObj.eta() = inputObj->eta();
42 outputObj.phi() = inputObj->phi();
43 outputObj.indices().at(0u) = 1u;
44 outputObj.indices().at(1u) = 2u;
45 }
46 };
47
48 // Decide whether an explicit host->device copy will be necessary or not.
49 if (m_mrs->hostMR() == nullptr) {
50
51 // In this case we have just one "main" memory resource. This should mean
52 // that the memory provided by that one memory resource, is accessible
53 // from both the host and the device.
54
55 // Tell the user what we're doing.
56 ATH_MSG_DEBUG("Using a single memory resource for both host and device");
57
58 // Create the final/output buffer.
59 auto output = std::make_unique<DeviceObjectCollection::buffer>(
60 std::vector<unsigned int>(inputHandle->size(), 2), m_mrs->mainMR());
61 m_copies->hostCopy(ctx)->setup(*output)->wait();
62
63 // Fill it with data directly.
64 copyToBuffer(*inputHandle, *output);
65
66 // Record the output buffer in StoreGate.
67 ATH_CHECK(outputHandle.record(std::move(output)));
68
69 } else {
70
71 // In this case we have separate "device"/"main" and "host" memory
72 // resources. In this case we first need to set up a buffer on the host, and
73 // copy data into that. Then we can set up a buffer on the device, and
74 // perform the host->device copy between the two buffers.
75
76 // Tell the user what we're doing.
77 ATH_MSG_DEBUG("Using separate memory resources for host and device");
78
79 // Create the host buffer.
80 DeviceObjectCollection::buffer hostBuffer(
81 std::vector<unsigned int>(inputHandle->size(), 2), *(m_mrs->hostMR()));
82 m_copies->hostCopy(ctx)->setup(hostBuffer)->wait();
83
84 // Fill it with data.
85 copyToBuffer(*inputHandle, hostBuffer);
86
87 // Get the "device" copy object.
88 auto deviceCopy = m_copies->deviceCopy(ctx);
89
90 // Create the device buffer.
91 auto output = std::make_unique<DeviceObjectCollection::buffer>(
92 std::vector<unsigned int>(inputHandle->size(), 2), m_mrs->mainMR(),
93 m_mrs->hostMR());
94 deviceCopy->setup(*output)->ignore();
95
96 // Perform the host->device copy.
97 (*deviceCopy)(hostBuffer, *output)->wait();
98
99 // Record the output buffer in StoreGate.
100 ATH_CHECK(outputHandle.record(std::move(output)));
101 }
102
103 // Return gracefully.
104 return StatusCode::SUCCESS;
105}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x)
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_inputKey
The input container.
ToolHandle< AthDevice::IMemoryResourcesTool > m_mrs
The memory resources tool to use for allocating memory on the device.
ToolHandle< AthDevice::ICopiesTool > m_copies
The copies tool to use for copying data to/from the device.
SG::WriteHandleKey< DeviceObjectCollection::buffer > m_outputKey
The output container.
virtual double phi() const override final
The azimuthal angle ( ) of the particle (has range to .).
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
output
Definition merge.py:16
TrackParticle_v1 TrackParticle
Reference the current persistent version:
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".

◆ extraDeps_update_handler()

void AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::extraDeps_update_handler ( Gaudi::Details::PropertyBase & ExtraDeps)
protectedinherited

Add StoreName to extra input/output deps as needed.

use the logic of the VarHandleKey to parse the DataObjID keys supplied via the ExtraInputs and ExtraOuputs Properties to add the StoreName if it's not explicitly given

◆ extraOutputDeps()

const DataObjIDColl & AthCommonAlgorithm< Gaudi::Algorithm >::extraOutputDeps ( ) const
overridevirtualinherited

Return the list of extra output dependencies.

This list is extended to include symlinks implied by inheritance relations.

Definition at line 89 of file AthCommonAlgorithm.cxx.

54{
55 // If we didn't find any symlinks to add, just return the collection
56 // from the base class. Otherwise, return the extended collection.
57 if (!m_extendedExtraObjects.empty()) {
59 }
61}
Common base class for algorithms.

◆ filterPassed()

virtual bool AthCommonAlgorithm< Gaudi::Algorithm >::filterPassed ( const EventContext & ctx) const
inlinevirtualinherited

Get filter decision:

Definition at line 93 of file AthCommonAlgorithm.h.

93 {
94 return execState( ctx ).filterPassed();
95 }
virtual bool filterPassed(const EventContext &ctx) const
Get filter decision:

◆ initialize()

StatusCode AthExDevice::EventDataCopyExampleAlg::initialize ( )
overridevirtual

Function initialising the algorithm.

Definition at line 12 of file EventDataCopyExampleAlg.cxx.

12 {
13
14 // Initialize the StoreGate keys.
15 ATH_CHECK(m_inputKey.initialize());
16 ATH_CHECK(m_outputKey.initialize());
17
18 // Retrieve the tools.
19 ATH_CHECK(m_copies.retrieve());
20 ATH_CHECK(m_mrs.retrieve());
21
22 // Return gracefully.
23 return StatusCode::SUCCESS;
24}

◆ inputHandles()

virtual std::vector< Gaudi::DataHandle * > AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::inputHandles ( ) const
overridevirtualinherited

Return this algorithm's input handles.

We override this to include handle instances from key arrays if they have not yet been declared. See comments on updateVHKA.

◆ isClonable()

virtual bool AthCommonAlgorithm< Gaudi::Algorithm >::isClonable ( ) const
inlineoverridevirtualinherited

Specify if the algorithm is clonable.

Only relevant for non-reentrant algorithms. Actual number of clones needs to be set via the "Cardinality" property.

Reimplemented in AFP_DigiTop, AlgB, AlgT, BCM_Digitization, CscDigitBuilder, CscDigitToCscRDO, G4AtlasAlg, G4RunAlg, HGTD_Digitization, HiveAlgBase, InDet::GNNSeedingTrackMaker, InDet::SCT_Clusterization, InDet::SiSPGNNTrackMaker, InDet::SiSPSeededTrackFinder, InDet::SiTrackerSpacePointFinder, ISF::SimKernelMT, ITk::StripDigitization, ITkPixelCablingAlg, ITkStripCablingAlg, LArHitEMapMaker, LArTTL1Maker, LUCID_DigiTop, LVL1::L1TopoSimulation, MergeCalibHits, MergeGenericMuonSimHitColl, MergeHijingPars, MergeMcEventCollection, MergeTrackRecordCollection, MergeTruthJets, MergeTruthParticles, MuonDigitizer, PileUpMTAlg, PixelDigitization, RoIBResultToxAOD, SCT_ByteStreamErrorsTestAlg, SCT_CablingCondAlgFromCoraCool, SCT_CablingCondAlgFromText, SCT_ConditionsParameterTestAlg, SCT_ConditionsSummaryTestAlg, SCT_ConfigurationConditionsTestAlg, SCT_Digitization, SCT_FlaggedConditionTestAlg, SCT_LinkMaskingTestAlg, SCT_MajorityConditionsTestAlg, SCT_ModuleVetoTestAlg, SCT_MonitorConditionsTestAlg, SCT_PrepDataToxAOD, SCT_RawDataToxAOD, SCT_ReadCalibChipDataTestAlg, SCT_ReadCalibDataTestAlg, SCT_RODVetoTestAlg, SCT_SensorsTestAlg, SCT_SiliconConditionsTestAlg, SCT_StripVetoTestAlg, SCT_TdaqEnabledTestAlg, SCT_TestCablingAlg, SCTEventFlagWriter, SCTRawDataProvider, SCTSiLorentzAngleTestAlg, SCTSiPropertiesTestAlg, SGInputLoader, Simulation::BeamEffectsAlg, TileHitVecToCnt, TileMuonFitter, TilePulseForTileMuonReceiver, TileRawChannelMaker, TRTDigitization, and ZDC_DigiTop.

Definition at line 68 of file AthCommonAlgorithm.h.

68 {
69 return true;
70 }

◆ msg()

MsgStream & AthCommonMsg< Gaudi::Algorithm >::msg ( ) const
inlineinherited

Definition at line 24 of file AthCommonMsg.h.

24 {
25 return this->msgStream();
26 }

◆ msgLvl()

bool AthCommonMsg< Gaudi::Algorithm >::msgLvl ( const MSG::Level lvl) const
inlineinherited

Definition at line 30 of file AthCommonMsg.h.

30 {
31 return this->msgLevel(lvl);
32 }

◆ outputHandles()

virtual std::vector< Gaudi::DataHandle * > AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::outputHandles ( ) const
overridevirtualinherited

Return this algorithm's output handles.

We override this to include handle instances from key arrays if they have not yet been declared. See comments on updateVHKA.

◆ renounce()

std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::renounce ( T & h)
inlineprotectedinherited

Definition at line 380 of file AthCommonDataStore.h.

381 {
382 h.renounce();
384 }
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce(T &h)

◆ renounceArray()

void AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::renounceArray ( SG::VarHandleKeyArray & handlesArray)
inlineprotectedinherited

remove all handles from I/O resolution

Definition at line 364 of file AthCommonDataStore.h.

364 {
366 }

◆ setFilterPassed()

virtual void AthCommonAlgorithm< Gaudi::Algorithm >::setFilterPassed ( bool state,
const EventContext & ctx ) const
inlinevirtualinherited

Set filter decision:

Reimplemented in AthFilterAlgorithm.

Definition at line 99 of file AthCommonAlgorithm.h.

99 {
101 }
virtual void setFilterPassed(bool state, const EventContext &ctx) const
Set filter decision:

◆ sysExecute()

StatusCode AthCommonAlgorithm< Gaudi::Algorithm >::sysExecute ( const EventContext & ctx)
overridevirtualinherited

Execute an algorithm.

We override this in order to work around an issue with the Algorithm base class storing the event context in a member variable that can cause crashes in MT jobs.

Reimplemented in AthAnalysisAlgorithm.

Definition at line 80 of file AthCommonAlgorithm.cxx.

41{
42 return BaseAlg::sysExecute (ctx);
43}

◆ sysInitialize()

StatusCode AthCommonAlgorithm< Gaudi::Algorithm >::sysInitialize ( )
overridevirtualinherited

Override sysInitialize.

Override sysInitialize from the base class.

Loop through all output handles, and if they're WriteCondHandles, automatically register them and this Algorithm with the CondSvc

Scan through all outputHandles, and if they're WriteCondHandles, register them with the CondSvc

Reimplemented from AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >.

Reimplemented in AthAnalysisAlgorithm, AthFilterAlgorithm, AthHistogramAlgorithm, HypoBase, InputMakerBase, and PyAthena::Alg.

Definition at line 60 of file AthCommonAlgorithm.cxx.

71 {
73
74 if (sc.isFailure()) {
75 return sc;
76 }
77
78 ServiceHandle<ICondSvc> cs("CondSvc",name());
79 for (auto h : outputHandles()) {
80 if (h->isCondition() && h->mode() == Gaudi::DataHandle::Writer) {
81 // do this inside the loop so we don't create the CondSvc until needed
82 if ( cs.retrieve().isFailure() ) {
83 ATH_MSG_WARNING("no CondSvc found: won't autoreg WriteCondHandles");
85 }
86 if (cs->regHandle(this,*h).isFailure()) {
88 ATH_MSG_ERROR("unable to register WriteCondHandle " << h->fullKey()
89 << " with CondSvc");
90 }
91 }
92 }
93 return sc;
94}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
virtual StatusCode sysInitialize() override
virtual std::vector< Gaudi::DataHandle * > outputHandles() const override

◆ sysStart()

virtual StatusCode AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::sysStart ( )
overridevirtualinherited

Handle START transition.

We override this in order to make sure that conditions handle keys can cache a pointer to the conditions container.

◆ updateVHKA()

void AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::updateVHKA ( Gaudi::Details::PropertyBase & )
inlineinherited

Definition at line 308 of file AthCommonDataStore.h.

308 {
309 // debug() << "updateVHKA for property " << p.name() << " " << p.toString()
310 // << " size: " << m_vhka.size() << endmsg;
311 for (auto &a : m_vhka) {
313 for (auto k : keys) {
314 k->setOwner(this);
315 }
316 }
317 }

Member Data Documentation

◆ m_copies

ToolHandle<AthDevice::ICopiesTool> AthExDevice::EventDataCopyExampleAlg::m_copies
private
Initial value:
{
this, "CopiesTool", "",
"The copies tool to use for copying data to/from the device"}

The copies tool to use for copying data to/from the device.

Definition at line 55 of file EventDataCopyExampleAlg.h.

55 {
56 this, "CopiesTool", "",
57 "The copies tool to use for copying data to/from the device"};

◆ m_detStore

StoreGateSvc_t AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::m_detStore
privateinherited

Pointer to StoreGate (detector store by default).

Definition at line 393 of file AthCommonDataStore.h.

◆ m_evtStore

StoreGateSvc_t AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::m_evtStore
privateinherited

Pointer to StoreGate (event store by default).

Definition at line 390 of file AthCommonDataStore.h.

◆ m_extendedExtraObjects

DataObjIDColl AthCommonAlgorithm< Gaudi::Algorithm >::m_extendedExtraObjects
privateinherited

Extra output dependency collection, extended by AthAlgorithmDHUpdate to add symlinks.

Empty if no symlinks were found.

Definition at line 108 of file AthCommonAlgorithm.h.

◆ m_inputKey

SG::ReadHandleKey<xAOD::TrackParticleContainer> AthExDevice::EventDataCopyExampleAlg::m_inputKey
private
Initial value:
{
this, "InputContainer", "InDetTrackParticles",
"The input track particle container"}

The input container.

Definition at line 46 of file EventDataCopyExampleAlg.h.

46 {
47 this, "InputContainer", "InDetTrackParticles",
48 "The input track particle container"};

◆ m_mrs

ToolHandle<AthDevice::IMemoryResourcesTool> AthExDevice::EventDataCopyExampleAlg::m_mrs
private
Initial value:
{
this, "MemoryResourcesTool", "",
"The memory resources tool to use for allocating memory on the device"}

The memory resources tool to use for allocating memory on the device.

Definition at line 59 of file EventDataCopyExampleAlg.h.

59 {
60 this, "MemoryResourcesTool", "",
61 "The memory resources tool to use for allocating memory on the device"};

◆ m_outputKey

SG::WriteHandleKey<DeviceObjectCollection::buffer> AthExDevice::EventDataCopyExampleAlg::m_outputKey
private
Initial value:
{
this, "OutputContainer", "InDetTrackParticlesCopy",
"The output track particle container"}

The output container.

Definition at line 50 of file EventDataCopyExampleAlg.h.

50 {
51 this, "OutputContainer", "InDetTrackParticlesCopy",
52 "The output track particle container"};

◆ m_varHandleArraysDeclared

bool AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::m_varHandleArraysDeclared
privateinherited

Definition at line 399 of file AthCommonDataStore.h.

◆ m_vhka

std::vector<SG::VarHandleKeyArray*> AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::m_vhka
privateinherited

Definition at line 398 of file AthCommonDataStore.h.


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