How to output time since start?

Hi,

I understand how /run/printProgress prints the status after certain new events. Wondering if there is a way to show the execution time since start just like print progress?

Can that be implemented neatly in macro?

I don’t know of one. I used an instance of G4Timer in my RunAction to collect the execution time for the run, and save it out at end-of-run. You could do the same in EventAction for each event.

@mkelsey: Here is what I cooked up. This is implemented in EventAction::BeginofEventAction. Sharing just in case if someone is interested in the future.

 // Run status
  G4int eventID=anEvent->GetEventID();
  G4Run* run = static_cast<G4Run*>( G4RunManager::GetRunManager()->GetNonConstCurrentRun() );
  G4int nOfEvents = run->GetNumberOfEventToBeProcessed();
  G4double perCent = 10.; // status increment in percent

  if(fmod(eventID,double(nOfEvents*perCent*0.01))==0)
  {
    time_t my_time = time(NULL);
    tm *ltm = localtime(&my_time);
    G4double status=(100*(eventID/double(nOfEvents))); 
    std::cout << "=> Event " << eventID << " starts ("<< status << "%, "<< ltm->tm_hour << ":" <<  ltm->tm_min << ":" << ltm->tm_sec << ")" << std::endl;
  }

Example output:

=> Event 0 starts (0%, 10:35:41)
=> Event 500 starts (10%, 10:35:44)
=> Event 1000 starts (20%, 10:35:46)
=> Event 1500 starts (30%, 10:35:47)
   ...
3 Likes

That works. My only caveat is that “perCent” is defined in G4SystemOfUnits.hh, so if you’re doing any unit conversions for printout, you’ll get a compiler warning. Maybe name that variable “eventPercentage” or something?

Yeah good point. I overlooked that, but yeah can certainly be done. Thanks!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.