Moving TGraph to a new file

In order to do event based parallelism in ATLAS, we have a mother
process that forks worker child processes to individual cores, each of
which then processes a number of events individually. In order that
these child processes not interfere with each others’ I/O, they each
write their outputs into individual directories. At the end of the
job, the outputs are merged. In order to maximize memory sharing, this
forking happens after the first event is processed, by which time many
output files have already been opened. So what we do is clone these
files into the individual worker directories, and reset file
descriptors to point to the appropriate places.

We need to do this in a way that’s transparent to the users, so that
if they hold a pointer to something in the original file, this pointer
still needs to be valid after the forking has migrated the files to
the new locations.

We have a service (the THistSvc in Gaudi) that manages all Histograms,
Trees and Graphs that are registered with it. It holds all the
pointers to the individual TTrees, THNs, and TGraphs. When the mother
process clones the original TFiles in the individual worker
directories, we update all these objects that are registered with the
service, so that the pointers point to the objects in the new files,
but the value of the pointers haven’t changed. This way, users can
still keep using a pointer that they got before the forking.

When dealing with TFiles that contain TTrees and THNs, this isn’t a
problem as after we have copied the file structure to the new
location, we can just do a SetDirectory() that reflects the new TFile.

However, there’s no such method in TGraphs.

What I’ve tried doing is cloning the TGraph in the new file (either
via the constructor or a Clone() method), then doing a memcpy to
overwrite the original pointer with the clone, so that the original
pointer will reference a TGraph in the new file, but this doesn’t
work.

Can anyone suggest a solution?

               cheers,  Charles.

Hi Charles,

TGraph do not know in which directory there are being held and are not automatically added to any directory
(But strangly enough TGraph2D do and do have a SetDirectory method).

If the TGraph are held in a TDirectory they have been append to it via ‘directory->Append(graph_pointer)’ and to move the graph from one directory to the other you would need to use:old_directory->Remove(graph_pointer); new_directory->Append(graph_pointer);

Cheers,
Philippe

Thanks Philippe!That seems to work.

I had tried the dir->Append(TGraph*), but it had segfaulted, as I had neglected to do the old->Remove(TGraph*).

   cheers,  Charles.

(And sorry about the crosspost).

Hi Philippe,

Could you or any ROOT developer please harmonize this,
i.e. implement TGraph2D directory methods (DirectoryAutoAdd, SetDirectory and GetDirectory) and attributes (fDirectory) in TGraph?

Cheers,
Z

Are there any limitations not to do it?
Cheers,
Z

Hi,

We have to design/implement it in a way that is backward compatible. We will be discussing this issue in the next few weeks.

Cheers,
Philippe

Hi,

The usage pattern of TGraph and TGraph2D are very different, effectively the size of TGraph objects are usually much smaller and they are often more TGraphs. Thus we want to keep the management/weight of the TGraph has small as possible. TGraph2D is more akin to an histogram.

In addition, any change to the behavior of TGraph is relation to the ownership would not be backward compatible unless we default to not adding it to the directory … in which case we somewhat introduce more confusion by having this one class have a different default that the other autoAdd objects …

Cheers,
Philippe.

Ok :frowning:
Could you please mention how to deal with TGraph in the manual then?
I’ve been looking for this feature quite a while…
Cheers,
Z

Done.
Philippe.