Extending ROOT with Shared Libraries

and an Example of Object I/O


In this tutorial we will show how to extend a running ROOT module with shared libraries. Also we'll show how to create a ROOT database and how to save and retrieve your own object hierachies.

This tutorial uses the shared library event.sl containing the Event and Track classes created in "The CINT Dictionary Generator" page.

Loading a shared library in a running ROOT session is trivial, first start root, then type:

root [0] gSystem.Load("event.sl")
(int)0

This is all there is to it to load a shared library into a running ROOT session. A return value of 0 means that the load was successful. Now lets verify that the classes Event and Track can be seen by the system:

root [1] .class Event
===========================================================================
class Event //Simple event class
 size=0x18
 (tagnum=443,voffset=-1,isabstract=0,parent=-1,gcomp=0,=~cd=0)
List of base class--------------------------------------------------------
0x0        public: TObject //Basic ROOT object
List of member variable---------------------------------------------------
Defined in Event
0x0        private: Int_t fId //event sequential id
0x0        private: Float_t fTotalMom //total momentum
0x0        private: class TCollection* fTracks //collection of tracks
0x7ad8fa80 static class TClass* fgIsA
List of member function---------------------------------------------------
Defined in Event
filename       line:size busy function type and name
(compiled)        0:0    0 public: class Event Event(void);
(compiled)        0:0    0 public: class Event Event(const Int_t id);
(compiled)        0:0    0 public: void AddTrack(class Track *const t);
(compiled)        0:0    0 public: Int_t GetId(void) const;
(compiled)        0:0    0 public: Int_t GetNoTracks(void) const;
(compiled)        0:0    0 public: virtual void Print(Option_t* opt);
(compiled)        0:0    0 public: Float_t TotalMomentum(void);
(compiled)        0:0    0 public: const char* DeclFileName(void);
(compiled)        0:0    0 public: int DeclFileLine(void);
(compiled)        0:0    0 public: const char* ImplFileName(void);
(compiled)        0:0    0 public: int ImplFileLine(void);
(compiled)        0:0    0 public: Version_t Class_Version(void);
(compiled)        0:0    0 public: virtual class TClass* IsA(void) const;
(compiled)        0:0    0 public: virtual void ShowMembers(class TMemberInspector& insp,char* parent);
(compiled)        0:0    0 public: virtual void Streamer(class TBuffer& b);
(compiled)        0:0    0 public: void Dictionary(void);
(compiled)        0:0    0 public: class Event Event(class Event&);
(compiled)        0:0    0 public: void ~Event(void);
root [2] gClassTable.Print()

Defined classes
class                              version  initialized
=======================================================
Event                                  1        No
...
...

The command ".class classname" shows a class definition as known by the builtin CINT interpreter. To check that the classes were properly added to the ROOT system (i.e. not only known to the interpreter, but also to ROOT) we can print the contents of the global class table using the command "gClassTable.Print()". If the classes appear in the .class listing but not in the class table change is that you forgot to insert the ClassImp macro in the class implementation file. In the output of the .class command we see also how the system uses the comments you provided in the class definition.

When loading a shared library using gSystem.Load() the system will look for the library in the Root.DynamicPath search path. On how to set this search path in your .rootrc config file is described in the TEnv class description.

Now lets play a bit with our Event and Track classes.


Rene Brun, Fons Rademakers
Last update 28/8/96 by FR