RE: [ROOT] how do I load objects from RootFile without searching

From: Faine, Valeri (fine@bnl.gov)
Date: Wed Jan 22 2003 - 21:22:46 MET


> 
> Question:
>    TDirectory::Get("ObjName");
>    first searches for the object named "ObjName" in a given RootFile
>    and then loads the object into memory.
> 
>    I want to eliminate the process of searching.
>    i.e. I want to find a function that does the second part of Get()
>         --> to load the object in memory given an offset.

I am afraid you can not avoid it. There is no magic stick. The position
of object in the file is kept within TKey object. The later is a part of
TKey collection. When you open TFile the entire collection of TKey's is
to be read into the memory.

One can not get just a single member of the entire collection alone. One
has to read the entire collection into the memory first.


>    Since we can get the info of the offset (seekKey) of
>    the object stored in a rootfile and we can know the offset
beforehand,
>    we could have a function like:
>    (TObject *) Load(offset)
>    which just goes to the offset in the file and load the object into
> memory.
>    This presumably will be somewhat faster than Get("ObjName").

If you could preserve (or recreated) somehow the instance of the TKey
class then you could have applied its methods to bring the object into
the memory.
http://root.cern.ch/root/htmldoc/TKey.html#TKey:ReadObj
This implies that you should be capable

  1. to keep the instance of TKey somewhere
  2. bypass reading of TKey collection into memory at the time the TFile
is instantiated.

On other hand I can not image the time to look up the TKey collection
takes time that is large enough to justify inventing your own TKey
collection database with your own search algorithm.



> 
>    Is there something in the class library to allow me to do this ???
> 
>    GetListOfKeys() can provide SeekKey for the object, which we can
>    store in a hash table such as
>    STL::map(string(objName), unsigned_int(offset)).
>    But in TDirectory, I could not find any function that does:
>    (TObject *) Load(seekKey).
 
This I don't understand. The TKeys' are kept in the hash table anyway
(see:
http://root.cern.ch/root/htmldoc/src/TDirectory.cxx.html#TDirectory:Buil
d 

   fKeys       = new THashList(100,50);

  Hope this helps, Valeri



This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:08 MET