KaliVeda  1.13/01
Heavy-Ion Analysis Toolkit
KVDBRecord.cpp
Go to the documentation of this file.
1 /***************************************************************************
2 $Id: KVDBRecord.cpp,v 1.23 2007/05/31 09:59:22 franklan Exp $
3  KVDBRecord.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 #include "Riostream.h"
19 #include "KVDBRecord.h"
20 #include "KVDBTable.h"
21 #include "KVDBKey.h"
22 #include "TROOT.h"
23 
24 using namespace std;
25 
27 
28 //__________________________________________________________________________
29 
31 
33 {
34  SetOwner(kTRUE);
35 }
36 
37 
38 
40 
42  const Char_t* title): TFolder(name, title)
43 {
44  SetOwner(kTRUE);
45 }
46 
47 
48 
50 
51 KVDBRecord::~KVDBRecord()
52 {
53  gROOT->GetListOfCleanups()->Remove(this);
54 }
55 
56 
57 
64 
66 {
67 // Add a key to the list of available keys and return kTRUE
68 // if it is added. If "check" is kTRUE , we check if the new key's name
69 // already exists, if not the key is added otherwise it's not added
70 // and the method return kFALSE.
71 //
72 
73 
74  if (check && GetKey(key->GetName())) {
75  TObject::Warning("AddKey(KVDBKey*,Bool_t)",
76  "A key named %s already exists.", key->GetName());
77  return kFALSE;
78  }
79 
80  Add(key);
81  key->SetParent(this);
82 
83  return kTRUE;
84 }
85 
86 
87 
94 
95 KVDBKey* KVDBRecord::AddKey(const Char_t* name, const Char_t* title,
96  Bool_t check)
97 {
98 // Add a key to the list of available keys and return kTRUE
99 // it's added. If "check" is kTRUE , we check if the new key's name
100 // already exists, if not the key is added otherwise it's not added
101 // and the method return kFALSE.
102 //
103 
104  if (check && GetKey(name)) {
105  TObject::Warning("AddKey(const Char_t*, const Char_t*,Bool_t)",
106  "A key named %s already exists.", name);
107  return NULL;
108  }
109 
110  KVDBKey* key = new KVDBKey(name, title, this);
111  Add(key);
112 
113  return key;
114 }
115 
116 
117 
121 
123  Bool_t linkback)
124 {
125  //Link this record to the record "rec" in the DB table with name "key_name"
126  //The record will be added to the list of records in KVDBKey "key_name"
127 
128  KVDBKey* key = GetKey(key_name);
129  if (key)
130  return key->LinkTo(rec, linkback);
131  else {
132  TObject::Warning("AddLink(const Char_t*,KVDBRecord*)",
133  "No key named %s found.", key_name);
134  return kFALSE;
135  }
136 
137 }
138 
139 
140 
141 
144 
145 void KVDBRecord::RemoveLink(const Char_t* key_name, KVDBRecord* rec,
146  Bool_t linkback)
147 {
148  //Remove the link between this record and the record "rec" in the DB table"key_name"
149 
150  KVDBKey* key = GetKey(key_name);
151  if (key)
152  key->Unlink(rec, linkback);
153  else {
154  TObject::Warning("RemoveLink(const Char_t*,KVDBRecord*)",
155  "No key named %s found.", key_name);
156  }
157 
158 }
159 
160 
161 
162 
165 
166 void KVDBRecord::RemoveAllLinks(const Char_t* key_name)
167 {
168  //Remove all links between this record and the records in the DB table"key_name"
169 
170  KVDBKey* key = GetKey(key_name);
171  if (key)
172  key->UnlinkAll();
173  else {
174  TObject::Warning("RemoveAllLinks(const Char_t*)",
175  "No key named %s found.", key_name);
176  }
177 
178 }
179 
180 
181 
182 
185 
186 KVDBRecord* KVDBRecord::GetLink(const Char_t* key, const Char_t* link) const
187 {
188  //Returns the record named "link" in the table named "key"
189 
190  KVDBKey* key_ = GetKey(key);
191  if (key_)
192  return key_->GetLink(link);
193  else {
194  TObject::Warning("GetLink(const Char_t*,const Char_t*)const",
195  "No key named %s found.", key);
196  return NULL;
197  }
198 }
199 
200 
201 
202 
205 
207 {
208  //Returns the list of records linked to this record in table "key"
209 
210  KVDBKey* key_ = GetKey(key);
211  if (key_)
212  return key_->GetLinks();
213 
214  return NULL;
215 }
216 
217 
218 
219 
221 
223 {
224 
225  cout << "_______________________________________________________" <<
226  endl;
227  cout << GetName() << " " << GetTitle() << endl;
228  cout << "Available Keys :" << endl;
229  TIter next(GetKeys());
230  KVDBKey* key;
231  while ((key = (KVDBKey*) next())) {
232  cout << " " << key->GetName() << endl;
233  }
234  cout << "_______________________________________________________" <<
235  endl;
236 }
237 
238 
239 
240 
242 
244 {
245  TNamed::ls();
246 }
247 
248 
249 
250 
251 
255 
257 {
258  // Compare two record numbers for sorting lists.
259  // Lists will be sorted in ascending order.
260 
261  KVDBRecord* dbobj =
262  dynamic_cast < KVDBRecord* >(const_cast < TObject* >(obj));
263  return (dbobj->GetNumber() ==
264  GetNumber() ? 0 : (dbobj->GetNumber() > GetNumber() ? -1 : 1));
265 }
266 
267 
268 
270 
272 {
273  return (KVDBTable*)gROOT->FindObject(fFullPathTable.Data());
274 }
275 
276 
277 
279 
280 void KVDBRecord::SetTable(const KVDBTable* table)
281 {
282  fFullPathTable = table->GetFullPath();
283 }
284 
285 
286 
287 
289 
291 {
292  TString knom(key);
293  knom.Prepend("Key:");
294  return (KVDBKey*) FindObject(knom.Data());
295 }
296 
297 
298 
300 
302 {
303  return (TList*) GetListOfFolders();
304 }
305 
306 
307 
308 
int Int_t
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
Cross-reference in a KVDataBase.
Definition: KVDBKey.h:37
virtual void SetParent(KVDBRecord *parent)
Definition: KVDBKey.cpp:226
virtual KVRList * GetLinks() const
return the list of cross-referenced objects
Definition: KVDBKey.h:64
virtual KVDBRecord * GetLink(const Char_t *link) const
Definition: KVDBKey.cpp:208
virtual void UnlinkAll()
Definition: KVDBKey.cpp:165
virtual void Unlink(KVDBRecord *rec, Bool_t linkback=kTRUE)
Definition: KVDBKey.cpp:135
virtual Bool_t LinkTo(KVDBRecord *rec, Bool_t linkback=kTRUE)
Definition: KVDBKey.cpp:81
Record folder for the database.
Definition: KVDBRecord.h:42
virtual void SetTable(const KVDBTable *table)
Definition: KVDBRecord.cpp:280
virtual void Print(Option_t *option="") const
Definition: KVDBRecord.cpp:222
virtual KVDBKey * GetKey(const Char_t *key) const
Definition: KVDBRecord.cpp:290
virtual void ls(Option_t *option="*") const
Definition: KVDBRecord.cpp:243
virtual Bool_t AddKey(KVDBKey *key, Bool_t check=kTRUE)
Definition: KVDBRecord.cpp:65
virtual KVDBRecord * GetLink(const Char_t *key, const Char_t *link) const
Returns the record named "link" in the table named "key".
Definition: KVDBRecord.cpp:186
virtual Int_t Compare(const TObject *obj) const
Definition: KVDBRecord.cpp:256
TString fFullPathTable
full path to parent table in folder structure
Definition: KVDBRecord.h:46
virtual Bool_t AddLink(const Char_t *key_name, KVDBRecord *rec, Bool_t linkback=kTRUE)
Definition: KVDBRecord.cpp:122
virtual void RemoveLink(const Char_t *key_name, KVDBRecord *rec, Bool_t linkback=kTRUE)
Remove the link between this record and the record "rec" in the DB table"key_name".
Definition: KVDBRecord.cpp:145
virtual KVRList * GetLinks(const Char_t *key) const
Returns the list of records linked to this record in table "key".
Definition: KVDBRecord.cpp:206
virtual void RemoveAllLinks(const Char_t *key)
Remove all links between this record and the records in the DB table"key_name".
Definition: KVDBRecord.cpp:166
virtual Int_t GetNumber() const
Definition: KVDBRecord.h:72
virtual TList * GetKeys() const
Definition: KVDBRecord.cpp:301
virtual KVDBTable * GetTable() const
Definition: KVDBRecord.cpp:271
Table in a database.
Definition: KVDBTable.h:33
virtual const Char_t * GetFullPath() const
Definition: KVDBTable.h:74
Wrapper for TRefArray adding some functionality.
Definition: KVRList.h:36
virtual void Add(TObject *obj)
TCollection * GetListOfFolders() const
virtual void SetOwner(Bool_t owner=kTRUE)
virtual TObject * FindObject(const char *name) const
virtual void ls(Option_t *option="") const
virtual const char * GetName() const
virtual const char * GetTitle() const
virtual void Warning(const char *method, const char *msgfmt,...) const
const char * Data() const
TString & Prepend(char c, Ssiz_t rep=1)