Confusing implementation of scoreboard

Dear All,

I’m trying to understand about scoreboard and I would came across as the below snippet code, But Why does $cast need it? Is this normally used technic?
Why does it need Object Copy?

and write_exam method also was made by virtual (As I know the virtual need to inheritance class), Why does this make Virtual what for?


   virtual function void write_exam(exam_packet packet);
     exam_packet sb_packet;
     // Make a copy for storing in the scoreboard
     $cast( sb_packet,  packet.clone());  // Clone returns uvm_object type


class example_scoreboard extends uvm_scoreboard;

   // TLM Port Declarations
   `uvm_analysis_imp_decl(_exam)
   ...

   uvm_analysis_imp_exam    #(exam_packet, router_scoreboard) sb_exam_in;
   ...

   virtual function void write_exam(exam_packet packet);
     exam_packet sb_packet;
     // Make a copy for storing in the scoreboard
     $cast( sb_packet,  packet.clone());  // Clone returns uvm_object type
     packets_in++;
     case (sb_packet.addr)
        2'b00: begin 
                sb_queue0.push_back(sb_packet);
                `uvm_info(get_type_name(), "Added packet to Scoreboard Queue 0", UVM_HIGH)
               end
                in_dropped++;
               end
     endcase
    endfunction
    

In reply to UVM_LOVE:
You have 2 questions:
(1) why do we need to do the cast
(2) Why do we use virtual methods.

Answers:
(1) as shown in your comment. The method clone returns as type uvm_object. But we need exam_packet. For this reason we are doing this so-called type cast using the sytem function $cast.
(2) A non-virtual method (function/task) fix the method to the class object when constructed. Virtual method functionality is set at run‐time, which allows extended class handles to be assigned to base class handles and run‐time method calls using the base class handle will execute the extended class method functionality (polymorphism).

BTW you should use in your scorboard uvm_tlm_analysis_fifo instead of queues.

In reply to chr_sue:

In reply to UVM_LOVE:
You have 2 questions:
(1) why do we need to do the cast
(2) Why do we use virtual methods.
Answers:
(1) as shown in your comment. The method clone returns as type uvm_object. But we need exam_packet. For this reason we are doing this so-called type cast using the sytem function $cast.
(2) A non-virtual method (function/task) fix the method to the class object when constructed. Virtual method functionality is set at run‐time, which allows extended class handles to be assigned to base class handles and run‐time method calls using the base class handle will execute the extended class method functionality (polymorphism).
BTW you should use in your scorboard uvm_tlm_analysis_fifo instead of queues.

Sir Thanks for letting me know that.
Sir Could you give me any information why I should use uvm_tlm_analysis_fifo instead of queues?

In reply to chr_sue:

In reply to UVM_LOVE:
You have 2 questions:
(1) why do we need to do the cast
(2) Why do we use virtual methods.
Answers:
(1) as shown in your comment. The method clone returns as type uvm_object. But we need exam_packet. For this reason we are doing this so-called type cast using the sytem function $cast.
(2) A non-virtual method (function/task) fix the method to the class object when constructed. Virtual method functionality is set at run‐time, which allows extended class handles to be assigned to base class handles and run‐time method calls using the base class handle will execute the extended class method functionality (polymorphism).
BTW you should use in your scorboard uvm_tlm_analysis_fifo instead of queues.

Sir,

I think that “$cast( sb_packet, packet.clone()); // Clone returns uvm_object type” can be commented out and then can be implemented “sb_packet = packet;”

What’s the difference between $cast( sb_packet, packet.clone()); and “sb_packet = packet”?

You should read “what is the difference between dynamic and static casting?”