Retrieving all events from a Run

Hi All,
I am trying to retrieve all the events in RunAction::EndOfRunAction(const G4Run* aRun) function. For that, I have used GetEventVector() to get the vector of G4Events, and then my intention is to access different parameters of all the hits for each G4Event and save it in a text file for further downstream analysis.

While running in interactive mode the vector<const G4Event*>* events is returning correct number of events in a given run, however in the batch mode this returns zero. Following is the snippet of the code:

G4RunManager* runManager = G4RunManager::GetRunManager();
const G4Run* currentRun = runManager->GetCurrentRun();

if (currentRun) { const std::vector<const G4Event*>* events = currentRun->GetEventVector(); }

Can someone please mention how to make it work in batch mode?

Thank you.