CbmRoot
PDataBase.h
Go to the documentation of this file.
1 // Author: I. Froehlich
2 // Written: 11.04.2007
3 // Revised:
4 // PDataBase
5 // Replacement for the particle data base in PData
6 
7 #ifndef _PDATABASE_H_
8 #define _PDATABASE_H_
9 
10 #include "Pdefines.h"
11 #include "TROOT.h"
12 #include <iostream>
13 
14 #define PDATABASE_MAX_DOUBLE_PARAM 20
15 #define PDATABASE_MAX_STRING_PARAM 20
16 #define PDATABASE_MAX_INT_PARAM 150
17 #define PDATABASE_MAX_TOBJ_PARAM 10
18 
19 #define PDATABASE_MAX_LINES 1000
20 
21 using namespace std;
22 
23 class PDataBase;
26 
27 class PDataBase : public TObject {
28 
29 private:
30  //Entries properties
31  const char* param_double_name
32  [PDATABASE_MAX_DOUBLE_PARAM]; //the parameter name matching the ID
33  const char* param_string_name[PDATABASE_MAX_STRING_PARAM];
34  const char* param_int_name[PDATABASE_MAX_INT_PARAM];
35  const char* param_tobj_name[PDATABASE_MAX_INT_PARAM];
36  const char* param_double_descr
37  [PDATABASE_MAX_DOUBLE_PARAM]; //the parameter long description
38  const char* param_string_descr[PDATABASE_MAX_STRING_PARAM];
39  const char* param_int_descr[PDATABASE_MAX_INT_PARAM];
40  const char* param_tobj_descr[PDATABASE_MAX_INT_PARAM];
45 
46  //TODO: Params need description
47 
48  Int_t* param_int_key[PDATABASE_MAX_INT_PARAM];
49  Int_t param_int_key_max[PDATABASE_MAX_INT_PARAM];
50 
51  //The entries array itself
52  //for each entry, we add the pointer array to our params
57 
58  Int_t lastkey;
59 
60  Bool_t
61  CheckEntry(Int_t key); //check if key with unique name already existing
62  Int_t ConvertParamKey(const char*& newparamname, Int_t key);
63 
64 public:
65  //constructor
66  PDataBase();
67 
68  void Performance(void);
69 
70  void SetFastKey(Int_t pkey, Int_t maxkey);
71 
72  //return value of the makeParam's: the param_id of -1 on failure
73  Int_t
74  MakeParamDouble(const char* paramname,
75  const char* descr); //add "paramname" to double database
76  Int_t
77  MakeParamString(const char* paramname,
78  const char* descr); //add "paramname" to string database
79  Int_t MakeParamInt(const char* paramname,
80  const char* descr); //add "paramname" to int database
81  Int_t MakeParamTObj(const char* paramname,
82  const char* descr); //add "paramname" to object database
83 
84  Int_t
85  GetParamDouble(const char* paramname); //get "paramname" from double database
86  Int_t
87  GetParamString(const char* paramname); //get "paramname" from string database
88  Int_t GetParamInt(const char* paramname,
89  Int_t length = -1); //get "paramname" from string database
90  Int_t GetParamTObj(const char* paramname);
91 
92  char* GetDescription(const char* paramname);
93 
94  void GetFastParamInt(const char* paramname, Int_t* pkey) {
95  if ((*pkey) < 0) *pkey = GetParamInt(paramname);
96  };
97  void GetFastParamString(const char* paramname, Int_t* pkey) {
98  if ((*pkey) < 0) *pkey = GetParamString(paramname);
99  };
100  void GetFastParamDouble(const char* paramname, Int_t* pkey) {
101  if ((*pkey) < 0) *pkey = GetParamDouble(paramname);
102  };
103  void GetFastParamTObj(const char* paramname, Int_t* pkey) {
104  if ((*pkey) < 0) *pkey = GetParamTObj(paramname);
105  };
106 
107  using TObject::GetName;
108  const char* GetName(Int_t key);
109  //getting particle/decay properties from data base
110  //return kFALSE if 1.) key not existing or 2.) Param not existing or 3.) Param not used for entry
111  Bool_t GetParamDouble(Int_t key, const char* paramname, Double_t** result);
112  Bool_t GetParamString(Int_t key, const char* paramname, const char** result);
113  Bool_t GetParamInt(Int_t key,
114  const char* paramname,
115  Int_t** result,
116  Int_t length = -1);
117  Bool_t GetParamTObj(Int_t key, const char* paramname, TObject** result);
118 
119  //same as above but with the pkey as obtained by the getFastParam's
120  Bool_t GetParamInt(Int_t key, Int_t pkey, Int_t** result);
121  Bool_t GetParamString(Int_t key, Int_t pkey, const char** result);
122  Bool_t GetParamDouble(Int_t key, Int_t pkey, Double_t** result);
123  Bool_t GetParamTObj(Int_t key, Int_t pkey, TObject** result);
124 
125  //setting value instead of pointer
126  Bool_t GetParamInt(Int_t key, Int_t pkey, Int_t* result) {
127  Int_t* p;
128  Bool_t b = GetParamInt(key, pkey, &p);
129  if (b && p)
130  *result = *p;
131  else
132  *result = 0;
133  return b;
134  };
135 
136  //getting param by primary name
137  Bool_t GetParamInt(const char* name, const char* paramname, Int_t** result) {
138  return GetParamInt(GetEntry(name), paramname, result);
139  };
140  Bool_t
141  GetParamDouble(const char* name, const char* paramname, Double_t** result) {
142  return GetParamDouble(GetEntry(name), paramname, result);
143  };
144  Bool_t
145  GetParamString(const char* name, const char* paramname, const char** result) {
146  return GetParamString(GetEntry(name), paramname, result);
147  };
148  Bool_t
149  GetParamTObj(const char* name, const char* paramname, TObject** result) {
150  return GetParamTObj(GetEntry(name), paramname, result);
151  };
152 
153  //Getting param by matching integer value
154  Bool_t GetParamInt(const char* paramname1,
155  Int_t value1,
156  const char* paramname2,
157  Int_t** result) {
158  return GetParamInt(GetEntryInt(paramname1, value1), paramname2, result);
159  };
160  Bool_t GetParamDouble(const char* paramname1,
161  Int_t value1,
162  const char* paramname2,
163  Double_t** result) {
164  return GetParamDouble(GetEntryInt(paramname1, value1), paramname2, result);
165  };
166  Bool_t GetParamString(const char* paramname1,
167  Int_t value1,
168  const char* paramname2,
169  const char** result) {
170  return GetParamString(GetEntryInt(paramname1, value1), paramname2, result);
171  };
172  Bool_t GetParamTObj(const char* paramname1,
173  Int_t value1,
174  const char* paramname2,
175  TObject** result) {
176  return GetParamTObj(GetEntryInt(paramname1, value1), paramname2, result);
177  };
178 
179  //same as above when the pkey are known...
180  Bool_t GetParamInt(Int_t pkey1, Int_t value1, Int_t pkey2, Int_t** result) {
181  // cout << pkey1 << ":" << value1<< ":" << pkey2<< ":" << endl;
182  return GetParamInt(GetEntryInt(pkey1, value1), pkey2, result);
183  };
184  Bool_t
185  GetParamDouble(Int_t pkey1, Int_t value1, Int_t pkey2, Double_t** result) {
186  return GetParamDouble(GetEntryInt(pkey1, value1), pkey2, result);
187  };
188  Bool_t
189  GetParamString(Int_t pkey1, Int_t value1, Int_t pkey2, const char** result) {
190  return GetParamString(GetEntryInt(pkey1, value1), pkey2, result);
191  };
192  Bool_t
193  GetParamTObj(Int_t pkey1, Int_t value1, Int_t pkey2, TObject** result) {
194  return GetParamTObj(GetEntryInt(pkey1, value1), pkey2, result);
195  };
196 
197 
198  Bool_t SetParamDouble(Int_t key, const char* paramname, Double_t* result);
199  Bool_t SetParamString(Int_t key, const char* paramname, char* result);
200  Bool_t SetParamInt(Int_t key, const char* paramname, Int_t* result);
201  Bool_t SetParamTObj(Int_t key, const char* paramname, TObject* result);
202 
203  //faster:
204  Bool_t SetParamTObj(Int_t key, Int_t pp, TObject* result);
205 
206  Bool_t
207  SetParamDouble(const char* name, const char* paramname, Double_t result) {
208  Int_t key = GetEntry(name);
209  if (key < 0) return kFALSE;
210  return SetParamDouble(key, paramname, new Double_t(result));
211  }
212  Bool_t SetParamInt(const char* name, const char* paramname, Int_t result) {
213  Int_t key = GetEntry(name);
214  if (key < 0) return kFALSE;
215  return SetParamInt(key, paramname, new Int_t(result));
216  }
217  Bool_t SetParamString(const char* name, const char* paramname, char* result) {
218  Int_t key = GetEntry(name);
219  if (key < 0) return kFALSE;
220  return SetParamString(key, paramname, result);
221  };
222  Bool_t
223  SetParamTObj(const char* name, const char* paramname, TObject* result) {
224  Int_t key = GetEntry(name);
225  if (key < 0) return kFALSE;
226  return SetParamTObj(key, paramname, result);
227  };
228 
229  //Dealing with the entries
230  Bool_t AddEntry(Int_t key, const char* name);
231  Int_t AddEntry(const char* name);
232  Int_t GetEntry(const char* name);
233  Int_t GetEntryInt(const char* paramname, Int_t value);
234  Int_t GetEntryInt(Int_t pkey, Int_t value);
235 
236  //listings
237  Int_t AddListEntry(const char* name,
238  const char* count,
239  const char* link,
240  const char* newname);
241  Bool_t MakeListIterator(Int_t key,
242  const char* count,
243  const char* link,
244  Int_t* listkey);
245  Bool_t MakeListIterator(Int_t key, Int_t count, Int_t link, Int_t* listkey);
246 
247  Bool_t
248  ListEntries(Int_t key = -1, Int_t option = 0, const char* pattern = nullptr);
249 
250  void Print(const Option_t* delme) const;
251 
252 
253  ClassDef(PDataBase, 0); //Relational data base for pluto
254 };
255 
256 #endif
PDataBase::SetParamInt
Bool_t SetParamInt(const char *name, const char *paramname, Int_t result)
Definition: PDataBase.h:212
PDataBase::SetParamTObj
Bool_t SetParamTObj(const char *name, const char *paramname, TObject *result)
Definition: PDataBase.h:223
PDATABASE_MAX_STRING_PARAM
#define PDATABASE_MAX_STRING_PARAM
Definition: PDataBase.h:15
fDataBase
PDataBase & fDataBase()
Definition: PDataBase.cxx:21
PDataBase::GetParamDouble
Bool_t GetParamDouble(const char *name, const char *paramname, Double_t **result)
Definition: PDataBase.h:141
PDataBase::param_tobj_pointer
Int_t param_tobj_pointer
Definition: PDataBase.h:44
makeDataBase
PDataBase * makeDataBase()
Definition: PDataBase.cxx:26
PDataBase::GetParamInt
Bool_t GetParamInt(Int_t pkey1, Int_t value1, Int_t pkey2, Int_t **result)
Definition: PDataBase.h:180
PDATABASE_MAX_TOBJ_PARAM
#define PDATABASE_MAX_TOBJ_PARAM
Definition: PDataBase.h:17
PDataBase::GetFastParamDouble
void GetFastParamDouble(const char *paramname, Int_t *pkey)
Definition: PDataBase.h:100
PDataBase::GetParamString
Bool_t GetParamString(const char *name, const char *paramname, const char **result)
Definition: PDataBase.h:145
PDataBase::SetParamDouble
Bool_t SetParamDouble(const char *name, const char *paramname, Double_t result)
Definition: PDataBase.h:207
PDataBase::param_double_pointer
Int_t param_double_pointer
Definition: PDataBase.h:41
PDataBase::param_int_pointer
Int_t param_int_pointer
Definition: PDataBase.h:43
PDataBase::GetParamInt
Bool_t GetParamInt(Int_t key, Int_t pkey, Int_t *result)
Definition: PDataBase.h:126
Pdefines.h
PDataBase::param_string_pointer
Int_t param_string_pointer
Definition: PDataBase.h:42
PDataBase::GetParamDouble
Bool_t GetParamDouble(Int_t pkey1, Int_t value1, Int_t pkey2, Double_t **result)
Definition: PDataBase.h:185
PDataBase::ClassDef
ClassDef(PDataBase, 0)
PDataBase::GetFastParamString
void GetFastParamString(const char *paramname, Int_t *pkey)
Definition: PDataBase.h:97
PDataBase::GetFastParamTObj
void GetFastParamTObj(const char *paramname, Int_t *pkey)
Definition: PDataBase.h:103
PDataBase::GetParamTObj
Bool_t GetParamTObj(const char *name, const char *paramname, TObject **result)
Definition: PDataBase.h:149
PDataBase::GetParamTObj
Bool_t GetParamTObj(const char *paramname1, Int_t value1, const char *paramname2, TObject **result)
Definition: PDataBase.h:172
PDataBase::GetParamString
Bool_t GetParamString(Int_t pkey1, Int_t value1, Int_t pkey2, const char **result)
Definition: PDataBase.h:189
PDataBase::GetParamInt
Bool_t GetParamInt(const char *name, const char *paramname, Int_t **result)
Definition: PDataBase.h:137
PDataBase::GetParamTObj
Bool_t GetParamTObj(Int_t pkey1, Int_t value1, Int_t pkey2, TObject **result)
Definition: PDataBase.h:193
PDATABASE_MAX_LINES
#define PDATABASE_MAX_LINES
Definition: PDataBase.h:19
PDataBase::GetParamString
Bool_t GetParamString(const char *paramname1, Int_t value1, const char *paramname2, const char **result)
Definition: PDataBase.h:166
PDataBase::GetParamInt
Bool_t GetParamInt(const char *paramname1, Int_t value1, const char *paramname2, Int_t **result)
Definition: PDataBase.h:154
PDataBase
Definition: PDataBase.h:27
PDataBase::lastkey
Int_t lastkey
Definition: PDataBase.h:58
PDataBase::GetFastParamInt
void GetFastParamInt(const char *paramname, Int_t *pkey)
Definition: PDataBase.h:94
PDATABASE_MAX_INT_PARAM
#define PDATABASE_MAX_INT_PARAM
Definition: PDataBase.h:16
PDataBase::GetParamDouble
Bool_t GetParamDouble(const char *paramname1, Int_t value1, const char *paramname2, Double_t **result)
Definition: PDataBase.h:160
PDATABASE_MAX_DOUBLE_PARAM
#define PDATABASE_MAX_DOUBLE_PARAM
Definition: PDataBase.h:14
PDataBase::SetParamString
Bool_t SetParamString(const char *name, const char *paramname, char *result)
Definition: PDataBase.h:217