ATLAS Offline Software
Loading...
Searching...
No Matches
Generators
GeneratorObjectsTPCnv
src
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
"
16
#include "
AtlasHepMC/GenVertex.h
"
17
#include "
AtlasHepMC/GenParticle.h
"
18
#include "
AthAllocators/DataPool.h
"
19
20
21
namespace
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
48
struct
ClearGenEvent
49
{
50
static
void
clear
(
HepMC::GenEvent
*
evt
) {
evt
->clear(); }
51
};
52
::DataPool<HepMC::GenEvent, ClearGenEvent>
evt
;
53
HepMC::GenEvent
*
getGenEvent
()
54
{
55
return
evt
.nextElementPtr();
56
}
57
58
struct
ClearGenVertex
59
{
60
static
void
clear
(HepMC::GenVertex*
vtx
) { *
vtx
= HepMC::GenVertex(); }
61
};
62
::DataPool<HepMC::GenVertex, ClearGenVertex>
vtx
;
63
HepMC::GenVertexPtr
getGenVertex
()
64
{
65
return
HepMC::GenVertexPtr
(
vtx
.nextElementPtr(), [](HepMC::GenVertex*){});
66
}
67
68
69
struct
ClearGenParticle
70
{
71
static
void
clear
(HepMC::GenParticle*
part
) { *
part
= HepMC::GenParticle(); }
72
};
73
::DataPool<HepMC::GenParticle, ClearGenParticle>
part
;
74
HepMC::GenParticlePtr
getGenParticle
()
75
{
76
return
HepMC::GenParticlePtr
(
part
.nextElementPtr(), [](HepMC::GenParticle*){});
77
}
78
79
};
80
81
}
// end namespace HepMC
82
83
#endif
// GENERATOROBJECTSATHENAPOOL_HEPMCDATAPOOL_H
DataPool.h
GenEvent.h
GenParticle.h
GenVertex.h
HepMC
Definition
Barcode.h:13
HepMC::GenParticlePtr
HepMC3::GenParticlePtr GenParticlePtr
Definition
GenParticle.h:19
HepMC::GenVertexPtr
HepMC3::GenVertexPtr GenVertexPtr
Definition
GenVertex.h:23
HepMC::GenEvent
HepMC3::GenEvent GenEvent
Definition
GenEvent.h:39
HepMC::DataPool::ClearGenEvent
Definition
HepMcDataPool.h:49
HepMC::DataPool::ClearGenEvent::clear
static void clear(HepMC::GenEvent *evt)
Definition
HepMcDataPool.h:50
HepMC::DataPool::ClearGenParticle
Definition
HepMcDataPool.h:70
HepMC::DataPool::ClearGenParticle::clear
static void clear(HepMC::GenParticle *part)
Definition
HepMcDataPool.h:71
HepMC::DataPool::ClearGenVertex
Definition
HepMcDataPool.h:59
HepMC::DataPool::ClearGenVertex::clear
static void clear(HepMC::GenVertex *vtx)
Definition
HepMcDataPool.h:60
HepMC::DataPool
Definition
HepMcDataPool.h:23
HepMC::DataPool::evt
::DataPool< HepMC::GenEvent, ClearGenEvent > evt
Definition
HepMcDataPool.h:52
HepMC::DataPool::part
::DataPool< HepMC::GenParticle, ClearGenParticle > part
Definition
HepMcDataPool.h:73
HepMC::DataPool::getGenParticle
HepMC::GenParticlePtr getGenParticle()
Definition
HepMcDataPool.h:74
HepMC::DataPool::getGenEvent
HepMC::GenEvent * getGenEvent()
Definition
HepMcDataPool.h:53
HepMC::DataPool::getGenVertex
HepMC::GenVertexPtr getGenVertex()
Definition
HepMcDataPool.h:63
HepMC::DataPool::vtx
::DataPool< HepMC::GenVertex, ClearGenVertex > vtx
Definition
HepMcDataPool.h:62
Generated on
for ATLAS Offline Software by
1.16.1