Name of the parent object from a child object

Hi,

What is the way of finding the name of parent object/component from a child object/component?

For instance, I’d like to find the name of the ovm_env component that ‘has a’ monitor component inside an agent component and print it. The get_full_name() method gives full name. Is there a way to get only the name of the ovm_env.

From the xbus example in the downloaded ovm folder shows similar code for retrieving the name of the agent housing the monitor.
trans_collected.slave = m_parent.get_name();
What is the code for finding the name of ovm_env or other component instantiations up the hierarchy?

Regards
Kal

Hi Kal ,

You could use the get_parent() function. It returns a handle to this component’s parent.

Regards

Hi Chinmay,

get_parent() returns the handle to parent of component. I browsed through the ovm_component class and m_parent is doing the same.

Also to know the name of env or a class up the hierarchy, the get_parent needs to be issued again and again. For example, in xbus example, to know the env, the code has to be

ovm_component m_origin;
    ...
    ...  

   virtual protected task some_task();
    ...
     ...  
     m_origin = get_parent();
    m_origin = m_origin.get_parent();
    ovm_report_info(get_type_name(), $psprintf("Parent Component  get_parent %0s \n", m_origin.get_name()), OVM_LOW);
    endtask : some_task
It would be nice, if there is a simpler way than that.

Rgds
Kal

Hi Kal,
You can pass the name of the parent object to the child in the parent class build phase, so that you can access that passed string variable in the child class wherever it is required.
Example:
class agent extends ovm_agent;
proj_monitor monitor;
function void build()
monitor.parent_obj_name = get_name();
endfunction : build
endclass : agent

class proj_monitor extends ovm_monitor;
string parent_obj_name;
//use the above string variable to get the name of the parent object.
endclass : proj_monitor

Regards,
Leela Krishna.