pflib v3.0.0-rc1-25-gb91774e
Pretty Fine HGCROC Interaction Library
All Classes Namespaces Files Functions Variables Typedefs Pages
pflib::Compiler Class Reference

The object that does the compiling. More...

#include <Compile.h>

Collaboration diagram for pflib::Compiler:
[legend]

Public Member Functions

void 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.
 
std::map< int, std::map< int, uint8_t > > 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.
 
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::stringparameters (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 &parameter_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 ParameterLUTparameter_lut_
 
const PageLUTpage_lut_
 

Detailed Description

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.

Member Function Documentation

◆ compile() [1/5]

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.

ret_map[page_number][register_number] == register_value

The input settings map has an expected structure:

  • key1: name of page (e.g. Channel_0, or Digital_Half_1)
  • key2: name of parameter (e.g. Inputdac)
  • val: value of parameter

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,

  • Channel_* - matches all 71 channels pages
  • CALIB* - matches both calib channel pages
  • Global_Analog* - matches both global analog pages
Parameters
[in]settingspage names, parameter names, and parameter value settings
Returns
page numbers, register numbers, and register value settings

◆ compile() [2/5]

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.

  • DIV_PLL_{A,B} -> DIV_PLL (two bit field)
  • EN{1,2,3}_probe_pll -> PLL_probe_amplitude (three bit field)
  • EN-pE{0,1,2}_probe_pll -> PLL_probe_pre_scale (three bit field)
  • S{0,1}_probe_pll -> PLL_probe_pre_phase (two bit field)
  • EN{1,2,3} -> eT_amplitude (three bit field)
  • EN-pE{0,1,2} -> eT_pre_scale (three bit field)
  • S{0,1} -> eT_pre_phase (two bit field)
Parameters
[in]pagename of page parameter is on
[in]paramname of parameter
[in]valvalue parameter should be
[in,out]registerspage numbers, register numbers, and register values to apply parameter to

◆ compile() [3/5]

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.

Parameters
[in]page_namename of page parameter is on
[in]param_namename of parameter
[in]valvalue parameter should be set to
Returns
page numbers, register numbers, and register values to set

◆ compile() [4/5]

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

See also
extract for how the YAML files are parsed
Parameters
[in]setting_fileYAML file to extract and compile
[in]prepend_defaultsstart construction of settings map by including defaults from all parameter settings
Returns
page numbers, register numbers, and register value settings

◆ compile() [5/5]

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

See also
extract for how the YAML files are parsed
Parameters
[in]setting_fileslist of YAML files to extract in order and compile
[in]prepend_defaultsstart construction of settings map by including defaults from all parameter settings
Returns
page numbers, register numbers, and register value settings

◆ decompile()

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.

Parameters
[in]compiled_configpage number, register number, register value settings
[in]be_carefultrue if we should print warnings and skip partially-set params
Returns
page name, parameter name, parameter value of registers provided

◆ defaults()

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.

Returns
map of page name and parameter names to default values

◆ extract() [1/2]

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.

Globbing Examples

channel_* :
channel_off : 1

will match all channel pages and turn them off.

channel_ :
channel_off : 1

will throw an exception because no page is named 'channel_'.

channel_1 :
channel_off : 1

will turn off channel_1 (and only channel 1)

channel_1* :
channel_off : 1

will turn off all channels beginning with 1 (1, 10, 11, 12, etc...)

Parameters
[in]setting_fileslist of YAML files to extract in order
[in,out]settingspage name, parameter name, parameter value settings extracted from YAML file(s)

◆ extract() [2/2]

void pflib::Compiler::extract ( YAML::Node params,
std::map< std::string, std::map< std::string, int > > & settings )
private

Extract a map of page_name, param_name to their values by crawling the YAML tree.

Exceptions
pflib::Exceptionif 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).
Parameters
[in]paramsa YAML::Node to start extraction from
[in,out]settingsmap of names to values for extract parameters

◆ 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.

  • DigitalHalf
  • ChannelWise
  • Top
  • MasterTDC
  • ReferenceVoltage
  • GlobalAnalog
Returns
vector of parameter names for that page type

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