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

Public Member Functions

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

Public Attributes

 name = name
 cached name for this TTree
 
 title = title
 cached title for this TTree
 
 refiner_function = refiner_function
 cached copy of the instance's refiner function
 

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__()

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

Definition at line 825 of file refiners.py.

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

Member Function Documentation

◆ __call__()

__call__ ( self,
harvesting_module,
crops = None,
* args,
** kwds )
inherited
implementation of the function-call of the Refiner instance
     r = Refiner()
     r(harvester) # decoration
     r(harvester, crops, args, keywords) # refinement

Definition at line 55 of file refiners.py.

55 def __call__(self, harvesting_module, crops=None, *args, **kwds):
56 """implementation of the function-call of the Refiner instance
57 r = Refiner()
58 r(harvester) # decoration
59 r(harvester, crops, args, keywords) # refinement
60 """
61 if crops is None:
62 # Decoration mode
63 harvesting_module.refiners.append(self)
64 return harvesting_module
65 else:
66 # Refining mode
67 return self.refine(harvesting_module, crops, *args, **kwds)
68

◆ __get__()

__get__ ( self,
harvesting_module,
cls = None )
inherited
Getter of the Refiner instance

Definition at line 42 of file refiners.py.

42 def __get__(self, harvesting_module, cls=None):
43 """Getter of the Refiner instance"""
44 if harvesting_module is None:
45 # Class access
46 return self
47 else:
48 # Instance access
49 refine = self.refine
50
51 def bound_call(*args, **kwds):
52 return refine(harvesting_module, *args, **kwds)
53 return bound_call
54

◆ add_branch()

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()

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 = name

cached name for this TTree

Definition at line 832 of file refiners.py.

◆ refiner_function

refiner_function = refiner_function
inherited

cached copy of the instance's refiner function

Definition at line 40 of file refiners.py.

◆ title

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: