EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FairParamList.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file FairParamList.cxx
1 //*-- AUTHOR : Ilse Koenig
2 //*-- Last modified : 28/01/2009 by Ilse Koenig
3 
4 #include "FairParamList.h"
5 #include "FairLogger.h"
6 
7 #include "TClass.h"
8 #include "TStreamerInfo.h"
9 #include "RVersion.h"
10 #include "TBuffer.h"
11 
12 #include "TBufferFile.h"
13 
14 #include <iostream>
15 #include <iomanip>
16 #include <stdlib.h>
17 
18 //_HADES_CLASS_DESCRIPTION
20 //
21 // FairParamObj
22 //
23 // Class for parameters stored in binary format in Oracle and used as list
24 // elements in FairParamList::paramList.
25 //
26 // The overloaded constructors and fill-functions accept single values or arrays of type
27 // UChar_t, Int_t, Float_t, Double_t, char_t, Text_t.
28 // The arguments for arrays are
29 // the name of the parameter
30 // the pointer to the array
31 // the length of the array
32 // The data are automatically converted to an UChar_t array.
33 // For classes also the class version is stored, for ROOT classes also the TStreamerInfo.
34 //
35 // -------------------------------------------------------------------------------------
36 //
37 // FairParamList
38 //
39 // Class for the generic Oracle and ASCII interface for parameter containers
40 // derived from HParCond
41 //
42 // The class contains a list to stores objects of type FairParamObj
43 // The list objects store the name, the value, the parameter type and some
44 // additional information depending for the object type.
45 //
46 // All add/addObject functions add an initialized parameter to the list for
47 // writing. The functions create a new list element and copy the data into
48 // this object.
49 // Add functions:
50 // 1. accepted basic types: Int_t, Float_t, Double_t, UChar_t
51 // 2. accepted ROOT arrays: TArrayI, TArrayF, TArrayD, TArrayC
52 // 3. accepted string: Text_t*
53 // This can be any text, for example also numbers in hexadecimal or
54 // scientific format. The number of characters must be specified (default 1).
55 // AddObject function:
56 // Accepts classes derived from TObject.
57 // The persistent data elements are streamed into an UChar_t array using the
58 // class streamer. For ROOT classes, for example histograms, the ROOT streamer
59 // info is stored in an additional binary array.
60 //
61 // All fill/fillObject functions convert the data in the list element back
62 // to the type of the parameter and copies them into the data element in the
63 // initialization process.
64 // 1. Single parameters of basic type:
65 // The functions return kFALSE, if the parameter is not in the list.
66 // 2. Arrays:
67 // a) If the array size is specified (return code Bool_t), the functions return
68 // kFALSE, if the number of data elements in the list objects is not the same.
69 // b) If the array size is not specified (return code Int_t), the array is
70 // recreated with the size of the number of data elements in the list object.
71 // The functions return the number of data elements or 0, if the parameter
72 // was not found.
73 // 3. Classes:
74 // The class version is checked and a warning printed, if it is not identical
75 // with the current version (typically class version of list object higher than
76 // version in the actual parameter container). The class streamer takes care
77 // for backward compatibility. A warning is printed, if the ROOT version is
78 // different from the current version.
79 // The function returns the number of bytes in the list object or 0, if the
80 // parameter was not found in the list.
81 //
83 
84 
87 
88 FairParamObj::FairParamObj(const Text_t* name)
89  :TNamed(name,""),
90  paramValue(NULL),
91  arraySize(0),
92  paramType("UChar_t"),
93  basicType(kFALSE),
94  bytesPerValue(1),
95  classVersion(-1),
96  streamerInfo(NULL),
97  streamerInfoSize(0)
98 {
99 }
100 
102  :TNamed(o),
103  paramValue(NULL),
104  arraySize(o.arraySize),
105  paramType(o.paramType),
106  basicType(o.basicType),
107  bytesPerValue(o.bytesPerValue),
108  classVersion(o.classVersion),
109  streamerInfo(NULL),
110  streamerInfoSize(o.streamerInfoSize)
111 {
112  paramValue=new UChar_t[arraySize];
113  memcpy(paramValue,o.getParamValue(),arraySize);
114  if (streamerInfoSize>0) {
116  }
117 }
118 
120  :TNamed(name,""),
121  paramValue(NULL),
122  arraySize(sizeof(Int_t)),
123  paramType("Int_t"),
124  basicType(kTRUE),
125  bytesPerValue(sizeof(Int_t)),
126  classVersion(-1),
127  streamerInfo(NULL),
128  streamerInfoSize(0)
129 {
130  // Constructor for a Int_t value
131  paramValue=new UChar_t[arraySize];
132  memcpy(paramValue,&value,arraySize);
133 }
134 
135 FairParamObj::FairParamObj(const Text_t* name,Float_t value)
136  :TNamed(name,""),
137  paramValue(NULL),
138  arraySize(sizeof(Float_t)),
139  paramType("Float_t"),
140  basicType(kTRUE),
141  bytesPerValue(sizeof(Float_t)),
142  classVersion(-1),
143  streamerInfo(NULL),
144  streamerInfoSize(0)
145 {
146  // Constructor for a Float_t value
147  paramValue=new UChar_t[arraySize];
148  memcpy(paramValue,&value,arraySize);
149 }
150 
151 FairParamObj::FairParamObj(const Text_t* name,Double_t value)
152  :TNamed(name,""),
153  paramValue(NULL),
154  arraySize(sizeof(Double_t)),
155  paramType("Double_t"),
156  basicType(kTRUE),
157  bytesPerValue(sizeof(Double_t)),
158  classVersion(-1),
159  streamerInfo(NULL),
160  streamerInfoSize(0)
161 {
162  // Constructor for a Double_t value
163  paramValue=new UChar_t[arraySize];
164  memcpy(paramValue,&value,arraySize);
165 }
166 
167 FairParamObj::FairParamObj(const Text_t* name,const Int_t* value,const Int_t nValues)
168  :TNamed(name,""),
169  paramValue(NULL),
170  arraySize(sizeof(Int_t)*nValues),
171  paramType("Int_t"),
172  basicType(kTRUE),
173  bytesPerValue(sizeof(Int_t)),
174  classVersion(-1),
175  streamerInfo(NULL),
176  streamerInfoSize(0)
177 {
178  // Constructor for an array with nValues elements of type Int_t
179  paramValue=new UChar_t[arraySize];
180  memcpy(paramValue,value,arraySize);
181 }
182 
183 
184 FairParamObj::FairParamObj(const Text_t* name,const Float_t* value,const Int_t nValues)
185  :TNamed(name,""),
186  paramValue(NULL),
187  arraySize(sizeof(Float_t)*nValues),
188  paramType("Float_t"),
189  basicType(kTRUE),
190  bytesPerValue(sizeof(Float_t)),
191  classVersion(-1),
192  streamerInfo(NULL),
193  streamerInfoSize(0)
194 {
195  // Constructor for an array with nValues elements of type Float_t
196  paramValue=new UChar_t[arraySize];
197  memcpy(paramValue,value,arraySize);
198 }
199 
200 FairParamObj::FairParamObj(const Text_t* name,const Double_t* value,const Int_t nValues)
201  :TNamed(name,""),
202  paramValue(NULL),
203  arraySize(sizeof(Double_t)*nValues),
204  paramType("Double_t"),
205  basicType(kTRUE),
206  bytesPerValue(sizeof(Double_t)),
207  classVersion(-1),
208  streamerInfo(NULL),
209  streamerInfoSize(0)
210 {
211  // Constructor for an array with nValues elements of type Double_t
212  paramValue=new UChar_t[arraySize];
213  memcpy(paramValue,value,arraySize);
214 }
215 
216 FairParamObj::FairParamObj(const Text_t* name,const Text_t* value)
217  :TNamed(name,""),
218  paramValue(NULL),
219  arraySize(strlen(value)),
220  paramType("Text_t"),
221  basicType(kTRUE),
222  bytesPerValue(sizeof(Char_t)),
223  classVersion(-1),
224  streamerInfo(NULL),
225  streamerInfoSize(0)
226 {
227  // Constructor for a string value
228  paramValue=new UChar_t[arraySize];
229  memcpy(paramValue,value,arraySize);
230 }
231 
232 
233 FairParamObj::FairParamObj(const Text_t* name,const Char_t* value,const Int_t nValues)
234  :TNamed(name,""),
235  paramValue(NULL),
236  arraySize(sizeof(Char_t)*nValues),
237  paramType("Char_t"),
238  basicType(kTRUE),
239  bytesPerValue(sizeof(Char_t)),
240  classVersion(-1),
241  streamerInfo(NULL),
242  streamerInfoSize(0)
243 {
244  // Constructor for an array with nValues elements of type Char_t
245  paramValue=new UChar_t[arraySize];
246  memcpy(paramValue,value,arraySize);
247 }
248 
249 FairParamObj::FairParamObj(const Text_t* name,const UChar_t* value,const Int_t nValues)
250  :TNamed(name,""),
251  paramValue(NULL),
252  arraySize(sizeof(UChar_t)*nValues),
253  paramType("UChar_t"),
254  basicType(kTRUE),
255  bytesPerValue(sizeof(UChar_t)),
256  classVersion(-1),
257  streamerInfo(NULL),
258  streamerInfoSize(0)
259 {
260  paramValue=new UChar_t[arraySize];
261  memcpy(paramValue,value,arraySize);
262 }
263 
265 {
266  // Destructor
267  if (paramValue) {
268  delete [] paramValue;
269  paramValue=0;
270  }
271  if (streamerInfo) {
272  delete [] streamerInfo;
273  streamerInfo=0;
274  }
275 }
276 
277 void FairParamObj::setParamType(const Text_t* t)
278 {
279  // Sets the parameter type. Accepted type names are:
280  // UChar_t (default)
281  // Char_t
282  // Int_t
283  // Float_t
284  // Double_t
285  // Text_t
286  // class name
287  paramType=t;
288  if (strcmp(t,"Char_t")==0) {
289  basicType=kTRUE;
290  bytesPerValue=sizeof(Char_t);
291  } else if (strcmp(t,"Int_t")==0) {
292  basicType=kTRUE;
293  bytesPerValue=sizeof(Int_t);
294  } else if (strcmp(t,"Float_t")==0) {
295  basicType=kTRUE;
296  bytesPerValue=sizeof(Float_t);
297  } else if (strcmp(t,"Double_t")==0) {
298  basicType=kTRUE;
299  bytesPerValue=sizeof(Double_t);
300  } else if (strcmp(t,"Text_t")==0) {
301  basicType=kTRUE;
302  bytesPerValue=sizeof(Char_t);
303  } else {
304  basicType=kFALSE;
305  bytesPerValue=1;
306  }
307  if (basicType==kTRUE) {
308  classVersion=-1;
310  streamerInfo=0;
311  }
312 }
313 
314 UChar_t* FairParamObj::setLength(Int_t l)
315 {
316  // Sets the length of the binary array
317  if (paramValue) { delete [] paramValue; }
318  arraySize=l;
319  if (l>0) {
320  paramValue=new UChar_t[arraySize];
321  } else {
322  paramValue=0;
323  }
324  return paramValue;
325 }
326 
327 void FairParamObj::setParamValue(UChar_t* value,const Int_t length)
328 {
329  // Sets the parameter value (the array is not copied!)
330  if (paramValue) { delete [] paramValue; }
333 }
334 
336 {
337  // Sets the length of the streamer info
338  if (streamerInfo) { delete [] streamerInfo; }
340  if (l>0) {
341  streamerInfo=new UChar_t[streamerInfoSize];
342  } else {
343  streamerInfo=0;
344  }
345  return streamerInfo;
346 }
347 
348 void FairParamObj::setStreamerInfo(UChar_t* array,const Int_t length)
349 {
350  // Sets the streamer info of ROOT classes (the array is not copied!)
351  if (streamerInfo) { delete [] streamerInfo; }
353  streamerInfo=array;
354 }
355 
357 {
358  // Returns the number of values in the array, respectively 1 for classes and strings
359  Int_t n=1;
360  if (basicType) {
362  }
363  return n;
364 }
365 
367 {
368  // Prints the name and type of the parameters, respectively class name and version.
369  // Prints also the numbers for an array of type Int_t, Float_t, Double_t.
370  std::cout<<GetName()<<": ";
371  if (classVersion>=0) {
372  std::cout<<"\n Class Type: "<<paramType.Data()<<"\n Class Version: "
373  <<classVersion<<std::endl;
374  } else if (strcmp(paramType,"Text_t")==0) {
375  TString val((Char_t*)paramValue,arraySize);
376  val.ReplaceAll("\n","\n ");
377  std::cout<<paramType<<"\n "<<val.Data()<<std::endl;
378  } else {
379  Int_t nParams=getNumParams();
380  if (nParams==1) {
381  std::cout<<paramType<<" ";
382  } else {
383  std::cout<<paramType<<" array, nValues: "<<nParams<<"\n ";
384  }
385  if (strcmp(paramType,"Char_t")==0) {
386  Char_t* val=(Char_t*)paramValue;
387  printData(val,nParams);
388  } else if (strcmp(paramType,"Int_t")==0) {
389  Int_t* val=(Int_t*)paramValue;
390  printData(val,nParams);
391  } else if (strcmp(paramType,"Float_t")==0) {
392  Float_t* val=(Float_t*)paramValue;
393  printData(val,nParams);
394  } else if (strcmp(paramType,"Double_t")==0) {
395  Double_t* val=(Double_t*)paramValue;
396  printData(val,nParams);
397  } else {
398  std::cout<<"Type: "<<paramType<<" Array length: "<<arraySize<<std::endl;
399  }
400  }
401 }
402 
403 template <class type> void FairParamObj::printData(type* val, Int_t nParams)
404 {
405  Int_t i=0, k=0;
406  while (k<nParams) {
407  if (i==10) {
408  std::cout<<"\n ";
409  i=0;
410  }
411  std::cout<<val[k]<<" ";
412  i++;
413  k++;
414  if (k>50) {
415  std::cout<<"...";
416  break;
417  }
418  }
419  std::cout<<std::endl;
420 }
421 
422 //-----------------------------------------------------------------------------------
423 
425  :TObject(),
426  paramList(new TList()),
427  fLogger(FairLogger::GetLogger())
428 {
429  // Constructor
430  // paramList=new TList;
431 }
432 
434 {
435  // Destructor
436  if (paramList) {
437  paramList->Delete();
438  delete paramList;
439  paramList=0;
440  }
441 }
442 
444 {
445  // Adds a FairParamObj object to the list
446  paramList->Add(new FairParamObj(p));
447 }
448 
449 void FairParamList::add(const Text_t* name,const Text_t* value)
450 {
451  // Adds a string parameter to the list
452  // name = name of the parameter
453  // value = string value
454  paramList->Add(new FairParamObj(name,value));
455 }
456 
457 void FairParamList::add(const Text_t* name,const Int_t value)
458 {
459  // Adds a parameter of type Int_t to the list
460  paramList->Add(new FairParamObj(name,value));
461 }
462 
463 void FairParamList::add(const Text_t* name,const Float_t value)
464 {
465  // Adds a parameter of type Float_t to the list
466  paramList->Add(new FairParamObj(name,value));
467 }
468 
469 void FairParamList::add(const Text_t* name,const Double_t value)
470 {
471  // Adds a parameter of type Double_t to the list
472  paramList->Add(new FairParamObj(name,value));
473 }
474 
475 void FairParamList::add(const Text_t* name,TArrayI& value)
476 {
477  // Adds a parameter of type TArrayI to the list
478  paramList->Add(new FairParamObj(name,value.GetArray(),value.GetSize()));
479 }
480 
481 void FairParamList::add(const Text_t* name,TArrayC& value)
482 {
483  // Adds a parameter of type TArrayC to the list
484  paramList->Add(new FairParamObj(name,value.GetArray(),value.GetSize()));
485 }
486 
487 void FairParamList::add(const Text_t* name,TArrayF& value)
488 {
489  // Adds a parameter of type TArrayF to the list
490  paramList->Add(new FairParamObj(name,value.GetArray(),value.GetSize()));
491 }
492 
493 void FairParamList::add(const Text_t* name,TArrayD& value)
494 {
495  // Adds a parameter of type TArrayD to the list
496  paramList->Add(new FairParamObj(name,value.GetArray(),value.GetSize()));
497 }
498 
499 void FairParamList::add(const Text_t* name,const UChar_t* values,const Int_t nValues)
500 {
501  // Adds a binary array of size nValues to the list
502  paramList->Add(new FairParamObj(name,values,nValues));
503 }
504 
505 void FairParamList::add(const Text_t* name,const Int_t* values,const Int_t nValues)
506 {
507  // Adds an array of type Int_t and of size nValues as binary to the list
508  paramList->Add(new FairParamObj(name,values,nValues));
509 }
510 
511 void FairParamList::add(const Text_t* name,const Float_t* values,const Int_t nValues)
512 {
513  // Adds an array of type Float_t and of size nValues as binary to the list
514  paramList->Add(new FairParamObj(name,values,nValues));
515 }
516 
517 void FairParamList::add(const Text_t* name,const Double_t* values,const Int_t nValues)
518 {
519  // Adds an array of type Double_t and of size nValues as binary to the list
520  paramList->Add(new FairParamObj(name,values,nValues));
521 }
522 
523 void FairParamList::addObject(const Text_t* name,TObject* obj)
524 {
525  // Adds a TObject to the list, sets the class version and the streamer info for
526  // ROOT classes
527  if (!obj) { return; }
528  FairParamObj* o=new FairParamObj(name);
529  o->setParamType(obj->IsA()->GetName());
530  o->setClassVersion(obj->IsA()->GetClassVersion());
531  TFile* filesave=gFile;
532  FairParamTFile* paramFile=new FairParamTFile();
533  gFile=paramFile;
534  const Int_t bufsize=10000;
535 
536  TBufferFile* buffer=new TBufferFile(TBuffer::kWrite,bufsize);
537 
538  buffer->SetParent(paramFile);
539  buffer->MapObject(obj);
540  obj->Streamer(*buffer);
541  Int_t len=buffer->Length();
542  Char_t* buf=new char[len];
543  memcpy(buf,buffer->Buffer(),len);
544  o->setParamValue((UChar_t*)buf,len);
545  TArrayC* fClassIndex=paramFile->GetClassIndex();
546  if (fClassIndex&&fClassIndex->fArray[0] != 0) {
547  TIter next(gROOT->GetListOfStreamerInfo());
548  TStreamerInfo* info;
549  TList list;
550  while ((info=(TStreamerInfo*)next())) {
551  Int_t uid=info->GetNumber();
552  if (fClassIndex->fArray[uid]) { list.Add(info); }
553  }
554  if (list.GetSize()>0) {
555  list.Sort();
556  fClassIndex->fArray[0]=2; //to prevent adding classes in TStreamerInfo::TagFile
557 
558  TBufferFile* infoBuffer=new TBufferFile(TBuffer::kWrite,bufsize);
559 
560  infoBuffer->MapObject(&list);
561  list.Streamer(*infoBuffer);
562  Int_t infolen=infoBuffer->Length();
563  Char_t* infobuf=new char[infolen];
564  memcpy(infobuf,infoBuffer->Buffer(),infolen);
565  o->setStreamerInfo((UChar_t*)infobuf,infolen);
566  delete infoBuffer;
567  } else {
568  o->setStreamerInfo(0,0);
569  }
570  }
571  fClassIndex->fArray[0]=0;
572  delete paramFile;
573  paramList->Add(o);
574  delete buffer;
575  gFile=filesave;
576 }
577 
579 {
580  // Prints the parameter list including values
581  TIter next(paramList);
582  FairParamObj* o;
583  while ((o=(FairParamObj*)next())!=0) { o->print(); }
584 }
585 
586 Bool_t FairParamList::fill(const Text_t* name,Text_t* value,const Int_t length)
587 {
588  // Copies the data from the list object into the parameter value of type string
589  FairParamObj* o=(FairParamObj*)paramList->FindObject(name);
590  if (value==0) { return kFALSE; }
591  if (o!=0 && strcmp(o->getParamType(),"Text_t")==0) {
592  Int_t l=o->getLength();
593  if (l<length-1) {
594  memcpy(value,(Char_t*)o->getParamValue(),l);
595  value[l]='\0';
596  return kTRUE;
597  } else {
598  fLogger->Error(MESSAGE_ORIGIN,"char array too small");
599  // Error("FairParamList::fill(const Text_t*,Text_t*)","char array too small");
600  }
601  }
602  fLogger->Error(MESSAGE_ORIGIN,"Could not find parameter %s", name);
603  // Error("FairParamList::fill \nNot found: %s",name);
604  return kFALSE;
605 }
606 
607 Bool_t FairParamList::fill(const Text_t* name,UChar_t* values,const Int_t nValues)
608 {
609  // Copies the data from the list object into the parameter array of type UChar_t of size nValues.
610  // The function returns an error, if the array size of the list object is not equal
611  // to nValues.
612  if (values==0) { return kFALSE; }
613  FairParamObj* o=(FairParamObj*)paramList->FindObject(name);
614  if (o!=0 && strcmp(o->getParamType(),"UChar_t")==0) {
615  Int_t n=o->getLength();
616  if (n==nValues) {
617  memcpy(values,o->getParamValue(),n);
618  return kTRUE;
619  } else {
620  fLogger->Error(MESSAGE_ORIGIN,"Different array sizes for parameter %s",name);
621  // Error("FairParamList::fill \nDifferent array sizes for parameter %s",name);
622  return kFALSE;
623  }
624  }
625  fLogger->Error(MESSAGE_ORIGIN,"Could not find parameter %s", name);
626  // Error("FairParamList::fill \nNot found: %s",name);
627  return kFALSE;
628 }
629 
630 Bool_t FairParamList::fill(const Text_t* name,Int_t* values,const Int_t nValues)
631 {
632  // Copies the data from the list object into the parameter array of type Int_t.
633  // The function returns an error, if the array size of the list object is not equal
634  // to nValues.
635  if (values==0) { return kFALSE; }
636  FairParamObj* o=(FairParamObj*)paramList->FindObject(name);
637  if (o!=0 && strcmp(o->getParamType(),"Int_t")==0) {
638  Int_t l=o->getLength();
639  Int_t n=o->getNumParams();
640  if (n==nValues) {
641  memcpy(values,o->getParamValue(),l);
642  return kTRUE;
643  } else {
644  fLogger->Error(MESSAGE_ORIGIN,"Different array sizes for parameter %s",name);
645  // Error("FairParamList::fill \nDifferent array sizes for parameter %s",name);
646  return kFALSE;
647  }
648  }
649  fLogger->Error(MESSAGE_ORIGIN,"Could not find parameter %s", name);
650  // Error("FairParamList::fill \nNot found: %s",name);
651  return kFALSE;
652 }
653 
654 Bool_t FairParamList::fill(const Text_t* name,Float_t* values,const Int_t nValues)
655 {
656  // Copies the data from the list object into the parameter array of type Float_t.
657  // The function returns an error, if the array size of the list object is not equal
658  // to nValues.
659  if (values==0) { return kFALSE; }
660  FairParamObj* o=(FairParamObj*)paramList->FindObject(name);
661  if (o!=0 && strcmp(o->getParamType(),"Float_t")==0) {
662  Int_t l=o->getLength();
663  Int_t n=o->getNumParams();
664  if (n==nValues) {
665  memcpy(values,o->getParamValue(),l);
666  return kTRUE;
667  } else {
668  fLogger->Error(MESSAGE_ORIGIN,"Different array sizes for parameter %s",name);
669  // Error("FairParamList::fill \nDifferent array sizes for parameter %s",name);
670  return kFALSE;
671  }
672  }
673  fLogger->Error(MESSAGE_ORIGIN,"Could not find parameter %s", name);
674  // Error("FairParamList::fill \nNot found: %s",name);
675  return kFALSE;
676 }
677 
678 Bool_t FairParamList::fill(const Text_t* name,Double_t* values,const Int_t nValues)
679 {
680  // Copies the data from the list object into the parameter array of type Double_t.
681  // The function returns an error, if the array size of the list object is not equal
682  // to nValues.
683  if (values==0) { return kFALSE; }
684  FairParamObj* o=(FairParamObj*)paramList->FindObject(name);
685  if (o!=0 && strcmp(o->getParamType(),"Double_t")==0) {
686  Int_t l=o->getLength();
687  Int_t n=o->getNumParams();
688  if (n==nValues) {
689  memcpy(values,o->getParamValue(),l);
690  return kTRUE;
691  } else {
692  fLogger->Error(MESSAGE_ORIGIN,"Different array sizes for parameter %s",name);
693  // Error("FairParamList::fill \nDifferent array sizes for parameter %s",name);
694  return kFALSE;
695  }
696  }
697  fLogger->Error(MESSAGE_ORIGIN,"Could not find parameter %s", name);
698  // Error("FairParamList::fill \nNot found: %s",name);
699  return kFALSE;
700 }
701 
702 Bool_t FairParamList::fill(const Text_t* name,TArrayI* value)
703 {
704  // Copies the data from the list object into the parameter value of type TArrayI
705  // The array is resized, if the number of data is different.
706  if (value==0) { return kFALSE; }
707  FairParamObj* o=(FairParamObj*)paramList->FindObject(name);
708  if (o!=0 && strcmp(o->getParamType(),"Int_t")==0) {
709  Int_t l=o->getLength();
710  Int_t n=o->getNumParams();
711  if (value->GetSize()!=n) { value->Set(n); }
712  memcpy(value->GetArray(),o->getParamValue(),l);
713  return kTRUE;
714  }
715  fLogger->Error(MESSAGE_ORIGIN,"Could not find parameter %s", name);
716  // Error("FairParamList::fill \nNot found: %s",name);
717  return kFALSE;
718 }
719 
720 Bool_t FairParamList::fill(const Text_t* name,TArrayC* value)
721 {
722  // Copies the data from the list object into the parameter value of type TArrayC
723  // The array is resized, if the number of data is different.
724  if (value==0) { return kFALSE; }
725  FairParamObj* o=(FairParamObj*)paramList->FindObject(name);
726  if (o!=0 && strcmp(o->getParamType(),"Char_t")==0) {
727  Int_t l=o->getLength();
728  if (value->GetSize()!=l) { value->Set(l); }
729  memcpy(value->GetArray(),o->getParamValue(),l);
730  return kTRUE;
731  }
732  fLogger->Error(MESSAGE_ORIGIN,"Could not find parameter %s", name);
733  // Error("FairParamList::fill \nNot found: %s",name);
734  return kFALSE;
735 }
736 
737 Bool_t FairParamList::fill(const Text_t* name,TArrayF* value)
738 {
739  // Copies the data from the list object into the parameter value of type TArrayF
740  // The array is resized, if the number of data is different.
741  if (value==0) { return kFALSE; }
742  FairParamObj* o=(FairParamObj*)paramList->FindObject(name);
743  if (o!=0 && strcmp(o->getParamType(),"Float_t")==0) {
744  Int_t l=o->getLength();
745  Int_t n=o->getNumParams();
746  if (value->GetSize()!=n) { value->Set(n); }
747  memcpy(value->GetArray(),o->getParamValue(),l);
748  return kTRUE;
749  }
750  fLogger->Error(MESSAGE_ORIGIN,"Could not find parameter %s", name);
751  // Error("FairParamList::fill \nNot found: %s",name);
752  return kFALSE;
753 }
754 
755 Bool_t FairParamList::fill(const Text_t* name,TArrayD* value)
756 {
757  // Copies the data from the list object into the parameter value of type TArrayD
758  // The array is resized, if the number of data is different.
759  if (value==0) { return kFALSE; }
760  FairParamObj* o=(FairParamObj*)paramList->FindObject(name);
761  if (o!=0 && strcmp(o->getParamType(),"Double_t")==0) {
762  Int_t l=o->getLength();
763  Int_t n=o->getNumParams();
764  if (value->GetSize()!=n) { value->Set(n); }
765  memcpy(value->GetArray(),o->getParamValue(),l);
766  return kTRUE;
767  }
768  fLogger->Error(MESSAGE_ORIGIN,"Could not find parameter %s", name);
769  // Error("FairParamList::fill \nNot found: %s",name);
770  return kFALSE;
771 }
772 
773 Int_t FairParamList::replace(const Text_t* name,UChar_t* values)
774 {
775  // Copies the data from the list object into the parameter array of type UChar_t.
776  // Recreates the array, if existing, and returns the number of array elements.
777  FairParamObj* o=(FairParamObj*)paramList->FindObject(name);
778  if (o!=0 && strcmp(o->getParamType(),"UChar_t")==0) {
779  Int_t l=o->getLength();
780  if (values) { delete values; }
781  values=new UChar_t[l];
782  memcpy(values,o->getParamValue(),l);
783  return l;
784  }
785  fLogger->Error(MESSAGE_ORIGIN,"Could not find parameter %s", name);
786  // Error("FairParamList::fill \nNot found: %s",name);
787  return 0;
788 }
789 
790 Int_t FairParamList::replace(const Text_t* name,Int_t* values)
791 {
792  // Copies the data from the list object into the parameter array of type Int_t.
793  // Recreates the array, if existing, and returns the number of array elements.
794  FairParamObj* o=(FairParamObj*)paramList->FindObject(name);
795  if (o!=0 && strcmp(o->getParamType(),"Int_t")==0) {
796  Int_t l=o->getLength();
797  Int_t n=o->getNumParams();
798  if (values) { delete values; }
799  values=new Int_t[n];
800  memcpy(values,o->getParamValue(),l);
801  return n;
802  }
803  fLogger->Error(MESSAGE_ORIGIN,"Could not find parameter %s", name);
804  // Error("FairParamList::fill \nNot found: %s",name);
805  return 0;
806 }
807 
808 Int_t FairParamList::replace(const Text_t* name,Float_t* values)
809 {
810  // Copies the data from the list object into the parameter array of type Float_t.
811  // Recreates the array, if existing, and returns the number of array elements.
812  FairParamObj* o=(FairParamObj*)paramList->FindObject(name);
813  if (o!=0 && strcmp(o->getParamType(),"Float_t")==0) {
814  Int_t l=o->getLength();
815  Int_t n=o->getNumParams();
816  if (values) { delete values; }
817  values=new Float_t[n];
818  memcpy(values,o->getParamValue(),l);
819  return n;
820  }
821  fLogger->Error(MESSAGE_ORIGIN,"Could not find parameter %s", name);
822  // Error("FairParamList::fill \nNot found: ",name);
823  return 0;
824 }
825 
826 Int_t FairParamList::replace(const Text_t* name,Double_t* values)
827 {
828  // Copies the data from the list object into the parameter array of type Double_t.
829  // Recreates the array, if existing, and returns the number of array elements.
830  FairParamObj* o=(FairParamObj*)paramList->FindObject(name);
831  if (o!=0 && strcmp(o->getParamType(),"Double_t")==0) {
832  Int_t l=o->getLength();
833  Int_t n=o->getNumParams();
834  if (values) { delete values; }
835  values=new Double_t[n];
836  memcpy(values,o->getParamValue(),l);
837  return n;
838  }
839  fLogger->Error(MESSAGE_ORIGIN,"Could not find parameter %s", name);
840  // Error("FairParamList::fill \nNot found: %s",name);
841  return 0;
842 }
843 
844 Bool_t FairParamList::fillObject(const Text_t* name,TObject* obj)
845 {
846  // Fills the object obj (must exist!) via the Streamer and returns the class version.
847  // Prints a warning if the class version in the list objects differs from the actual
848  // class version.
849  if (!obj) { return 0; }
850  FairParamObj* o=(FairParamObj*)paramList->FindObject(name);
851  if (o!=0 && strcmp(o->getParamType(),obj->IsA()->GetName())==0) {
852  if (o->getClassVersion()!=obj->IsA()->GetClassVersion()) {
853  fLogger->Warning(MESSAGE_ORIGIN,"Read Class Version = %i does not match actual version = %i",o->getClassVersion(),obj->IsA()->GetClassVersion());
854  }
855  // Warning("FairParamList::fill",
856  // "\n Read Class Version = %i does not match actual version = %i",
857  // o->getClassVersion(),obj->IsA()->GetClassVersion());
858  TFile* filesave=gFile;
859  gFile=0;
860  TBufferFile* buf=0;
861 
862  Int_t len=o->getStreamerInfoSize();
863  if (len>0&&o->getStreamerInfo()!=0) {
864  buf=new TBufferFile(TBuffer::kRead,len);
865  memcpy(buf->Buffer(),(Char_t*)o->getStreamerInfo(),len);
866  buf->SetBufferOffset(0);
867  TList list;
868  buf->MapObject(&list);
869  list.Streamer(*buf);
870  delete buf;
871  TStreamerInfo* info;
872  TIter next(&list);
873  while ((info = (TStreamerInfo*)next())) {
874  if (info->IsA() != TStreamerInfo::Class()) {
875  fLogger->Warning(MESSAGE_ORIGIN,"Not a TStreamerInfo object");
876  // Warning("FairParamList::fill","not a TStreamerInfo object");
877  continue;
878  }
879  info->BuildCheck();
880  }
881  list.Clear(); //this will delete all TStreamerInfo objects with kCanDelete
882  }
883  len=o->getLength();
884  buf=new TBufferFile(TBuffer::kRead,len);
885  memcpy(buf->Buffer(),(Char_t*)o->getParamValue(),len);
886  buf->SetBufferOffset(0);
887  buf->MapObject(obj);
888  obj->Streamer(*buf);
889  delete buf;
890  gFile=filesave;
891  return len;
892  }
893  fLogger->Error(MESSAGE_ORIGIN,"Could not find parameter %s", name);
894  // Error("FairParamList::fill \nNot found: %s",name);
895  return 0;
896 }