Message: Re: Saving data on .root File using ParGeant4 (Geant4 4.9.6p01 + TOP-C) Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

Idea Re: Saving data on .root File using ParGeant4 (Geant4 4.9.6p01 + TOP-C) 

Forum: Multithreading
Re: None Saving data on .root File using ParGeant4 (Geant4 4.9.6p01 + TOP-C) (Cristian Acuņa)
Date: 04 Feb, 2013
From: Andrea Dotti <Andrea Dotti>

Hello, as you guessed the simplest way of handling this situation is to have each thread to have its own file.

You can always merge them later in the analysis step (creating a TChain for ttrees and summing up together histograms:

Note that every file must have a unique name. There is a relatively simple way to do this. In your application you can add the unique thread ID to the ROOT file name. These are some lines of code I use myself in my application:

#include <TFile.h>
#include <G4MTGetTid.hh>
#include <iostream>
//... Where you create the TFile ...// std::ostringstream filename; filename << "file_" << gettid() << ".root"; TFile * file = TFile::Open( filename.str().c_str() , "recreate" );

The output file name will be: file_nnnn.root where nnnn is a unique number identifying your thread.

Please note that unfortunately this is not enough: many classes of ROOT are not thread safe, it means that you need to create mutexes and lock them around the relevant parts of the code. If you need more information on how to create mutexes and use them, please let me know and I will add more instructions to this thread.

Hope this helps, Andrea

On Mon, 04 Feb 2013 20:45:55 GMT, Cristian Acu&#65533;a wrote:

> Hello everybody!
> I'm a newbie (in programming and Geant4 as well), and I'm having
> problems with a certain simulation using Geant4 with TOP-C. I'm
> simulating a very simple geometry of a LYSO scintillator crystal with
> two sensors. I'm shooting gammas to it, and saving the Energy deposited
> on the sensors on an TNtuple and storing the data on a root file.
> The problem is that when I use the multi threaded version of the code, I
> have several errors with the storing of the data, because every slave
> process writes the data on the same file (the exact error is "Error in
> <TROOT::WriteTObject>: The current directory (root) is not associated
> with a file. The object (Tuple) has not been written.")
> If somebody knows a way to store data using ROOT (or g4tools) in an
> efficient way, I would appreciate the help very much.
> I think the solution may be to create a file for every slave and then
> store the data generated by every slave on this files and merge them,
> but I currently don't know how to do this.
> Thanks in advance.
> P.D: Sorry for the bad English.

Inline Depth:
 1 1
 All All
Outline Depth:
 1 1
 2 2
 All All
Add message: (add)

1 Feedback: Re: Saving data on .root File using ParGeant4 (Geant4 4.9.6p01 + TOP-C)   (Cristian Acuņa - 04 Feb, 2013)
(_ Ok: Re: Saving data on .root File using ParGeant4 (Geant4 4.9.6p01 + TOP-C)   (Cristian Acuņa - 07 Feb, 2013)
 Add Message Add Message
to: "Re: Saving data on .root File using ParGeant4 (Geant4 4.9.6p01 + TOP-C)"

 Subscribe Subscribe

This site runs SLAC HyperNews version 1.11-slac-98, derived from the original HyperNews