QwAnalysis
QwRootTree Class Reference

A wrapper class for a ROOT tree. More...

#include <QwRootFile.h>

Public Member Functions

 QwRootTree (const std::string &name, const std::string &desc, const std::string &prefix="")
 Constructor with name, and description. More...
 
 QwRootTree (const QwRootTree *tree, const std::string &prefix="")
 Constructor with existing tree. More...
 
template<class T >
 QwRootTree (const std::string &name, const std::string &desc, T &object, const std::string &prefix="")
 Constructor with name, description, and object. More...
 
template<class T >
 QwRootTree (const QwRootTree *tree, T &object, const std::string &prefix="")
 Constructor with existing tree, and object. More...
 
virtual ~QwRootTree ()
 Destructor. More...
 
template<class T >
void FillTreeBranches (const T &object)
 Fill the branches for generic objects. More...
 
Int_t Fill ()
 Fill the tree. More...
 
void Print () const
 Print the tree name and description. More...
 
TTree * GetTree () const
 Get the tree pointer for low level operations. More...
 

Private Member Functions

void ConstructNewTree ()
 Construct the tree. More...
 
void ConstructIndexTo (QwRootTree *to)
 Construct index from this tree to another tree. More...
 
template<class T >
void ConstructBranchAndVector (T &object)
 Construct the branches and vector for generic objects. More...
 
const std::string & GetName () const
 Get the name of the tree. More...
 
const std::string & GetDesc () const
 Get the description of the tree. More...
 
const std::string & GetPrefix () const
 Get the description of the tree. More...
 
std::string GetType () const
 Get the object type. More...
 
void SetPrescaling (UInt_t num_to_save, UInt_t num_to_skip)
 Set tree prescaling parameters. More...
 
void SetMaxTreeSize (Long64_t maxsize=1900000000)
 Set maximum tree size. More...
 
void SetAutoFlush (Long64_t autoflush=30000000)
 Set autoflush size. More...
 
void SetAutoSave (Long64_t autosave=300000000)
 Set autosave size. More...
 
void SetBasketSize (Int_t basketsize=16000)
 Set basket size. More...
 
void SetCircular (Long64_t buff=100000)
 

Private Attributes

TTree * fTree
 Tree pointer. More...
 
std::vector< Double_t > fVector
 Vector of leaves. More...
 
const std::string fName
 Name, description. More...
 
const std::string fDesc
 
const std::string fPrefix
 
std::string fType
 Object type. More...
 
UInt_t fCurrentEvent
 Tree prescaling parameters. More...
 
UInt_t fNumEventsCycle
 
UInt_t fNumEventsToSave
 
UInt_t fNumEventsToSkip
 
Long64_t fMaxTreeSize
 Maximum tree size, autoflush and autosave. More...
 
Long64_t fAutoFlush
 
Long64_t fAutoSave
 
Int_t fBasketSize
 

Friends

class QwRootFile
 

Detailed Description

A wrapper class for a ROOT tree.

This class provides the functionality to write to ROOT trees using a vector of doubles. The vector is part of this object, as well as a pointer to the tree that contains the branches. One ROOT tree can have multiple QwRootTree objects, for example in tracking mode both parity and tracking detectors can be stored in the same tree.

Definition at line 36 of file QwRootFile.h.

Constructor & Destructor Documentation

QwRootTree::QwRootTree ( const std::string &  name,
const std::string &  desc,
const std::string &  prefix = "" 
)
inline

Constructor with name, and description.

Definition at line 41 of file QwRootFile.h.

References ConstructNewTree().

42  : fName(name),fDesc(desc),fPrefix(prefix),fType("type undefined"),
44  // Construct tree
46  }
UInt_t fCurrentEvent
Tree prescaling parameters.
Definition: QwRootFile.h:196
const std::string fDesc
Definition: QwRootFile.h:181
UInt_t fNumEventsToSkip
Definition: QwRootFile.h:203
const std::string fName
Name, description.
Definition: QwRootFile.h:180
UInt_t fNumEventsToSave
Definition: QwRootFile.h:202
void ConstructNewTree()
Construct the tree.
Definition: QwRootFile.h:87
const std::string fPrefix
Definition: QwRootFile.h:182
std::string fType
Object type.
Definition: QwRootFile.h:189
UInt_t fNumEventsCycle
Definition: QwRootFile.h:201

+ Here is the call graph for this function:

QwRootTree::QwRootTree ( const QwRootTree tree,
const std::string &  prefix = "" 
)
inline

Constructor with existing tree.

Definition at line 49 of file QwRootFile.h.

References QwLog::endl(), fTree, GetDesc(), GetName(), and QwMessage.

50  : fName(tree->GetName()),fDesc(tree->GetDesc()),fPrefix(prefix),fType("type undefined"),
52  QwMessage << "Existing tree: " << tree->GetName() << ", " << tree->GetDesc() << QwLog::endl;
53  fTree = tree->fTree;
54  }
#define QwMessage
Predefined log drain for regular messages.
Definition: QwLog.h:50
TTree * fTree
Tree pointer.
Definition: QwRootFile.h:174
const std::string & GetName() const
Get the name of the tree.
Definition: QwRootFile.h:185
UInt_t fCurrentEvent
Tree prescaling parameters.
Definition: QwRootFile.h:196
const std::string fDesc
Definition: QwRootFile.h:181
UInt_t fNumEventsToSkip
Definition: QwRootFile.h:203
const std::string fName
Name, description.
Definition: QwRootFile.h:180
const std::string & GetDesc() const
Get the description of the tree.
Definition: QwRootFile.h:187
UInt_t fNumEventsToSave
Definition: QwRootFile.h:202
const std::string fPrefix
Definition: QwRootFile.h:182
std::string fType
Object type.
Definition: QwRootFile.h:189
UInt_t fNumEventsCycle
Definition: QwRootFile.h:201
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299

+ Here is the call graph for this function:

template<class T >
QwRootTree::QwRootTree ( const std::string &  name,
const std::string &  desc,
T &  object,
const std::string &  prefix = "" 
)
inline

Constructor with name, description, and object.

Definition at line 58 of file QwRootFile.h.

References ConstructBranchAndVector(), and ConstructNewTree().

59  : fName(name),fDesc(desc),fPrefix(prefix),fType("type undefined"),
61  // Construct tree
63 
64  // Construct branches and vector
66  }
UInt_t fCurrentEvent
Tree prescaling parameters.
Definition: QwRootFile.h:196
const std::string fDesc
Definition: QwRootFile.h:181
UInt_t fNumEventsToSkip
Definition: QwRootFile.h:203
const std::string fName
Name, description.
Definition: QwRootFile.h:180
void ConstructBranchAndVector(T &object)
Construct the branches and vector for generic objects.
Definition: QwRootFile.h:100
UInt_t fNumEventsToSave
Definition: QwRootFile.h:202
void ConstructNewTree()
Construct the tree.
Definition: QwRootFile.h:87
const std::string fPrefix
Definition: QwRootFile.h:182
std::string fType
Object type.
Definition: QwRootFile.h:189
UInt_t fNumEventsCycle
Definition: QwRootFile.h:201

+ Here is the call graph for this function:

template<class T >
QwRootTree::QwRootTree ( const QwRootTree tree,
T &  object,
const std::string &  prefix = "" 
)
inline

Constructor with existing tree, and object.

Definition at line 70 of file QwRootFile.h.

References ConstructBranchAndVector(), QwLog::endl(), fTree, GetDesc(), GetName(), and QwMessage.

71  : fName(tree->GetName()),fDesc(tree->GetDesc()),fPrefix(prefix),fType("type undefined"),
73  QwMessage << "Existing tree: " << tree->GetName() << ", " << tree->GetDesc() << QwLog::endl;
74  fTree = tree->fTree;
75 
76  // Construct branches and vector
78  }
#define QwMessage
Predefined log drain for regular messages.
Definition: QwLog.h:50
TTree * fTree
Tree pointer.
Definition: QwRootFile.h:174
const std::string & GetName() const
Get the name of the tree.
Definition: QwRootFile.h:185
UInt_t fCurrentEvent
Tree prescaling parameters.
Definition: QwRootFile.h:196
const std::string fDesc
Definition: QwRootFile.h:181
UInt_t fNumEventsToSkip
Definition: QwRootFile.h:203
const std::string fName
Name, description.
Definition: QwRootFile.h:180
const std::string & GetDesc() const
Get the description of the tree.
Definition: QwRootFile.h:187
void ConstructBranchAndVector(T &object)
Construct the branches and vector for generic objects.
Definition: QwRootFile.h:100
UInt_t fNumEventsToSave
Definition: QwRootFile.h:202
const std::string fPrefix
Definition: QwRootFile.h:182
std::string fType
Object type.
Definition: QwRootFile.h:189
UInt_t fNumEventsCycle
Definition: QwRootFile.h:201
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299

+ Here is the call graph for this function:

virtual QwRootTree::~QwRootTree ( )
inlinevirtual

Destructor.

Definition at line 81 of file QwRootFile.h.

81 { }

Member Function Documentation

template<class T >
void QwRootTree::ConstructBranchAndVector ( T &  object)
inlineprivate

Construct the branches and vector for generic objects.

Definition at line 100 of file QwRootFile.h.

References BRANCH_VECTOR_MAX_SIZE, QwLog::endl(), fPrefix, fTree, fType, fVector, and QwError.

Referenced by QwRootTree().

100  {
101  // Reserve space for the branch vector
103  // Associate branches with vector
104  TString prefix = Form("%s",fPrefix.c_str());
105  object.ConstructBranchAndVector(fTree, prefix, fVector);
106 
107  // Store the type of object
108  fType = typeid(object).name();
109 
110  // Check memory reservation
111  if (fVector.size() > BRANCH_VECTOR_MAX_SIZE) {
112  QwError << "The branch vector is too large: " << fVector.size() << " leaves! "
113  << "The maximum size is " << BRANCH_VECTOR_MAX_SIZE << "."
114  << QwLog::endl;
115  exit(-1);
116  }
117  }
TTree * fTree
Tree pointer.
Definition: QwRootFile.h:174
std::vector< Double_t > fVector
Vector of leaves.
Definition: QwRootFile.h:176
#define BRANCH_VECTOR_MAX_SIZE
Definition: QwRootFile.h:22
const std::string fPrefix
Definition: QwRootFile.h:182
std::string fType
Object type.
Definition: QwRootFile.h:189
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299
#define QwError
Predefined log drain for errors.
Definition: QwLog.h:40

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void QwRootTree::ConstructIndexTo ( QwRootTree to)
inlineprivate

Construct index from this tree to another tree.

Definition at line 93 of file QwRootFile.h.

References fCurrentEvent, fName, and fTree.

93  {
94  std::string name = "previous_entry_in_" + to->fName;
95  fTree->Branch(name.c_str(), &(to->fCurrentEvent));
96  }
TTree * fTree
Tree pointer.
Definition: QwRootFile.h:174
UInt_t fCurrentEvent
Tree prescaling parameters.
Definition: QwRootFile.h:196
const std::string fName
Name, description.
Definition: QwRootFile.h:180
void QwRootTree::ConstructNewTree ( )
inlineprivate

Construct the tree.

Definition at line 87 of file QwRootFile.h.

References QwLog::endl(), fDesc, fName, fTree, and QwMessage.

Referenced by QwRootTree().

87  {
88  QwMessage << "New tree: " << fName << ", " << fDesc << QwLog::endl;
89  fTree = new TTree(fName.c_str(), fDesc.c_str());
90  }
#define QwMessage
Predefined log drain for regular messages.
Definition: QwLog.h:50
TTree * fTree
Tree pointer.
Definition: QwRootFile.h:174
const std::string fDesc
Definition: QwRootFile.h:181
const std::string fName
Name, description.
Definition: QwRootFile.h:180
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Int_t QwRootTree::Fill ( )
inline

Fill the tree.

Definition at line 136 of file QwRootFile.h.

References QwLog::endl(), fCurrentEvent, fNumEventsCycle, fNumEventsToSave, fTree, and QwError.

136  {
137  fCurrentEvent++;
138 
139  // Tree prescaling
140  if (fNumEventsCycle > 0) {
143  return 0;
144  }
145 
146  // Fill the tree
147  Int_t retval = fTree->Fill();
148  // Check for errors
149  if (retval < 0) {
150  QwError << "Writing tree failed! Check disk space or quota." << QwLog::endl;
151  exit(retval);
152  }
153  return retval;
154  }
TTree * fTree
Tree pointer.
Definition: QwRootFile.h:174
UInt_t fCurrentEvent
Tree prescaling parameters.
Definition: QwRootFile.h:196
UInt_t fNumEventsToSave
Definition: QwRootFile.h:202
UInt_t fNumEventsCycle
Definition: QwRootFile.h:201
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299
#define QwError
Predefined log drain for errors.
Definition: QwLog.h:40

+ Here is the call graph for this function:

template<class T >
void QwRootTree::FillTreeBranches ( const T &  object)
inline

Fill the branches for generic objects.

Definition at line 124 of file QwRootFile.h.

References QwLog::endl(), fType, fVector, and QwError.

124  {
125  if (typeid(object).name() == fType) {
126  // Fill the branch vector
127  object.FillTreeVector(fVector);
128  } else {
129  QwError << "Attempting to fill tree vector for type " << fType << " with "
130  << "object of type " << typeid(object).name() << QwLog::endl;
131  exit(-1);
132  }
133  }
std::vector< Double_t > fVector
Vector of leaves.
Definition: QwRootFile.h:176
std::string fType
Object type.
Definition: QwRootFile.h:189
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299
#define QwError
Predefined log drain for errors.
Definition: QwLog.h:40

+ Here is the call graph for this function:

const std::string& QwRootTree::GetDesc ( ) const
inlineprivate

Get the description of the tree.

Definition at line 187 of file QwRootFile.h.

References fDesc.

Referenced by QwRootTree().

187 { return fDesc; };
const std::string fDesc
Definition: QwRootFile.h:181

+ Here is the caller graph for this function:

const std::string& QwRootTree::GetName ( ) const
inlineprivate

Get the name of the tree.

Definition at line 185 of file QwRootFile.h.

References fName.

Referenced by Print(), and QwRootTree().

185 { return fName; };
const std::string fName
Name, description.
Definition: QwRootFile.h:180

+ Here is the caller graph for this function:

const std::string& QwRootTree::GetPrefix ( ) const
inlineprivate

Get the description of the tree.

Definition at line 189 of file QwRootFile.h.

References fPrefix.

Referenced by Print().

189 { return fPrefix; };
const std::string fPrefix
Definition: QwRootFile.h:182

+ Here is the caller graph for this function:

TTree* QwRootTree::GetTree ( ) const
inline

Get the tree pointer for low level operations.

Definition at line 166 of file QwRootFile.h.

166 { return fTree; };
TTree * fTree
Tree pointer.
Definition: QwRootFile.h:174
std::string QwRootTree::GetType ( ) const
inlineprivate

Get the object type.

Definition at line 196 of file QwRootFile.h.

References fType.

Referenced by Print().

196 { return fType; };
std::string fType
Object type.
Definition: QwRootFile.h:189

+ Here is the caller graph for this function:

void QwRootTree::Print ( ) const
inline

Print the tree name and description.

Definition at line 158 of file QwRootFile.h.

References QwLog::endl(), fPrefix, GetName(), GetPrefix(), GetType(), and QwMessage.

158  {
159  QwMessage << GetName() << ", " << GetType();
160  if (fPrefix != "")
161  QwMessage << " (prefix " << GetPrefix() << ")";
163  }
#define QwMessage
Predefined log drain for regular messages.
Definition: QwLog.h:50
const std::string & GetName() const
Get the name of the tree.
Definition: QwRootFile.h:185
const std::string & GetPrefix() const
Get the description of the tree.
Definition: QwRootFile.h:189
std::string GetType() const
Get the object type.
Definition: QwRootFile.h:196
const std::string fPrefix
Definition: QwRootFile.h:182
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299

+ Here is the call graph for this function:

void QwRootTree::SetAutoFlush ( Long64_t  autoflush = 30000000)
inlineprivate

Set autoflush size.

Definition at line 226 of file QwRootFile.h.

References fAutoFlush, and fTree.

Referenced by QwRootFile::ConstructTreeBranches().

226  {
227  fAutoFlush = autoflush;
228  #if ROOT_VERSION_CODE >= ROOT_VERSION(5,26,00)
229  if (fTree) fTree->SetAutoFlush(autoflush);
230  #endif
231  }
TTree * fTree
Tree pointer.
Definition: QwRootFile.h:174
Long64_t fAutoFlush
Definition: QwRootFile.h:215

+ Here is the caller graph for this function:

void QwRootTree::SetAutoSave ( Long64_t  autosave = 300000000)
inlineprivate

Set autosave size.

Definition at line 234 of file QwRootFile.h.

References fAutoSave, and fTree.

Referenced by QwRootFile::ConstructTreeBranches().

234  {
235  fAutoSave = autosave;
236  if (fTree) fTree->SetAutoSave(autosave);
237  }
TTree * fTree
Tree pointer.
Definition: QwRootFile.h:174
Long64_t fAutoSave
Definition: QwRootFile.h:216

+ Here is the caller graph for this function:

void QwRootTree::SetBasketSize ( Int_t  basketsize = 16000)
inlineprivate

Set basket size.

Definition at line 240 of file QwRootFile.h.

References fBasketSize, and fTree.

Referenced by QwRootFile::ConstructTreeBranches().

240  {
241  fBasketSize = basketsize;
242  if (fTree) fTree->SetBasketSize("*",basketsize);
243  }
TTree * fTree
Tree pointer.
Definition: QwRootFile.h:174
Int_t fBasketSize
Definition: QwRootFile.h:217

+ Here is the caller graph for this function:

void QwRootTree::SetCircular ( Long64_t  buff = 100000)
inlineprivate

Definition at line 246 of file QwRootFile.h.

References fTree.

Referenced by QwRootFile::ConstructTreeBranches().

246  {
247  if (fTree) fTree->SetCircular(buff);
248  }
TTree * fTree
Tree pointer.
Definition: QwRootFile.h:174

+ Here is the caller graph for this function:

void QwRootTree::SetMaxTreeSize ( Long64_t  maxsize = 1900000000)
inlineprivate

Set maximum tree size.

Definition at line 220 of file QwRootFile.h.

References fMaxTreeSize, and fTree.

Referenced by QwRootFile::ConstructTreeBranches().

220  {
221  fMaxTreeSize = maxsize;
222  if (fTree) fTree->SetMaxTreeSize(maxsize);
223  }
TTree * fTree
Tree pointer.
Definition: QwRootFile.h:174
Long64_t fMaxTreeSize
Maximum tree size, autoflush and autosave.
Definition: QwRootFile.h:214

+ Here is the caller graph for this function:

void QwRootTree::SetPrescaling ( UInt_t  num_to_save,
UInt_t  num_to_skip 
)
inlineprivate

Set tree prescaling parameters.

Definition at line 206 of file QwRootFile.h.

References fNumEventsCycle, fNumEventsToSave, and fNumEventsToSkip.

Referenced by QwRootFile::ConstructTreeBranches().

206  {
207  fNumEventsToSave = num_to_save;
208  fNumEventsToSkip = num_to_skip;
210  }
UInt_t fNumEventsToSkip
Definition: QwRootFile.h:203
UInt_t fNumEventsToSave
Definition: QwRootFile.h:202
UInt_t fNumEventsCycle
Definition: QwRootFile.h:201

+ Here is the caller graph for this function:

Friends And Related Function Documentation

friend class QwRootFile
friend

Definition at line 166 of file QwRootFile.h.

Field Documentation

Long64_t QwRootTree::fAutoFlush
private

Definition at line 215 of file QwRootFile.h.

Referenced by SetAutoFlush().

Long64_t QwRootTree::fAutoSave
private

Definition at line 216 of file QwRootFile.h.

Referenced by SetAutoSave().

Int_t QwRootTree::fBasketSize
private

Definition at line 217 of file QwRootFile.h.

Referenced by SetBasketSize().

UInt_t QwRootTree::fCurrentEvent
private

Tree prescaling parameters.

Definition at line 196 of file QwRootFile.h.

Referenced by ConstructIndexTo(), and Fill().

const std::string QwRootTree::fDesc
private

Definition at line 181 of file QwRootFile.h.

Referenced by ConstructNewTree(), and GetDesc().

Long64_t QwRootTree::fMaxTreeSize
private

Maximum tree size, autoflush and autosave.

Definition at line 214 of file QwRootFile.h.

Referenced by SetMaxTreeSize().

const std::string QwRootTree::fName
private

Name, description.

Definition at line 180 of file QwRootFile.h.

Referenced by ConstructIndexTo(), ConstructNewTree(), and GetName().

UInt_t QwRootTree::fNumEventsCycle
private

Definition at line 201 of file QwRootFile.h.

Referenced by Fill(), and SetPrescaling().

UInt_t QwRootTree::fNumEventsToSave
private

Definition at line 202 of file QwRootFile.h.

Referenced by Fill(), and SetPrescaling().

UInt_t QwRootTree::fNumEventsToSkip
private

Definition at line 203 of file QwRootFile.h.

Referenced by SetPrescaling().

const std::string QwRootTree::fPrefix
private

Definition at line 182 of file QwRootFile.h.

Referenced by ConstructBranchAndVector(), GetPrefix(), and Print().

TTree* QwRootTree::fTree
private
std::string QwRootTree::fType
private

Object type.

Definition at line 189 of file QwRootFile.h.

Referenced by ConstructBranchAndVector(), FillTreeBranches(), and GetType().

std::vector<Double_t> QwRootTree::fVector
private

Vector of leaves.

Definition at line 176 of file QwRootFile.h.

Referenced by ConstructBranchAndVector(), and FillTreeBranches().


The documentation for this class was generated from the following file: