VMC
Version 2.2
Toggle main menu visibility
Loading...
Searching...
No Matches
source
src
TGeoMCBranchArrayContainer.cxx
Go to the documentation of this file.
1
// -----------------------------------------------------------------------
2
// Copyright (C) 2019 CERN and copyright holders of VMC Project.
3
// This software is distributed under the terms of the GNU General Public
4
// License v3 (GPL Version 3), copied verbatim in the file "LICENSE".
5
//
6
// See https://github.com/vmc-project/vmc for full licensing information.
7
// -----------------------------------------------------------------------
8
9
// Authors: Benedikt Volkel 07/03/2019
10
11
/*************************************************************************
12
* Copyright (C) 2019, Rene Brun and Fons Rademakers. *
13
* Copyright (C) 2019, ALICE Experiment at CERN. *
14
* All rights reserved. *
15
* *
16
* For the licensing terms see $ROOTSYS/LICENSE. *
17
* For the list of contributors see $ROOTSYS/README/CREDITS. *
18
*************************************************************************/
19
31
32
#include "
TGeoMCBranchArrayContainer.h
"
33
#include "TGeoManager.h"
34
#include "TError.h"
35
36
void
TGeoMCBranchArrayContainer::Initialize
(UInt_t maxLevels, UInt_t size)
37
{
38
fMaxLevels
= maxLevels;
39
if
(
fIsInitialized
) {
40
ResetCache
();
41
}
42
ExtendCache
(size);
43
fIsInitialized
= kTRUE;
44
}
45
46
void
TGeoMCBranchArrayContainer::InitializeFromGeoManager
(TGeoManager *man, UInt_t size)
47
{
48
Initialize
(man->GetMaxLevels(), size);
49
}
50
51
void
TGeoMCBranchArrayContainer::ResetCache
()
52
{
53
fCache
.clear();
54
fFreeIndices
.clear();
55
fIsInitialized
= kFALSE;
56
}
57
58
TGeoBranchArray *
TGeoMCBranchArrayContainer::GetNewGeoState
(UInt_t &userIndex)
59
{
60
if
(
fFreeIndices
.empty()) {
61
ExtendCache
(2 *
fCache
.size());
62
}
63
// Get index from the back
64
UInt_t internalIndex =
fFreeIndices
.back();
65
fFreeIndices
.pop_back();
66
// indices seen by the user are +1
67
userIndex = internalIndex + 1;
68
fCache
[internalIndex]->SetUniqueID(userIndex);
69
return
fCache
[internalIndex].get();
70
}
71
72
const
TGeoBranchArray *
TGeoMCBranchArrayContainer::GetGeoState
(UInt_t userIndex)
73
{
74
if
(userIndex == 0) {
75
return
nullptr
;
76
}
77
if
(userIndex >
fCache
.size()) {
78
::Fatal(
"TGeoMCBranchArrayContainer::GetGeoState"
,
79
"ID %u is not an index referring to TGeoBranchArray "
80
"managed by this TGeoMCBranchArrayContainer"
,
81
userIndex);
82
}
83
if
(
fCache
[userIndex - 1]->GetUniqueID() == 0) {
84
::Fatal(
"TGeoMCBranchArrayContainer::GetGeoState"
,
"Passed index %u refers to an empty/unused geo state"
,
85
userIndex);
86
}
87
return
fCache
[userIndex - 1].get();
88
}
89
90
void
TGeoMCBranchArrayContainer::FreeGeoState
(UInt_t userIndex)
91
{
92
if
(userIndex >
fCache
.size() || userIndex == 0) {
93
return
;
94
}
95
// Unlock this index so it is free for later use. No need to delete since TGeoBranchArray can be re-used
96
if
(
fCache
[userIndex - 1]->GetUniqueID() > 0) {
97
fFreeIndices
.push_back(userIndex - 1);
98
fCache
[userIndex - 1]->SetUniqueID(0);
99
}
100
}
101
102
void
TGeoMCBranchArrayContainer::FreeGeoState
(
const
TGeoBranchArray *geoState)
103
{
104
if
(geoState) {
105
FreeGeoState
(geoState->GetUniqueID());
106
}
107
}
108
109
void
TGeoMCBranchArrayContainer::FreeGeoStates
()
110
{
111
// Start counting at 1 since that is the index seen by the user which is assumed by
112
// TGeoMCBranchArrayContainer::FreeGeoState(UInt_t userIndex)
113
for
(UInt_t i = 0; i <
fCache
.size(); i++) {
114
FreeGeoState
(i + 1);
115
}
116
}
117
118
void
TGeoMCBranchArrayContainer::ExtendCache
(UInt_t targetSize)
119
{
120
if
(targetSize <=
fCache
.size()) {
121
targetSize = 2 *
fCache
.size();
122
}
123
fFreeIndices
.reserve(targetSize);
124
fCache
.reserve(targetSize);
125
for
(UInt_t i =
fCache
.size(); i < targetSize; i++) {
126
fCache
.emplace_back(TGeoBranchArray::MakeInstance(
fMaxLevels
));
127
fCache
.back()->SetUniqueID(0);
128
fFreeIndices
.push_back(i);
129
}
130
}
TGeoMCBranchArrayContainer.h
TGeoMCBranchArrayContainer::ExtendCache
void ExtendCache(UInt_t targetSize=1)
Resize the cache.
Definition
TGeoMCBranchArrayContainer.cxx:118
TGeoMCBranchArrayContainer::fMaxLevels
UInt_t fMaxLevels
Maximum level of node array inside a chached state.
Definition
TGeoMCBranchArrayContainer.h:73
TGeoMCBranchArrayContainer::Initialize
void Initialize(UInt_t maxlevels=100, UInt_t size=8)
Initialize manually specifying initial number of internal TGeoBranchArray objects.
Definition
TGeoMCBranchArrayContainer.cxx:36
TGeoMCBranchArrayContainer::GetNewGeoState
TGeoBranchArray * GetNewGeoState(UInt_t &userIndex)
Get a TGeoBranchArray to set to current geo state.
Definition
TGeoMCBranchArrayContainer.cxx:58
TGeoMCBranchArrayContainer::GetGeoState
const TGeoBranchArray * GetGeoState(UInt_t userIndex)
Get a TGeoBranchArray to read the current state from.
Definition
TGeoMCBranchArrayContainer.cxx:72
TGeoMCBranchArrayContainer::fFreeIndices
std::vector< UInt_t > fFreeIndices
Provide indices in fCachedStates which are already popped and can be re-populated again.
Definition
TGeoMCBranchArrayContainer.h:76
TGeoMCBranchArrayContainer::InitializeFromGeoManager
void InitializeFromGeoManager(TGeoManager *man, UInt_t size=8)
Initialize from TGeoManager to extract maxlevels.
Definition
TGeoMCBranchArrayContainer.cxx:46
TGeoMCBranchArrayContainer::fIsInitialized
Bool_t fIsInitialized
Flag if initialized.
Definition
TGeoMCBranchArrayContainer.h:78
TGeoMCBranchArrayContainer::ResetCache
void ResetCache()
Clear the internal cache.
Definition
TGeoMCBranchArrayContainer.cxx:51
TGeoMCBranchArrayContainer::FreeGeoStates
void FreeGeoStates()
Free all geo states at once but keep the container size.
Definition
TGeoMCBranchArrayContainer.cxx:109
TGeoMCBranchArrayContainer::FreeGeoState
void FreeGeoState(UInt_t userIndex)
Free the index of this geo state such that it can be re-used.
Definition
TGeoMCBranchArrayContainer.cxx:90
TGeoMCBranchArrayContainer::fCache
std::vector< std::unique_ptr< TGeoBranchArray > > fCache
Cache states via TGeoBranchArray.
Definition
TGeoMCBranchArrayContainer.h:71
Generated on
for VMC by
1.17.0