pflib v3.0.0-rc1-25-gb91774e
Pretty Fine HGCROC Interaction Library
|
The object that does the compiling. More...
#include <Compile.h>
Public Member Functions | |
void | compile (const std::string &page, const std::string ¶m, const int &val, std::map< int, std::map< int, uint8_t > > ®isters) |
Overlay a single parameter onto the input register map. | |
std::map< int, std::map< int, uint8_t > > | compile (const std::string &page_name, const std::string ¶m_name, const int &val) |
Compile a single parameter into the (potentially several) registers that it should set. | |
std::map< int, std::map< int, uint8_t > > | compile (const std::map< std::string, std::map< std::string, int > > &settings) |
Compiling which translates parameter values for the HGCROC into register values that can be written to the chip. | |
std::map< std::string, std::map< std::string, int > > | decompile (const std::map< int, std::map< int, uint8_t > > &compiled_config, bool be_careful) |
unpack register values into the page names, parameter names and parameter values mapping | |
std::vector< std::string > | parameters (const std::string &page) |
get the parameter names for the input page-type | |
std::map< std::string, std::map< std::string, int > > | defaults () |
get the default parameter values as specified in the manual | |
void | extract (const std::vector< std::string > &setting_files, std::map< std::string, std::map< std::string, int > > &settings) |
Extract the page name, parameter name, and parameter values from the YAML files into the passed settings map. | |
std::map< int, std::map< int, uint8_t > > | compile (const std::vector< std::string > &setting_files, bool prepend_defaults=true) |
compile a series of yaml files | |
std::map< int, std::map< int, uint8_t > > | compile (const std::string &setting_file, bool prepend_defaults=true) |
short hand for a single setting file | |
Static Public Member Functions | |
static Compiler | get (const std::string &roc_type_version) |
Get an instance of the compiler for the input HGCROC type_version string. | |
Private Member Functions | |
Compiler (const ParameterLUT ¶meter_lut, const PageLUT &page_lut) | |
Private constructor, only access Compiler instances from the static get method so that we can ensure they are properly configured. | |
void | extract (YAML::Node params, std::map< std::string, std::map< std::string, int > > &settings) |
Extract a map of page_name, param_name to their values by crawling the YAML tree. | |
Private Attributes | |
const ParameterLUT & | parameter_lut_ |
const PageLUT & | page_lut_ |
The object that does the compiling.
Since the compiler needs to be configured, we wrap all of the compiling methods into a class so that any callers must define the compiler configuration before they are able to compile.
Right now, the compiler only has one configuration parameter: which type and which version of the HGCROC it should compile for.
std::map< int, std::map< int, uint8_t > > pflib::Compiler::compile | ( | const std::map< std::string, std::map< std::string, int > > & | settings | ) |
Compiling which translates parameter values for the HGCROC into register values that can be written to the chip.
The input settings map has an expected structure:
The pages that a specific parameter and its value are applied to are decided by if key1 is a substring of the full page name. This allows the user to specify a group of pages by just giving a partial page name that is a substring of the pages that you wish to apply the parameter to. For example,
[in] | settings | page names, parameter names, and parameter value settings |
void pflib::Compiler::compile | ( | const std::string & | page, |
const std::string & | param, | ||
const int & | val, | ||
std::map< int, std::map< int, uint8_t > > & | registers ) |
Overlay a single parameter onto the input register map.
This only overwrites the bits that need to be changed for the input parameter. Any registers that don't exist will be set to 0 before being written to.
implementation of compiling a single value for the input parameter specification into the list of registers.
This accesses the PARAMETER_LUT map, its submaps, and the register_values map without any checks so it may throw a std::out_of_range error. Do checking of names before calling this one.
Most of the parameters have the same names as the ones in the HGCROC Manual; however, a few parameters on the Top sub-block (page) different in format and so we have changed them here. The translations from the manual to what is used here are listed below.
[in] | page | name of page parameter is on |
[in] | param | name of parameter |
[in] | val | value parameter should be |
[in,out] | registers | page numbers, register numbers, and register values to apply parameter to |
std::map< int, std::map< int, uint8_t > > pflib::Compiler::compile | ( | const std::string & | page_name, |
const std::string & | param_name, | ||
const int & | val ) |
Compile a single parameter into the (potentially several) registers that it should set.
Any other bits in the register(s) that this parameter affects will be set to zero.
[in] | page_name | name of page parameter is on |
[in] | param_name | name of parameter |
[in] | val | value parameter should be set to |
std::map< int, std::map< int, uint8_t > > pflib::Compiler::compile | ( | const std::string & | setting_file, |
bool | prepend_defaults = true ) |
short hand for a single setting file
[in] | setting_file | YAML file to extract and compile |
[in] | prepend_defaults | start construction of settings map by including defaults from all parameter settings |
std::map< int, std::map< int, uint8_t > > pflib::Compiler::compile | ( | const std::vector< std::string > & | setting_files, |
bool | prepend_defaults = true ) |
compile a series of yaml files
[in] | setting_files | list of YAML files to extract in order and compile |
[in] | prepend_defaults | start construction of settings map by including defaults from all parameter settings |
std::map< std::string, std::map< std::string, int > > pflib::Compiler::decompile | ( | const std::map< int, std::map< int, uint8_t > > & | compiled_config, |
bool | be_careful ) |
unpack register values into the page names, parameter names and parameter values mapping
ret_map[page_name][parameter_name] == parameter_value
The decompilation simply interates through all parameters and attempts to deduce their values from the input compiled config.
If be_careful is true and any of the registers required to deduce a parameter are missing, warnings are printed to std::cerr and the parameter is skipped. Additionally, warnings are printed for entire pages that are skipped.
If be_careful is false, then no warnings are printed and parameters are only skipped if all of the registers that constitute it are missing.
[in] | compiled_config | page number, register number, register value settings |
[in] | be_careful | true if we should print warnings and skip partially-set params |
std::map< std::string, std::map< std::string, int > > pflib::Compiler::defaults | ( | ) |
get the default parameter values as specified in the manual
This is a helpful command for simply printing a "template" YAML settings file although it will printout all pages individually.
void pflib::Compiler::extract | ( | const std::vector< std::string > & | setting_files, |
std::map< std::string, std::map< std::string, int > > & | settings ) |
Extract the page name, parameter name, and parameter values from the YAML files into the passed settings map.
Page names are allowed to be "globbed" so that multiple pages with the same parameters can be set in one chunk of YAML. The globbing is just checking for a prefix and you must end a globbing page with the *
character in order to signal that this chunk of YAML is to be used for all pages whose name start with the input prefix.
All matching is done case insensitively.
will match all channel pages and turn them off.
will throw an exception because no page is named 'channel_'.
will turn off channel_1 (and only channel 1)
will turn off all channels beginning with 1 (1, 10, 11, 12, etc...)
[in] | setting_files | list of YAML files to extract in order |
[in,out] | settings | page name, parameter name, parameter value settings extracted from YAML file(s) |
|
private |
Extract a map of page_name, param_name to their values by crawling the YAML tree.
pflib::Exception | if YAML file has a bad format (root node is not a map, page nodes are not maps, page name doesn't match any pages, or parameter's value does not exist). |
[in] | params | a YAML::Node to start extraction from |
[in,out] | settings | map of names to values for extract parameters |
std::vector< std::string > pflib::Compiler::parameters | ( | const std::string & | page | ) |
get the parameter names for the input page-type
The page-types are as specified in the HGC ROC manual without spaces and case insensitive.