Belle II Software development
SaveTreeRefiner Class Reference
Inheritance diagram for SaveTreeRefiner:
Refiner

Public Member Functions

def __init__ (self, name=None, title=None)
 
def refine (self, harvesting_module, crops, tdirectory=None, groupby_part_name=None, groupby_value=None, **kwds)
 
def add_branch (self, output_ttree, part_name, parts)
 

Public Attributes

 name
 cached name for this TTree
 
 title
 cached title for this TTree
 

Static Public Attributes

str default_name = "{module.id}_tree"
 default name for this TTree
 
str default_title = "Tree of {module.id}"
 default title for this TTree
 

Detailed Description

Refiner for ROOT TTrees

Definition at line 817 of file refiners.py.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  name = None,
  title = None 
)
Constructor for this refiner

Reimplemented from Refiner.

Definition at line 825 of file refiners.py.

827 title=None):
828 """Constructor for this refiner"""
829 super().__init__()
830
831
832 self.name = name
833
834 self.title = title
835

Member Function Documentation

◆ add_branch()

def add_branch (   self,
  output_ttree,
  part_name,
  parts 
)
Add a TBranch to the TTree

Definition at line 867 of file refiners.py.

867 def add_branch(self, output_ttree, part_name, parts):
868 """Add a TBranch to the TTree"""
869 input_value = np.zeros(1, dtype=float)
870
871 branch_type_spec = f'{part_name}/D'
872 tbranch = output_ttree.Branch(part_name, input_value, branch_type_spec)
873
874 if output_ttree.GetNbranches() == 1:
875 # On filling of the first branch we need to use the fill method of the TTree
876 # For all other branches we can use the one of the branch
877 # #justrootthings
878 for value in parts:
879 input_value[0] = value
880 output_ttree.Fill()
881
882 else:
883 for value in parts:
884 input_value[0] = value
885 tbranch.Fill()
886
887 output_ttree.GetEntry(0)
888 output_ttree.ResetBranchAddress(tbranch)
889 also_subbranches = True # No subbranches here but we drop the buffers just in case.
890 output_ttree.DropBranchFromCache(tbranch, also_subbranches)
891
892

◆ refine()

def refine (   self,
  harvesting_module,
  crops,
  tdirectory = None,
  groupby_part_name = None,
  groupby_value = None,
**  kwds 
)
Process the TTree

Reimplemented from Refiner.

Definition at line 836 of file refiners.py.

842 **kwds):
843 """Process the TTree"""
844
845 replacement_dict = dict(
846 refiner=self,
847 module=harvesting_module,
848 groupby_key='_' + groupby_part_name + groupby_value if groupby_part_name else "",
849 groupby=groupby_part_name, # deprecated
850 groupby_value=groupby_value, # deprecated
851 )
852
853 with root_cd(tdirectory):
854 name = self.name or self.default_name
855 title = self.title or self.default_title
856
857 name = formatter.format(name, **replacement_dict)
858 title = formatter.format(title, **replacement_dict)
859
860 output_ttree = ROOT.TTree(root_save_name(name), title)
861 for part_name, parts in iter_items_sorted_for_key(crops):
862 self.add_branch(output_ttree, part_name, parts)
863
864 output_ttree.FlushBaskets()
865 output_ttree.Write()
866

Member Data Documentation

◆ default_name

str default_name = "{module.id}_tree"
static

default name for this TTree

Definition at line 821 of file refiners.py.

◆ default_title

str default_title = "Tree of {module.id}"
static

default title for this TTree

Definition at line 823 of file refiners.py.

◆ name

name

cached name for this TTree

Definition at line 832 of file refiners.py.

◆ title

title

cached title for this TTree

Definition at line 834 of file refiners.py.


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