Accumulate data from several runs in multithread mode

Hi all,
I’m trying to collect data from several runs in MT mode in one ntuple with option analysisManager->SetNtupleMerging(true). Without this option, it works fine, I get all my data in first file (without _t1, _t2 etc. in name), but Geant creates empty files and that’s annoying to delete them every time.
With it, I get ntuple with empty branch (I check it in TBrowser and with script) named “row_wise_branch”.
That’s how I do data collection:
I open file and create histograms and one ntuple in constructor of RunAction. I fill histograms in several places of my program. In EndOfRunAction I accumulate some variables with G4AccumulableManager, then check IsMaster() and if it’s true, I fill ntuple with them. Then i check number of run, and if it’s last one, I write data in file and close it.
As I said, it works fine in singlethread mode and in MT mode without option SetNtupleMerging(true).
Also, If I set verbose level of analysisManager on 4, it doesn’t print any information about writing in file both with option and without it. That’s pretty strange, because I get histograms with data.
How to collect data correctly in this case?
Thanks.

Hello,

Could you, please, let us know your Geant4 version and your selection of output type?

If you fill your ntuple only on master then the empty files (with _tn extension) should be automatically removed. The mode with merging does not make sense in your use case as you do not define ntuples on workers, so there is nothing to be merged.

I will try to see why

  1. the clean-up of empty files fails
  2. there is no info from write file call with verbose = 4

Thank you,

1 Like

Hello, thank you for your answer! Seems I didn’t understand this option.
I use Geant 10.5 and ROOT output.
I checked another time, and seems I was wrong about info, I’m sorry.
If I write data in last run in workers of RunActon, I get info about writing in file with verbose = 4. If I write it in master - I don’t get message about writing and I get empty histos and ntuple.
But I still get empty files with _tn extension in both ways.
I have my project on GitLab, I can share access with you.
Thank you!

Thank you for the additional information.
So if I understand well, your use case is following:

  • there are histograms which are filled during event processing (on workers)
  • and an ntuple which is filled only on master

The analysis manager deletes the_tn files only is there are no ntuples; the file is preserved even when the ntuples are empty. So to get them deleted, you need to create your ntuple only on master. The problem you get, I think, is that if you use isMaster data member in this test it’s value is not yet updated by G4RunManager at this phase and that’s why the ntuple is created also on workers and the automatic deleting does not happen.

Could you change the test in your Run action constructor as follows:

  #include "G4Threading.hh"
  ...
  if (G4Threading::IsMasterThread()) {
    // Create ntuple only on master
    analysisManager->CreateNtuple("B4", "Edep and TrackL");
    analysisManager->CreateNtupleDColumn("Eabs");
    ...
    analysisManager->FinishNtuple();
  }

In BeginOfRunAction and EndOfRunAction, using isMaster data is ok. Let us know if this solves your problem.

1 Like

It didn’t solve a problem, but it changed things a little bit. I implemented it and I have this results:
If I call analysisManager->Write() in workers of EndOfRunAction of last run I get data in all my histos and in ntuple, and I get files with _tn extension. Every file have empty folder named as file, I can see it in TBrowser. Files have size of 31.6 kB.
If I call analysisManager->Write() in master of EndOfRunAction of last run I get data in ntuple and only in histos which I fill in master of EndOfRunAction. Histos, which I fill on workers, are empty. And I still get files with _tn extension, but in this case I can’t open them in TBrowser, and they have size of 299 bytes.
Thank you for your answers!