JAPAn
Just Another Parity Analyzer
Loading...
Searching...
No Matches
QwRootTree Class Reference

Wrapper class for ROOT tree management with vector-based data storage. More...

#include <QwRootFile.h>

+ Collaboration diagram for QwRootTree:

Public Member Functions

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

Private Member Functions

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

Private Attributes

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

Static Private Attributes

static const TString kUnitsName = "ppm/D:ppb/D:um/D:mm/D:mV_uA/D:V_uA/D"
 
static Double_t kUnitsValue [] = { 1e-6, 1e-9, 1e-3, 1 , 1e-3, 1}
 

Friends

class QwRootFile
 

Detailed Description

Wrapper class for ROOT tree management with vector-based data storage.

Provides functionality to write to ROOT trees using vectors of doubles, with support for branch construction, event filtering, and tree sharing. Handles both new tree creation and attachment to existing trees, enabling multiple subsystems to contribute data to a single ROOT tree.

Definition at line 367 of file QwRootFile.h.

Constructor & Destructor Documentation

◆ QwRootTree() [1/4]

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

Constructor with name, and description.

Definition at line 372 of file QwRootFile.h.

373 : fName(name),fDesc(desc),fPrefix(prefix),fType("type undefined"),
375 // Construct tree
377 }
void ConstructNewTree()
Construct the tree.
Definition QwRootFile.h:424
UInt_t fCurrentEvent
Tree prescaling parameters.
Definition QwRootFile.h:555
const std::string fPrefix
Definition QwRootFile.h:537
UInt_t fNumEventsToSave
Definition QwRootFile.h:557
UInt_t fNumEventsToSkip
Definition QwRootFile.h:558
const std::string fName
Name, description.
Definition QwRootFile.h:535
std::string fType
Object type.
Definition QwRootFile.h:548
UInt_t fNumEventsCycle
Definition QwRootFile.h:556
const std::string fDesc
Definition QwRootFile.h:536

References ConstructNewTree(), fCurrentEvent, fDesc, fName, fNumEventsCycle, fNumEventsToSave, fNumEventsToSkip, fPrefix, and fType.

Referenced by ConstructIndexTo(), QwRootTree(), and QwRootTree().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ QwRootTree() [2/4]

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

Constructor with existing tree.

Definition at line 380 of file QwRootFile.h.

381 : fName(tree->GetName()),fDesc(tree->GetDesc()),fPrefix(prefix),fType("type undefined"),
383 QwMessage << "Existing tree: " << tree->GetName() << ", " << tree->GetDesc() << QwLog::endl;
384 fTree = tree->fTree;
385 }
#define QwMessage
Predefined log drain for regular messages.
Definition QwLog.h:49
static std::ostream & endl(std::ostream &)
End of the line.
Definition QwLog.cc:297
const std::string & GetDesc() const
Get the description of the tree.
Definition QwRootFile.h:542
TTree * fTree
Tree pointer.
Definition QwRootFile.h:529
const std::string & GetName() const
Get the name of the tree.
Definition QwRootFile.h:540

References QwLog::endl(), fCurrentEvent, fDesc, fName, fNumEventsCycle, fNumEventsToSave, fNumEventsToSkip, fPrefix, fTree, fType, GetDesc(), GetName(), QwMessage, and QwRootTree().

+ Here is the call graph for this function:

◆ QwRootTree() [3/4]

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 389 of file QwRootFile.h.

390 : fName(name),fDesc(desc),fPrefix(prefix),fType("type undefined"),
392 // Construct tree
394
395 // Construct branch
397
398 // Construct branches and vector
400 }
void ConstructUnitsBranch()
Definition QwRootFile.h:438
void ConstructBranchAndVector(T &object)
Construct the branches and vector for generic objects.
Definition QwRootFile.h:451

References ConstructBranchAndVector(), ConstructNewTree(), ConstructUnitsBranch(), fCurrentEvent, fDesc, fName, fNumEventsCycle, fNumEventsToSave, fNumEventsToSkip, fPrefix, and fType.

+ Here is the call graph for this function:

◆ QwRootTree() [4/4]

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

Constructor with existing tree, and object.

Definition at line 404 of file QwRootFile.h.

405 : fName(tree->GetName()),fDesc(tree->GetDesc()),fPrefix(prefix),fType("type undefined"),
407 QwMessage << "Existing tree: " << tree->GetName() << ", " << tree->GetDesc() << QwLog::endl;
408 fTree = tree->fTree;
409
410 // Construct branches and vector
412 }

References ConstructBranchAndVector(), QwLog::endl(), fCurrentEvent, fDesc, fName, fNumEventsCycle, fNumEventsToSave, fNumEventsToSkip, fPrefix, fTree, fType, GetDesc(), GetName(), QwMessage, and QwRootTree().

+ Here is the call graph for this function:

◆ ~QwRootTree()

virtual QwRootTree::~QwRootTree ( )
inlinevirtual

Destructor.

Definition at line 415 of file QwRootFile.h.

415{ }

Member Function Documentation

◆ AutoSave()

Long64_t QwRootTree::AutoSave ( Option_t * option)
inline

Definition at line 486 of file QwRootFile.h.

486 {
487 return fTree->AutoSave(option);
488 }

References fTree.

◆ ConstructBranchAndVector()

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

Construct the branches and vector for generic objects.

Definition at line 451 of file QwRootFile.h.

451 {
452 // Reserve space for the branch vector
454 // Associate branches with vector
455 TString prefix = Form("%s",fPrefix.c_str());
456 object.ConstructBranchAndVector(fTree, prefix, fVector);
457
458 // Store the type of object
459 fType = typeid(object).name();
460
461 // Check memory reservation
462 if (fVector.size() > BRANCH_VECTOR_MAX_SIZE) {
463 QwError << "The branch vector is too large: " << fVector.size() << " leaves! "
464 << "The maximum size is " << BRANCH_VECTOR_MAX_SIZE << "."
465 << QwLog::endl;
466 exit(-1);
467 }
468 }
#define QwError
Predefined log drain for errors.
Definition QwLog.h:39
#define BRANCH_VECTOR_MAX_SIZE
Definition QwRootFile.h:42
QwRootTreeBranchVector fVector
Vector of leaves.
Definition QwRootFile.h:531

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

Referenced by QwRootTree(), and QwRootTree().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ConstructIndexTo()

void QwRootTree::ConstructIndexTo ( QwRootTree * to)
inlineprivate

Construct index from this tree to another tree.

Definition at line 444 of file QwRootFile.h.

444 {
445 std::string name = "previous_entry_in_" + to->fName;
446 fTree->Branch(name.c_str(), &(to->fCurrentEvent));
447 }

References fCurrentEvent, fName, fTree, and QwRootTree().

+ Here is the call graph for this function:

◆ ConstructNewTree()

void QwRootTree::ConstructNewTree ( )
inlineprivate

Construct the tree.

Definition at line 424 of file QwRootFile.h.

424 {
425 QwMessage << "New tree: " << fName << ", " << fDesc << QwLog::endl;
426
427 fTree = new TTree(fName.c_str(), fDesc.c_str());
428
429 // Ensure tree is in the current directory
430 if (gDirectory) {
431 fTree->SetDirectory(gDirectory);
432
433 } else {
434
435 }
436 }

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

Referenced by QwRootTree(), and QwRootTree().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ConstructUnitsBranch()

void QwRootTree::ConstructUnitsBranch ( )
inlineprivate

Definition at line 438 of file QwRootFile.h.

438 {
439 std::string name = "units";
440 fTree->Branch(name.c_str(), &kUnitsValue, kUnitsName);
441 }
static const TString kUnitsName
Definition QwRootFile.h:420
static Double_t kUnitsValue[]
Definition QwRootFile.h:20

References fTree, kUnitsName, and kUnitsValue.

Referenced by QwRootTree().

+ Here is the caller graph for this function:

◆ Fill()

Int_t QwRootTree::Fill ( )
inline

Fill the tree.

Definition at line 491 of file QwRootFile.h.

491 {
493
494 // Tree prescaling
495 if (fNumEventsCycle > 0) {
498 return 0;
499 }
500
501 // Fill the tree
502 Int_t retval = fTree->Fill();
503 // Check for errors
504 if (retval < 0) {
505 QwError << "Writing tree failed! Check disk space or quota." << QwLog::endl;
506 exit(retval);
507 }
508 return retval;
509 }

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

+ Here is the call graph for this function:

◆ FillTreeBranches()

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

Fill the branches for generic objects.

Definition at line 475 of file QwRootFile.h.

475 {
476 if (typeid(object).name() == fType) {
477 // Fill the branch vector
478 object.FillTreeVector(fVector);
479 } else {
480 QwError << "Attempting to fill tree vector for type " << fType << " with "
481 << "object of type " << typeid(object).name() << QwLog::endl;
482 exit(-1);
483 }
484 }

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

+ Here is the call graph for this function:

◆ GetDesc()

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

Get the description of the tree.

Definition at line 542 of file QwRootFile.h.

542{ return fDesc; };

References fDesc.

Referenced by QwRootTree(), and QwRootTree().

+ Here is the caller graph for this function:

◆ GetName()

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

Get the name of the tree.

Definition at line 540 of file QwRootFile.h.

540{ return fName; };

References fName.

Referenced by Print(), QwRootTree(), and QwRootTree().

+ Here is the caller graph for this function:

◆ GetPrefix()

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

Get the description of the tree.

Definition at line 544 of file QwRootFile.h.

544{ return fPrefix; };

References fPrefix.

Referenced by Print().

+ Here is the caller graph for this function:

◆ GetTree()

TTree * QwRootTree::GetTree ( ) const
inline

Get the tree pointer for low level operations.

Definition at line 521 of file QwRootFile.h.

521{ return fTree; };

References fTree.

◆ GetType()

std::string QwRootTree::GetType ( ) const
inlineprivate

Get the object type.

Definition at line 551 of file QwRootFile.h.

551{ return fType; };

References fType.

Referenced by Print().

+ Here is the caller graph for this function:

◆ Print()

void QwRootTree::Print ( ) const
inline

Print the tree name and description.

Definition at line 513 of file QwRootFile.h.

513 {
514 QwMessage << GetName() << ", " << GetType();
515 if (fPrefix != "")
516 QwMessage << " (prefix " << GetPrefix() << ")";
518 }
const std::string & GetPrefix() const
Get the description of the tree.
Definition QwRootFile.h:544
std::string GetType() const
Get the object type.
Definition QwRootFile.h:551

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

+ Here is the call graph for this function:

◆ SetAutoFlush()

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

Set autoflush size.

Definition at line 581 of file QwRootFile.h.

581 {
582 fAutoFlush = autoflush;
583 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,26,00)
584 if (fTree) fTree->SetAutoFlush(autoflush);
585 #endif
586 }
Long64_t fAutoFlush
Definition QwRootFile.h:570

References fAutoFlush, and fTree.

Referenced by QwRootFile::ConstructTreeBranches().

+ Here is the caller graph for this function:

◆ SetAutoSave()

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

Set autosave size.

Definition at line 589 of file QwRootFile.h.

589 {
590 fAutoSave = autosave;
591 if (fTree) fTree->SetAutoSave(autosave);
592 }
Long64_t fAutoSave
Definition QwRootFile.h:571

References fAutoSave, and fTree.

Referenced by QwRootFile::ConstructTreeBranches().

+ Here is the caller graph for this function:

◆ SetBasketSize()

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

Set basket size.

Definition at line 595 of file QwRootFile.h.

595 {
596 fBasketSize = basketsize;
597 if (fTree) fTree->SetBasketSize("*",basketsize);
598 }
Int_t fBasketSize
Definition QwRootFile.h:572

References fBasketSize, and fTree.

Referenced by QwRootFile::ConstructTreeBranches().

+ Here is the caller graph for this function:

◆ SetCircular()

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

Definition at line 601 of file QwRootFile.h.

601 {
602 if (fTree) fTree->SetCircular(buff);
603 }

References fTree.

Referenced by QwRootFile::ConstructTreeBranches().

+ Here is the caller graph for this function:

◆ SetMaxTreeSize()

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

Set maximum tree size.

Definition at line 575 of file QwRootFile.h.

575 {
576 fMaxTreeSize = maxsize;
577 if (fTree) fTree->SetMaxTreeSize(maxsize);
578 }
Long64_t fMaxTreeSize
Maximum tree size, autoflush and autosave.
Definition QwRootFile.h:569

References fMaxTreeSize, and fTree.

Referenced by QwRootFile::ConstructTreeBranches().

+ Here is the caller graph for this function:

◆ SetPrescaling()

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

Set tree prescaling parameters.

Definition at line 561 of file QwRootFile.h.

561 {
562 fNumEventsToSave = num_to_save;
563 fNumEventsToSkip = num_to_skip;
565 }

References fNumEventsCycle, fNumEventsToSave, and fNumEventsToSkip.

Referenced by QwRootFile::ConstructTreeBranches().

+ Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ QwRootFile

friend class QwRootFile
friend

Definition at line 524 of file QwRootFile.h.

References QwRootFile.

Referenced by QwRootFile.

Field Documentation

◆ fAutoFlush

Long64_t QwRootTree::fAutoFlush
private

Definition at line 570 of file QwRootFile.h.

Referenced by SetAutoFlush().

◆ fAutoSave

Long64_t QwRootTree::fAutoSave
private

Definition at line 571 of file QwRootFile.h.

Referenced by SetAutoSave().

◆ fBasketSize

Int_t QwRootTree::fBasketSize
private

Definition at line 572 of file QwRootFile.h.

Referenced by SetBasketSize().

◆ fCurrentEvent

UInt_t QwRootTree::fCurrentEvent
private

Tree prescaling parameters.

Definition at line 555 of file QwRootFile.h.

Referenced by ConstructIndexTo(), Fill(), QwRootTree(), QwRootTree(), QwRootTree(), and QwRootTree().

◆ fDesc

const std::string QwRootTree::fDesc
private

Definition at line 536 of file QwRootFile.h.

Referenced by ConstructNewTree(), GetDesc(), QwRootTree(), QwRootTree(), QwRootTree(), and QwRootTree().

◆ fMaxTreeSize

Long64_t QwRootTree::fMaxTreeSize
private

Maximum tree size, autoflush and autosave.

Definition at line 569 of file QwRootFile.h.

Referenced by SetMaxTreeSize().

◆ fName

const std::string QwRootTree::fName
private

Name, description.

Definition at line 535 of file QwRootFile.h.

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

◆ fNumEventsCycle

UInt_t QwRootTree::fNumEventsCycle
private

Definition at line 556 of file QwRootFile.h.

Referenced by Fill(), QwRootTree(), QwRootTree(), QwRootTree(), QwRootTree(), and SetPrescaling().

◆ fNumEventsToSave

UInt_t QwRootTree::fNumEventsToSave
private

Definition at line 557 of file QwRootFile.h.

Referenced by Fill(), QwRootTree(), QwRootTree(), QwRootTree(), QwRootTree(), and SetPrescaling().

◆ fNumEventsToSkip

UInt_t QwRootTree::fNumEventsToSkip
private

Definition at line 558 of file QwRootFile.h.

Referenced by QwRootTree(), QwRootTree(), QwRootTree(), QwRootTree(), and SetPrescaling().

◆ fPrefix

const std::string QwRootTree::fPrefix
private

◆ fTree

◆ fType

std::string QwRootTree::fType
private

◆ fVector

QwRootTreeBranchVector QwRootTree::fVector
private

Vector of leaves.

Definition at line 531 of file QwRootFile.h.

Referenced by ConstructBranchAndVector(), and FillTreeBranches().

◆ kUnitsName

const TString QwRootTree::kUnitsName = "ppm/D:ppb/D:um/D:mm/D:mV_uA/D:V_uA/D"
staticprivate

Definition at line 420 of file QwRootFile.h.

Referenced by ConstructUnitsBranch().

◆ kUnitsValue

Double_t QwRootTree::kUnitsValue = { 1e-6, 1e-9, 1e-3, 1 , 1e-3, 1}
staticprivate

Definition at line 20 of file QwRootFile.h.

Referenced by ConstructUnitsBranch().


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