Copying custom object from file to file without loading libs

I have a file which has a custom object stored inside of it. I would like to copy this object to another file, but WITHOUT having loaded the libraries that provide the class dictionary (I don’t want the program to be dependent upon them). Is this possible to do?

I tried using WriteObjectAny() and WriteTObject() but the results in the output file are always garbage and can’t be read in later.

Thanks.

Hi,

There is no good/easy way to read or write object that have been written using WriteObject without the shared library.
However you might be able to use TFile::MakeProject to generate a sufficient library (in simple cases).

Cheers,
Philippe.

PS. By the way, in which context are you trying to do this?

A function copying directly an object from file1 to file2
is not available in the current system (although it could be
implemented).
You can use the following workaround example

TFile f1("oldfile.root"); f1.MakeProject("mydir","*","recreate++"); A *a = (A*)f1.Get("name of object of class A"); TFile f2("newfile.root","recreate"); a->Write("name of object");
Rene

Hmm, when I run that code I get errors like the following:

MakeProject has generated 0 classes in mydir
mydir/MAKE file has been generated
g++: list.dll: No such file or directory
g++: stdfunc.dll: No such file or directory
g++: vector.dll: No such file or directory
Error in TUnixSystem::DynamicPathName: mydir/mydir.so does not exist in .:/nfs/farm/g/glast/
u05/GLAST_EXT/rh9_gcc32/ROOT/v4.02.00/root/lib:/nfs/farm/g/glast/u05/GLAST_EXT/rh9_gcc32/ROOT/
v4.02.00/root/lib:/nfs/farm/g/glast/u05/GLAST_EXT/rh9_gcc32/ROOT/v4.02.00/root/lib:/usr/oracle
/lib:/u/gl/goder/tonyj3
Error in TFile::WriteTObject: Directory ./foo_digi.root is not writable

I am using this code:

  TFile from(srcFilename);
  from.MakeProject("mydir", "*", "recreate++");
  MyClass* ptr = (MyClass*)from.Get("myobj");
  TFile to(destFilename);
  ptr->Write("myobj");

This problem (list.dll: no such file) has been solved.
For ROOT 4.02/00 you need to issue the following

TString r = gSystem->GetMakeSharedLib(); gSystem->SetMakeSharedLib(r.ReplaceAll("$LinkedLibs",""));to work around the problem.

Cheers,
Philippe.