Selectively instantiate covergroup

In reply to dave_59:
Below is the set for above config_db get

if (cfg.has_functional_coverage) begin
         cov = <class_name>::type_id::create("cov", this);
        uvm_config_db#(<class_name>_cfg)::set(this, "cov", "cfg", cfg);
  end

Actually
i have virtual interface which i am getting in uvm_subscriber build_phase() using config_db
I want to use this virtual interface in covergroups in uvm_subscriber class

 covergroup trans_cov_ @(posedge vif.clk_core iff vif.valid);
       coverbin __valid : coverpoint vif.valid {
      bins bin0 = {0,1};
    }
   endgroup // trans_cov

  function new(string name="<class_name>_coverage", uvm_component parent);
    super.new(name,parent);  
    trans_cov = new();   // this is what LRM recommand 
   endfunction : new

It not working when i access “vif.clk_core” in covergroup whose “vif” is visible (config_db get ) in build_phase