CbmRoot
Loading...
Searching...
No Matches
PDataBase.cxx
Go to the documentation of this file.
1/* Copyright (C) 2007-2020 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Florian Uhlig [committer] */
4
5// Particle ID, properties and decay data base
6
7#include "PDataBase.h"
8
9#include "TObjArray.h"
10#include "TObjString.h"
11#include "TStopwatch.h"
12#include "TString.h"
13//#include "PMesh.h"
14#include "PStdData.h"
15
17{
18 static PDataBase* ans = new PDataBase();
19 return *ans;
20}
21
23
24
26{
31 lastkey = 0;
32
33 //Init arrays to nullptr
34 for (int i = 0; i < PDATABASE_MAX_LINES; i++) {
35 for (int j = 0; j < PDATABASE_MAX_STRING_PARAM; j++)
36 strings[i][j] = nullptr;
37 for (int j = 0; j < PDATABASE_MAX_DOUBLE_PARAM; j++)
38 doubles[i][j] = nullptr;
39 for (int j = 0; j < PDATABASE_MAX_INT_PARAM; j++)
40 ints[i][j] = nullptr;
41 for (int j = 0; j < PDATABASE_MAX_TOBJ_PARAM; j++)
42 tobjs[i][j] = nullptr;
43 }
44
45 for (int j = 0; j < PDATABASE_MAX_INT_PARAM; j++) {
46 param_int_key[j] = nullptr;
47 param_int_key_max[j] = 0;
48 }
49
50 MakeParamString("name", "Database name");
51 //this is absolute minimum and required for testing for existence
52 // Info("PDataBase()","(%s)", PRINT_CTOR);
53}
54
55
56void PDataBase::Print(const Option_t*) const
57{
58 cout << param_int_pointer << " INT's booked (out of " << PDATABASE_MAX_INT_PARAM << ")" << endl;
59 for (int i = 0; i < param_int_pointer; i++)
60 cout << "INT:" << param_int_name[i] << ":" << param_int_descr[i] << endl;
61
62 cout << param_double_pointer << " DOUBLE's booked (out of " << PDATABASE_MAX_DOUBLE_PARAM << ")" << endl;
63 for (int i = 0; i < param_double_pointer; i++)
64 cout << "DOUBLE:" << param_double_name[i] << ":" << param_double_descr[i] << endl;
65
66 cout << param_string_pointer << " STRING's booked (out of " << PDATABASE_MAX_STRING_PARAM << ")" << endl;
67 for (int i = 0; i < param_string_pointer; i++)
68 cout << "STRING:" << param_string_name[i] << ":" << param_string_descr[i] << endl;
69
70 cout << param_tobj_pointer << " TOBJ's booked (out of " << PDATABASE_MAX_TOBJ_PARAM << ")" << endl;
71 for (int i = 0; i < param_tobj_pointer; i++)
72 cout << "TOBJ:" << param_tobj_name[i] << ":" << param_tobj_descr[i] << endl;
73}
74
75void PDataBase::SetFastKey(Int_t pkey, Int_t maxkey)
76{
77 //set if param(pkey) provides a unique fast key
78 //this is the case for e.g. "pid"
79 //set the maxkey to max "pid" value
80 param_int_key[pkey] = new Int_t[maxkey];
81 param_int_key_max[pkey] = maxkey;
82 for (int i = 0; i < maxkey; i++)
83 param_int_key[pkey][i] = -1;
84}
85
86Bool_t PDataBase::CheckEntry(Int_t key)
87{
88 //returns a kTRUE if a line with the "key" is already initialized
89 if ((key >= lastkey) || (key < -1)) return kFALSE;
90 // Int_t pp=getParamString("name");
91 Int_t pp = 0;
92 if (strings[key][pp] == nullptr) return kFALSE;
93 return kTRUE;
94};
95
96const char* PDataBase::GetName(Int_t key)
97{
98 //returns the primary name
99 if ((key >= lastkey) || (key < -1)) return nullptr;
100 // Int_t pp=getParamString("name");
101 Int_t pp = 0;
102 return strings[key][pp];
103};
104
105Int_t PDataBase::MakeParamDouble(const char* paramname, const char* descr)
106{
107 //check maximum size
109 Fatal("MakeParamDouble", "PDATABASE_MAX_DOUBLE_PARAM reached");
110 }
111 //check if paramname already exists
112 if (GetParamDouble(paramname) >= 0) {
113 Warning("MakeParamDouble", "Value %s already exists", paramname);
114 return -1;
115 }
119 return param_double_pointer - 1;
120}
121
122
123Int_t PDataBase ::MakeParamString(const char* paramname, const char* descr)
124{
125 //check maximum size
126 if (param_string_pointer == PDATABASE_MAX_STRING_PARAM) {
127 Fatal("MakeParamString", "PDATABASE_MAX_STRING_PARAM reached");
128 }
129 //check if paramname already exists
130 if (GetParamString(paramname) >= 0) {
131 Warning("MakeParamString", "Value %s already exists", paramname);
132 return -1;
133 }
134 param_string_name[param_string_pointer] = paramname;
135 param_string_descr[param_string_pointer] = descr;
136 param_string_pointer++;
137 return param_string_pointer - 1;
138}
139
140Int_t PDataBase ::MakeParamInt(const char* paramname, const char* descr)
141{
142 //check maximum size
143 if (param_int_pointer == PDATABASE_MAX_INT_PARAM) { Fatal("MakeParamInt", "PDATABASE_MAX_INT_PARAM reached"); }
144 //check if paramname already exists
145 if (GetParamInt(paramname) >= 0) {
146 Warning("MakeParamInt", "Value %s already exists", paramname);
147 return -1;
148 }
149 param_int_name[param_int_pointer] = paramname;
150 param_int_descr[param_int_pointer] = descr;
151 param_int_pointer++;
152 return param_int_pointer - 1;
153}
154
155Int_t PDataBase ::MakeParamTObj(const char* paramname, const char* descr)
156{
157 //check maximum size
158 if (param_tobj_pointer == PDATABASE_MAX_TOBJ_PARAM) { Fatal("MakeParamTObj", "PDATABASE_MAX_TOBJ_PARAM reached"); }
159 //check if paramname already exists
160 if (GetParamTObj(paramname) >= 0) {
161 Warning("MakeParamTObj", "Value %s already exists", paramname);
162 return -1;
163 }
164 param_tobj_name[param_tobj_pointer] = paramname;
165 param_tobj_descr[param_tobj_pointer] = descr;
166 param_tobj_pointer++;
167 return param_tobj_pointer - 1;
168}
169
170Int_t PDataBase ::GetParamDouble(const char* paramname)
171{
172 for (int i = 0; i < param_double_pointer; i++)
173 if (strcmp(paramname, param_double_name[i]) == 0) return i;
174 return -1;
175}
176
177Int_t PDataBase ::GetParamString(const char* paramname)
178{
179 //BUGBUG: If paramname is a pointer like "d1:name" this does not work->write getDescription
180 for (int i = 0; i < param_string_pointer; i++)
181 if (strcmp(paramname, param_string_name[i]) == 0) return i;
182 return -1;
183}
184
185Int_t PDataBase ::GetParamInt(const char* paramname, Int_t length)
186{
187 for (int i = 0; i < param_int_pointer; i++) {
188
189 if (length < 0) {
190 if (strcmp(paramname, param_int_name[i]) == 0) return i;
191 }
192 else {
193 if (strncmp(paramname, param_int_name[i], length) == 0) return i;
194 }
195 }
196 return -1;
197}
198
199Int_t PDataBase ::GetParamTObj(const char* paramname)
200{
201 for (int i = 0; i < param_tobj_pointer; i++)
202 if (strcmp(paramname, param_tobj_name[i]) == 0) return i;
203 return -1;
204}
205
206Int_t PDataBase ::ConvertParamKey(const char*& newparamname, Int_t key)
207{
208 //checks for the ":" delmiter, sets the pointer to the remaing string
209 //evaluate the new key
210 //cout << "newparamname init " <<newparamname << endl;
211 Int_t* newkey;
212 for (unsigned int i = 0; i < strlen(newparamname); i++) {
213 if (newparamname[i] == ':') {
214 if (!GetParamInt(key, newparamname, &newkey, i)) {
215 Warning("ConvertParamKey", "Value %s for key %i not existing", newparamname, key);
216 return -1;
217 }
218 newparamname = newparamname + i + 1;
219
220 return *newkey;
221 }
222 }
223 return -1;
224};
225
226TString PDataBase ::GetDescription(const char* paramname)
227{
228 //Interpretation of pattern
229 TString spattern(paramname);
230 TObjArray* array = spattern.Tokenize(TString(":"));
231 TString bla;
232 Int_t done = 0;
233 for (int pat = 0; pat < array->GetEntriesFast(); pat++) {
234 if (done) bla.Append("->");
235 TObjString* patoption = (TObjString*) (*array)[pat];
236 char* options = (char*) patoption->GetString().Data();
237 if (GetParamString(options) > -1) {
238 bla.Append(param_string_descr[GetParamString(options)]);
239 done = 1;
240 }
241 if (GetParamInt(options) > -1) {
242 bla.Append(param_int_descr[GetParamInt(options)]);
243 done = 1;
244 }
245 if (GetParamDouble(options) > -1) {
246 bla.Append(param_double_descr[GetParamDouble(options)]);
247 done = 1;
248 }
249 if (GetParamTObj(options) > -1) {
250 bla.Append(param_tobj_descr[GetParamTObj(options)]);
251 done = 1;
252 }
253 }
254 return bla;
255}
256
257Bool_t PDataBase ::GetParamDouble(Int_t key, const char* paramname, Double_t** result)
258{
259 //return kFALSE if 1.) key not existing or 2.) Param not existing or 3.) Param not used for key
260 if (!CheckEntry(key)) return kFALSE;
261 Int_t newkey = -1;
262 const char* newparamname = paramname;
263
264 if ((newkey = ConvertParamKey(newparamname, key)) >= 0) { return GetParamDouble(newkey, newparamname, result); }
265 paramname = newparamname;
266 Int_t pp = GetParamDouble(paramname);
267 if (pp < 0) return kFALSE;
268
269 if (doubles[key][pp] == nullptr) return kFALSE;
270
271 *result = doubles[key][pp];
272 return kTRUE;
273};
274
275Bool_t PDataBase ::GetParamDouble(Int_t key, Int_t pkey, Double_t** result)
276{
277 if (!CheckEntry(key)) return kFALSE;
278 if (pkey < 0) return kFALSE;
279 if (doubles[key][pkey] == nullptr) return kFALSE;
280 *result = doubles[key][pkey];
281 return kTRUE;
282};
283
284
285Bool_t PDataBase ::GetParamString(Int_t key, const char* paramname, const char** result)
286{
287 //return kFALSE if 1.) KEY not existing or 2.) Param not existing or 3.) Param not used for KEY
288 if (!CheckEntry(key)) return kFALSE;
289 Int_t newkey = -1;
290 const char* newparamname = paramname;
291
292 if ((newkey = ConvertParamKey(newparamname, key)) >= 0) { return GetParamString(newkey, newparamname, result); }
293 paramname = newparamname;
294 Int_t pp = GetParamString(paramname);
295 if (pp < 0) return kFALSE;
296
297 if (strings[key][pp] == nullptr) return kFALSE;
298
299 *result = strings[key][pp];
300 return kTRUE;
301};
302
303Bool_t PDataBase ::GetParamString(Int_t key, Int_t pkey, const char** result)
304{
305 if (!CheckEntry(key)) return kFALSE;
306 if (pkey < 0) return kFALSE;
307 if (strings[key][pkey] == nullptr) return kFALSE;
308 *result = strings[key][pkey];
309 return kTRUE;
310};
311
312Bool_t PDataBase ::GetParamInt(Int_t key, const char* paramname, Int_t** result, Int_t length)
313{
314 //return kFALSE if 1.) key not existing or 2.) Param not existing or 3.) Param not used for key
315 if (!CheckEntry(key)) return kFALSE;
316
317 Int_t newkey = -1;
318 const char* newparamname = paramname;
319 if (length < 0) {
320 if ((newkey = ConvertParamKey(newparamname, key)) >= 0) { return GetParamInt(newkey, newparamname, result); }
321 }
322 paramname = newparamname;
323 Int_t pp = GetParamInt(paramname, length);
324 if (pp < 0) return kFALSE;
325
326 if (ints[key][pp] == nullptr) return kFALSE;
327
328 *result = ints[key][pp];
329 return kTRUE;
330};
331
332Bool_t PDataBase ::GetParamInt(Int_t key, Int_t pkey, Int_t** result)
333{
334 if (!CheckEntry(key)) return kFALSE;
335
336 if (pkey < 0) return kFALSE;
337 if (ints[key][pkey] == nullptr) return kFALSE;
338 *result = ints[key][pkey];
339 return kTRUE;
340};
341
342Bool_t PDataBase ::GetParamTObj(Int_t key, const char* paramname, TObject** result)
343{
344 //return kFALSE if 1.) KEY not existing or 2.) Param not existing or 3.) Param not used for KEY
345 if (!CheckEntry(key)) return kFALSE;
346 Int_t newkey = -1;
347 const char* newparamname = paramname;
348
349 if ((newkey = ConvertParamKey(newparamname, key)) >= 0) { return GetParamTObj(newkey, newparamname, result); }
350 paramname = newparamname;
351 Int_t pp = GetParamTObj(paramname);
352 if (pp < 0) return kFALSE;
353
354 if (tobjs[key][pp] == nullptr) return kFALSE;
355
356 *result = tobjs[key][pp];
357 return kTRUE;
358};
359
360Bool_t PDataBase ::GetParamTObj(Int_t key, Int_t pkey, TObject** result)
361{
362 if (!CheckEntry(key)) return kFALSE;
363 if (pkey < 0) return kFALSE;
364 if (tobjs[key][pkey] == nullptr) return kFALSE;
365 *result = tobjs[key][pkey];
366 return kTRUE;
367};
368
369
370Bool_t PDataBase ::SetParamDouble(Int_t key, const char* paramname, Double_t* result)
371{
372 //return kFALSE if 1.) KEY not existing or 2.) Param not existing or 3.) Param not used for KEY
373 if (!CheckEntry(key)) {
374 cout << "PDataBase::SetParamDouble: key " << key << " not existing" << endl;
375 return kFALSE;
376 }
377
378 Int_t pp = GetParamDouble(paramname);
379 if (pp < 0) {
380 cout << "PDataBase::SetParamDouble: paramname " << paramname << " not existing" << endl;
381 return kFALSE;
382 }
383
384 doubles[key][pp] = result;
385 return kTRUE;
386};
387
388Bool_t PDataBase ::SetParamString(Int_t key, const char* paramname, char* result)
389{
390 //return kFALSE if 1.) KEY not existing or 2.) Param not existing or 3.) Param not used for KEY
391 if (!CheckEntry(key)) {
392 Error("SetParamString", "key %i not existing", key);
393 return kFALSE;
394 }
395
396 Int_t pp = GetParamString(paramname);
397 if (pp < 0) {
398 Error("SetParamString", "paramname %s not existing", paramname);
399 return kFALSE;
400 }
401
402 strings[key][pp] = result;
403 return kTRUE;
404};
405
406Bool_t PDataBase ::SetParamInt(Int_t key, const char* paramname, Int_t* result)
407{
408 //return kFALSE if 1.) KEY not existing or 2.) Param not existing or 3.) Param not used for KEY
409 if (!CheckEntry(key)) {
410 Error("SetParamInt", "key %i not existing", key);
411 return kFALSE;
412 }
413
414 Int_t pp = GetParamInt(paramname);
415 if (pp < 0) {
416 Error("SetParamInt", "paramname %s not existing", paramname);
417 return kFALSE;
418 }
419
420 ints[key][pp] = result;
421 return kTRUE;
422};
423
424Bool_t PDataBase ::SetParamTObj(Int_t key, const char* paramname, TObject* result)
425{
426 //return kFALSE if 1.) KEY not existing or 2.) Param not existing or 3.) Param not used for KEY
427 if (!CheckEntry(key)) {
428 Error("SetParamTObj", "key %i not existing", key);
429 return kFALSE;
430 }
431
432 Int_t pp = GetParamTObj(paramname);
433 if (pp < 0) {
434 Error("SetParamTObj", "paramname %s not existing", paramname);
435 return kFALSE;
436 }
437
438 tobjs[key][pp] = result;
439 return kTRUE;
440};
441
442Bool_t PDataBase ::SetParamTObj(Int_t key, Int_t pp, TObject* result)
443{
444 //return kFALSE if 1.) KEY not existing or 2.) Param not existing or 3.) Param not used for KEY
445 if (!CheckEntry(key)) {
446 Error("SetParamTObj", "key %i not existing", key);
447 return kFALSE;
448 }
449
450 tobjs[key][pp] = result;
451 return kTRUE;
452};
453
454Int_t PDataBase ::GetEntry(const char* name)
455{
456 for (int i = 0; i < lastkey; i++) {
457 if (strings[i][0])
458 if (strcmp(name, strings[i][0]) == 0) return i;
459 }
460 return -1;
461};
462
463
464Int_t PDataBase ::GetEntryInt(const char* paramname, Int_t value)
465{
466 Int_t* result;
467 for (int i = 0; i < lastkey; i++) {
468 if (GetParamInt(i, paramname, &result)) {
469 if (*result == value) return i;
470 }
471 }
472 return -1;
473};
474
475Int_t PDataBase ::GetEntryInt(Int_t pkey, Int_t value)
476{
477 //return the index key if param(pkey) is matching the value
478 //otherwise -1
479 Int_t* result;
480
481 //use fast checking is available
482 if (param_int_key[pkey]) {
483 if ((value >= 0) && (value < param_int_key_max[pkey])) {
484 if (param_int_key[pkey][value] != -1) { return param_int_key[pkey][value]; }
485 else {
486 for (int i = 0; i < lastkey; i++) {
487 if (GetParamInt(i, pkey, &result)) {
488 if (*result == value) {
489 //cout << "init " << pkey << ":" << value << endl;
490 param_int_key[pkey][value] = i;
491 return i;
492 }
493 }
494 }
495 }
496 }
497 }
498 //slow version: loop over entries
499
500 for (int i = 0; i < lastkey; i++) {
501 if (GetParamInt(i, pkey, &result)) {
502 if (*result == value) return i;
503 }
504 }
505 return -1;
506};
507
508Bool_t PDataBase ::AddEntry(Int_t key, const char* name)
509{
510 if (CheckEntry(key)) {
511 Warning("AddEntry", "Key %i already existing", key);
512 return kFALSE;
513 }
514 if (GetEntry(name) >= 0) {
515 Warning("AddEntry", "An entry with name %s already exists", name);
516 CRASH;
517 return kFALSE;
518 }
519 Int_t pp = GetParamString("name");
520 strings[key][pp] = name;
521 return kTRUE;
522};
523
524Int_t PDataBase ::AddEntry(const char* name)
525{
526 if (AddEntry(lastkey, name)) {
527 lastkey++;
528 return lastkey - 1;
529 }
530 return -1;
531};
532
533Int_t PDataBase::AddListEntry(const char* name, const char* count, const char* link, const char* newname)
534{
535 //This is used to add linked-lists the the entry "name"
536 //The "count" (which should be an int param) holds the number of links
537 //"link" is used for:
538 //1.) setting the key to the last entry of the lists (updated on the fly)
539 //2.) setting the key from the last list entry to the last-but-one
540 //The first list entry points back to the original "name", thus forming a ring
541 //"newname" is the name of the new list entry
542
543 Int_t* i_count;
544 Int_t* i_link;
545 Int_t* i_newlink;
546 Int_t key = GetEntry(name);
547 Int_t targetkey = GetEntry(newname);
548 if (key < 0) {
549 Warning("AddListEntry", "Unable to get entry %s", name);
550 //Fatal("AddListEntry","Unable to get entry %s",name);
551 return -1;
552 }
553
554 //test if linked list already initialized
555 if (!GetParamInt(key, count, &i_count)) {
556 //initialize
557 //first add the new entry before modifying the old one
558 if (targetkey < 0) targetkey = AddEntry(newname);
559 if (targetkey < 0) {
560 Warning("AddListEntry", "Unable to name entry %s", newname);
561 return -1;
562 }
563 //if this worked, set the link from the new to the old entry
564 //TODO: More consitency checks
565
566 i_count = new Int_t(1);
567 SetParamInt(key, count, i_count);
568 i_link = new Int_t(targetkey);
569 SetParamInt(key, link, i_link);
570 i_newlink = new Int_t(key);
571 SetParamInt(targetkey, link, i_newlink);
572 }
573 else {
574 //first add the new entry before modifying the old one
575 if (targetkey < 0) targetkey = AddEntry(newname);
576 if (targetkey < 0) {
577 Warning("AddListEntry", "Unable to name entry %s", newname);
578 return -1;
579 }
580 //increment target count
581 GetParamInt(key, count, &i_count);
582 (*i_count)++;
583
584 //Find the last entry in the chain
585 Int_t listkey = -1, lastkey1 = -1;
586 while (makeDataBase()->MakeListIterator(key, count, link, &listkey)) {
587 lastkey1 = listkey;
588 }
589
590 //copy old pointer to new entry
591 //GetParamInt (key, link,&i_link);
592 GetParamInt(lastkey1, link, &i_link);
593 i_newlink = new Int_t(*i_link);
594 SetParamInt(targetkey, link, i_newlink);
595 //set new entry
596 i_link = new Int_t(targetkey);
597 SetParamInt(lastkey1, link, i_link);
598 }
599 return targetkey;
600};
601
602Bool_t PDataBase ::MakeListIterator(Int_t key, const char* count, const char* link, Int_t* listkey)
603{
604 //get the list entries which belongs to "key" and is described by "counts" and "link"
605 //(both has to be defined in a proper way)
606 //It is very important that on the 1st call *listkey is -1
607 //on the value kTRUE, *listkey contains the key link to the list entry
608 //on the value kFALSE, the iteration has been finished (or not started due to an error)
609 Int_t *i_count, *loc_listkey_p;
610
611 if (key == -1) return kFALSE;
612 if (*listkey == -1) { //first call: check list header entry
613 if (count) {
614 if (!GetParamInt(key, count, &i_count)) {
615 Warning("MakeListIterator", "count %s not found", count);
616 return kFALSE;
617 }
618 }
619 if (!GetParamInt(key, link, &loc_listkey_p)) {
620 Warning("MakeListIterator", "link %s not found", link);
621 return kFALSE;
622 }
623 }
624 else {
625 if (!GetParamInt(*listkey, link, &loc_listkey_p)) return kFALSE;
626 }
627 //now copy to external
628 *listkey = *loc_listkey_p;
629 if (*listkey == key) {
630 *listkey = -1;
631 return kFALSE;
632 }
633 return kTRUE;
634}
635
636Bool_t PDataBase ::MakeListIterator(Int_t key, Int_t count, Int_t link, Int_t* listkey)
637{
638 //get the list entries which belongs to "key" and is described by "counts" and "link"
639 //(both has to be defined in a proper way)
640 //It is very important that on the 1st call *listkey is -1
641 //on the value kTRUE, *listkey contains the key link to the list entry
642 //on the value kFALSE, the iteration has been finished (or not started due to an error)
643 Int_t *i_count, *loc_listkey_p;
644
645 if (key == -1) return kFALSE;
646 if (*listkey == -1) { //first call: check list header entry
647 if (count >= 0) {
648 if (!GetParamInt(key, count, &i_count)) {
649 Warning("MakeListIterator", "count %i not found", count);
650 return kFALSE;
651 }
652 }
653 if (!GetParamInt(key, link, &loc_listkey_p)) {
654 Warning("MakeListIterator", "link %i not found", link);
655 return kFALSE;
656 }
657 }
658 else {
659 if (!GetParamInt(*listkey, link, &loc_listkey_p)) return kFALSE;
660 }
661 //now copy to external
662 *listkey = *loc_listkey_p;
663 if (*listkey == key) {
664 *listkey = -1;
665 return kFALSE;
666 }
667 return kTRUE;
668}
669
670
671Bool_t PDataBase ::ListEntries(Int_t key, Int_t option, const char* pattern)
672{
673 //key=line (or -1 for all)
674 //option=0 : line break =1: no line break
675 //pattern like "mass,width"
676
677 Int_t start = 0;
678 Int_t end = PDATABASE_MAX_LINES - 1;
679 Double_t* result;
680 const char* result2;
681 Int_t* result3;
682 TObject* result4;
685 Int_t valid_key[PDATABASE_MAX_LINES];
686
687 for (int i = 0; i < (PDATABASE_MAX_DOUBLE_PARAM + PDATABASE_MAX_STRING_PARAM); i++) {
688 max_sz[i] = 0;
689 for (int j = 0; j < PDATABASE_MAX_LINES; j++) {
690 sz[j][i] = 0;
691 valid_key[j] = 0;
692 }
693 }
694
695
696 //Interpretation of pattern
697 TString spattern(pattern);
698 TObjArray* array = spattern.Tokenize(TString(","));
699
700 if (key >= 0) { start = end = key; }
701 for (int run = 0; run < 2; run++) {
702 //run0: check size etc.
703 //run1: print info
704 for (int i = start; i <= end; i++) {
705 //TODO: check if at least one param is there
706 if (run && valid_key[i] > 0) {
707 if (option) {
708 cout << i << ":";
709 if (i < 10) cout << " ";
710 if (i < 100) cout << " ";
711 if (i < 1000) cout << " ";
712 }
713 else
714 cout << "Database key=" << i << endl;
715 }
716 for (int pat = 0; pat < array->GetEntriesFast(); pat++) {
719 //Too many string->Something is wrong
720 cout << "PDataBase::listEntries: Too many pattern strings" << endl;
721 return kFALSE;
722 }
723 TObjString* patoption = (TObjString*) (*array)[pat];
724 char* options = (char*) patoption->GetString().Data();
725 Bool_t checkline = kTRUE;
726 Bool_t invert = kFALSE;
727 if (options[0] == '*') {
728 //check paramteter, but not used for line selection
729 options++;
730 checkline = kFALSE;
731 }
732 if (options[0] == '!') {
733 options++;
734 invert = kTRUE;
735 }
736
737 if (GetParamDouble(i, options, &result)) {
738 if (run) {
739 if (valid_key[i] > 0) {
740
741 if (option) cout << options << "=";
742 else
743 cout << GetDescription(options) << "=";
744 printf("%f", *result);
745 if (option) cout << " ";
746 else
747 cout << " \n";
748 }
749 }
750 else {
751 size_t buf_size = 1000;
752 char bla[buf_size]; //I dont know a better way to get the length
753 // (if somebody has an idea -> help yourself)
754 int results_length = snprintf(bla, buf_size - 1, "%f", *result);
755 sz[i][pat] = results_length;
756 if (sz[i][pat] > max_sz[pat]) max_sz[pat] = sz[i][pat];
757 if (checkline && !invert) valid_key[i]++;
758 else if (invert && checkline)
759 valid_key[i] = -999;
760 }
761 }
762
763 else if (GetParamInt(i, options, &result3)) {
764 if (run) {
765 if (valid_key[i] > 0) {
766 if (option) cout << options << "=";
767 else
768 cout << GetDescription(options) << "=";
769 printf("%i", *result3);
770 if (option) cout << " ";
771 else
772 cout << " \n";
773 }
774 }
775 else {
776 size_t buf_size = 1000;
777 char bla[buf_size]; //I dont know a better way to get the length
778 // (if somebody has an idea -> help yourself)
779 int result_length = snprintf(bla, buf_size - 1, "%i", *result3);
780 sz[i][pat] = result_length;
781 if (sz[i][pat] > max_sz[pat]) max_sz[pat] = sz[i][pat];
782 if (checkline && !invert) valid_key[i]++;
783 else if (invert && checkline)
784 valid_key[i] = -999;
785 }
786 }
787
788 else if (GetParamString(i, options, &result2)) {
789 if (run) {
790 if (valid_key[i] > 0) {
791 if (option) cout << options << "=" << result2;
792 else
793 cout << GetDescription(options) << "=" << result2;
794 if (option) cout << " ";
795 else
796 cout << " \n";
797 }
798 }
799 else {
800 sz[i][pat] = strlen(result2);
801 if (sz[i][pat] > max_sz[pat]) max_sz[pat] = sz[i][pat];
802 if (checkline && !invert) valid_key[i]++;
803 else if (invert && checkline)
804 valid_key[i] = -999;
805 }
806 }
807
808 else if (GetParamTObj(i, options, &result4)) {
809 if (run) {
810 if (valid_key[i] > 0) {
811
812 if (option) cout << options << "=<yes>";
813 else
814 cout << GetDescription(options) << "=<yes>";
815 if (option) cout << " ";
816 else
817 cout << " \n";
818 }
819 }
820 else {
821 sz[i][pat] = 4; //for the yes
822 if (sz[i][pat] > max_sz[pat]) max_sz[pat] = sz[i][pat];
823 if (checkline && !invert) valid_key[i]++;
824 else if (invert && checkline)
825 valid_key[i] = -999;
826 }
827 }
828
829 // else if (invert && checkline) valid_key[i]++;
830
831
832 if (option && run && valid_key[i] > 0) {
833 //fill missing gaps
834 int ga = sz[i][pat];
835 //account for missing option string
836 if (!ga) ga -= strlen(options) + 2;
837 for (int x = ga; x < max_sz[pat]; x++) {
838 cout << " ";
839 }
840 }
841 }
842
843 if (run && valid_key[i] > 0) cout << "\n";
844 }
845 }
846 delete array;
847 return kTRUE;
848};
849
850
851void PDataBase ::Performance(void)
852{
853 TStopwatch timer;
854 //way1: loop over pids, and get the name
855 timer.Start();
856 Int_t mypid = 0, pid_param = 0, *i_result;
857 for (int r = 0; r < 10000; r++)
858 for (int i = 0; i < 50; i++) {
859 //get the pid from name
860 int k = 0;
861 for (k = 0; (k < 50) && strcmp(strings[i][0], strings[k][0]); k++) {}
862 mypid += k;
863 // cout << strings[i][0] << " is " << k << endl;
864 }
865 cout << timer.RealTime() << endl;
866 cout << mypid << endl;
867 mypid = 0;
868
869 timer.Start();
870 //now the new way
871 for (int r = 0; r < 10000; r++)
872 for (int i = 0; i < 50; i++) {
873 GetFastParamInt("pid", &pid_param);
874 if (!GetParamInt(GetEntry(strings[i][0]), pid_param, &i_result)) {
875 // if (! getFastParamInt (pid_param,i, &i_result)) {
876 cout << "PStaticData::ID: " << i << " not found" << endl;
877 }
878 mypid += *i_result;
879 // cout << strings[i][0] << " is " << *i_result << endl;
880 }
881 cout << timer.RealTime() << endl;
882 cout << mypid << endl;
883}
884
885
ClassImp(CbmConverterManager)
PDataBase * makeDataBase()
Definition PDataBase.cxx:22
PDataBase & fDataBase()
Definition PDataBase.cxx:16
#define PDATABASE_MAX_INT_PARAM
Definition PDataBase.h:22
#define PDATABASE_MAX_TOBJ_PARAM
Definition PDataBase.h:23
#define PDATABASE_MAX_LINES
Definition PDataBase.h:25
PDataBase * makeDataBase()
Definition PDataBase.cxx:22
#define PDATABASE_MAX_STRING_PARAM
Definition PDataBase.h:21
#define PDATABASE_MAX_DOUBLE_PARAM
Definition PDataBase.h:20
#define CRASH
Definition Pdefines.h:10
const char * param_double_descr[PDATABASE_MAX_DOUBLE_PARAM]
Definition PDataBase.h:41
Int_t param_int_pointer
Definition PDataBase.h:47
Int_t MakeParamDouble(const char *paramname, const char *descr)
TObject * tobjs[PDATABASE_MAX_LINES][PDATABASE_MAX_TOBJ_PARAM]
Definition PDataBase.h:60
Int_t param_tobj_pointer
Definition PDataBase.h:48
Bool_t AddEntry(Int_t key, const char *name)
Int_t * param_int_key[PDATABASE_MAX_INT_PARAM]
Definition PDataBase.h:52
void Print(const Option_t *delme) const
Definition PDataBase.cxx:56
Double_t * doubles[PDATABASE_MAX_LINES][PDATABASE_MAX_DOUBLE_PARAM]
Definition PDataBase.h:58
Int_t GetParamDouble(const char *paramname)
const char * param_string_descr[PDATABASE_MAX_STRING_PARAM]
Definition PDataBase.h:42
const char * param_tobj_descr[PDATABASE_MAX_INT_PARAM]
Definition PDataBase.h:44
const char * param_string_name[PDATABASE_MAX_STRING_PARAM]
Definition PDataBase.h:38
Int_t MakeParamString(const char *paramname, const char *descr)
const char * param_int_descr[PDATABASE_MAX_INT_PARAM]
Definition PDataBase.h:43
Int_t GetEntry(const char *name)
const char * param_tobj_name[PDATABASE_MAX_INT_PARAM]
Definition PDataBase.h:40
const char * strings[PDATABASE_MAX_LINES][PDATABASE_MAX_STRING_PARAM]
Definition PDataBase.h:57
void SetFastKey(Int_t pkey, Int_t maxkey)
Definition PDataBase.cxx:75
Int_t AddListEntry(const char *name, const char *count, const char *link, const char *newname)
Int_t param_int_key_max[PDATABASE_MAX_INT_PARAM]
Definition PDataBase.h:53
Int_t param_double_pointer
Definition PDataBase.h:45
Int_t lastkey
Definition PDataBase.h:62
Int_t * ints[PDATABASE_MAX_LINES][PDATABASE_MAX_INT_PARAM]
Definition PDataBase.h:59
const char * GetName(Int_t key)
Definition PDataBase.cxx:96
Bool_t CheckEntry(Int_t key)
Definition PDataBase.cxx:86
Bool_t MakeListIterator(Int_t key, const char *count, const char *link, Int_t *listkey)
const char * param_int_name[PDATABASE_MAX_INT_PARAM]
Definition PDataBase.h:39
const char * param_double_name[PDATABASE_MAX_DOUBLE_PARAM]
Definition PDataBase.h:37
Int_t GetParamInt(const char *paramname, Int_t length=-1)
Bool_t SetParamInt(Int_t key, const char *paramname, Int_t *result)
Int_t param_string_pointer
Definition PDataBase.h:46