Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TGeoMCBranchArrayContainer.h
Go to the documentation of this file.
1 // @(#)root/vmc:$Id$
2 // Authors: Benedikt Volkel 07/03/2019
3 
4 /*************************************************************************
5  * Copyright (C) 2019, Rene Brun and Fons Rademakers. *
6  * Copyright (C) 2019, ALICE Experiment at CERN. *
7  * All rights reserved. *
8  * *
9  * For the licensing terms see $ROOTSYS/LICENSE. *
10  * For the list of contributors see $ROOTSYS/README/CREDITS. *
11  *************************************************************************/
12 
13 // Class TGeoMCBranchArrayContainer
14 // ---------------------
15 // cache for storing TGeoBranchArray objects
16 //
17 
18 #ifndef ROOT_TGeoMCBranchArrayContainer
19 #define ROOT_TGeoMCBranchArrayContainer
20 
21 #include <vector>
22 #include <memory>
23 
24 #include "TGeoBranchArray.h"
25 
26 class TGeoManager;
27 
28 class TGeoMCBranchArrayContainer {
29 public:
30  /// Default constructor
31  TGeoMCBranchArrayContainer() = default;
32  /// Destructor
33  ~TGeoMCBranchArrayContainer() = default;
34 
35  /// Initialize manually specifying initial number of internal
36  /// TGeoBranchArray objects
37  void Initialize(UInt_t maxlevels = 100, UInt_t size = 8);
38  /// Initialize from TGeoManager to extract maxlevels
39  void InitializeFromGeoManager(TGeoManager *man, UInt_t size = 8);
40  /// Clear the internal cache
41  void ResetCache();
42 
43  /// Get a TGeoBranchArray to set to current geo state.
44  TGeoBranchArray *GetNewGeoState(UInt_t &userIndex);
45  /// Get a TGeoBranchArray to read the current state from.
46  const TGeoBranchArray *GetGeoState(UInt_t userIndex);
47  /// Free the index of this geo state such that it can be re-used
48  void FreeGeoState(UInt_t userIndex);
49  /// Free the index of this geo state such that it can be re-used
50  void FreeGeoState(const TGeoBranchArray *geoState);
51  /// Free all geo states at once but keep the container size
52  void FreeGeoStates();
53 
54 private:
55  /// Copying kept private
56  TGeoMCBranchArrayContainer(const TGeoMCBranchArrayContainer &);
57  /// Assignement kept private
58  TGeoMCBranchArrayContainer &operator=(const TGeoMCBranchArrayContainer &);
59  /// Resize the cache
60  void ExtendCache(UInt_t targetSize = 1);
61 
62 private:
63  /// Cache states via TGeoBranchArray
64  std::vector<std::unique_ptr<TGeoBranchArray>> fCache;
65  /// Maximum level of node array inside a chached state.
66  UInt_t fMaxLevels = 100;
67  /// Provide indices in fCachedStates which are already popped and can be
68  /// re-populated again.
69  std::vector<UInt_t> fFreeIndices;
70  /// Flag if initialized
71  Bool_t fIsInitialized = kFALSE;
72 
73  ClassDefNV(TGeoMCBranchArrayContainer, 1)
74 };
75 
76 #endif /* ROOT_TGeoMCBranchArrayContainer */