ATLAS Offline Software
Loading...
Searching...
No Matches
HepMcDataPool.h
Go to the documentation of this file.
1
2
3/*
4 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
5*/
6
7// HepMcDataPool.h
8// Header file for a set of utilities for DataPool w/ HepMC classes
9// Author: S.Binet<binet@cern.ch>
11#ifndef GENERATOROBJECTSATHENAPOOL_HEPMCDATAPOOL_H
12#define GENERATOROBJECTSATHENAPOOL_HEPMCDATAPOOL_H
13
14// HepMC / CLHEP includes
15#include "AtlasHepMC/GenEvent.h"
19
20
21namespace HepMC {
22
23 struct DataPool {
24
25 // Helpers for allocating HepMC objects from a DataPool.
26 // But because HepMC3 keeps shared_ptr's to its objects, we need
27 // to be careful here.
28 //
29 // First, the memory we get from the pool is actually owned by the pool,
30 // so we don't want the shared_ptr's to actually delete anything.
31 // We accomplish this by creating the shared_ptr's for particles and
32 // vertices with null deleters. (This isn't an issue for the GenEvent
33 // objects, since we don't manage them what shared_ptr, but we do need
34 // to be careful not to put them in an owning DataVector.)
35 //
36 // Second, before we create a shared_ptr with a pointer we've just
37 // gotten from the DataPool, we need to be sure that there aren't any
38 // other shared_ptr's to the same object --- otherwise, the behavior
39 // is undefined. (We hide the worst consequences of this by the fact
40 // that we have no-op deleters, but it can still result in the weak
41 // references in GenParticle mysteriously expiring. See ATR-26790.)
42 // So we need to clear the objects before that. We could in principle
43 // do that in the get* functions, but it's nicer to set up clear hooks
44 // in the DataPool so that that happens when objects are returned
45 // to the pool. (And that way, we don't maintain allocated memory
46 // from free objects in the pool.)
47
49 {
50 static void clear (HepMC::GenEvent* evt) { evt->clear(); }
51 };
54 {
55 return evt.nextElementPtr();
56 }
57
59 {
60 static void clear (HepMC::GenVertex* vtx) { *vtx = HepMC::GenVertex(); }
61 };
64 {
65 return HepMC::GenVertexPtr (vtx.nextElementPtr(), [](HepMC::GenVertex*){});
66 }
67
68
70 {
71 static void clear (HepMC::GenParticle* part) { *part = HepMC::GenParticle(); }
72 };
75 {
76 return HepMC::GenParticlePtr (part.nextElementPtr(), [](HepMC::GenParticle*){});
77 }
78
79 };
80
81} // end namespace HepMC
82
83#endif // GENERATOROBJECTSATHENAPOOL_HEPMCDATAPOOL_H
HepMC3::GenParticlePtr GenParticlePtr
Definition GenParticle.h:19
HepMC3::GenVertexPtr GenVertexPtr
Definition GenVertex.h:23
HepMC3::GenEvent GenEvent
Definition GenEvent.h:39
static void clear(HepMC::GenEvent *evt)
static void clear(HepMC::GenParticle *part)
static void clear(HepMC::GenVertex *vtx)
::DataPool< HepMC::GenEvent, ClearGenEvent > evt
::DataPool< HepMC::GenParticle, ClearGenParticle > part
HepMC::GenParticlePtr getGenParticle()
HepMC::GenEvent * getGenEvent()
HepMC::GenVertexPtr getGenVertex()
::DataPool< HepMC::GenVertex, ClearGenVertex > vtx