KaliVeda
Toolkit for HIC analysis
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 
26 using namespace std;
27 
29 
30 
31 
34 {
35  fIsUnique = kFALSE;
36 }
37 
38 
39 
40 
42 
43 KVDBTable::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 {
47  SetName(name);
48  SetTitle(type);
49  fIsUnique = unique;
50  if (unique) fFolders = new KVUniqueNameList;
51  else fFolders = new KVHashList;
52  SetOwner();
53 }
54 
55 
56 
57 
59 
60 KVDBTable::~KVDBTable()
61 {
62  gROOT->GetListOfCleanups()->Remove(this);
63 }
64 
65 
66 
67 
74 
76 {
77  // Add a KVDBRecord to the list of available records and return kTRUE
78  //
79  // If a default formatting string for names of numbered records has been
80  // set (see SetDefaultFormat(const TString&)) the name of the record
81  // will be automatically set here according to the format and its number.
82 
83  if (HasDefaultFormat()) rec->SetName(Form(fDefFormatNumRec.Data(), rec->GetNumber()));
84  Add(rec);
85  rec->SetTable(this);
86  return kTRUE;
87 }
88 
89 
90 
91 
94 
96 {
97  //Remove a KVDBRecord from the list of available records
98 
99  Remove(rec);
100  rec->SetTable(0);
101 }
102 
103 
104 
105 
107 
109 {
110  cout << ClassName() << " : " << GetName() << " <---> " << GetTitle() << " ["
111  << GetRecords()->GetSize() << " records]" << endl;
112 }
113 
114 
115 
123 
125 {
126  // Set a default formatting string for names of numbered records.
127  // e.g. if fmt="Rec#%d", each record which is added to the table will have
128  // its name automatically set to "Rec#1", "Rec#2", etc., according to the
129  // record number.
130  // This allows to replace a slow sequential scan for a record based on number
131  // (GetRecord(Int_t)) with a fast hash-based look-up
132 
133  fDefFormatNumRec = fmt.Data();
134 }
135 
136 
137 
138 
147 
149 {
150  // Sequential search for record using its number.
151  // To keep things simple, we only search in the top level of the folder structure.
152  //
153  // NOTE: if there are many records, this sequential search can be long.
154  // If a default format for the record name using its number has been defined
155  // (see SetDefaultFormat(const TString&)) the search will be performed using
156  // the resulting formatted object name, which is fast (hash list).
157 
158  if (HasDefaultFormat()) return GetRecord(Form(fDefFormatNumRec.Data(), num));
159 
160  TIter next(GetListOfFolders());
161  KVDBRecord* obj = 0;
162  while ((obj = (KVDBRecord*) next()) && (obj->GetNumber() != num));
163  return (obj ? (obj->GetNumber() == num ? obj : 0) : 0);
164 }
165 
166 
167 
168 
173 
175 {
176  // The list of records is a KVHashList or KVUniqueNameList
177  // Call this method if the names of the records change after having been
178  // added to the table, otherwise GetRecord(const char*) will not work.
179 
180  ((KVHashList*)fFolders)->Rehash();
181 }
182 
183 
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
TString fDefFormatNumRec
default formatting for names of numbered records
Definition: KVDBTable.h:50
virtual Bool_t AddRecord(KVDBRecord *add)
Definition: KVDBTable.cpp:75
void Rehash(void)
Definition: KVDBTable.cpp:174
virtual void RemoveRecord(KVDBRecord *add)
Remove a KVDBRecord from the list of available records.
Definition: KVDBTable.cpp:95
Bool_t HasDefaultFormat() const
Definition: KVDBTable.h:81
void SetDefaultFormat(const TString &)
Definition: KVDBTable.cpp:124
Bool_t fIsUnique
Must each record name be unique ?
Definition: KVDBTable.h:48
virtual KVDBRecord * GetRecord(const Char_t *rec_name) const
Definition: KVDBTable.h:58
void ls(Option_t *option="*") const override
Definition: KVDBTable.cpp:108
virtual KVSeqCollection * GetRecords() const
Definition: KVDBTable.h:63
Extended version of ROOT THashList.
Definition: KVHashList.h:29
Int_t GetSize() const override
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)