FairRoot/PandaRoot
RhoColumn.cxx
Go to the documentation of this file.
1 // //
3 // RhoColumn //
4 // //
5 // Nested class hierarchy to hold information about RhoTuple columns. //
6 // //
7 // Author List: //
8 // Marcel Kunze, RUB,Mar. 99 //
9 // Apr.2001 (MK),Inherit from TNamed to support THashList //
10 // Copyright (C) 1999-2001,Ruhr-University Bochum. //
11 // Ralf Kliemt, HIM/GSI Feb.2013 (Cleanup & Restructuring) //
12 // //
14 
15 #include "TTree.h"
16 #include "TBranch.h"
17 
18 #include "RhoHistogram/RhoColumn.h"
19 
20 #include <iostream>
21 using namespace std;
22 
23 // Bool columns,stored as char (= 8 bit unsigned int):
24 RhoBoolColumn::RhoBoolColumn ( const char* l,const Bool_t& v,const Bool_t& d,TTree* tp ) :
25  RhoColumn ( l ),fDefValue ( d )
26 {
27  // Create a new branch:
28  fPointer = new Char_t;
29  * ( Char_t* ) fPointer = v;
30  TString leafs ( l ) ;
31  leafs += "/b";
32  fBranch = tp->Branch ( fLabel,fPointer,&*leafs,8000 );
33 }
34 
37  const Bool_t& d,TTree* tp ) :
38  RhoColumn ( l ),fDefValue ( d )
39 {
40  // Create a new branch:
41  fMax = v.length();
42  Char_t* bp = new Char_t[fMax];
43  fPointer = bp;
44  for ( Int_t i = 0; i < fMax; ++i ) { bp[i] = v ( i ); }
45  TString leafs ( fLabel );
46  leafs += "[";
47  char buf[33];
48  sprintf ( buf,"%i",fMax );
49  leafs += buf;
50  leafs += "]/b";
51  fBranch = tp->Branch ( fLabel, ( void* ) &bp[0],&*leafs,8000 );
52 }
53 
54 void RhoBoolArrColumn::SetValue ( const void* p,RhoColumn* )
55 {
57  if ( (Int_t)vp->length() < fMax ) {
58  cerr << "BoolArrColumn::SetValue: input vector too short,"
59  << "use default values" << endl;
60  SetDefValue();
61  } else {
62  for ( Int_t i = 0; i < fMax; ++i ) { ( ( Char_t* ) fPointer ) [i] = ( *vp ) ( i ); }
63  }
64 }
65 
68  const Bool_t& d,RhoColumn* inp,
69  TTree* tp ) :
70  RhoColumn ( l ),fDefValue ( d ),fIndexPtr ( inp )
71 {
72  // Make a new branch:
73  Int_t* np = ( Int_t* ) fIndexPtr->GetPointer();
74  Char_t* bp = new Char_t[*np];
75  fPointer = bp;
76  for ( Int_t i = 0; i < *np; ++i ) { bp[i] = v ( i ); }
77  TString leafs ( fLabel );
78  leafs += "[";
79  leafs += fIndexPtr->GetLabel();
80  leafs += "]/b";
81  fBranch = tp->Branch ( fLabel, ( void* ) &bp[0],&*leafs,8000 );
82 }
83 
85 {
86  if ( fPointer ) { delete [] ( Bool_t* ) fPointer; }
87  Int_t fMax = * ( ( Int_t* ) ( fIndexPtr->GetPointer() ) );
88  Char_t* bp = new Char_t[fMax];
89  fPointer = bp;
90  for ( Int_t i = 0; i < fMax; ++i ) { bp[i] = fDefValue; }
91  fBranch->SetAddress ( &bp[0] );
92 }
93 
94 void RhoBoolDynArrColumn::SetValue ( const void* p,RhoColumn* cp )
95 {
97  Int_t* np = ( Int_t* ) cp->GetPointer();
98  if ( *np > (int)vp->length() ) {
99  cerr << "BoolDynArrColumn::SetValue: input vector too short,"
100  << "use default values" << endl;
101  SetDefValue();
102  } else {
103  Char_t* bp = new Char_t[*np];
104  if ( fPointer ) { delete[] ( Bool_t* ) fPointer; }
105  fPointer = bp;
106  for ( Int_t i = 0; i < *np; ++i ) { bp[i] = ( *vp ) ( i ); }
107  fBranch->SetAddress ( &bp[0] );
108  }
109 }
110 
111 
112 // Int columns:
113 RhoIntColumn::RhoIntColumn ( const char* l,const Int_t& v,const Int_t& d,TTree* tp ) :
114  RhoColumn ( l ),fDefValue ( d )
115 {
116  // Create a new branch:
117  fPointer = new Int_t;
118  * ( Int_t* ) fPointer = v;
119  TString leafs ( l ) ;
120  leafs += "/I";
121  fBranch = tp->Branch ( fLabel,fPointer,&*leafs,8000 );
122 }
123 
125  const RhoHTAbsValVector<Int_t> & v,
126  const Int_t& d,TTree* tp ) :
127  RhoColumn ( l ),fDefValue ( d )
128 {
129  // Create a new branch:
130  fMax = v.length();
131  Int_t* ip = new Int_t[fMax];
132  fPointer = ip;
133  for ( Int_t i = 0; i < fMax; ++i ) { ip[i] = v ( i ); }
134  TString leafs ( fLabel );
135  leafs += "[";
136  char buf[33];
137  sprintf ( buf,"%i",fMax );
138  leafs += buf;
139  leafs += "]/I";
140  fBranch = tp->Branch ( fLabel,&ip[0],&*leafs,8000 );
141 }
142 
143 void RhoIntArrColumn::SetValue ( const void* p,RhoColumn* )
144 {
145  const RhoHTAbsValVector<Int_t>* vp = ( const RhoHTAbsValVector<Int_t>* ) p;
146  if ( (Int_t)vp->length() < fMax ) {
147  cerr << "IntArrColumn::SetValue: input vector too short,"
148  << "use default values" << endl;
149  SetDefValue();
150  } else {
151  for ( Int_t i = 0; i < fMax; ++i ) { ( ( Int_t* ) fPointer ) [i] = ( *vp ) ( i ); }
152  }
153 }
154 
156  const RhoHTAbsValVector<Int_t> & v,
157  const Int_t& d,RhoColumn* inp,
158  TTree* tp ) :
159  RhoColumn ( l ),fDefValue ( d ),fIndexPtr ( inp )
160 {
161  // Make a new branch:
162  Int_t* np = ( Int_t* ) fIndexPtr->GetPointer();
163  Int_t* ip = new Int_t[*np];
164  fPointer = ip;
165  for ( Int_t i = 0; i < *np; ++i ) { ip[i] = v ( i ); }
166  TString leafs ( fLabel );
167  leafs += "[";
168  leafs += fIndexPtr->GetLabel();
169  leafs += "]/I";
170  fBranch = tp->Branch ( fLabel,&ip[0],&*leafs,8000 );
171 }
172 
174 {
175  if ( fPointer ) { delete [] ( Int_t* ) fPointer; }
176  Int_t fMax = * ( ( Int_t* ) ( fIndexPtr->GetPointer() ) );
177  Int_t* ip = new Int_t[fMax];
178  fPointer = ip;
179  for ( Int_t i = 0; i < fMax; ++i ) { ip[i] = fDefValue; }
180  fBranch->SetAddress ( &ip[0] );
181 }
182 
183 void RhoIntDynArrColumn::SetValue ( const void* p,RhoColumn* cp )
184 {
185  const RhoHTAbsValVector<Int_t>* vp = ( const RhoHTAbsValVector<Int_t>* ) p;
186  Int_t* np = ( Int_t* ) cp->GetPointer();
187  if ( *np > (int)vp->length() ) {
188  cerr << "IntDynArrColumn::SetValue: input vector too short,"
189  << "use default values" << endl;
190  SetDefValue();
191  } else {
192  Int_t* ip = new Int_t[*np];
193  if ( fPointer ) { delete[] ( Int_t* ) fPointer; }
194  fPointer = ip;
195  for ( Int_t i = 0; i < *np; ++i ) { ip[i] = ( *vp ) ( i ); }
196  fBranch->SetAddress ( &ip[0] );
197  }
198 }
199 
200 // Float columns:
201 RhoFloatColumn::RhoFloatColumn ( const char* l,const Float_t& v,const Float_t& d,TTree* tp ) :
202  RhoColumn ( l ),fDefValue ( d )
203 {
204  // Create a new branch:
205  fPointer = new Float_t;
206  * ( Float_t* ) fPointer = v;
207  TString leafs ( l ) ;
208  leafs += "/F";
209  fBranch = tp->Branch ( fLabel,fPointer,&*leafs,8000 );
210 }
211 
214  const Float_t& d,TTree* tp ) :
215  RhoColumn ( l ),fDefValue ( d )
216 {
217  // Create a new branch:
218  fMax = v.length();
219  Float_t* fp = new Float_t[fMax];
220  fPointer = fp;
221  for ( Int_t i = 0; i < fMax; ++i ) { fp[i] = v ( i ); }
222  TString leafs ( fLabel );
223  leafs += "[";
224  char buf[33];
225  sprintf ( buf,"%i",fMax );
226  leafs += buf;
227  leafs += "]/F";
228  fBranch = tp->Branch ( fLabel,&fp[0],&*leafs,8000 );
229 }
230 
231 /*void RhoFloatArrColumn::SetValue ( const void* p,RhoColumn* cp )
232 {
233  const RhoHTAbsValVector<Float_t>* vp = ( const RhoHTAbsValVector<Float_t>* ) p;
234  if ( vp->length() < fMax ) {
235  cerr << "FloatArrColumn::SetValue: input vector too short,"
236  << "use default values" << endl;
237  SetDefValue();
238  } else {
239  for ( Int_t i = 0; i < fMax; ++i ) { ( ( Float_t* ) fPointer ) [i] = ( *vp ) ( i ); }
240  }
241 }*/
243 {
244  const TVector *vp = (const TVector*) p;
245  if ( vp->GetNoElements() < fMax ) {
246  cerr << "FloatArrColumn::SetValue: input vector too short,"
247  << "use default values" << endl;
248  SetDefValue();
249  } else {
250  for ( Int_t i = 0; i < fMax; ++i ) { ( ( Float_t* ) fPointer ) [i] = ( *vp ) ( i ); }
251  }
252 }
253 
256  const Float_t& d,RhoColumn* ip,
257  TTree* tp ) :
258  RhoColumn ( l ),fDefValue ( d ),fIndexPtr ( ip )
259 {
260  // Make a new branch:
261  Int_t* np = ( Int_t* ) fIndexPtr->GetPointer();
262  Float_t* fp = new Float_t[*np];
263  fPointer = fp;
264  for ( Int_t i = 0; i < *np; ++i ) { fp[i] = v ( i ); }
265  TString leafs ( fLabel );
266  leafs += "[";
267  leafs += fIndexPtr->GetLabel();
268  leafs += "]/F";
269  fBranch = tp->Branch ( fLabel,&fp[0],&*leafs,8000 );
270 }
271 
273 {
274  if ( fPointer ) { delete [] ( Float_t* ) fPointer; }
275  Int_t fMax = * ( ( Int_t* ) ( fIndexPtr->GetPointer() ) );
276  Float_t* fp = new Float_t[fMax];
277  fPointer = fp;
278  for ( Int_t i = 0; i < fMax; ++i ) { fp[i] = fDefValue; }
279  fBranch->SetAddress ( &fp[0] );
280 }
281 
282 /*void RhoFloatDynArrColumn::SetValue ( const void* p,RhoColumn* cp )
283 {
284  const RhoHTAbsValVector<Float_t>* vp = ( const RhoHTAbsValVector<Float_t>* ) p;
285  Int_t* np = ( Int_t* ) cp->GetPointer();
286  if ( *np > vp->length() ) {
287  cerr << "IntDynArrColumn::SetValue: input vector too short,"
288  << "use default values" << endl;
289  SetDefValue();
290  } else {
291  Float_t* fp = new Float_t[*np];
292  if ( fPointer ) { delete[] ( Float_t* ) fPointer; }
293  fPointer = fp;
294  for ( Int_t i = 0; i < *np; ++i ) { fp[i] = ( *vp ) ( i ); }
295  fBranch->SetAddress ( &fp[0] );
296  }
297 }*/
299 {
300  const TVector *vp = (const TVector*) p;
301  Int_t* np = ( Int_t* ) cp->GetPointer();
302  if ( *np > vp->GetNoElements() ) {
303  cerr << "IntDynArrColumn::SetValue: input vector too short,"
304  << "use default values" << endl;
305  SetDefValue();
306  } else {
307  Float_t* fp = new Float_t[*np];
308  if ( fPointer ) { delete[] ( Float_t* ) fPointer; }
309  fPointer = fp;
310  for ( Int_t i = 0; i < *np; ++i ) { fp[i] = ( *vp ) ( i ); }
311  fBranch->SetAddress ( &fp[0] );
312  }
313 }
314 
315 RhoFloatArrColumn::RhoFloatArrColumn ( const char* l,const TVector& v,const Float_t& d,TTree* tp ) :
316  RhoColumn ( l ),fDefValue ( d )
317 {
318  // Create a new branch:
319  fMax = v.GetNoElements();
320  Real_t* fp = new Real_t[fMax];
321  fPointer = fp;
322  for ( Int_t i = 0; i < fMax; ++i ) { fp[i] = v ( i ); }
323  TString leafs ( fLabel );
324  leafs += "[";
325  char buf[33];
326  sprintf ( buf,"%i",fMax );
327  leafs += buf;
328  leafs += "]/F";
329  fBranch = tp->Branch ( fLabel,&fp[0],&*leafs,8000 );
330 }
331 
332 RhoFloatDynArrColumn::RhoFloatDynArrColumn ( const char* l,const TVector& v,const Float_t& d,RhoColumn* ip,TTree* tp ) :
333  RhoColumn ( l ),fDefValue ( d ),fIndexPtr ( ip )
334 {
335  // Make a new branch:
336  Int_t* np = ( Int_t* ) fIndexPtr->GetPointer();
337  Real_t* fp = new Real_t[*np];
338  fPointer = fp;
339  for ( Int_t i = 0; i < *np; ++i ) { fp[i] = v ( i ); }
340  TString leafs ( fLabel );
341  leafs += "[";
342  leafs += fIndexPtr->GetLabel();
343  leafs += "]/F";
344  fBranch = tp->Branch ( fLabel,&fp[0],&*leafs,8000 );
345 }
346 
347 
348 // Double columns:
349 RhoDoubleColumn::RhoDoubleColumn ( const char* l,const Double_t& v,const Double_t& d,TTree* tp ) :
350  RhoColumn ( l ),fDefValue ( d )
351 {
352  // Create a new branch:
353  fPointer = new Double_t;
354  * ( Double_t* ) fPointer = v;
355  TString leafs ( l ) ;
356  leafs += "/D";
357  fBranch = tp->Branch ( fLabel,fPointer,&*leafs,8000 );
358 }
359 
362  const Double_t& d,TTree* tp ) :
363  RhoColumn ( l ),fDefValue ( d )
364 {
365  // Create a new branch:
366  fMax = v.length();
367  Double_t* dp = new Double_t[fMax];
368  fPointer = dp;
369  for ( Int_t i = 0; i < fMax; ++i ) { dp[i] = v ( i ); }
370  TString leafs ( fLabel );
371  leafs += "[";
372  char buf[33];
373  sprintf ( buf,"%i",fMax );
374  leafs += buf;
375  leafs += "]/D";
376  fBranch = tp->Branch ( fLabel,&dp[0],&*leafs,8000 );
377 }
378 
380 {
382  if ( (Int_t)vp->length() < fMax ) {
383  cerr << "DoubleArrColumn::SetValue: input vector too short,"
384  << "use default values" << endl;
385  SetDefValue();
386  } else {
387  for ( Int_t i = 0; i < fMax; ++i ) { ( ( Double_t* ) fPointer ) [i] = ( *vp ) ( i ); }
388  }
389 }
390 
393  const Double_t& d,RhoColumn* ip,
394  TTree* tp ) :
395  RhoColumn ( l ),fDefValue ( d ),fIndexPtr ( ip )
396 {
397  // Make a new branch:
398  Int_t* np = ( Int_t* ) ( fIndexPtr->GetPointer() );
399  Double_t* dp = new Double_t[*np];
400  fPointer = dp;
401  for ( Int_t i = 0; i < *np; ++i ) { dp[i] = v ( i ); }
402  TString leafs ( fLabel );
403  leafs += "[";
404  leafs += fIndexPtr->GetLabel();
405  leafs += "]/D";
406  fBranch = tp->Branch ( fLabel,&dp[0],&*leafs,8000 );
407 }
408 
410 {
411  if ( fPointer ) { delete [] ( Double_t* ) fPointer; }
412  Int_t fMax = * ( ( Int_t* ) ( fIndexPtr->GetPointer() ) );
413  Double_t* dp = new Double_t[fMax];
414  fPointer = dp;
415  for ( Int_t i = 0; i < fMax; ++i ) { dp[i] = fDefValue; }
416  fBranch->SetAddress ( &dp[0] );
417 }
418 
420 {
422  Int_t* np = ( Int_t* ) cp->GetPointer();
423  if ( *np > (int)vp->length() ) {
424  cerr << "IntDynArrColumn::SetValue: input vector too short,"
425  << "use default values" << endl;
426  SetDefValue();
427  } else {
428  Double_t* dp = new Double_t[*np];
429  if ( fPointer ) { delete[] ( Double_t* ) fPointer; }
430  fPointer = dp;
431  for ( Int_t i = 0; i < *np; ++i ) { dp[i] = ( *vp ) ( i ); }
432  fBranch->SetAddress ( &dp[0] );
433  }
434 }
435 
436 
437 // String column:
438 RhoStringColumn::RhoStringColumn ( const TString& lb,const TString& v,const TString& d,TTree* tp ) :
439  RhoColumn ( lb ),fDefValue ( d )
440 {
441  // Create a new branch:
442  Int_t l = v.Length();
443  char* cp = new char[l+1];
444  fPointer = cp;
445  strcpy ( cp,&*v );
446  TString leafs ( lb );
447  leafs += "/C";
448  fBranch = tp->Branch ( lb, ( void* ) cp,&*leafs,8000 );
449 }
450 
452 {
453  if ( fPointer ) { delete[] ( TString* ) fPointer; }
454  Int_t l = fDefValue.Length();
455  char* cp = new char[l+1];
456  fPointer = cp;
457  strcpy ( cp,&*fDefValue );
458  fBranch->SetAddress ( &cp[0] );
459 }
460 
461 void RhoStringColumn::SetValue ( const void* p,RhoColumn* )
462 {
463  const char* cpin = ( const char* ) p;
464  if ( fPointer ) { delete[] ( TString* ) fPointer; }
465  Int_t l = strlen ( cpin );
466  char* chp = new char[l+1];
467  fPointer = chp;
468  strcpy ( chp,cpin );
469  fBranch->SetAddress ( &chp[0] );
470 }
virtual void SetValue(const void *, RhoColumn *cp=0)
Definition: RhoColumn.cxx:461
RhoDoubleColumn(const char *, const Double_t &, const Double_t &, TTree *)
Definition: RhoColumn.cxx:349
RhoColumn * fIndexPtr
Definition: RhoColumn.h:306
RhoFloatArrColumn(const char *, const RhoHTAbsValVector< Float_t > &, const Float_t &, TTree *)
Definition: RhoColumn.cxx:212
virtual void SetValue(const void *, RhoColumn *cp=0)
Definition: RhoColumn.cxx:379
TObjArray * d
Int_t i
Definition: run_full.C:25
RhoIntDynArrColumn(const char *, const RhoHTAbsValVector< Int_t > &, const Int_t &, RhoColumn *, TTree *)
Definition: RhoColumn.cxx:155
RhoColumn * fIndexPtr
Definition: RhoColumn.h:202
RhoBoolDynArrColumn(const char *, const RhoHTAbsValVector< Bool_t > &, const Bool_t &, RhoColumn *, TTree *)
Definition: RhoColumn.cxx:66
virtual size_t length() const =0
RhoStringColumn(const TString &, const TString &, const TString &, TTree *)
Definition: RhoColumn.cxx:438
RhoFloatColumn(const char *, const Float_t &, const Float_t &, TTree *)
Definition: RhoColumn.cxx:201
RhoBoolArrColumn(const char *, const RhoHTAbsValVector< Bool_t > &, const Bool_t &, TTree *)
Definition: RhoColumn.cxx:35
virtual void SetValue(const void *, RhoColumn *cp=0)
Definition: RhoColumn.cxx:94
TBranch * fBranch
Definition: RhoColumn.h:152
virtual void SetDefValue()
Definition: RhoColumn.h:283
RhoDoubleArrColumn(const char *, const RhoHTAbsValVector< Double_t > &, const Double_t &, TTree *)
Definition: RhoColumn.cxx:360
__m128 v
Definition: P4_F32vec4.h:4
const TString & GetLabel() const
Definition: RhoColumn.h:128
Double_t p
Definition: anasim.C:58
RhoBoolColumn(const char *, const Bool_t &, const Bool_t &, TTree *)
Definition: RhoColumn.cxx:24
virtual void SetDefValue()
Definition: RhoColumn.cxx:451
TString fDefValue
Definition: RhoColumn.h:371
RhoColumn * fIndexPtr
Definition: RhoColumn.h:252
Double_t
virtual void SetDefValue()
Definition: RhoColumn.h:335
virtual void SetDefValue()
Definition: RhoColumn.cxx:84
virtual void SetDefValue()
Definition: RhoColumn.h:181
void * GetPointer()
Definition: RhoColumn.h:134
TString fLabel
Definition: RhoColumn.h:149
virtual void SetValue(const void *, RhoColumn *cp=0)
Definition: RhoColumn.cxx:183
virtual void SetValue(const void *, RhoColumn *cp=0)
Definition: RhoColumn.cxx:419
virtual void SetDefValue()
Definition: RhoColumn.cxx:409
virtual void SetValue(const void *, RhoColumn *cp=0)
Definition: RhoColumn.cxx:143
virtual void SetValue(const void *, RhoColumn *cp=0)
Definition: RhoColumn.cxx:242
RhoIntColumn(const char *, const Int_t &, const Int_t &, TTree *)
Definition: RhoColumn.cxx:113
virtual void SetDefValue()
Definition: RhoColumn.h:231
virtual void SetValue(const void *, RhoColumn *cp=0)
Definition: RhoColumn.cxx:298
void * fPointer
Definition: RhoColumn.h:151
return buf
RhoIntArrColumn(const char *, const RhoHTAbsValVector< Int_t > &, const Int_t &, TTree *)
Definition: RhoColumn.cxx:124
TF1 * bp
Definition: hist-t7.C:69
RhoColumn * fIndexPtr
Definition: RhoColumn.h:356
RhoFloatDynArrColumn(const char *, const RhoHTAbsValVector< Float_t > &, const Float_t &, RhoColumn *, TTree *)
Definition: RhoColumn.cxx:254
RhoDoubleDynArrColumn(const char *, const RhoHTAbsValVector< Double_t > &, const Double_t &, RhoColumn *, TTree *)
Definition: RhoColumn.cxx:391
virtual void SetDefValue()
Definition: RhoColumn.cxx:272
virtual void SetDefValue()
Definition: RhoColumn.cxx:173
virtual void SetValue(const void *, RhoColumn *cp=0)
Definition: RhoColumn.cxx:54