KaliVeda  1.13/01
Heavy-Ion Analysis Toolkit
KVDataBranchHandler.cpp
Go to the documentation of this file.
1 //Created by KVClassFactory on Fri Dec 11 11:52:02 2009
2 //Author: John Frankland,,,
3 
4 #include "KVDataBranchHandler.h"
5 
7 
8 
9 
15  const Char_t* type, const Char_t* prefix) :
16  KVBase()
17 {
18  // Initialise branch handler for given TTree, object, member variable named 'var',
19  // of leaf type 'type' (see TBranch constructor) and an optional branch prefix p
20  // (will be prepended as 'p.').
21 
22  fTree = tree;
23  Long_t offset = obj->IsA()->GetDataMemberOffset(var);
24  if (!offset) {
25  Error("KVDataBranchHandler", "Offset for member %s of %s is 0", var, obj->GetName());
26  fAddr = 0;
27  fBranch = 0;
28  return;
29  }
30  fAddr = (void*)((Long_t)obj + offset);
31  if (strcmp(prefix, "")) SetName(Form("%s.%s.%s", prefix, obj->GetName(), var));
32  else SetName(Form("%s.%s", obj->GetName(), var));
33  SetType(Form("%s/%s", GetName(), type));
34  fBranch = fTree->GetBranch(GetName());
35  if (!ConnectBranch()) CreateBranch();
36 }
37 
38 
39 
42 
44 {
45  // Destructor
46 }
47 
48 
49 
54 
56 {
57  // Connect member variable to branch for reading.
58  // If branch exists returns kTRUE.
59  // If branch does not exist, returns kFALSE.
60 
61  if (!fBranch) return kFALSE;
63  return kTRUE;
64 }
65 
66 
67 
70 
72 {
73  // Create new branch in TTree for member variable and return its address.
74 
75  if (!fAddr) return 0;
76  //Info("CreateBranch", "fTree->Branch(\"%s\", %p, \"%s\")", GetName(), fAddr, GetType());
77  return (fBranch = fTree->Branch(GetName(), fAddr, GetType()));
78 }
79 
80 
81 
long Long_t
ClassImp(KVPartitionList) void KVPartitionList
Initialisation.
char Char_t
const Bool_t kFALSE
bool Bool_t
const Bool_t kTRUE
int type
char * Form(const char *fmt,...)
Base class for KaliVeda framework.
Definition: KVBase.h:141
virtual const Char_t * GetType() const
Definition: KVBase.h:176
Handles TTree branches for storing member variables of classes.
virtual ~KVDataBranchHandler()
Destructor.
TBranch * fBranch
the branch
void * fAddr
address of variable
TBranch * CreateBranch()
Create new branch in TTree for member variable and return its address.
TTree * fTree
the TTree
virtual void SetAddress(void *add)
virtual const char * GetName() const
virtual Int_t Branch(const char *folder, Int_t bufsize=32000, Int_t splitlevel=99)
gr SetName("gr")
void Error(const char *location, const char *va_(fmt),...)