TIMBER  beta
Tree Interface for Making Binned Events with RDataFrame
Public Member Functions | Public Attributes | List of all members
ModuleWorker Class Reference

Class to handle C++ class modules generically. More...

Inheritance diagram for ModuleWorker:
Inheritance graph
[legend]
Collaboration diagram for ModuleWorker:
Collaboration graph
[legend]

Public Member Functions

def __init__ (self, name, script, constructor=[], mainFunc='eval', columnList=None, isClone=False, cloneFuncInfo=None)
 Constructor. More...
 
def Clone (self, name, newMainFunc=None)
 Makes a clone of current instance. More...
 
def GetCall (self, evalArgs={}, toCheck=None)
 Gets the call to the method to be evaluated per-event. More...
 
def GetFuncNames (self)
 Gets list of function names in C++ script. More...
 
def GetMainFunc (self)
 Gets full main function name. More...
 
def MakeCall (self, inArgs={}, toCheck=None)
 Makes the call (stored in class instance) to the method with the branch/column names deduced or added from input. More...
 

Public Attributes

 name
 str Correction name
 

Detailed Description

Class to handle C++ class modules generically.

Uses clang in python to parse the C++ code and determine function names, namespaces, and argument names and types.

Writing the C++ modules requires the desired branch/column names must be specified or be used as the argument variable names to allow the framework to automatically determine what branch/column to use in GetCall().

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  name,
  script,
  constructor = [],
  mainFunc = 'eval',
  columnList = None,
  isClone = False,
  cloneFuncInfo = None 
)

Constructor.

Parameters
name(str): Unique name to identify the instantiated worker object.
script(str): Path to C++ script with function to calculate correction. For a TIMBER module, use the header file.
constructor([str], optional): List of arguments to script class constructor. Defaults to [].
mainFunc(str, optional): Name of the function to use inside script. Defaults to None and the class will try to deduce it.
columnList([str], optional): List of column names to search mainFunc arguments against. Defaults to None and the standard NanoAOD columns from LoadColumnNames() will be used.
isClone(bool, optional): For internal use when cloning. Defaults to False. If True, will not duplicate compile the same script if two functions are needed in one C++ script.
cloneFuncInfo(dict, optional): For internal use when cloning. Defaults to None. Should be the _funcInfo from the object from which this one is cloned.

Member Function Documentation

◆ Clone()

def Clone (   self,
  name,
  newMainFunc = None 
)

Makes a clone of current instance.

If multiple functions are in the same script, one can clone the correction and reassign the mainFunc to avoid compiling the same script twice.

Parameters
name(str): Clone name.
newMainFunc(str, optional): Name of the function to use inside script. Defaults to None and the original is used.
Returns
ModuleWorker Clone of instance with same script but different function (newMainFunc).

◆ GetCall()

def GetCall (   self,
  evalArgs = {},
  toCheck = None 
)

Gets the call to the method to be evaluated per-event.

Parameters
evalArgs(list, optional): Args to use for eval if MakeCall() has not already been called. Defaults to []. If MakeCall() has not already been called and inArgs == [], then the arguments to the method will be deduced from the C++ method definition argument names.
toCheck(Node, ROOT.RDataFrame, list, optional): Object with column information to check argument names exist. Defaults to None in which case a default NanoAODv6 list is loaded.
Returns
str The string that calls the method to evaluate per-event. Pass to Analyzer.Define(), Analyzer.Cut(), etc.

◆ GetFuncNames()

def GetFuncNames (   self)

Gets list of function names in C++ script.

Returns
[str]: List of possible function names found in C++ script.

◆ GetMainFunc()

def GetMainFunc (   self)

Gets full main function name.

Returns
str Name of function assigned from C++ script.

◆ MakeCall()

def MakeCall (   self,
  inArgs = {},
  toCheck = None 
)

Makes the call (stored in class instance) to the method with the branch/column names deduced or added from input.

Parameters
inArgs(dict, optional): Dict with keys as C++ method argument names and values as the actual argument to provide (branch/column names) for per-event evaluation. For any argument names where a key is not provided, will attempt to find branch/column that already matches based on name. Defaults to {} in which case ther will be automatic deduction from the argument names written in the C++ script.
toCheck(Node, ROOT.RDataFrame, list, optional): Object with column information to check argument names exist. Defaults to None in which case a default NanoAODv6 list is loaded.
Exceptions
NameErrorIf argument written in C++ script cannot be found in available columns.
ValueErrorIf provided number of arguments does not match the number in the method.
Returns
strCall to function from C++ script.

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