Skip to content

Commit f5fc5c4

Browse files
karabowiChristianTackeGSI
authored andcommitted
fix(sim): Remove WriteFolder from FairMCApplication::InitGeometry
The function `WriteFolder` (since the introduction of the `MTMode`) was misused to remove the `TFolder` from `gROOT` after it was used to create the output tree. Purely for that reason `WriteFolder` was called in the `InitGeometry()`. This folder is no longer removed in the sink's `WriteFolder()`. Introduced a new `FairRootManager::RemoveOutputFolderForMtMode()` function which removes the `TFolder` from `gROOT`, which is needed in the MT mode in TGeant4 transport. Used this function in `FairMCApplicaiton::InitGeometry()` and in `FairMCApplication::InitFinalizer()`.
1 parent 0f8dfe0 commit f5fc5c4

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

fairroot/base/sim/FairMCApplication.cxx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ void FairMCApplication::InitGeometry()
874874
if (fRootManager && !fParent) {
875875
RegisterOutput();
876876
if (GetIsMT()) {
877-
fRootManager->WriteFolder();
877+
fRootManager->RemoveOutputFolderForMtMode();
878878
}
879879
}
880880
fMCEventHeader->SetRunID(runId);
@@ -937,6 +937,7 @@ void FairMCApplication::InitFinalizer()
937937
{
938938
std::lock_guard guard(mtx);
939939
fRootManager->WriteFolder();
940+
fRootManager->RemoveOutputFolderForMtMode();
940941
}
941942
}
942943

fairroot/base/sink/FairRootFileSink.cxx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,6 @@ void FairRootFileSink::WriteFolder()
245245
fOutTree = new TTree(FairRootManager::GetTreeName(), Form("/%s", FairRootManager::GetFolderName()), 99);
246246
TruncateBranchNames();
247247
CreatePersistentBranchesAny();
248-
249-
// Delete the folder to make place in the gROOT for fOutFolder created by the Geant4MT threads
250-
gROOT->GetRootFolder()->Remove(fOutFolder);
251248
}
252249
}
253250

fairroot/base/steer/FairRootManager.cxx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include <TNamed.h>
3939
#include <TObjArray.h> // for TObjArray
4040
#include <TObjString.h> // for TObjString
41+
#include <TROOT.h> // for gROOT
4142
#include <TTree.h> // for TTree
4243
#include <algorithm> // for find
4344
#include <atomic>
@@ -221,8 +222,8 @@ TClonesArray* FairRootManager::Register(TString branchName, TString className, T
221222

222223
TClonesArray* FairRootManager::GetEmptyTClonesArray(TString branchName)
223224
{
224-
if (fActiveContainer.find(branchName)
225-
!= fActiveContainer.end()) { // if a TClonesArray is registered in the active container
225+
if (fActiveContainer.find(branchName) != fActiveContainer.end())
226+
{ // if a TClonesArray is registered in the active container
226227
if (fActiveContainer[branchName] == 0) { // the address of the TClonesArray is still valid
227228
std::cout << "-E- FairRootManager::GetEmptyTClonesArray: Container deleted outside FairRootManager!"
228229
<< std::endl;
@@ -383,6 +384,12 @@ void FairRootManager::WriteFolder()
383384
}
384385
}
385386

387+
void FairRootManager::RemoveOutputFolderForMtMode()
388+
{
389+
auto rootFolder = static_cast<TFolder*>(gROOT->GetRootFolder());
390+
rootFolder->Remove(rootFolder->FindObject(GetFolderName()));
391+
}
392+
386393
Bool_t FairRootManager::SpecifyRunId()
387394
{
388395
if (!fSource) {

fairroot/base/steer/FairRootManager.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
#include <TRefArray.h> // for TRefArray
1919
#include <TString.h> // for TString, operator<
2020
#include <fairlogger/Logger.h>
21+
#include <list>
2122
#include <map> // for map, multimap, etc
2223
#include <memory>
2324
#include <string>
2425
#include <type_traits> // is_pointer, remove_pointer, is_const, remove...
2526
#include <typeinfo>
26-
#include <list>
2727

2828
class BinaryFunctor;
2929
class FairEventHeader;
@@ -218,6 +218,11 @@ class FairRootManager : public TObject
218218
void WriteFileHeader(FairFileHeader* f);
219219
/**Write the folder structure used to create the tree to the output file */
220220
void WriteFolder();
221+
/**
222+
* \brief Internal: Remove the folder describing the output tree structure from gROOT, called in TGeant4 MT
223+
* simulation mode
224+
*/
225+
void RemoveOutputFolderForMtMode();
221226

222227
/**Check the maximum event number we can run to*/
223228
Int_t CheckMaxEventNo(Int_t EvtEnd = 0);

0 commit comments

Comments
 (0)