G4Exception related to multi-threading after upgraded to 11.2

I have a very simple Geant4 application that is about 100 lines of code:

It compiles fine with Geant4 11.2 on macOS Sonoma 14.2.1 with a M2 chip. However, when I run it with the following macro file:

I got the following error messages right after the first /run/beamOn 1

G4WT2 > ... write file : scoring_t2.root - done
G4WT2 > ... close file : scoring_t2.root - done
G4WT2 > ... delete empty file : scoring_t2.root - done
G4WT2 > 
-------- WWWW ------- G4Exception-START -------- WWWW -------
*** G4Exception : Analysis_W001
      issued by : G4TFileManager<FT>::SetIsEmpty
Failed to get file scoring_t2.root
*** This is just a warning message. ***
-------- WWWW -------- G4Exception-END --------- WWWW -------

... write file : scoring.root - done
... close file : scoring.root - done
... delete empty file : scoring.root - done

-------- WWWW ------- G4Exception-START -------- WWWW -------
*** G4Exception : Analysis_W001
      issued by : G4TFileManager<FT>::SetIsEmpty
Failed to get file scoring.root
*** This is just a warning message. ***
-------- WWWW -------- G4Exception-END --------- WWWW -------

What could be the cause?

Thanks!

Jing

It might be because your root file is empty, it seems that the new version of Geant4 will delete empty files.

Hello,

The problem is in your application. When using G4TScoreNtupleWriter, there is no need to create G4AnalysisManager or G4TScoreHistFiller.

Creating G4AnalysisManager would be useful if you would have also analysis objects (histograms and/or ntuples) created in your code, in addition to those created automatically by the score ntuple writer.

G4TScoreHistFiller is useful when you want to let your primitive scorers fill
histograms, but in this case, you would need to create these histograms in your macro and assign them to you scorers. As none of these use cases apply to your application, you can remove these objects fron your RunAction.

Then, the G4TScoreNtupleWriter construction has to be moved to your main() (see also e.g. basic example B3a), as this class takes care of creating the analysis manager objects on master and workers:

int main(int argc,char** argv)
{
        // ... skipped

        G4VisManager *vis = new G4VisExecutive("quiet"); vis->Initialize();

        G4TScoreNtupleWriter<G4AnalysisManager> scoreNtupleWriter;
        scoreNtupleWriter.SetVerboseLevel(1);
        scoreNtupleWriter.SetNtupleMerging(true);

        if (argc==1) { // interactive mode

	// ... skipped
}	

After moving this class out of RunAction, there is no need to create the RunAction class at all, and you can remove it from your ActionInitialization.

After these changes, the empty output files (scoring.root from the first three runs) will be still deleted as empty, but without any warning, and the last output file, which was renamed to output.root in your run.mac, and which contains data, will be kept.

Best regards,

@ivana, thanks for the detailed explanation! Reading the code of G4TScoreHistFiller and G4TScoreNtupleWriter, I realize that both can create an analysis manager by themselves. However, since the analysis manager is a singleton, they will share the same analysis manager. Is that right?

I am OK with giving up G4AnalysisManager, but I can imagine that someone may want to create both histograms and ntuples in a single run. If we are not allowed to use G4TScoreHistFiller and G4TScoreNtupleWriter in parallel, how can we achieve this?

Last question, shall we use G4TScoreNtupleWriter<G4AnalysisManager> scoreNtupleWriter; or G4TScoreNtupleWriter<G4GenericAnalysisManager> scoreNtupleWriter;? I thought G4GenericAnalysisManager allows the user to switch in between root and hdf5 format. I’d like to keep that flexibility.

Thanks!

Jing

@ivana, I removed G4GenericAnalysisManager and G4TScoreHistFiller from the code, and the error message disappeared. The updated code can be found here: GitHub - jintonic/mingle: Mini Geant4 Learning Example. But I got some new error messages. I can open a new post to discuss that if they are not related.

Adding task 0 to task-group...
Adding task 1 to task-group...
Adding task 2 to task-group...
G4WT3 > /score/create/boxMesh mesh
Adding task 3 to task-group...
G4WT7 > /score/create/boxMesh mesh
Adding task 4 to task-group...
G4WT3 > 
-------- WWWW ------- G4Exception-START -------- WWWW -------
*** G4Exception : UIMAN0123
      issued by : G4UImanager::ApplyCommand
ERROR[/score/create/boxMesh] : Scoring mesh <mesh> already exists. Command ignored.
Error code : 1
*** This is just a warning message. ***
-------- WWWW -------- G4Exception-END --------- WWWW -------

Adding task 5 to task-group...
G4WT3 > /score/mesh/boxSize 4 1 1 cm
Adding task 6 to task-group...
Adding task 7 to task-group...
G4WT2 > /score/create/boxMesh mesh
Adding task 8 to task-group...
Adding task 9 to task-group...
G4WT7 > 
-------- WWWW ------- G4Exception-START -------- WWWW -------
*** G4Exception : UIMAN0123
      issued by : G4UImanager::ApplyCommand
ERROR[/score/create/boxMesh] : Scoring mesh <mesh> already exists. Command ignored.
Error code : 1
*** This is just a warning message. ***
-------- WWWW -------- G4Exception-END --------- WWWW -------

Adding task 10 to task-group...
Adding task 11 to task-group...
Adding task 12 to task-group...
Adding task 13 to task-group...
Adding task 14 to task-group...
G4WT7 > /score/mesh/boxSize 4 1 1 cm
Adding task 15 to task-group...
G4WT2 > 
-------- WWWW ------- G4Exception-START -------- WWWW -------
*** G4Exception : UIMAN0123
      issued by : G4UImanager::ApplyCommand
ERROR[/score/create/boxMesh] : Scoring mesh <mesh> already exists. Command ignored.
Error code : 1
*** This is just a warning message. ***
-------- WWWW -------- G4Exception-END --------- WWWW -------

G4WT3 > 
-------- WWWW ------- G4Exception-START -------- WWWW -------
*** G4Exception : UIMAN0123
      issued by : G4UImanager::ApplyCommand
ERROR: No mesh is currently open. Open/create a mesh first. Command ignored.
Error code : 1
*** This is just a warning message. ***
-------- WWWW -------- G4Exception-END --------- WWWW -------

Hello,

You are allowed to create both G4AnalysisManager and G4TScoreNtupleWriter in parallel; G4TScoreNtupleWriter performs a check if there is already a file open via G4AnalysisManager, and in this case it does not call Open/CloseFile itself but relies on the user code. However this information about the file ownership is set only once, and it is not reset with CloseFile, what causes a failure in your use case, when OpenFile is called only for the third run. I will take a look at this and fix it. In meantime, if users need to have both G4AnalysisManager and G4TScoreNtupleWriter, they should call Open/CloseFile either in all runs or in none run.

G4AnalysisManager is defined in G4AnalysisManager.hh as another name for the G4GenericAnalysisManager via C++ using directive, so both ways are equivalent.

Best regards,

The warnings issued after /score/create/boxMesh mesh look like a bug; the messages happen when a scoring mesh is created only after processing a run.

It can be reproduced with the Geant4 extended example runAndEvent/RE03, if we add a code for one run processing in the beginning of run1.mac. I suggest you to open a bug report.

The warnings issued after /score/create/realWorldLogVol CsI (not shown in your post) seem to me justified, as they coplain about creating a new mesh while there is already existing one.

I see. This behavior is fine. I guess you just need to emphasize it somewhere in the developer’s manual. There is probably no need to change your code.

Thanks, Jing

Is there a macro command to delete the old mesh? If not, does it mean that I have to provide different macro files for different mesh settings?

No, there is no such command defined. (You can check yourself by viewing all commands under /score in you user interface.)

Yes, instead of changing your scoring mesh during run processing you can run your application with different macro files.

1 Like

Yes, I checked /score/ before asking. I did not find anything there. But I just wanted to make sure that I did not miss anything.