1 |
yjlee |
1.1 |
#ifndef HCOLUMN_H
|
2 |
|
|
#define HCOLUMN_H
|
3 |
|
|
|
4 |
|
|
/** \class HColumn Ganzhur/HafHistogram/interface/HColumn.h
|
5 |
|
|
*
|
6 |
|
|
* Description:
|
7 |
|
|
* Analysis code of the CMS experiment;
|
8 |
|
|
* Original version is a part of HAF package developed for CMS: UserCode/HAF
|
9 |
|
|
* Nested class hierarchy to hold information about HTuple columns
|
10 |
|
|
*
|
11 |
|
|
* \author Marcel Kunze, Ruhr-University Bochum, Germany
|
12 |
|
|
*
|
13 |
|
|
* \version $Id: HColumn.h,v 1.4 2010/03/05 10:24:31 musella Exp $
|
14 |
|
|
*
|
15 |
|
|
*/
|
16 |
|
|
|
17 |
|
|
#include <assert.h>
|
18 |
|
|
#include "TNamed.h"
|
19 |
|
|
#include "TString.h"
|
20 |
|
|
#include "TVector.h"
|
21 |
|
|
#include "TTree.h"
|
22 |
|
|
#include "TBranch.h"
|
23 |
|
|
|
24 |
|
|
#include "TLorentzVector.h"
|
25 |
|
|
#include "TVector3.h"
|
26 |
|
|
#include "TClonesArray.h"
|
27 |
|
|
|
28 |
|
|
#ifndef HTRange_HH
|
29 |
|
|
#define HTRange_HH
|
30 |
|
|
|
31 |
|
|
template<class T>
|
32 |
|
|
class HTRange {
|
33 |
|
|
|
34 |
|
|
public:
|
35 |
|
|
|
36 |
|
|
HTRange() :
|
37 |
|
|
fDefined(kFALSE), fLower(0), fUpper(0)
|
38 |
|
|
{
|
39 |
|
|
}
|
40 |
|
|
|
41 |
|
|
HTRange(T lower, T upper) :
|
42 |
|
|
fDefined(kTRUE), fLower(lower), fUpper(upper)
|
43 |
|
|
{
|
44 |
|
|
}
|
45 |
|
|
|
46 |
|
|
HTRange(const HTRange<T>& o) :
|
47 |
|
|
fDefined(o.fDefined), fLower(o.fLower), fUpper(o.fUpper)
|
48 |
|
|
{
|
49 |
|
|
}
|
50 |
|
|
|
51 |
|
|
virtual ~HTRange() {}
|
52 |
|
|
|
53 |
|
|
HTRange<T>& operator= (const HTRange<T> &o)
|
54 |
|
|
{
|
55 |
|
|
if (&o == this) return *this;
|
56 |
|
|
fDefined = o.fDefined ;
|
57 |
|
|
fLower = o.fLower ;
|
58 |
|
|
fUpper = o.fUpper ;
|
59 |
|
|
return *this ;
|
60 |
|
|
}
|
61 |
|
|
|
62 |
|
|
Bool_t operator()() const { return fDefined ; }
|
63 |
|
|
|
64 |
|
|
T lower() const { return fLower ; }
|
65 |
|
|
T upper() const { return fUpper ; }
|
66 |
|
|
|
67 |
|
|
private:
|
68 |
|
|
|
69 |
|
|
Bool_t fDefined ;
|
70 |
|
|
T fLower, fUpper ;
|
71 |
|
|
|
72 |
|
|
};
|
73 |
|
|
#endif
|
74 |
|
|
|
75 |
|
|
|
76 |
|
|
#ifndef HTAbsValVector_HH
|
77 |
|
|
#define HTAbsValVector_HH
|
78 |
|
|
|
79 |
|
|
template<class T>
|
80 |
|
|
class HTAbsValVector {
|
81 |
|
|
|
82 |
|
|
public:
|
83 |
|
|
|
84 |
|
|
// This must return the number of the stored elements
|
85 |
|
|
virtual size_t length() const = 0 ;
|
86 |
|
|
|
87 |
|
|
// This provides access to the indifidual elements.
|
88 |
|
|
// Index runs from 0 to length()-1. Here () means that we do not requre
|
89 |
|
|
// index checking from it, though the real classe may do what they like.
|
90 |
|
|
virtual const T& operator()(size_t i) const = 0;
|
91 |
|
|
virtual T& operator()(size_t i) = 0;
|
92 |
|
|
virtual const T& operator[](size_t i) const = 0;
|
93 |
|
|
virtual T& operator[](size_t i) = 0;
|
94 |
|
|
|
95 |
|
|
};
|
96 |
|
|
#endif
|
97 |
|
|
|
98 |
|
|
|
99 |
|
|
#ifndef HTAbsValArray_HH
|
100 |
|
|
#define HTAbsValArray_HH
|
101 |
|
|
|
102 |
|
|
template<class T, size_t N>
|
103 |
|
|
class HTValArray : public HTAbsValVector<T> {
|
104 |
|
|
|
105 |
|
|
public:
|
106 |
|
|
|
107 |
|
|
HTValArray() {}
|
108 |
|
|
HTValArray( const T& v ) ;
|
109 |
|
|
HTValArray( const HTValArray<T,N> &v ) ;
|
110 |
|
|
|
111 |
|
|
HTValArray<T,N>& operator=( const HTValArray<T,N> &v ) ;
|
112 |
|
|
|
113 |
|
|
virtual size_t length() const ;
|
114 |
|
|
virtual const T& operator()(size_t i) const ;
|
115 |
|
|
|
116 |
|
|
T& operator()(size_t i) { return _array[i] ; }
|
117 |
|
|
const T& operator[](size_t i) const {
|
118 |
|
|
assert ( i<N ) ;
|
119 |
|
|
return _array[i] ;
|
120 |
|
|
}
|
121 |
|
|
T& operator[](size_t i) {
|
122 |
|
|
assert ( i<N ) ;
|
123 |
|
|
return _array[i] ;
|
124 |
|
|
}
|
125 |
|
|
|
126 |
|
|
private:
|
127 |
|
|
|
128 |
|
|
T _array[N] ;
|
129 |
|
|
|
130 |
|
|
};
|
131 |
|
|
|
132 |
|
|
template<class T, size_t N>
|
133 |
|
|
HTValArray<T,N>::HTValArray( const T& v )
|
134 |
|
|
{
|
135 |
|
|
for ( int i = 0 ; i < N ; i ++ ) {
|
136 |
|
|
_array[i] = v ;
|
137 |
|
|
}
|
138 |
|
|
}
|
139 |
|
|
|
140 |
|
|
template<class T, size_t N>
|
141 |
|
|
HTValArray<T,N>::HTValArray( const HTValArray<T,N> &v )
|
142 |
|
|
{
|
143 |
|
|
for ( int i = 0 ; i < N ; i ++ ) {
|
144 |
|
|
_array[i] = v._array[i] ;
|
145 |
|
|
}
|
146 |
|
|
}
|
147 |
|
|
|
148 |
|
|
template<class T, size_t N>
|
149 |
|
|
HTValArray<T,N>&
|
150 |
|
|
HTValArray<T,N>::operator=( const HTValArray<T,N> &v )
|
151 |
|
|
{
|
152 |
|
|
for ( int i = 0 ; i < N ; i ++ ) {
|
153 |
|
|
_array[i] = v._array[i] ;
|
154 |
|
|
}
|
155 |
|
|
return *this ;
|
156 |
|
|
}
|
157 |
|
|
|
158 |
|
|
template<class T, size_t N>
|
159 |
|
|
size_t
|
160 |
|
|
HTValArray<T,N>::length() const
|
161 |
|
|
{
|
162 |
|
|
return N;
|
163 |
|
|
}
|
164 |
|
|
|
165 |
|
|
template<class T, size_t N>
|
166 |
|
|
const T&
|
167 |
|
|
HTValArray<T,N>::operator()(size_t i) const
|
168 |
|
|
{
|
169 |
|
|
return _array[i] ;
|
170 |
|
|
}
|
171 |
|
|
|
172 |
|
|
#endif
|
173 |
|
|
|
174 |
|
|
|
175 |
|
|
#ifndef HTValVector_HH
|
176 |
|
|
#define HTValVector_HH
|
177 |
|
|
|
178 |
|
|
using namespace std;
|
179 |
|
|
#include <deque>
|
180 |
|
|
|
181 |
|
|
template<class T>
|
182 |
|
|
class HTValVector : public HTAbsValVector<T>
|
183 |
|
|
{
|
184 |
|
|
|
185 |
|
|
public:
|
186 |
|
|
|
187 |
|
|
typedef typename deque<T>::value_type value_type;
|
188 |
|
|
typedef typename deque<T>::pointer pointer;
|
189 |
|
|
typedef typename deque<T>::const_pointer conts_pointer;
|
190 |
|
|
typedef typename deque<T>::iterator iterator;
|
191 |
|
|
typedef typename deque<T>::const_iterator const_iterator;
|
192 |
|
|
typedef typename deque<T>::reference reference;
|
193 |
|
|
typedef typename deque<T>::const_reference const_reference;
|
194 |
|
|
typedef typename deque<T>::size_type size_type;
|
195 |
|
|
typedef typename deque<T>::difference_type difference_type;
|
196 |
|
|
|
197 |
|
|
HTValVector() : _d() {}
|
198 |
|
|
HTValVector( size_type n ) : _d(n) {}
|
199 |
|
|
HTValVector( const HTValVector<T> &d ) : _d(d._d) {}
|
200 |
|
|
HTValVector( const deque<T> &d ) : _d(d) {}
|
201 |
|
|
|
202 |
|
|
virtual ~HTValVector() {}
|
203 |
|
|
|
204 |
|
|
virtual HTValVector<T>& operator=(const HTValVector<T>& d) { _d=d._d; return *this; }
|
205 |
|
|
virtual bool operator<(const HTValVector<T>& d) { return _d<d._d; }
|
206 |
|
|
virtual bool operator==(const HTValVector<T>& d) { return _d==d._d; }
|
207 |
|
|
virtual const T& operator()(size_type i) const { return _d[i]; }
|
208 |
|
|
virtual T& operator()(size_type i) { return _d[i]; }
|
209 |
|
|
virtual const T& operator[](size_type i) const { return _d[i]; }
|
210 |
|
|
virtual T& operator[](size_type i) { return _d[i]; }
|
211 |
|
|
|
212 |
|
|
virtual size_type size() const { return _d.size(); }
|
213 |
|
|
virtual size_type length() const { return _d.size(); }
|
214 |
|
|
virtual size_type entries() const { return _d.size(); }
|
215 |
|
|
virtual void append(const T& t) { _d.push_back(t); }
|
216 |
|
|
virtual void prepend(const T& t) { _d.push_front(t); }
|
217 |
|
|
virtual bool remove(const T& t) {
|
218 |
|
|
for( iterator i=_d.begin(); i!=_d.end(); ++i ) {
|
219 |
|
|
if( *i == t ) {
|
220 |
|
|
_d.erase(i);
|
221 |
|
|
return true;
|
222 |
|
|
}
|
223 |
|
|
}
|
224 |
|
|
return false;
|
225 |
|
|
}
|
226 |
|
|
virtual bool contains(const T& t) const {
|
227 |
|
|
for( const_iterator i=_d.begin(); i!=_d.end(); ++i ) {
|
228 |
|
|
if( *i == t ) return true;
|
229 |
|
|
}
|
230 |
|
|
return false;
|
231 |
|
|
}
|
232 |
|
|
virtual bool isEmpty() const { return _d.empty(); }
|
233 |
|
|
virtual void reshape(size_type n) { _d.resize(n); }
|
234 |
|
|
virtual iterator begin() { return _d.begin(); }
|
235 |
|
|
virtual iterator end() { return _d.end(); }
|
236 |
|
|
virtual void clear() { _d.clear(); }
|
237 |
|
|
|
238 |
|
|
protected:
|
239 |
|
|
|
240 |
|
|
deque<T> _d;
|
241 |
|
|
|
242 |
|
|
};
|
243 |
|
|
|
244 |
|
|
#endif
|
245 |
|
|
|
246 |
|
|
|
247 |
|
|
#ifndef HTValOrderedVector_HH
|
248 |
|
|
#define HTValOrderedVector_HH
|
249 |
|
|
|
250 |
|
|
using namespace std;
|
251 |
|
|
#include <vector>
|
252 |
|
|
#include <deque>
|
253 |
|
|
|
254 |
|
|
template<class T>
|
255 |
|
|
class HTValOrderedVector : public HTValVector<T>
|
256 |
|
|
{
|
257 |
|
|
|
258 |
|
|
public:
|
259 |
|
|
|
260 |
|
|
typedef typename deque<T>::size_type size_type;
|
261 |
|
|
|
262 |
|
|
HTValOrderedVector() : HTValVector<T>() {}
|
263 |
|
|
HTValOrderedVector( size_type n ) : HTValVector<T>() {}
|
264 |
|
|
HTValOrderedVector( const HTValOrderedVector<T> &v )
|
265 |
|
|
: HTValVector<T>(v) {}
|
266 |
|
|
HTValOrderedVector( const vector<T> &v ) : HTValVector<T>(v) {}
|
267 |
|
|
|
268 |
|
|
virtual ~HTValOrderedVector() {}
|
269 |
|
|
|
270 |
|
|
void resize(size_type n) {}
|
271 |
|
|
|
272 |
|
|
};
|
273 |
|
|
|
274 |
|
|
#endif
|
275 |
|
|
|
276 |
|
|
|
277 |
|
|
// Parent class (abstract):
|
278 |
|
|
class HColumn : public TNamed {
|
279 |
|
|
|
280 |
|
|
public:
|
281 |
|
|
|
282 |
|
|
HColumn(const char* l) :
|
283 |
|
|
TNamed(l,l), fLabel(l), fUseDefValue(0), fPointer(0), fBranch(0) {}
|
284 |
|
|
virtual ~HColumn() {}
|
285 |
|
|
const TString &GetLabel() const { return fLabel; }
|
286 |
|
|
TBranch* GetBrPointer() { return fBranch; }
|
287 |
|
|
void* GetPointer() { return fPointer; }
|
288 |
|
|
void SetPointer(void* p) { fPointer = p; }
|
289 |
|
|
void SetUseDefValue(Int_t b) { fUseDefValue = b; }
|
290 |
|
|
const Int_t & GetUseDefValue() const { return fUseDefValue; }
|
291 |
|
|
virtual void SetDefValue() = 0;
|
292 |
|
|
virtual void SetValue(const void*, HColumn* cp=0) = 0;
|
293 |
|
|
|
294 |
|
|
protected:
|
295 |
|
|
|
296 |
|
|
TString fLabel;
|
297 |
|
|
Int_t fUseDefValue;
|
298 |
|
|
void* fPointer; //!
|
299 |
|
|
TBranch* fBranch;
|
300 |
|
|
|
301 |
|
|
ClassDef(HColumn,1) // HColumn
|
302 |
|
|
|
303 |
|
|
};
|
304 |
|
|
|
305 |
|
|
|
306 |
|
|
// Classes for Bool_t:
|
307 |
|
|
class BoolColumn : public HColumn {
|
308 |
|
|
public:
|
309 |
|
|
BoolColumn(const char*, const Bool_t &, const Bool_t &, TTree*);
|
310 |
|
|
virtual ~BoolColumn() { delete (Bool_t*)fPointer; }
|
311 |
|
|
virtual void SetDefValue() { *(Char_t*)fPointer = fDefValue; }
|
312 |
|
|
virtual void SetValue(const void* p, HColumn* cp=0) {
|
313 |
|
|
*(Char_t*)fPointer = *(const Bool_t*)p;
|
314 |
|
|
}
|
315 |
|
|
private:
|
316 |
|
|
Bool_t fDefValue;
|
317 |
|
|
};
|
318 |
|
|
|
319 |
|
|
class BoolArrColumn : public HColumn {
|
320 |
|
|
public:
|
321 |
|
|
BoolArrColumn(const char*, const HTAbsValVector<Bool_t> &, const Bool_t &,
|
322 |
|
|
TTree*);
|
323 |
|
|
virtual ~BoolArrColumn() { delete[] (Bool_t*)fPointer; }
|
324 |
|
|
virtual void SetDefValue() {
|
325 |
|
|
for(Int_t i = 0; i < fMax; ++i) ((Char_t*)fPointer)[i] = fDefValue;
|
326 |
|
|
}
|
327 |
|
|
virtual void SetValue(const void*, HColumn* cp=0);
|
328 |
|
|
private:
|
329 |
|
|
Bool_t fDefValue;
|
330 |
|
|
Int_t fMax;
|
331 |
|
|
};
|
332 |
|
|
|
333 |
|
|
class BoolDynArrColumn : public HColumn {
|
334 |
|
|
public:
|
335 |
|
|
BoolDynArrColumn(const char*, const HTAbsValVector<Bool_t> &,
|
336 |
|
|
const Bool_t &, HColumn*, TTree*);
|
337 |
|
|
virtual ~BoolDynArrColumn() { delete[] (Bool_t*)fPointer; }
|
338 |
|
|
virtual void SetDefValue();
|
339 |
|
|
virtual void SetValue(const void*, HColumn* cp=0);
|
340 |
|
|
private:
|
341 |
|
|
Bool_t fDefValue;
|
342 |
|
|
HColumn* fIndexPtr;
|
343 |
|
|
};
|
344 |
|
|
|
345 |
|
|
// Classes for Int_t:
|
346 |
|
|
class IntColumn : public HColumn {
|
347 |
|
|
public:
|
348 |
|
|
IntColumn(const char*, const Int_t &, const Int_t &, TTree*);
|
349 |
|
|
virtual ~IntColumn() { delete (Int_t*)fPointer; }
|
350 |
|
|
virtual void SetDefValue() { *(Int_t*)fPointer = fDefValue; }
|
351 |
|
|
virtual void SetValue(const void* p, HColumn* cp=0) {
|
352 |
|
|
*(Int_t*)fPointer = *(const Int_t*)p;
|
353 |
|
|
}
|
354 |
|
|
private:
|
355 |
|
|
Int_t fDefValue;
|
356 |
|
|
};
|
357 |
|
|
|
358 |
|
|
class IntArrColumn : public HColumn {
|
359 |
|
|
public:
|
360 |
|
|
IntArrColumn(const char*, const HTAbsValVector<Int_t> &, const Int_t &,
|
361 |
|
|
TTree*);
|
362 |
|
|
virtual ~IntArrColumn() { delete[] (Int_t*)fPointer; }
|
363 |
|
|
virtual void SetDefValue() {
|
364 |
|
|
for(Int_t i = 0; i < fMax; ++i) ((Int_t*)fPointer)[i] = fDefValue;
|
365 |
|
|
}
|
366 |
|
|
virtual void SetValue(const void*, HColumn* cp=0);
|
367 |
|
|
private:
|
368 |
|
|
Int_t fDefValue;
|
369 |
|
|
Int_t fMax;
|
370 |
|
|
};
|
371 |
|
|
|
372 |
|
|
class IntDynArrColumn : public HColumn {
|
373 |
|
|
public:
|
374 |
|
|
IntDynArrColumn(const char*, const HTAbsValVector<Int_t> &,
|
375 |
|
|
const Int_t &, HColumn*, TTree*);
|
376 |
|
|
virtual ~IntDynArrColumn() { delete[] (Int_t*)fPointer; }
|
377 |
|
|
virtual void SetDefValue();
|
378 |
|
|
virtual void SetValue(const void*, HColumn* cp=0);
|
379 |
|
|
private:
|
380 |
|
|
Int_t fDefValue;
|
381 |
|
|
HColumn* fIndexPtr;
|
382 |
|
|
};
|
383 |
|
|
|
384 |
|
|
// Classes for Float_t:
|
385 |
|
|
class FloatColumn : public HColumn {
|
386 |
|
|
public:
|
387 |
|
|
FloatColumn(const char*, const Float_t &, const Float_t &, TTree*);
|
388 |
|
|
virtual ~FloatColumn() { delete (Float_t*)fPointer; }
|
389 |
|
|
virtual void SetDefValue() { *(Float_t*)fPointer = fDefValue; }
|
390 |
|
|
virtual void SetValue(const void* p, HColumn* cp=0) {
|
391 |
|
|
*(Float_t*)fPointer = *(const Float_t*)p;
|
392 |
|
|
}
|
393 |
|
|
private:
|
394 |
|
|
Float_t fDefValue;
|
395 |
|
|
};
|
396 |
|
|
|
397 |
|
|
class FloatArrColumn : public HColumn {
|
398 |
|
|
public:
|
399 |
|
|
FloatArrColumn(const char*, const HTAbsValVector<Float_t> &, const Float_t &,
|
400 |
|
|
TTree*);
|
401 |
|
|
FloatArrColumn(const char*, const TVector &, const Float_t &,
|
402 |
|
|
TTree*);
|
403 |
|
|
virtual ~FloatArrColumn() { delete[] (Float_t*)fPointer; }
|
404 |
|
|
virtual void SetDefValue() {
|
405 |
|
|
for(Int_t i = 0; i < fMax; ++i) ((Float_t*)fPointer)[i] = fDefValue;
|
406 |
|
|
}
|
407 |
|
|
virtual void SetValue(const void*, HColumn* cp=0);
|
408 |
|
|
private:
|
409 |
|
|
Float_t fDefValue;
|
410 |
|
|
Int_t fMax;
|
411 |
|
|
};
|
412 |
|
|
|
413 |
|
|
class FloatDynArrColumn : public HColumn {
|
414 |
|
|
public:
|
415 |
|
|
FloatDynArrColumn(const char*, const HTAbsValVector<Float_t> &,
|
416 |
|
|
const Float_t &, HColumn*, TTree*);
|
417 |
|
|
FloatDynArrColumn(const char*, const TVector &,
|
418 |
|
|
const Float_t &, HColumn*, TTree*);
|
419 |
|
|
virtual ~FloatDynArrColumn() { delete[] (Float_t*)fPointer; }
|
420 |
|
|
virtual void SetDefValue();
|
421 |
|
|
virtual void SetValue(const void*, HColumn* cp=0);
|
422 |
|
|
private:
|
423 |
|
|
Float_t fDefValue;
|
424 |
|
|
HColumn* fIndexPtr;
|
425 |
|
|
};
|
426 |
|
|
|
427 |
|
|
// Classes for Double_t:
|
428 |
|
|
class DoubleColumn : public HColumn {
|
429 |
|
|
public:
|
430 |
|
|
DoubleColumn(const char*, const Double_t &, const Double_t &, TTree*);
|
431 |
|
|
virtual ~DoubleColumn() { delete (Double_t*)fPointer; }
|
432 |
|
|
virtual void SetDefValue() { *(Double_t*)fPointer = fDefValue; }
|
433 |
|
|
virtual void SetValue(const void* p, HColumn* cp=0) {
|
434 |
|
|
*(Double_t*)fPointer = *(const Double_t*)p;
|
435 |
|
|
}
|
436 |
|
|
private:
|
437 |
|
|
Double_t fDefValue;
|
438 |
|
|
};
|
439 |
|
|
|
440 |
|
|
class DoubleArrColumn : public HColumn {
|
441 |
|
|
public:
|
442 |
|
|
DoubleArrColumn(const char*, const HTAbsValVector<Double_t> &,
|
443 |
|
|
const Double_t &, TTree*);
|
444 |
|
|
virtual ~DoubleArrColumn() { delete[] (Double_t*)fPointer; }
|
445 |
|
|
virtual void SetDefValue() {
|
446 |
|
|
for(Int_t i = 0; i < fMax; ++i) ((Double_t*)fPointer)[i] = fDefValue;
|
447 |
|
|
}
|
448 |
|
|
virtual void SetValue(const void*, HColumn* cp=0);
|
449 |
|
|
private:
|
450 |
|
|
Double_t fDefValue;
|
451 |
|
|
Int_t fMax;
|
452 |
|
|
};
|
453 |
|
|
|
454 |
|
|
class DoubleDynArrColumn : public HColumn {
|
455 |
|
|
public:
|
456 |
|
|
DoubleDynArrColumn(const char*, const HTAbsValVector<Double_t> &,
|
457 |
|
|
const Double_t &, HColumn*, TTree*);
|
458 |
|
|
virtual ~DoubleDynArrColumn() { delete[] (Double_t*)fPointer; }
|
459 |
|
|
virtual void SetDefValue();
|
460 |
|
|
virtual void SetValue(const void*, HColumn* cp=0);
|
461 |
|
|
private:
|
462 |
|
|
Double_t fDefValue;
|
463 |
|
|
HColumn* fIndexPtr;
|
464 |
|
|
};
|
465 |
|
|
|
466 |
|
|
// String column:
|
467 |
|
|
class StringColumn : public HColumn {
|
468 |
|
|
public:
|
469 |
|
|
StringColumn(const TString &, const TString &,
|
470 |
|
|
const TString &, TTree*);
|
471 |
|
|
virtual ~StringColumn() { delete[] (TString*)fPointer; }
|
472 |
|
|
virtual void SetDefValue();
|
473 |
|
|
virtual void SetValue(const void*, HColumn* cp=0);
|
474 |
|
|
private:
|
475 |
|
|
TString fDefValue;
|
476 |
|
|
};
|
477 |
|
|
|
478 |
|
|
// Classes for generic objects
|
479 |
|
|
template <class T>
|
480 |
|
|
class ClassColumn : public HColumn {
|
481 |
|
|
public:
|
482 |
|
|
ClassColumn(const char * name, const T& v, const T& d, TTree * t) :
|
483 |
|
|
HColumn(name), fDefValue(d)
|
484 |
|
|
{
|
485 |
|
|
// Create a new branch:
|
486 |
|
|
T * p = new T(v);
|
487 |
|
|
fPointer = p;
|
488 |
|
|
fBranch = t->Branch(name,p);
|
489 |
|
|
}
|
490 |
|
|
virtual void SetDefValue() { *(T*)fPointer = fDefValue; }
|
491 |
|
|
virtual void SetValue(const void* p, HColumn* cp=0) { *(T*)fPointer = *(const T*)p; }
|
492 |
|
|
private:
|
493 |
|
|
T fDefValue;
|
494 |
|
|
};
|
495 |
|
|
|
496 |
|
|
typedef ClassColumn<TLorentzVector> TLorentzColum;
|
497 |
|
|
typedef ClassColumn<TVector3> TVector3Colum;
|
498 |
|
|
|
499 |
|
|
template <class T>
|
500 |
|
|
class ClonesColumn : public HColumn {
|
501 |
|
|
public:
|
502 |
|
|
ClonesColumn(const char * name, const HTAbsValVector<T>& v, const T& d, HColumn* inp, TTree* t) :
|
503 |
|
|
HColumn(name), fDefValue(d), fIndexPtr(inp)
|
504 |
|
|
{
|
505 |
|
|
// Create a new branch:
|
506 |
|
|
fClones = new TClonesArray(fDefValue.ClassName(),v.length());
|
507 |
|
|
fPointer = fClones;
|
508 |
|
|
fBranch = t->Branch(name,&fClones,128000,0);
|
509 |
|
|
SetValue(&v);
|
510 |
|
|
}
|
511 |
|
|
virtual void SetDefValue()
|
512 |
|
|
{
|
513 |
|
|
fClones->Delete();
|
514 |
|
|
int np = *((Int_t*)(fIndexPtr->GetPointer()));
|
515 |
|
|
for( Int_t i = 0; i < np; ++i) new( (*fClones)[i] ) T(fDefValue);
|
516 |
|
|
}
|
517 |
|
|
virtual void SetValue(const void* p, HColumn* cp=0)
|
518 |
|
|
{
|
519 |
|
|
const HTAbsValVector<T>& vp = *(const HTAbsValVector<T>*) p;
|
520 |
|
|
int np = vp.length();
|
521 |
|
|
if( cp != 0 ) {
|
522 |
|
|
np = *((Int_t*)(cp->GetPointer()));
|
523 |
|
|
}
|
524 |
|
|
fClones->Delete();
|
525 |
|
|
if( np > (int)vp.length() ) {
|
526 |
|
|
SetDefValue();
|
527 |
|
|
} else {
|
528 |
|
|
for( Int_t i = 0; i < np; ++i) new( (*fClones)[i] ) T(vp(i));
|
529 |
|
|
}
|
530 |
|
|
}
|
531 |
|
|
|
532 |
|
|
private:
|
533 |
|
|
TClonesArray * fClones;
|
534 |
|
|
T fDefValue;
|
535 |
|
|
HColumn * fIndexPtr;
|
536 |
|
|
};
|
537 |
|
|
|
538 |
|
|
typedef ClonesColumn<TLorentzVector> TLorentzClonesColumn;
|
539 |
|
|
typedef ClonesColumn<TVector3> TVector3ClonesColum;
|
540 |
|
|
|
541 |
|
|
|
542 |
|
|
#endif
|