185Int_t PDataBase ::GetParamInt(
const char* paramname, Int_t length)
187 for (
int i = 0; i < param_int_pointer; i++) {
190 if (strcmp(paramname, param_int_name[i]) == 0)
return i;
193 if (strncmp(paramname, param_int_name[i], length) == 0)
return i;
206Int_t PDataBase ::ConvertParamKey(
const char*& newparamname, Int_t key)
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);
218 newparamname = newparamname + i + 1;
226TString PDataBase ::GetDescription(
const char* paramname)
229 TString spattern(paramname);
230 TObjArray* array = spattern.Tokenize(TString(
":"));
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)]);
241 if (GetParamInt(options) > -1) {
242 bla.Append(param_int_descr[GetParamInt(options)]);
245 if (GetParamDouble(options) > -1) {
246 bla.Append(param_double_descr[GetParamDouble(options)]);
249 if (GetParamTObj(options) > -1) {
250 bla.Append(param_tobj_descr[GetParamTObj(options)]);
257Bool_t PDataBase ::GetParamDouble(Int_t key,
const char* paramname, Double_t** result)
260 if (!CheckEntry(key))
return kFALSE;
262 const char* newparamname = paramname;
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;
269 if (doubles[key][pp] ==
nullptr)
return kFALSE;
271 *result = doubles[key][pp];
285Bool_t PDataBase ::GetParamString(Int_t key,
const char* paramname,
const char** result)
288 if (!CheckEntry(key))
return kFALSE;
290 const char* newparamname = paramname;
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;
297 if (strings[key][pp] ==
nullptr)
return kFALSE;
299 *result = strings[key][pp];
312Bool_t PDataBase ::GetParamInt(Int_t key,
const char* paramname, Int_t** result, Int_t length)
315 if (!CheckEntry(key))
return kFALSE;
318 const char* newparamname = paramname;
320 if ((newkey = ConvertParamKey(newparamname, key)) >= 0) {
return GetParamInt(newkey, newparamname, result); }
322 paramname = newparamname;
323 Int_t pp = GetParamInt(paramname, length);
324 if (pp < 0)
return kFALSE;
326 if (ints[key][pp] ==
nullptr)
return kFALSE;
328 *result = ints[key][pp];
342Bool_t PDataBase ::GetParamTObj(Int_t key,
const char* paramname, TObject** result)
345 if (!CheckEntry(key))
return kFALSE;
347 const char* newparamname = paramname;
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;
354 if (tobjs[key][pp] ==
nullptr)
return kFALSE;
356 *result = tobjs[key][pp];
464Int_t PDataBase ::GetEntryInt(
const char* paramname, Int_t value)
467 for (
int i = 0; i < lastkey; i++) {
468 if (GetParamInt(i, paramname, &result)) {
469 if (*result == value)
return i;
475Int_t PDataBase ::GetEntryInt(Int_t pkey, Int_t value)
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]; }
486 for (
int i = 0; i < lastkey; i++) {
487 if (GetParamInt(i, pkey, &result)) {
488 if (*result == value) {
490 param_int_key[pkey][value] = i;
500 for (
int i = 0; i < lastkey; i++) {
501 if (GetParamInt(i, pkey, &result)) {
502 if (*result == value)
return i;
547 Int_t targetkey =
GetEntry(newname);
549 Warning(
"AddListEntry",
"Unable to get entry %s", name);
558 if (targetkey < 0) targetkey =
AddEntry(newname);
560 Warning(
"AddListEntry",
"Unable to name entry %s", newname);
566 i_count =
new Int_t(1);
568 i_link =
new Int_t(targetkey);
570 i_newlink =
new Int_t(key);
575 if (targetkey < 0) targetkey =
AddEntry(newname);
577 Warning(
"AddListEntry",
"Unable to name entry %s", newname);
585 Int_t listkey = -1, lastkey1 = -1;
593 i_newlink =
new Int_t(*i_link);
596 i_link =
new Int_t(targetkey);
602Bool_t PDataBase ::MakeListIterator(Int_t key,
const char* count,
const char* link, Int_t* listkey)
609 Int_t *i_count, *loc_listkey_p;
611 if (key == -1)
return kFALSE;
612 if (*listkey == -1) {
614 if (!GetParamInt(key, count, &i_count)) {
615 Warning(
"MakeListIterator",
"count %s not found", count);
619 if (!GetParamInt(key, link, &loc_listkey_p)) {
620 Warning(
"MakeListIterator",
"link %s not found", link);
625 if (!GetParamInt(*listkey, link, &loc_listkey_p))
return kFALSE;
628 *listkey = *loc_listkey_p;
629 if (*listkey == key) {
636Bool_t PDataBase ::MakeListIterator(Int_t key, Int_t count, Int_t link, Int_t* listkey)
643 Int_t *i_count, *loc_listkey_p;
645 if (key == -1)
return kFALSE;
646 if (*listkey == -1) {
648 if (!GetParamInt(key, count, &i_count)) {
649 Warning(
"MakeListIterator",
"count %i not found", count);
653 if (!GetParamInt(key, link, &loc_listkey_p)) {
654 Warning(
"MakeListIterator",
"link %i not found", link);
659 if (!GetParamInt(*listkey, link, &loc_listkey_p))
return kFALSE;
662 *listkey = *loc_listkey_p;
663 if (*listkey == key) {
671Bool_t PDataBase ::ListEntries(Int_t key, Int_t option,
const char* pattern)
697 TString spattern(pattern);
698 TObjArray* array = spattern.Tokenize(TString(
","));
700 if (key >= 0) { start = end = key; }
701 for (
int run = 0; run < 2; run++) {
704 for (
int i = start; i <= end; i++) {
706 if (run && valid_key[i] > 0) {
709 if (i < 10) cout <<
" ";
710 if (i < 100) cout <<
" ";
711 if (i < 1000) cout <<
" ";
714 cout <<
"Database key=" << i << endl;
716 for (
int pat = 0; pat < array->GetEntriesFast(); pat++) {
720 cout <<
"PDataBase::listEntries: Too many pattern strings" << endl;
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] ==
'*') {
732 if (options[0] ==
'!') {
737 if (GetParamDouble(i, options, &result)) {
739 if (valid_key[i] > 0) {
741 if (option) cout << options <<
"=";
743 cout << GetDescription(options) <<
"=";
744 printf(
"%f", *result);
745 if (option) cout <<
" ";
751 size_t buf_size = 1000;
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)
763 else if (GetParamInt(i, options, &result3)) {
765 if (valid_key[i] > 0) {
766 if (option) cout << options <<
"=";
768 cout << GetDescription(options) <<
"=";
769 printf(
"%i", *result3);
770 if (option) cout <<
" ";
776 size_t buf_size = 1000;
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)
788 else if (GetParamString(i, options, &result2)) {
790 if (valid_key[i] > 0) {
791 if (option) cout << options <<
"=" << result2;
793 cout << GetDescription(options) <<
"=" << result2;
794 if (option) cout <<
" ";
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)
808 else if (GetParamTObj(i, options, &result4)) {
810 if (valid_key[i] > 0) {
812 if (option) cout << options <<
"=<yes>";
814 cout << GetDescription(options) <<
"=<yes>";
815 if (option) cout <<
" ";
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)
832 if (option && run && valid_key[i] > 0) {
836 if (!ga) ga -= strlen(options) + 2;
837 for (
int x = ga;
x < max_sz[pat];
x++) {
843 if (run && valid_key[i] > 0) cout <<
"\n";
851void PDataBase ::Performance(
void)
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++) {
861 for (k = 0; (k < 50) && strcmp(strings[i][0], strings[k][0]); k++) {}
865 cout << timer.RealTime() << endl;
866 cout << mypid << endl;
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)) {
876 cout <<
"PStaticData::ID: " << i <<
" not found" << endl;
881 cout << timer.RealTime() << endl;
882 cout << mypid << endl;