Casting in UVM

Hi,

I am trying to cast an object in a build phase as shown below.
$cast(m_cpu_config[0], name); // where as the “name” is a type string and it holds the design hierarchy “top.a1.b2.c3.dv.rim.get_config_object()”

from the above hierarchy path “top.a1.b2.c3” is variable and “dv.rim.get_config_object()” is fixed while building the environment.
the environment gets the variable path from configdb while building it so i was doing it as shown below.

string name;
name = $psprintf(“%s.dv.rim.get_config_object()”, get_hier_from_cfgdb()); //get_hier_from_cfgdb() returns the path top.a1.b2.c3
$cast(m_cpu_config[0] , name);

doing so i am facing the below failure.

** Error: (vsim-3971) $cast to type ‘class libbdv.cpu_pkg::cpu_cfg_c’ from ‘string’

can someone please help me out.

Thanks,
Aktab

In reply to maazlee:

You can’t convert strings to hierarchical paths. You should use the config_db calls with the appropriate targeting of your config object.

In reply to cgales:

Thanks cgales,
from the above hierarchy example i gave (top.a1.b2.c3.dv.rim.get_config_object()), rim is a type module, and i am not able to configdb set this rim.
can you suggest a way to set the model type via configdb.

-Aktab

In reply to maazlee:

You need to explain what you are trying to accomplish and how your environment is organized.

Typically, configuration objects are created/configured by the test component to meet the requirements of the test. These configuration objects are then passed down the hierarchy to the sub-components as required. If you need the configuration object in more than one location, you just add it to the config_db with the required hierarchy.