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

375 : fName(name),fDesc(desc),fPrefix(prefix),fType("type undefined"),
377 // Construct tree
379 }
void ConstructNewTree()
Construct the tree.
Definition QwRootFile.h:426
UInt_t fCurrentEvent
Tree prescaling parameters.
Definition QwRootFile.h:567
const std::string fPrefix
Definition QwRootFile.h:549
UInt_t fNumEventsToSave
Definition QwRootFile.h:569
UInt_t fNumEventsToSkip
Definition QwRootFile.h:570
const std::string fName
Name, description.
Definition QwRootFile.h:547
std::string fType
Object type.
Definition QwRootFile.h:560
UInt_t fNumEventsCycle
Definition QwRootFile.h:568
const std::string fDesc
Definition QwRootFile.h:548

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

383 : fName(tree->GetName()),fDesc(tree->GetDesc()),fPrefix(prefix),fType("type undefined"),
385 QwMessage << "Existing tree: " << tree->GetName() << ", " << tree->GetDesc() << QwLog::endl;
386 fTree = tree->fTree;
387 }
#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:554
TTree * fTree
Tree pointer.
Definition QwRootFile.h:541
const std::string & GetName() const
Get the name of the tree.
Definition QwRootFile.h:552

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

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

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

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

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

417{ }

Member Function Documentation

◆ AutoSave()

Long64_t QwRootTree::AutoSave ( Option_t * option)
inline

Definition at line 498 of file QwRootFile.h.

498 {
499 return fTree->AutoSave(option);
500 }

References fTree.

◆ ConstructBranchAndVector()

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

Construct the branches and vector for generic objects.

Definition at line 453 of file QwRootFile.h.

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

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

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

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

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

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

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

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

503 {
505
506 // Tree prescaling
507 if (fNumEventsCycle > 0) {
510 return 0;
511 }
512
513 // Fill the tree
514 Int_t retval = fTree->Fill();
515 // Check for errors
516 if (retval < 0) {
517 QwError << "Writing tree failed! Check disk space or quota." << QwLog::endl;
518 exit(retval);
519 }
520 return retval;
521 }

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

477 {
478 // Prescale peek. Gathering the branch vector (FillTreeVector) copies
479 // every channel value and is a sizeable fraction of the per-event cost.
480 // When the tree is prescaled, Fill() will discard this event anyway, so
481 // skip the gather as well. This mirrors Fill()'s computation exactly
482 // (Fill() does ++fCurrentEvent then %= fNumEventsCycle), so the gather
483 // and the write always agree on which events are kept.
484 if (fNumEventsCycle > 0) {
485 UInt_t predicted = (fCurrentEvent + 1) % fNumEventsCycle;
486 if (predicted > fNumEventsToSave) return;
487 }
488 if (typeid(object).name() == fType) {
489 // Fill the branch vector
490 object.FillTreeVector(fVector);
491 } else {
492 QwError << "Attempting to fill tree vector for type " << fType << " with "
493 << "object of type " << typeid(object).name() << QwLog::endl;
494 exit(-1);
495 }
496 }

References QwLog::endl(), fCurrentEvent, fNumEventsCycle, fNumEventsToSave, 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 554 of file QwRootFile.h.

554{ 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 552 of file QwRootFile.h.

552{ 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 556 of file QwRootFile.h.

556{ 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 533 of file QwRootFile.h.

533{ return fTree; };

References fTree.

◆ GetType()

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

Get the object type.

Definition at line 563 of file QwRootFile.h.

563{ 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 525 of file QwRootFile.h.

525 {
526 QwMessage << GetName() << ", " << GetType();
527 if (fPrefix != "")
528 QwMessage << " (prefix " << GetPrefix() << ")";
530 }
const std::string & GetPrefix() const
Get the description of the tree.
Definition QwRootFile.h:556
std::string GetType() const
Get the object type.
Definition QwRootFile.h:563

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

593 {
594 fAutoFlush = autoflush;
595 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,26,00)
596 if (fTree) fTree->SetAutoFlush(autoflush);
597 #endif
598 }
Long64_t fAutoFlush
Definition QwRootFile.h:582

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

601 {
602 fAutoSave = autosave;
603 if (fTree) fTree->SetAutoSave(autosave);
604 }
Long64_t fAutoSave
Definition QwRootFile.h:583

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

607 {
608 fBasketSize = basketsize;
609 if (fTree) fTree->SetBasketSize("*",basketsize);
610 }
Int_t fBasketSize
Definition QwRootFile.h:584

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

613 {
614 if (fTree) fTree->SetCircular(buff);
615 }

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

587 {
588 fMaxTreeSize = maxsize;
589 if (fTree) fTree->SetMaxTreeSize(maxsize);
590 }
Long64_t fMaxTreeSize
Maximum tree size, autoflush and autosave.
Definition QwRootFile.h:581

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

573 {
574 fNumEventsToSave = num_to_save;
575 fNumEventsToSkip = num_to_skip;
577 }

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

References QwRootFile.

Referenced by QwRootFile.

Field Documentation

◆ fAutoFlush

Long64_t QwRootTree::fAutoFlush
private

Definition at line 582 of file QwRootFile.h.

Referenced by SetAutoFlush().

◆ fAutoSave

Long64_t QwRootTree::fAutoSave
private

Definition at line 583 of file QwRootFile.h.

Referenced by SetAutoSave().

◆ fBasketSize

Int_t QwRootTree::fBasketSize
private

Definition at line 584 of file QwRootFile.h.

Referenced by SetBasketSize().

◆ fCurrentEvent

UInt_t QwRootTree::fCurrentEvent
private

Tree prescaling parameters.

Definition at line 567 of file QwRootFile.h.

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

◆ fDesc

const std::string QwRootTree::fDesc
private

Definition at line 548 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 581 of file QwRootFile.h.

Referenced by SetMaxTreeSize().

◆ fName

const std::string QwRootTree::fName
private

Name, description.

Definition at line 547 of file QwRootFile.h.

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

◆ fNumEventsCycle

UInt_t QwRootTree::fNumEventsCycle
private

◆ fNumEventsToSave

UInt_t QwRootTree::fNumEventsToSave
private

◆ fNumEventsToSkip

UInt_t QwRootTree::fNumEventsToSkip
private

Definition at line 570 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 543 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 422 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 23 of file QwRootFile.h.

Referenced by ConstructUnitsBranch().


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