Code Generation
- class code_generation.code_generation.CodeGenerator(main_template_path, sub_template_path, configuration, analysis_name, config_name, executable_name, output_folder, threads=1)[source]
Class used to generate code from a given Configuration. The code is generated in a folder, which is the name of the executable. Inside the folder the source file for the executable is generated, as well as and include and source dir. Within those two folders, a subfolder for each scope is generated and within those, the code for each producer is generated. Each file contains all calls for one producer from the config.
- Parameters:
main_template_path (str) – the path to the cxx template for the executable
sub_template_path (str) – the path to the cxx template for the code subsets
configuration (Configuration) – the configuration to generate code from
analysis_name (str) – the name of the analysis
executable_name (str) – the name of the executable
output_folder (str) – the folder to write the code to
config_name (str)
threads (int)
- Returns:
None
- generate_code()[source]
Generate the code from the configuration and create the subsets. Run through the whole configuration and create a subset for each producer within the configuration.
Start with the global scope and then all other scopes. All generated code is stored in the folder self.output_folder.
- Parameters:
None
- Returns:
None
- Return type:
None
- generate_main_code()[source]
Generate the call commands for all the subsets. Additionally, generate all include statements for the main executable. :param None:
- Returns:
Tuple, the generated calls and the generated includes
- Return type:
Tuple[str, str]
- generate_run_commands()[source]
generate the dataframe snapshot commands for the main executable. A seperate output file is generated for each scope, that contains at least one output quantity. The process tracking is also generated here.
- Parameters:
None
- Returns:
str - the generated run commands
- Return type:
str
- generate_subsets(scope)[source]
Generate the subsets for the given scope :param scope: the scope to generate the subsets for
- Returns:
None
- Parameters:
scope (str)
- Return type:
None
- get_cmake_path()[source]
Get the path to the cmake file :param None:
- Returns:
the path to the cmake file
- Return type:
str
- get_git_status()[source]
Get the git status of the main repo. The status is determined via the checks/git-status.sh script.
- Return type:
None
- load_template(template_path)[source]
Load the template from the given path :param template_path: the path to the template
- Returns:
str - the template
- Parameters:
template_path (str)
- Return type:
str
- set_debug_flag()[source]
Set the debug flag in the template if the debug variable is set to true
- Returns:
None
- Return type:
str
- set_output_paths()[source]
adds the code for the output paths to the run commands.
- Return type:
str
- set_output_quantities()[source]
Set the output quantities in the template if the debug variable is set to true
- Returns:
None
- Return type:
str
- set_quantities_shift_map()[source]
This function is used to generate a mapping of all quantities and the shifts, the quantities are used in to be stored in the output file. The ordering is based on the quantities:
Example:
{ "quantity_1" : ["shift_1", "shift_2", "shift_3"], "quantity_2" : ["shift_1"], "quantity_3" : ["shift_1", "shift_2"], }
This information will be stored in the root file as quantities_shift_map and can be accessed to get the correct mapping
- Return type:
str
- set_setup_printout()[source]
adds the code for the timing information on the dataframe setup to the run commands.
- Return type:
str
- set_shift_quantities_map()[source]
This function is used to generate a mapping of all quantities and the shifts, the quantities are used in to be stored in the output file. The ordering is based on the shifts:
Example:
{ "shift_1" : ["quantity_1", "quantity_2", "quantity_3"], "shift_2" : ["quantity_1", "quantity_3"], "shift_3" : ["quantity_1"] }
This information will be stored in the root file as shift_quantities_map and can be accessed to get the correct mapping
- Return type:
str
- set_shifts()[source]
Set the shifts in the template if the debug variable is set to true
- Returns:
None
- Return type:
str
- set_thead_flag(threads)[source]
Set the multithreading flag in the template if the number of threads is greater than 1.
- Parameters:
threads (int) – The number of threads to be used.
- Returns:
None
- Return type:
None
- sort_scopes()[source]
Sort the scopes alphabetically, keeping the global scope at the beginning
- Return type:
None
- class code_generation.code_generation.CodeSubset(file_name, template, producer, scope, folder, configuration_parameters, name, analysis_name)[source]
Class used to generate code for a smaller subset. For each subset, a new object must be created.
- Parameters:
file_name (str) – The name of the file to be generated.
template (str) – The template to be used for the generation.
producer (Union[Producer, ProducerGroup]) – The producer, of which the code will be generated.
scope (str) – The scope of the code generation.
folder (str) – The folder in which the code will be generated.
parameters – The parameters to be used for the generation.
name (str) – The name of the code subset.
analysis_name (str) – Name of the analysis configuration.
configuration_parameters (Dict[str, Any])
- Returns:
None
- call(inputscope, outputscope)[source]
Return the call to the code subset. This call is used in the generated code of the executalbe.
- Parameters:
inputscope (str) – The scope of the input dataframe.
outputscope (str) – The scope of the output dataframe.
- Returns:
the call to the code subset
- Return type:
str
- create()[source]
Create the code subset. Calls the writecalls function of the producer to generate the code.
- Parameters:
None
- Returns:
None
- include()[source]
Return the include statement for the code subset
- Parameters:
None
- Returns:
the include statement for the code subset
- Return type:
str
- write()[source]
Write the code subset to a file, both the header and the source. Before writing the files, check if they already exists, and if they exist and are not different, skip writing them. This is to avoid unnecessary recompilation, since the compiler will check the timestamps of the files.
- Parameters:
None
- Returns:
None
- code_generation.code_generation.addon_includes(analysis_name, file_name)[source]
Add the includes all .hxx files from analysis configuration folder: analysis_configurations/{analysis_name}/cpp_addons/include :param analysis_name: the name of the analysis :param file_name: Name of file that is templated
- Returns:
str - the include statements for the cpp addons
- Parameters:
analysis_name (str)
file_name (str)
- Return type:
str