KaliVeda
Toolkit for HIC analysis
Loading...
Searching...
No Matches
KVDataBase Class Reference

Detailed Description

Simple cross-referenced database structure.

KVDataBase, along with KVDBKey, KVDBRecord and KVDBTable, are base classes for the implementation of simple cross-referenced database structures. The database is made up of tables with unique names, each table contains a list of records. Records in different tables may be linked together using keys, providing cross-referenced entries.

All these objects are ROOT TFolder objects. The KVDataBase object is added to the ROOT folder and may be browsed in the TBrowser.

           An example of use is given here:
KVDataBase my_db("my_db","Beatles' discography");
my_db.AddTable("Albums","All the albums made by The Beatles",kTRUE);
my_db.AddTable("Songs","All the songs written or recorded by The Beatles",kTRUE);
my_db.AddTable("Years","For chronological information",kTRUE);
my_db.GetTable("Years")->AddRecord(new KVDBRecord("1966","The Year 1966"));
my_db.GetTable("Years")->AddRecord(new KVDBRecord("1967","The Year 1967"));
my_db.GetTable("Years")->AddRecord(new KVDBRecord("1968","The Year 1968"));
my_db.GetTable("Songs")->AddRecord(new KVDBRecord("Taxman","1. Taxman"));
my_db.GetTable("Songs")->AddRecord(new KVDBRecord("Eleanor","2. Eleanor Rigby"));
my_db.GetTable("Songs")->AddRecord(new KVDBRecord("LSD","3. Lucy in the Sky with Diamonds"));
my_db.GetTable("Songs")->AddRecord(new KVDBRecord("Better","4. Getting Better"));
my_db.GetTable("Songs")->AddRecord(new KVDBRecord("USSR","1. Back In The USSR"));
my_db.GetTable("Songs")->AddRecord(new KVDBRecord("Prudence","2. Dear Prudence"));
my_db.GetTable("Albums")->AddRecord(new KVDBRecord("Revolver","Revolver"));
my_db.GetTable("Albums")->AddRecord(new KVDBRecord("Pepper","Sgt. Pepper's Lonely Hearts' Club Band"));
my_db.GetTable("Albums")->AddRecord(new KVDBRecord("White","The Beatles"));
my_db.GetTable("Albums")->GetRecord("Revolver")->AddKey("Songs","Songs on the album Revolver");
my_db.GetTable("Albums")->GetRecord("Pepper")->AddKey("Songs","Songs on the album Sgt. Pepper");
my_db.GetTable("Albums")->GetRecord("White")->AddKey("Songs","Songs on the album The Beatles");
my_db.GetTable("Albums")->GetRecord("Revolver")->AddLink("Songs",my_db.GetTable("Songs")->GetRecord("Taxman"));
my_db.GetTable("Albums")->GetRecord("Revolver")->AddLink("Songs",my_db.GetTable("Songs")->GetRecord("Eleanor"));
my_db.GetTable("Albums")->GetRecord("Pepper")->AddLink("Songs",my_db.GetTable("Songs")->GetRecord("LSD"));
my_db.GetTable("Albums")->GetRecord("Pepper")->AddLink("Songs",my_db.GetTable("Songs")->GetRecord("Better"));
my_db.GetTable("Albums")->GetRecord("White")->AddLink("Songs",my_db.GetTable("Songs")->GetRecord("USSR"));
my_db.GetTable("Albums")->GetRecord("White")->AddLink("Songs",my_db.GetTable("Songs")->GetRecord("Prudence"));
my_db.GetTable("Years")->GetRecord("1966")->AddKey("Songs","Songs from 1966");
my_db.GetTable("Years")->GetRecord("1967")->AddKey("Songs","Songs from 1967");
my_db.GetTable("Years")->GetRecord("1968")->AddKey("Songs","Songs from 1968");
my_db.GetTable("Years")->GetRecord("1966")->AddLink("Songs",my_db.GetTable("Songs")->GetRecord("Taxman"));
my_db.GetTable("Years")->GetRecord("1966")->AddLink("Songs",my_db.GetTable("Songs")->GetRecord("Eleanor"));
my_db.GetTable("Years")->GetRecord("1967")->AddLink("Songs",my_db.GetTable("Songs")->GetRecord("LSD"));
my_db.GetTable("Years")->GetRecord("1967")->AddLink("Songs",my_db.GetTable("Songs")->GetRecord("Better"));
my_db.GetTable("Years")->GetRecord("1968")->AddLink("Songs",my_db.GetTable("Songs")->GetRecord("USSR"));
my_db.GetTable("Years")->GetRecord("1968")->AddLink("Songs",my_db.GetTable("Songs")->GetRecord("Prudence"));
}
Record folder for the database.
Definition KVDBRecord.h:43
Simple cross-referenced database structure.
Definition KVDataBase.h:137

After setting up the database in this way, some typical output would be:

root [12] my_db.Print()
_______________________________________________________
my_db Beatles' discography
Available Tables :
Albums
Songs
Years
_______________________________________________________
root [14] my_db.GetTable("Songs")->ls()
OBJ: KVDBRecord Taxman 1. Taxman : 0 at: 0x89b5910
OBJ: KVDBRecord Eleanor 2. Eleanor Rigby : 0 at: 0x89acb50
OBJ: KVDBRecord LSD 3. Lucy in the Sky with Diamonds : 0 at: 0x89b59f0
OBJ: KVDBRecord Better 4. Getting Better : 0 at: 0x89b5c08
OBJ: KVDBRecord USSR 1. Back In The USSR : 0 at: 0x89b5c40
OBJ: KVDBRecord Prudence 2. Dear Prudence : 0 at: 0x89b5cd8
root [15] my_db.GetTable("Albums")->GetRecord("White")->Print()
_______________________________________________________
White The Beatles
Available Keys :
Songs
_______________________________________________________
root [16] my_db.GetTable("Songs")->GetRecord("LSD")->Print()
_______________________________________________________
LSD 3. Lucy in the Sky with Diamonds
Available Keys :
Albums
Years
_______________________________________________________
root [18] my_db.GetTable("Songs")->GetRecord("LSD")->GetKey("Albums")->ls()
OBJ: KVDBRecord Pepper Sgt. Pepper's Lonely Hearts' Club Band : 0 at: 0x89b5b00
root [19] my_db.GetTable("Songs")->GetRecord("LSD")->GetKey("Years")->ls()
OBJ: KVDBRecord 1967 The Year 1967 : 0 at: 0x89b57a0

Definition at line 137 of file KVDataBase.h.

#include <KVDataBase.h>

Inheritance diagram for KVDataBase:

Public Member Functions

 KVDataBase ()
 
 KVDataBase (const Char_t *name)
 
 KVDataBase (const Char_t *name, const Char_t *title)
 
virtual ~KVDataBase ()
 reset global database pointer if it was pointing to this DB
 
virtual KVDBTableAddTable (const Char_t *name, const Char_t *title, Bool_t unique=kFALSE)
 
virtual Bool_t AddTable (KVDBTable *table)
 
virtual KVDBRecordGetRecord (const Char_t *table_name, const Char_t *rec_name) const
 
virtual KVDBTableGetTable (const Char_t *table) const
 
virtual TListGetTables () const
 
virtual void Print (Option_t *option="") const
 
- Public Member Functions inherited from TFolder
 TFolder ()
 
 TFolder (const char *name, const char *title)
 
virtual ~TFolder ()
 
virtual void Add (TObject *obj)
 
TFolderAddFolder (const char *name, const char *title, TCollection *collection=nullptr)
 
void Browse (TBrowser *b) override
 
void Clear (Option_t *option="") override
 
void Copy (TObject &) const override
 
virtual const char * FindFullPathName (const char *name) const
 
virtual const char * FindFullPathName (const TObject *obj) const
 
TObjectFindObject (const char *name) const override
 
TObjectFindObject (const TObject *obj) const override
 
virtual TObjectFindObjectAny (const char *name) const
 
TCollectionGetListOfFolders () const
 
TClassIsA () const override
 
Bool_t IsFolder () const override
 
Bool_t IsOwner () const
 
void ls (Option_t *option="") const override
 
virtual Int_t Occurence (const TObject *obj) const
 
void RecursiveRemove (TObject *obj) override
 
virtual void Remove (TObject *obj)
 
void SaveAs (const char *filename="", Option_t *option="") const override
 
virtual void SetOwner (Bool_t owner=kTRUE)
 
void Streamer (TBuffer &) override
 
void StreamerNVirtual (TBuffer &ClassDef_StreamerNVirtual_b)
 
- Public Member Functions inherited from TNamed
 TNamed ()
 
 TNamed (const char *name, const char *title)
 
 TNamed (const TNamed &named)
 
 TNamed (const TString &name, const TString &title)
 
virtual ~TNamed ()
 
void Clear (Option_t *option="") override
 
TObjectClone (const char *newname="") const override
 
Int_t Compare (const TObject *obj) const override
 
void Copy (TObject &named) const override
 
virtual void FillBuffer (char *&buffer)
 
const char * GetName () const override
 
const char * GetTitle () const override
 
ULong_t Hash () const override
 
TClassIsA () const override
 
Bool_t IsSortable () const override
 
void ls (Option_t *option="") const override
 
TNamedoperator= (const TNamed &rhs)
 
void Print (Option_t *option="") const override
 
virtual void SetName (const char *name)
 
virtual void SetNameTitle (const char *name, const char *title)
 
virtual void SetTitle (const char *title="")
 
virtual Int_t Sizeof () const
 
void Streamer (TBuffer &) override
 
void StreamerNVirtual (TBuffer &ClassDef_StreamerNVirtual_b)
 
- Public Member Functions inherited from TObject
 TObject ()
 
 TObject (const TObject &object)
 
virtual ~TObject ()
 
void AbstractMethod (const char *method) const
 
virtual void AppendPad (Option_t *option="")
 
ULong_t CheckedHash ()
 
virtual const char * ClassName () const
 
virtual void Delete (Option_t *option="")
 
virtual Int_t DistancetoPrimitive (Int_t px, Int_t py)
 
virtual void Draw (Option_t *option="")
 
virtual void DrawClass () const
 
virtual TObjectDrawClone (Option_t *option="") const
 
virtual void Dump () const
 
virtual void Error (const char *method, const char *msgfmt,...) const
 
virtual void Execute (const char *method, const char *params, Int_t *error=nullptr)
 
virtual void Execute (TMethod *method, TObjArray *params, Int_t *error=nullptr)
 
virtual void ExecuteEvent (Int_t event, Int_t px, Int_t py)
 
virtual void Fatal (const char *method, const char *msgfmt,...) const
 
virtual Option_tGetDrawOption () const
 
virtual const char * GetIconName () const
 
virtual char * GetObjectInfo (Int_t px, Int_t py) const
 
virtual Option_tGetOption () const
 
virtual UInt_t GetUniqueID () const
 
virtual Bool_t HandleTimer (TTimer *timer)
 
Bool_t HasInconsistentHash () const
 
virtual void Info (const char *method, const char *msgfmt,...) const
 
virtual Bool_t InheritsFrom (const char *classname) const
 
virtual Bool_t InheritsFrom (const TClass *cl) const
 
virtual void Inspect () const
 
void InvertBit (UInt_t f)
 
Bool_t IsDestructed () const
 
virtual Bool_t IsEqual (const TObject *obj) const
 
R__ALWAYS_INLINE Bool_t IsOnHeap () const
 
R__ALWAYS_INLINE Bool_t IsZombie () const
 
void MayNotUse (const char *method) const
 
virtual Bool_t Notify ()
 
void Obsolete (const char *method, const char *asOfVers, const char *removedFromVers) const
 
void operator delete (void *ptr)
 
void operator delete (void *ptr, void *vp)
 
void operator delete[] (void *ptr)
 
void operator delete[] (void *ptr, void *vp)
 
voidoperator new (size_t sz)
 
voidoperator new (size_t sz, void *vp)
 
voidoperator new[] (size_t sz)
 
voidoperator new[] (size_t sz, void *vp)
 
TObjectoperator= (const TObject &rhs)
 
virtual void Paint (Option_t *option="")
 
virtual void Pop ()
 
virtual Int_t Read (const char *name)
 
void ResetBit (UInt_t f)
 
virtual void SavePrimitive (std::ostream &out, Option_t *option="")
 
void SetBit (UInt_t f)
 
void SetBit (UInt_t f, Bool_t set)
 
virtual void SetDrawOption (Option_t *option="")
 
virtual void SetUniqueID (UInt_t uid)
 
void StreamerNVirtual (TBuffer &ClassDef_StreamerNVirtual_b)
 
virtual void SysError (const char *method, const char *msgfmt,...) const
 
R__ALWAYS_INLINE Bool_t TestBit (UInt_t f) const
 
Int_t TestBits (UInt_t f) const
 
virtual void UseCurrentStyle ()
 
virtual void Warning (const char *method, const char *msgfmt,...) const
 
virtual Int_t Write (const char *name=nullptr, Int_t option=0, Int_t bufsize=0)
 
virtual Int_t Write (const char *name=nullptr, Int_t option=0, Int_t bufsize=0) const
 

Private Attributes

TString fFolderName
 

Additional Inherited Members

- Public Types inherited from TObject
enum  EDeprecatedStatusBits
 
enum  EStatusBits
 
- Static Public Member Functions inherited from TFolder
static TClassClass ()
 
static const char * Class_Name ()
 
static constexpr Version_t Class_Version ()
 
static const char * DeclFileName ()
 
- Static Public Member Functions inherited from TNamed
static TClassClass ()
 
static const char * Class_Name ()
 
static constexpr Version_t Class_Version ()
 
static const char * DeclFileName ()
 
- Static Public Member Functions inherited from TObject
static TClassClass ()
 
static const char * Class_Name ()
 
static constexpr Version_t Class_Version ()
 
static const char * DeclFileName ()
 
static Longptr_t GetDtorOnly ()
 
static Bool_t GetObjectStat ()
 
static void SetDtorOnly (void *obj)
 
static void SetObjectStat (Bool_t stat)
 
- Public Attributes inherited from TObject
 kBitMask
 
 kCanDelete
 
 kCannotPick
 
 kHasUUID
 
 kInconsistent
 
 kInvalidObject
 
 kIsOnHeap
 
 kIsReferenced
 
 kMustCleanup
 
 kNoContextMenu
 
 kNotDeleted
 
 kObjInCanvas
 
 kOverwrite
 
 kSingleKey
 
 kWriteDelete
 
 kZombie
 
- Protected Member Functions inherited from TObject
virtual void DoError (int level, const char *location, const char *fmt, va_list va) const
 
void MakeZombie ()
 
- Protected Attributes inherited from TFolder
TCollectionfFolders
 
Bool_t fIsOwner
 
- Protected Attributes inherited from TNamed
TString fName
 
TString fTitle
 
- Protected Attributes inherited from TObject
 kOnlyPrepStep
 

Constructor & Destructor Documentation

◆ KVDataBase() [1/3]

KVDataBase::KVDataBase ( )

Definition at line 31 of file KVDataBase.cpp.

◆ KVDataBase() [2/3]

KVDataBase::KVDataBase ( const Char_t name)

Definition at line 53 of file KVDataBase.cpp.

◆ KVDataBase() [3/3]

KVDataBase::KVDataBase ( const Char_t name,
const Char_t title 
)

Definition at line 41 of file KVDataBase.cpp.

◆ ~KVDataBase()

KVDataBase::~KVDataBase ( )
virtual

reset global database pointer if it was pointing to this DB

Definition at line 66 of file KVDataBase.cpp.

Member Function Documentation

◆ AddTable() [1/2]

KVDBTable * KVDataBase::AddTable ( const Char_t name,
const Char_t title,
Bool_t  unique = kFALSE 
)
virtual

Add a table to the list of tables and check if the new table's name already exists. If it exists the table is not added and null pointer is returned, otherwise a new table is created and added to the list and its address is returned. Table with this name already in DB ?

Definition at line 109 of file KVDataBase.cpp.

◆ AddTable() [2/2]

Bool_t KVDataBase::AddTable ( KVDBTable tab)
virtual

Add a table to the list of available tables and return kTRUE it's added. As each table must have a unique name we check if the new table's name already exists, if not the table is added otherwise it's not added and the method return kFALSE.

table with this name already in DB ?

Definition at line 84 of file KVDataBase.cpp.

◆ GetRecord()

KVDBRecord * KVDataBase::GetRecord ( const Char_t table_name,
const Char_t rec_name 
) const
virtual

Return the KVDBRecord rec_name found in the table table_name

Definition at line 133 of file KVDataBase.cpp.

◆ GetTable()

KVDBTable * KVDataBase::GetTable ( const Char_t table) const
inlinevirtual

Definition at line 159 of file KVDataBase.h.

◆ GetTables()

TList * KVDataBase::GetTables ( ) const
inlinevirtual

Definition at line 164 of file KVDataBase.h.

◆ Print()

void KVDataBase::Print ( Option_t option = "") const
virtual

Reimplemented from TObject.

Definition at line 152 of file KVDataBase.cpp.

Member Data Documentation

◆ fFolderName

TString KVDataBase::fFolderName
private

Definition at line 139 of file KVDataBase.h.