KaliVeda
Toolkit for HIC analysis
Loading...
Searching...
No Matches
KVDBTable.cpp
1/***************************************************************************
2$Id: KVDBTable.cpp,v 1.18 2007/04/27 14:46:29 franklan Exp $
3 KVTable.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 "KVDBTable.h"
19#include "KVDBRecord.h"
20#include "Riostream.h"
21#include "TROOT.h"
22
23#include <KVUniqueNameList.h>
24
25
26using namespace std;
27
29
30
31
32
34{
35 fIsUnique = kFALSE;
36}
37
38
39
40
42
43KVDBTable::KVDBTable(const Char_t* name, const Char_t* type,
44 Bool_t unique)
45 : TFolder() // do not call TFolder(name,type) ctor as it creates a default TList for fFolders
46{
49 fIsUnique = unique;
50 if (unique) fFolders = new KVUniqueNameList;
51 else fFolders = new KVHashList;
52 SetOwner();
53}
54
55
56
57
59
61{
62 gROOT->GetListOfCleanups()->Remove(this);
63}
64
65
66
67
73
75{
76 // Add a KVDBRecord to the list of available records and return kTRUE
77 // If a default formatting string for names of numbered records has been
78 // set (see SetDefaultFormat(const TString&)) the name of the record
79 // will be automatically set here according to the format and its number.
80
81 if (HasDefaultFormat()) rec->SetName(Form(fDefFormatNumRec.Data(), rec->GetNumber()));
82 Add(rec);
83 rec->SetTable(this);
84 return kTRUE;
85}
86
87
88
89
92
94{
95 //Remove a KVDBRecord from the list of available records
96
97 Remove(rec);
98 rec->SetTable(0);
99}
100
101
102
103
105
107{
108 cout << ClassName() << " : " << GetName() << " <---> " << GetTitle() << " ["
109 << GetRecords()->GetSize() << " records]" << endl;
110}
111
112
113
121
123{
124 // Set a default formatting string for names of numbered records.
125 // e.g. if fmt="Rec#%d", each record which is added to the table will have
126 // its name automatically set to "Rec#1", "Rec#2", etc., according to the
127 // record number.
128 // This allows to replace a slow sequential scan for a record based on number
129 // (GetRecord(Int_t)) with a fast hash-based look-up
130
131 fDefFormatNumRec = fmt.Data();
132}
133
134
135
136
145
147{
148 // Sequential search for record using its number.
149 // To keep things simple, we only search in the top level of the folder structure.
150 //
151 // NOTE: if there are many records, this sequential search can be long.
152 // If a default format for the record name using its number has been defined
153 // (see SetDefaultFormat(const TString&)) the search will be performed using
154 // the resulting formatted object name, which is fast (hash list).
155
156 if (HasDefaultFormat()) return GetRecord(Form(fDefFormatNumRec.Data(), num));
157
158 TIter next(GetListOfFolders());
159 KVDBRecord* obj = 0;
160 while ((obj = (KVDBRecord*) next()) && (obj->GetNumber() != num));
161 return (obj ? (obj->GetNumber() == num ? obj : 0) : 0);
162}
163
164
165
166
171
173{
174 // The list of records is a KVHashList or KVUniqueNameList
175 // Call this method if the names of the records change after having been
176 // added to the table, otherwise GetRecord(const char*) will not work.
177
178 ((KVHashList*)fFolders)->Rehash();
179}
180
181
int Int_t
bool Bool_t
char Char_t
constexpr Bool_t kFALSE
constexpr Bool_t kTRUE
const char Option_t
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char name[80]
#define gROOT
char * Form(const char *fmt,...)
Record folder for the database.
Definition KVDBRecord.h:43
virtual Int_t GetNumber() const
Definition KVDBRecord.h:73
Table in a database.
Definition KVDBTable.h:34
virtual KVSeqCollection * GetRecords() const
Definition KVDBTable.h:63
TString fDefFormatNumRec
default formatting for names of numbered records
Definition KVDBTable.h:50
virtual Bool_t AddRecord(KVDBRecord *add)
Definition KVDBTable.cpp:74
virtual KVDBRecord * GetRecord(const Char_t *rec_name) const
Definition KVDBTable.h:58
void Rehash(void)
virtual void RemoveRecord(KVDBRecord *add)
Remove a KVDBRecord from the list of available records.
Definition KVDBTable.cpp:93
Bool_t HasDefaultFormat() const
Definition KVDBTable.h:81
void SetDefaultFormat(const TString &)
virtual ~KVDBTable()
Definition KVDBTable.cpp:60
Bool_t fIsUnique
Must each record name be unique ?
Definition KVDBTable.h:48
virtual void ls(Option_t *option="*") const
Extended version of ROOT THashList.
Definition KVHashList.h:29
virtual Int_t GetSize() const
Optimised list in which named objects can only be placed once.
TCollection * GetListOfFolders() const
virtual void Add(TObject *obj)
virtual void SetOwner(Bool_t owner=kTRUE)
TCollection * fFolders
virtual void Remove(TObject *obj)
virtual void SetTitle(const char *title="")
const char * GetName() const override
const char * GetTitle() const override
virtual void SetName(const char *name)
virtual const char * ClassName() const
const char * Data() const
rec
ClassImp(TPyArg)