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