James M White wrote: > > Greetings, > I have a few basic questions about the RTTI facility and I/O > via the TTree class. They are: > > 1) If you have a collection of objects that is too large to keep in > memory is the TTree the only/best collection class to use? > Root supports two methods to write objects to a file: a, For any object of a class derived from TObject you can do: object.Write(keyname); This method uses the object serialization tecnique described at: http://root.cern.ch/root/HowtoWrite.html A key with name keyname is associated to this object. This key will be visible with file.ls(). This method can be used when the number of objects is small, say less than 100000. You have direct access to any object in a directory. You can delete objects(keys) one by one. You can add a new cycle for a given key. The objects written in this way can be inspected via the TBrowser. b, Using TTree. You should use this method when you want to write a large collection of objects with a similar class structure. This is typically the case for High Energy Physics events. TTrees are designed for sequential write and sequential&direct access read. A TTree structure contains pointers to each event/object and in case the TTree contains several branches, one can read selectively only one branch. This technique is particularly efficient when doing data analysis on large data sets. TTrees can span several files. In this case, use the TChain class to logically group these TTrees. > 2) Can you change the size of an object in the TTree (by adding a new > member into a container within the object) without re-building the > tree? > TTrees are written sequentially. You cannot replace directly one event. You can only add a new event at the end of a file. However, there is a solution to your problem. You can use a standard TTree + one or more objects like TBtree (balanced tree) or TMap. In the TBtree, you can keep an association between the serial event number in the big TTree and a unique identifier (32, 64bits or whatever you need). You write your TBtree using a key (method a). In case the TBtree object is too large to fit in memory, you create several TBtree objects. For example, assume you have to maintain a data base with 10**8 entries, you could create 100 TBtree directory objects. Each TBtree will nicely fit in memory. You have direct and efficient access to any entry in you table. From your table, you have direct access to a TTree event. In case, you need to modify one object, you append a new version for this object in the TTree. You know the serial number in the TTree (returned by TTree::GetEntries). You just update your table with this serial number. > 3) Can you insert a new object into the middle of a TTree without > re-building the tree? > same technique as described above. > 4) I want to use a TMap to associate a TString to a class type and > then create new objects of a particular type based on a given TString? > I've looked at the RTTI facility but am unclear on exactly how this > would work. This is possible with the ROOT Run Time Type Identification. If you have a string containing the name of a class (say MyClass), you can create an object of this class with the following statements: TClass *cl = gROOT->GetClass("MyClass"); MyClass *object = (MyClass*)cl->New(); The first ststement returns a pointer to the class descriptor object for the class identified by the string "MyClass". The second statement instantiates an object of this class by calling the default constructor for this class. More info about the ROOT RTTI can be found at: http://root.cern.ch/root/Dictionary.html http://root.cern.ch/root/Using.html Rene Brun
This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:26:19 MET