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.



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).


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
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");

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/ does not exist in .:/nfs/farm/g/glast/
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);

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.