How to Understand a Class Structure ?

The class structure and Object-Orientation make possible more modular programming. However, programs consisting of several hundred classes and several hundred thousand lines of code may be difficult to understand, in particular for novice users. ROOT provides a set of tools to help understanding an existing class structure, a data structure in memory or files.

  • TClass::Draw can be used to draw the inheritance tree for a given object. All ROOT classes are documented with their associated inheritance tree (see for example TPaveText). This tree can be generated interactively via the command: object->DrawClass() or by selecting the DrawClass item when pointing with the right moose button to an object in a canvas. The tree is automatically generated when a given class is processed through the documentation tool (class THtml). For example:
  •    THtml html;
       html.MakeClass(myclass);
  • TObject::Inspect can be used to view the contents of a given object. A table is shown where, for each data member, its name, current value and its title are given.

  • If a data member is a pointer to another object, one can click on the pointer and, in turn, inspect the pointed object,etc.

  • TObject::Dump is the same as TObject::Inspect, except that the output is on stdout. An object dump can be written to a file. Example:
       TFile f("hsimple.root"); // connects a file
       f.Dump();                // dump the object f
    Produces the following dump of the object f:
    fBEGIN                   64          First used byte in file
    fEND                     459500      Last used byte in file
    fVersion                 9010        File format version
    fCompress                1           (=1 file is compressed, 0 otherwise)
    fOption.*fData           READ
    fUnits                   4           Number of bytes for file pointers
    fSeekFree                459414      Location on disk of free segments structure
    fNbytesFree              86          Number of bytes for free segments structure
    fWritten                 0           Number of objects written so far
    fSumBuffer               0           Sum of buffer sizes of objects written so far
    fSum2Buffer              0           Sum of squares of buffer sizes of objects written so far
    *fStream                 ->4033f690  Input file stream identifier
    *fOStream                ->0         Output stream (output on same file as fStream)
    *fFree                   ->0         Free segments linked list table
    fModified                1           true if directory has been modified
    fWritable                0           true if directory is writable
    fDatimeC.fDatime         139248235   Date (relative to 1995) + time
    fDatimeM.fDatime         139248246   Date (relative to 1995) + time
    fNbytesKeys              307         Number of bytes for the keys
    fNbytesName              120         Number of bytes in TNamed at creation time
    fSeekDir                 64          Location of directory on file
    fSeekParent              0           Location of parent directory on file
    fSeekKeys                459107      Location of Keys record on file
    *fFile                   ->4033f508  pointer to current file in memory
    *fKeys                   ->4033f628  Pointer to keys list in memory
    *fMother                 ->0         pointer to mother of the list
    *fIndex                  ->0         Index of the list
    *fListHead               ->4033f5f0  Pointer to Objects in this directory
    fName.*fData             hsimple.root
    fTitle.*fData            
    fUniqueID                0           object unique identifier
    fBits                    50331649    bit field status word
  • The ROOT general object browser (see TBrowser) can be used to browse collections such as the list of classes, geometries, files and TTrees. A browser can be started from the Start Browser item in the canvas View menu or by creating a browser object. Example: TBrowser b. More than one browser can be active at any time.

  •  

  • TFile::ls can be used to list objects in a file or directory.
  •  

  • list->ls() lists objects in a collection pointed by list.
  •  

  • list->Dump() dumps all objects in a collection pointed by list.
  •  

  • TFile::Map dumps the structure of a file. One line is printed for every record written to the file with the following information:
     
       - Date/Time when the object was written.
       - Position of the object (starting byte number).
       - Number of bytes occupied by the object.
       - Object class name. 
       - Compression factor (if file is compressed).
    For example, to see the map of the file generated by the tutorial hsimple, you can type the following commands:
     
       TFile f("hsimple.root"); // connect file
       f.Map();
    
    This produces the following output:
     
    970106/120943  At:64        N=150       TFile         
    970106/120944  At:214       N=28909     TBasket        CX =  1.11
    970106/120945  At:29123     N=29046     TBasket        CX =  1.10
    970106/120946  At:58169     N=29021     TBasket        CX =  1.10
    970106/120946  At:87190     N=28994     TBasket        CX =  1.10
    970106/120947  At:116184    N=29069     TBasket        CX =  1.10
    970106/120948  At:145253    N=29101     TBasket        CX =  1.10
    970106/120948  At:174354    N=29019     TBasket        CX =  1.10
    970106/120949  At:203373    N=28930     TBasket        CX =  1.11
    970106/120949  At:232303    N=29040     TBasket        CX =  1.10
    970106/120950  At:261343    N=29001     TBasket        CX =  1.10
    970106/120951  At:290344    N=29035     TBasket        CX =  1.10
    970106/120951  At:319379    N=29003     TBasket        CX =  1.10
    970106/120952  At:348382    N=29008     TBasket        CX =  1.10
    970106/120953  At:377390    N=29049     TBasket        CX =  1.10
    970106/120953  At:406439    N=29025     TBasket        CX =  1.10
    970106/120953  At:435464    N=455       TH1F           CX =  1.80
    970106/120954  At:435919    N=1724      TH2F           CX =  4.33
    970106/120954  At:437643    N=1850      TProfile       CX =  1.55
    970106/120954  At:439493    N=19614     TNtuple        CX =  1.74
    970106/120954  At:459107    N=307       TFile         
    970106/121159  At:459414    N=86        TFile         

     

  • gObjectTable->Print(). ROOT keeps tracks of all objects created into a special table in memory. In the development phase of a program, it is frequent to create objects and forget to delete them (memory leaks). Printing the object table shows the number of instances for each class currently active in memory. It also shows the total number of bytes occupied by these objects. Example: gObjectTable->Print(); produces the following output:
    Object statistics
    class                     cnt    on heap     size    total size    heap size
    ============================================================================
    TH1F                        1          1      448           448          448
    TObject                    11         11       12           132          132
    TFileType                   6          6       36           216          216
    TRint                       1          1      116           116          116
    TClassTable                 1          1       12            12           12
    TObjectTable                1          1       12            12           12
    THashList                   5          5       40           200          200
    THashTable                  5          5       36           180          180
    TList                      24         24       36           864          864
    TStyle                      1          1      328           328          328
    TGeometry                   1          1       64            64           64
    TGaxis                      1          0      124           124            0
    TAxis                       6          3       88           528          264
    TUnixSystem                 1          1      256           256          256
    TPostScript                 1          1      764           764          764
    TOrdCollection              4          4       40           160          160
    TEnv                        1          1       24            24           24
    TBenchmark                  1          1       52            52           52
    TSignalHandler              1          1       20            20           20
    TFileHandler                2          2       20            40           40
    TCint                       1          1      208           208          208
    TFile                       1          1      160           160          160
    TROOT                       1          0      244           244            0
    TClass                      6          6       64           384          384
    TKey                        4          4       80           320          320
    TStopwatch                  1          0       56            56            0
    TGuiFactory                 2          2       28            56           56
    TGXW                        1          1       84            84           84
    TRandom                     1          1       32            32           32
    TGX11                       1          1      176           176          176
    ----------------------------------------------------------------------------
    Total:                     94         88     3660          6260         5572
    ============================================================================