Belle II Software development
RootQuantityExtract Class Reference

Public Member Functions

def __init__ (self, extractor=None)
 
def addExtractor (self, class_type, extractor)
 
def extract (self, obj)
 

Public Attributes

 extractor
 the dictionary used for data extraction, key is the ROOT type and value a list of extractors
 

Detailed Description

Class to automatically extract quantities from ROOT Objects

Definition at line 84 of file quantity_extract.py.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  extractor = None 
)
Initialize the class with a set of quantity extractors

Definition at line 89 of file quantity_extract.py.

89 def __init__(self, extractor=None):
90 """
91 Initialize the class with a set of quantity extractors
92 """
93
94
96 self.extractor = extractor
97
98 if self.extractor is None:
99 # use default
100 self.extractor = default_extractor()
101

Member Function Documentation

◆ addExtractor()

def addExtractor (   self,
  class_type,
  extractor 
)
Adds an extractor to this class

@param class_type: the string you get when
running <root_object>.IsA().GetName()
This is used to map the correct extractor to
this root object

Definition at line 102 of file quantity_extract.py.

102 def addExtractor(self, class_type, extractor):
103 """
104 Adds an extractor to this class
105
106 @param class_type: the string you get when
107 running <root_object>.IsA().GetName()
108 This is used to map the correct extractor to
109 this root object
110 """
111
112 # check if extractors for this type are already
113 # registered
114 if class_type in self.extractor:
115 self.extractor[class_type].append(extractor)
116 else:
117 self.extractor[class_type] = [extractor]
118

◆ extract()

def extract (   self,
  obj 
)
Extract quantities from a root object

@return: a dictionary of extracted quantities

Definition at line 119 of file quantity_extract.py.

119 def extract(self, obj):
120 """
121 Extract quantities from a root object
122
123 @return: a dictionary of extracted quantities
124 """
125 this_class_type = obj.IsA().GetName()
126
127 if this_class_type in self.extractor:
128 ext_list = self.extractor[this_class_type]
129
130 # run list of extractors
131 # convert the returned tuple list to a dictionary
132 result = []
133 for x in ext_list:
134 # run the extractor
135 result_list = x(obj)
136 result += result_list
137 # convert the list of tuples into a dictionary
138 return dict(result)
139 else:
140 # no extractors available for this type
141 return {}

Member Data Documentation

◆ extractor

extractor

the dictionary used for data extraction, key is the ROOT type and value a list of extractors

Definition at line 96 of file quantity_extract.py.


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