29 void TGeoMCBranchArrayContainer::Initialize(UInt_t maxLevels, UInt_t size)
31 fMaxLevels = maxLevels;
36 fIsInitialized = kTRUE;
39 void TGeoMCBranchArrayContainer::InitializeFromGeoManager(TGeoManager *man, UInt_t size)
41 Initialize(man->GetMaxLevels(), size);
44 void TGeoMCBranchArrayContainer::ResetCache()
48 fIsInitialized = kFALSE;
51 TGeoBranchArray *TGeoMCBranchArrayContainer::GetNewGeoState(UInt_t &userIndex)
53 if (fFreeIndices.empty()) {
54 ExtendCache(2 * fCache.size());
57 UInt_t internalIndex = fFreeIndices.back();
58 fFreeIndices.pop_back();
60 userIndex = internalIndex + 1;
61 fCache[internalIndex]->SetUniqueID(userIndex);
62 return fCache[internalIndex].get();
65 const TGeoBranchArray *TGeoMCBranchArrayContainer::GetGeoState(UInt_t userIndex)
70 if (userIndex > fCache.size()) {
71 ::Fatal(
"TGeoMCBranchArrayContainer::GetGeoState",
72 "ID %u is not an index referring to TGeoBranchArray "
73 "managed by this TGeoMCBranchArrayContainer",
76 if (fCache[userIndex - 1]->GetUniqueID() == 0) {
77 ::Fatal(
"TGeoMCBranchArrayContainer::GetGeoState",
"Passed index %u refers to an empty/unused geo state",
80 return fCache[userIndex - 1].get();
83 void TGeoMCBranchArrayContainer::FreeGeoState(UInt_t userIndex)
85 if (userIndex > fCache.size() || userIndex == 0) {
89 if (fCache[userIndex - 1]->GetUniqueID() > 0) {
90 fFreeIndices.push_back(userIndex - 1);
91 fCache[userIndex - 1]->SetUniqueID(0);
95 void TGeoMCBranchArrayContainer::FreeGeoState(
const TGeoBranchArray *geoState)
98 FreeGeoState(geoState->GetUniqueID());
102 void TGeoMCBranchArrayContainer::FreeGeoStates()
106 for (UInt_t i = 0; i < fCache.size(); i++) {
111 void TGeoMCBranchArrayContainer::ExtendCache(UInt_t targetSize)
113 if (targetSize <= fCache.size()) {
114 targetSize = 2 * fCache.size();
116 fFreeIndices.reserve(targetSize);
117 fCache.reserve(targetSize);
118 for (UInt_t i = fCache.size(); i < targetSize; i++) {
119 fCache.emplace_back(TGeoBranchArray::MakeInstance(fMaxLevels));
120 fCache.back()->SetUniqueID(0);
121 fFreeIndices.push_back(i);