Root examples
Akiya Miyamoto, 17-September-1998
Get list of classes
-
{
-
// List created classes.
-
TSeqCollection
*list=gROOT->GetListOfClasses();
-
TIter next(list);
-
TClass *c;
-
while( (c=(TClass*)next())
) {
-
printf("class name is %s\n",c->GetName());
-
}
-
}
Make a branch
-
// To create the branch in the tree,
-
Int_t split=1;
-
Int_t bsize=4000;
-
TNamed *obj=this;
-
tree->Branch(GetName(),
GetClass(), &obj, bsize, split);
-
// This statement creates the branch
in the tree.
-
// If split=0, only single branch
is created. Whole data member of the
-
// class is saved in the single branch.
If Streamer method which is
-
// created automatically by rootcint
is not adequate, user can white
-
// their own streamer method( Append
- to the class name in LinkDef.h to
-
// suppress automatic generation of
Streamer method.)
-
// If split=1, whole data member of
the class are further devided untill
-
// they are basic data type.
In this case, single variable forms sub-branches.
Make html documents
-
{
-
// A macro
to create html documents.
-
// Execute
this macro, after loading library which defines classes.
-
-
THtml html;
-
html.SetOutputDir("html/");
-
html.SetSourceDir("./");
-
html.MakeAll();
-
// This
will create html documents of all classes in html/ directory.
-
}
GUI howto
-
From the cint environment, only button
function can be used.
-
Other function such as menu bar and
dialog must be prepared as an
-
compiledcoded as an compiled shared
library. Otherwise, some trick
-
must be used. Classes which
are defined in a cint macro can not be
-
included in the cint dictionary properly.
-
Keyed IO
-
{
-
TFile f("file.root");
-
TNamed obj("Mine");//
Create named object
-
obj->Write()
;// Write object, key is Mine;1
-
obj->Write()
;// Write same object, key is Mine;2
-
obj->Write()
;// Write same object once more, key is Mine;3
-
-
obj->Read("Mine");//
Read Mine;3
-
TKey *key=f->GetKey("Mine",2);
// Get key for cycle 2
-
obj->Read(key);
// read Mine;2
-
-
obj=(TNamed*)f->Get("Mine;2")
;// Get Mine;2
-
obj=(TNamed*)f->Get("Mine");
// Get Mine;3
-
-
// TDirectory->EncodeNameCycle(
.., .. , .. )
-
// TDirectory->DecodeNameCycle(
.., .. , .. )
-
// use these
function to convert namecylce to name and cycle
-
}
-