KaliVeda  1.12/06
Heavy-Ion Analysis Toolkit
KVDataBase.cpp
Go to the documentation of this file.
1 /***************************************************************************
2 $Id: KVDataBase.cpp,v 1.26 2009/01/22 13:55:00 franklan Exp $
3  KVDataBase.cpp - description
4  -------------------
5  begin : jeu fév 6 2003
6  copyright : (C) 2003 by Alexis Mignon
7  email : mignon@ganil.fr
8  ***************************************************************************/
9 
10 /***************************************************************************
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * *
17  ***************************************************************************/
18 
19 #include "KVDataBase.h"
20 #include "TROOT.h"
21 #include "Riostream.h"
22 #include "TPluginManager.h"
23 #include "KVNumberList.h"
24 
25 using namespace std;
26 
27 
29 
32 {
33  gROOT->GetRootFolder()->Add(this);
34  SetOwner(kTRUE);
35 }
36 
37 
38 
40 
41 KVDataBase::KVDataBase(const Char_t* name, const Char_t* title)
42  : TFolder(name, title)
43 {
44  gROOT->GetRootFolder()->Add(this);
45  SetOwner(kTRUE);
46  fFolderName = name;
47 }
48 
49 
50 
52 
54  : TFolder(name, "database")
55 {
56  gROOT->GetRootFolder()->Add(this);
57  SetOwner(kTRUE);
58  fFolderName = name;
59 }
60 
61 
62 
65 
66 KVDataBase::~KVDataBase()
67 {
68  //reset global database pointer if it was pointing to this DB
69  gROOT->GetRootFolder()->Remove(this);
70  gROOT->GetListOfCleanups()->Remove(this);
71  Info("~KVDataBase", "%s", GetName());
72 }
73 
74 
75 
83 
85 {
86 // Add a table to the list of available tables and return kTRUE
87 // it's added. As each table must have a unique name we check if the new table's name
88 // already exists, if not the table is added otherwise it's not added
89 // and the method return kFALSE.
90 //
91 
92  //table with this name already in DB ?
93  if (GetTable(tab->GetName()))
94  return kFALSE;
95 
96  Add(tab);
97  tab->SetFullPath(Form("//root/%s/%s", fFolderName.Data(), tab->GetName()));
98  return kTRUE;
99 }
100 
101 
102 
108 
109 KVDBTable* KVDataBase::AddTable(const Char_t* name, const Char_t* title,
110  Bool_t unique)
111 {
112 // Add a table to the list of tables and check if the new table's name already exists.
113 // If it exists the table is not added and null pointer is returned, otherwise a new
114 // table is created and added to the list and its address is returned.
115 
116  //Table with this name already in DB ?
117  if (GetTable(name))
118  return 0;
119 
120  KVDBTable* table = new KVDBTable(name, title, unique);
121  Add(table);
122  table->SetFullPath(Form("//root/%s/%s", fFolderName.Data(), name));
123  return table;
124 }
125 
126 
127 
132 
134  const Char_t* rec_name) const
135 {
136 //
137 // Return the KVDBRecord rec_name found in the table table_name
138 //
139  KVDBTable* table = GetTable(table_name);
140  if (!table) {
141  TObject::Warning("GetRecord(const Char_t*,const Char_t*)",
142  "No Table named %s found.", table_name);
143  return NULL;
144  }
145  return table->GetRecord(rec_name);
146 }
147 
148 
149 
151 
153 {
154 
155 
156  cout << "_______________________________________________________" <<
157  endl;
158  cout << ClassName() << " : " << GetName() << " <---> " << GetTitle() <<
159  endl;
160  cout << "Available Tables :" << endl;
161  TIter next(GetTables());
162  KVDBTable* table;
163  while ((table = (KVDBTable*) next())) {
164  cout << " " << table->GetName() << endl;
165  }
166  cout << "_______________________________________________________" <<
167  endl;
168 }
169 
170 
171 
172 
ClassImp(KVPartitionList) void KVPartitionList
Initialisation.
char Char_t
const Bool_t kFALSE
bool Bool_t
const Bool_t kTRUE
const char Option_t
#define gROOT
char * Form(const char *fmt,...)
Record folder for the database.
Definition: KVDBRecord.h:42
Table in a database.
Definition: KVDBTable.h:33
virtual void SetFullPath(const Char_t *path)
Definition: KVDBTable.h:70
virtual KVDBRecord * GetRecord(const Char_t *rec_name) const
Definition: KVDBTable.h:57
Simple cross-referenced database structure.
Definition: KVDataBase.h:136
virtual void Print(Option_t *option="") const
Definition: KVDataBase.cpp:152
virtual KVDBTable * GetTable(const Char_t *table) const
Definition: KVDataBase.h:158
virtual KVDBRecord * GetRecord(const Char_t *table_name, const Char_t *rec_name) const
Definition: KVDataBase.cpp:133
virtual TList * GetTables() const
Definition: KVDataBase.h:163
TString fFolderName
Definition: KVDataBase.h:138
virtual Bool_t AddTable(KVDBTable *table)
Definition: KVDataBase.cpp:84
virtual void Add(TObject *obj)
virtual void SetOwner(Bool_t owner=kTRUE)
virtual const char * GetName() const
virtual const char * GetTitle() const
virtual const char * ClassName() const
virtual void Warning(const char *method, const char *msgfmt,...) const
virtual void Info(const char *method, const char *msgfmt,...) const
const char * Data() const