PandaRoot
PndTCAMutableContainer.h
Go to the documentation of this file.
1 //****************************************************************************
2 //* This file is part of PandaRoot. *
3 //* *
4 //* PandaRoot is distributed under the terms of the *
5 //* GNU General Public License (GPL) version 3, *
6 //* copied verbatim in the file "LICENSE". *
7 //* *
8 //* Copyright (C) 2006 - 2024 FAIR GmbH and copyright holders of PandaRoot *
9 //* The copyright holders are listed in the file "COPYRIGHTHOLDERS". *
10 //* The authors are listed in the file "AUTHORS". *
11 //****************************************************************************
12 
27 #ifndef PNDTCAMUTABLECONTAINER_HH
28 #define PNDTCAMUTABLECONTAINER_HH
29 
30 #include <stdexcept>
31 #include <vector>
32 
33 #include "TClonesArray.h"
34 #include "TString.h"
35 
36 #include "FairLogger.h"
37 #include "FairRootManager.h"
38 
39 #include "PndMutableContainerI.h"
40 
49 template <class T>
51  public:
58  PndTCAMutableContainer(const TString &t_foldername = "", Bool_t t_persistency = kTRUE) : PndMutableContainerI<T>(t_foldername, t_persistency) {}
59 
65 
70  virtual void Reset() final
71  {
72  if (this->fTCA != nullptr) {
73  this->fTCA->Delete();
74  }
75  }
82  virtual T *CreateCopy(const T &t_element)
83  {
84  if (fTCA != nullptr) {
85  new ((*fTCA)[fTCA->GetEntriesFast()]) T{t_element};
86  } else {
87  LOG(error) << "PndTCAMutableContainer::CreateCopy() no underlying TClonesArray";
88  return nullptr;
89  }
90  return GetElement(GetSize() - 1);
91  }
92 
98  virtual void RemoveAt(Int_t t_index)
99  {
100  if (this->fTCA != nullptr) {
101  this->fTCA->RemoveAt(t_index);
102  }
103  }
104 
109  virtual void Compress()
110  {
111  if (this->fTCA != nullptr) {
112  this->fTCA->Compress();
113  }
114  }
115 
122  virtual T *GetElement(Int_t t_idx) const final
123  {
124  if (fTCA != nullptr) {
125  return static_cast<T *>(fTCA->At(t_idx));
126  }
127  return nullptr;
128  }
129 
135  virtual ssize_t GetSize() const final
136  {
137  if (fTCA != nullptr) {
138  return fTCA->GetEntriesFast();
139  }
140  return 0;
141  }
142 
148  void SetTCA(TClonesArray *t_tca) { fTCA = t_tca; }
149 
155  TClonesArray *GetTCA() { return fTCA; }
156 
157  protected:
158  TClonesArray *fTCA{nullptr};
159 };
160 
161 #endif /*PNDTCAMUTABLECONTAINER_HH*/
virtual ~PndTCAMutableContainer()
Destroy the PndTCAOutput Container object.
void SetTCA(TClonesArray *t_tca)
Set the TClonesArray address.
TClonesArray * GetTCA()
Get the TClonesArray address.
virtual void Reset() final
Delete all elements.
virtual ssize_t GetSize() const final
Get the number of elements.
virtual T * GetElement(Int_t t_idx) const final
Get pointer to the t_idx-th element.
PndTCAMutableContainer implementation of PndMutableContainerI<T> for FairRootManager and TClonesArray...
PndTCAMutableContainer(const TString &t_foldername="", Bool_t t_persistency=kTRUE)
Construct a new PndTCAMutableContainer object.
virtual T * CreateCopy(const T &t_element)
Create a copy of t_element in the TClonesArray and return a pointer to it.
virtual void Compress()
Compress.
virtual void RemoveAt(Int_t t_index)
remove the t_index-th element