Re: TObject::Write() - OverWrite - discussive

Rene Brun (Rene.Brun@cern.ch)
Fri, 10 Jul 1998 11:55:43 +0200


Valeriy Onuchin wrote:
>
> Hello Rooters!
>
> TObject::Write() method does not provide
> Overwrite/Update functionality, each time you write TObject
> new TKey is created and written to TFile.
>
> Of course I can simply delete TObject/TKey from TFile
> and write it again, or write my own method Overwrite() for
> my application.
> But it seems to me the problem is more general -
> TObject::Write() method doesn't have options (Write(,,option)).
>
> My question - if overwrite functionality of TObject::Write()
> method be implemented in the future?
>
> With best regards, Valery.

Hi Valery,
I have implemented this functionality in our latest version.
It will appear as 2.00/10.
I did not want to modify the calling sequence of TObject::Write.
I simply use a convention for the first argument.

New option in TObject::Write(const char *name).
If the first character of name is '+', a previous key with
name=name is overwritten by this new object.
example 1, with a TNamed derived object:
obj->Write("+")
will replace the previous key (named obj->GetName()) by the
new object
and the same name.
example 2, (TNamed derived object or not):
obj->Write("+Hello");
will replace an existing object named "Hello" in the file by the
new object

The choice of "+" is may be debatable (in my mind, overwrite).
"-" is may be better (would mean, delete previous cycle if any).

Rene Brun