ATLAS Offline Software
PerfMonTestPolyVectorAlgWithArenas.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 #include "AthAllocators/DataPool.h" /* NEW */
8 
9 #include "Hit.h"
11 /* #define DEBUG_ME 1 */
12 
13 using namespace PerfMonTest;
14 using namespace::std;
15 
17 
19 // Public methods:
21 
22 // Constructors
25  ISvcLocator* pSvcLocator ) :
26  AthAlgorithm ( name, pSvcLocator ),
27  m_vectorSize(1024*1024), m_2bReserved(m_vectorSize), m_mixture(1), m_mapIt(false)
28 {
29  declareProperty("VectorSize", m_vectorSize, "the size of the Hit container");
30  declareProperty("ToBeReserved", m_2bReserved, "the number of element to be reserved");
31  declareProperty("Mixture", m_mixture, "equal to the ratio DHIT/FHIT - 1 (default 1 == all DHits)");
32  declareProperty("MapIt", m_mapIt, "add current hit to a map");
33 }
34 
35 // Destructor
38 {
39  ATH_MSG_DEBUG("Calling destructor");
40 }
41 
42 // Athena Algorithm's Hooks
45 {
46  ATH_MSG_INFO("Initializing ");
47  return StatusCode::SUCCESS;
48 }
49 
51 {
52  ATH_MSG_INFO("Finalizing ");
53  return StatusCode::SUCCESS;
54 }
55 
57 {
58  DataPool<DHit> dhitPool;
59  DataPool<FHit> fhitPool;
60  ATH_MSG_DEBUG("Executing ");
61  HitPtrContainer vptr(SG::VIEW_ELEMENTS); //<<< NEW
62  vptr.reserve(m_2bReserved.value());
63  int vcap(vptr.capacity());
64  int vold;
65 #ifdef DEBUG_ME
66  IHit* p1(0);
67  IHit* p2(0);
68 #endif
69  IHit* p3(0);
70  cout << "initial capacity " << vcap << endl;
71  int size(m_vectorSize.value());
72  for(int i(0); i<size; ++i) {
73  vold=vcap;
74 #ifdef DEBUG_ME
75  p1=p2;
76  p2=p3;
77 #endif
78  p3=(i % m_mixture.value()) ?
79  (IHit*) new(fhitPool.nextElementPtr()) FHit(i, i, i):
80  (IHit*) new(dhitPool.nextElementPtr()) DHit(i, i, i); //<<< NEW
81  vptr.push_back(p3);
82  vcap=vptr.capacity();
83  if (m_mapIt.value()) m_mixMap[i]=p3;
84  if (vold != vcap) cout << "iteration " << i << " new capacity " << vcap <<endl;
85 #ifdef DEBUG_ME
86  if (((int)p3-(int)p2) != ((int)p2-(int)p1)) cout << "iteration " << i << " new chunk @" << hex << p3 << " previous was @" << p2 << dec << endl;
87 #ifdef REALLY_DEBUG_ME
88  cout << "iteration " << i << " P3 @" << hex << p3 << " p2 @" << p2 << " p1 @" << p1 << dec << ' ' << (int)p3-(int)p2 << ' ' <<(int)p2-(int)p1 <<endl;
89 #endif
90 #endif
91  }
92 
93  return StatusCode::SUCCESS;
94 }
DataVector::reserve
void reserve(size_type n)
Attempt to preallocate enough memory for a specified number of elements.
PerfMonTest::PolyVectorAlgWithArenas::~PolyVectorAlgWithArenas
virtual ~PolyVectorAlgWithArenas()
Destructor:
Definition: PerfMonTestPolyVectorAlgWithArenas.cxx:37
PerfMonTest::PolyVectorAlgWithArenas::PolyVectorAlgWithArenas
PolyVectorAlgWithArenas()
no implementation
PerfMonTest::FHit
Definition: Control/PerformanceMonitoring/PerfMonTests/src/Hit.h:30
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
AthMsgStreamMacros.h
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
SG::VIEW_ELEMENTS
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition: OwnershipPolicy.h:18
PerfMonTest::DHit
Definition: Control/PerformanceMonitoring/PerfMonTests/src/Hit.h:15
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
TRTCalib_cfilter.p1
p1
Definition: TRTCalib_cfilter.py:130
PerfMonTest::IHit
Definition: Control/PerformanceMonitoring/PerfMonTests/src/Hit.h:8
PerfMonTest::PolyVectorAlgWithArenas::m_2bReserved
IntegerProperty m_2bReserved
Property to setup the amount of elements to reserve.
Definition: PerfMonTestPolyVectorAlgWithArenas.h:42
PerfMonTestPolyVectorAlgWithArenas.h
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
TRTCalib_cfilter.p2
p2
Definition: TRTCalib_cfilter.py:131
lumiFormat.i
int i
Definition: lumiFormat.py:85
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
Hit.h
PerfMonTest
PerfMonTestPolyVectorAlg.h Example for the memory optimization tutorial.
Definition: Control/PerformanceMonitoring/PerfMonTests/src/Hit.h:7
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
DataPool::nextElementPtr
pointer nextElementPtr()
obtain the next available element in pool by pointer pool is resized if its limit has been reached On...
HitPtrContainer
DataVector< IHit > HitPtrContainer
Definition: PerfMonTestPolyVectorAlgWithArenas.cxx:16
AthAlgorithm
Definition: AthAlgorithm.h:47
DataVector::capacity
size_type capacity() const noexcept
Returns the total number of elements that the collection can hold before needing to allocate more mem...
DataPool.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
PerfMonTest::PolyVectorAlgWithArenas::m_mixture
IntegerProperty m_mixture
Property to set DHIT/FHIT ratio.
Definition: PerfMonTestPolyVectorAlgWithArenas.h:44
PerfMonTest::PolyVectorAlgWithArenas::execute
virtual StatusCode execute()
Definition: PerfMonTestPolyVectorAlgWithArenas.cxx:56
DataVector.h
An STL vector of pointers that by default owns its pointed-to elements.
PerfMonTest::PolyVectorAlgWithArenas::m_mapIt
BooleanProperty m_mapIt
Property to introduce some fragmentation.
Definition: PerfMonTestPolyVectorAlgWithArenas.h:46
PerfMonTest::PolyVectorAlgWithArenas::m_mixMap
std::map< int, IHit * > m_mixMap
Definition: PerfMonTestPolyVectorAlgWithArenas.h:47
DataPool
a typed memory pool that saves time spent allocation small object. This is typically used by containe...
Definition: DataPool.h:47
PerfMonTest::PolyVectorAlgWithArenas::finalize
virtual StatusCode finalize()
Definition: PerfMonTestPolyVectorAlgWithArenas.cxx:50
TRTCalib_cfilter.p3
p3
Definition: TRTCalib_cfilter.py:132
PerfMonTest::PolyVectorAlgWithArenas::m_vectorSize
IntegerProperty m_vectorSize
Property to setup the size of the Hit container.
Definition: PerfMonTestPolyVectorAlgWithArenas.h:40
PerfMonTest::PolyVectorAlgWithArenas::initialize
virtual StatusCode initialize()
Definition: PerfMonTestPolyVectorAlgWithArenas.cxx:44