-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathTStarJetVectorContainer.h
173 lines (144 loc) · 3.83 KB
/
TStarJetVectorContainer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#ifndef __TSTARJETVECTORCONTAINER__HH
#define __TSTARJETVECTORCONTAINER__HH
#include <TObject.h>
#include <TRef.h>
#include <TClonesArray.h>
#include <TClass.h>
#include <TArrayI.h>
#include <TArrayD.h>
#include "TStarJetPicoDefinitions.h"
template <class T>
class TStarJetVectorContainer : public TObject
{
public:
TStarJetVectorContainer();
TStarJetVectorContainer(const TStarJetVectorContainer<T> &t);
virtual ~TStarJetVectorContainer();
void Clear(Option_t *Option = "");
void Reset(Option_t *Option = "");
TClonesArray *GetArray() const {return fElements;}
Int_t GetEntries() const {return fNEntries;}
// use those in a consistent way - either one for each instance
void Add(T *part);
void AddContainer(TStarJetVectorContainer<T> *t);
void CopyFeatures(TStarJetVectorContainer<T> *t);
T *Get(Int_t n);
void PrintAll(Option_t *Option = "");
void SetFeature(Double_t val, Int_t what) {fFeatures[what] = val;}
Double_t GetFeature(Int_t what) {return fFeatures[what];}
void SetRefMult(Int_t val) {fRefMult = val;}
Int_t GetRefMult() {return fRefMult;}
protected:
private:
TClonesArray *fElements; //->array of elements
//static TClonesArray *fgElements; //!
Int_t fNEntries;
TRef fLastElement;
TArrayD fFeatures;
Int_t fRefMult; //reference multiplicity
ClassDefT(TStarJetVectorContainer<T>, 1)
};
//----------------------------------------------------------//
template <class T>
TStarJetVectorContainer<T>::TStarJetVectorContainer()
: TObject()
, fElements(0)
, fNEntries(0)
, fFeatures(_NUMBER_OF_EVENT_FEATURES)
, fRefMult(0)
{
if (fElements == 0)
{
TString tname = T::Class()->GetName();
//__INFO(Form("Creating class for %s", tname.Data()));
fElements = new TClonesArray(tname.Data(), 1000);
}
fNEntries = 0;
}
template <class T>
TStarJetVectorContainer<T>::TStarJetVectorContainer(const TStarJetVectorContainer<T> &t)
: TObject(t)
, fElements(t.fElements)
, fNEntries(t.fNEntries)
, fFeatures(_NUMBER_OF_EVENT_FEATURES)
, fRefMult(0)
{
;
}
template <class T>
TStarJetVectorContainer<T>::~TStarJetVectorContainer()
{
//Clear();
Reset();
}
template <class T>
void TStarJetVectorContainer<T>::Clear(Option_t */*Option*/)
{
// this costs huge mem!
//fElements->Clear("C");
// delete not...
fElements->Delete();
fNEntries = 0;
fFeatures.Set(_NUMBER_OF_EVENT_FEATURES);
fFeatures.Reset(0.0);
fRefMult = 0;
}
template <class T>
void TStarJetVectorContainer<T>::PrintAll(Option_t *Option)
{
this->Print(Option);
for (Int_t i = 0; i < this->GetEntries(); i++)
{
T *temp = this->Get(i);
temp->Print(Option);
}
}
template <class T>
void TStarJetVectorContainer<T>::Reset(Option_t */*Option*/)
{
fElements->Clear("C");
delete fElements;
fElements = 0;
fNEntries = 0;
fFeatures.Set(_NUMBER_OF_EVENT_FEATURES);
fFeatures.Reset(0.0);
fRefMult = 0;
}
template <class T>
void TStarJetVectorContainer<T>::Add(T *obj)
{
TClonesArray &arr = *fElements;
new(arr[fNEntries++]) T(*obj);
//T *newObj = new(arr[fNEntries++]) T(*obj);
//__INFO(Form("new 0x%x", newObj));
}
template <class T>
void TStarJetVectorContainer<T>::AddContainer(TStarJetVectorContainer<T> *t)
{
if (t != 0)
{
for (Int_t i = 0; i < t->GetEntries(); i++)
{
T *temp = t->Get(i);
Add(temp);
}
}
}
template <class T>
void TStarJetVectorContainer<T>::CopyFeatures(TStarJetVectorContainer<T> *t)
{
for (Int_t i = 0; i < fFeatures.GetSize(); i++)
{
fFeatures[i] = t->GetFeature(i);
}
}
template <class T>
T *TStarJetVectorContainer<T>::Get(Int_t n)
{
if (n < fNEntries)
{
return (T *)fElements->At(n);
}
return 0;
}
#endif