EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FairTSQLObject.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file FairTSQLObject.cxx
1 /***************************************
2  * Author: M.Babai (M.Babai@rug.nl) *
3  * License: *
4  * Version: *
5  ***************************************/
6 #include "FairTSQLObject.h"
7 
8 // ROOT
9 #include "TClass.h"
10 #include "TList.h"
11 #include "TDataMember.h"
12 #include "TDictionary.h"
13 #include "TMethod.h"
14 #include "TMethodCall.h"
15 
17 
18 
22  : TObject(),
23  fCurCls(0),
24  fcurDict(0),
25  fMemberList(0),
26  fMethodList(0)
27 {}
28 
36 {}
37 
44 {
45  InitCurClass();
46  return ( *(this->fCurCls) );
47 }
48 
55 {
56  InitMemList();
57  return ( *(this->fMemberList) );
58 }
59 
67 {
69  return (*fMethodList);
70 }
71 
76 {
77  if(!fcurDict) {
78  fcurDict = TDictionary::GetDictionary(this->GetName());
79  }
80  return (*fcurDict);
81 }
82 
91 std::string* FairTSQLObject::GetMemberTypeName(std::string const& mName)
92 {
93  return (GetMemberTypeName(mName.c_str()));
94 }
95 
104 std::string* FairTSQLObject::GetMemberTypeName(char const* mName)
105 {
106  std::string* out;
107  // Init Member list.
108  InitMemList();
109 
110  // Find the object with the given name in the list
111  TObject* tmpOb = fMemberList->FindObject(mName);
112 
113  if(tmpOb) { //Found object, fetch type
114  TDataMember* dm = fCurCls->GetDataMember(tmpOb->GetName());
115  if(dm) {
116  out = new std::string(dm->GetTrueTypeName());
117  } else {
118  out = new std::string("UNKNOWN_OBJECT");
119  }
120  } else { // Did not find the object in the list
121  out = new std::string("UNKNOWN_OBJECT");
122  }
123  return out;
124 }
125 
135 {
136  FairDBObjectMemberTypes curType;
137  std::string* tmpName = GetMemberTypeName(mName);
138 
139  if( (*tmpName) == "char") {
140  curType = CHAR;
141  } else if( (*tmpName) == "int") {
142  curType = INT;
143  } else if((*tmpName) == "unsigned int") {
144  curType = UINT;
145  } else if( (*tmpName) == "float") {
146  curType = FLOAT;
147  } else if( (*tmpName) == "double") {
148  curType = DOUBLE;
149  } else if( (*tmpName) == "TArrayI") {
150  curType = INT_ARRAY;
151  } else if( (*tmpName) == "TArrayI*" ) {
152  curType = INT_ARRAY_PTR;
153  } else if( (*tmpName) == "TArrayF" ) {
154  curType = FLOAT_ARRAY;
155  } else if ((*tmpName) == "TArrayF*") {
156  curType = FLOAT_ARRAY_PTR;
157  } else if( (*tmpName) == "TArrayD" ) {
158  curType = DOUBLE_ARRAY;
159  } else if ( (*tmpName) == "TArrayD*" ) {
160  curType = DOUBLE_ARRAY_PTR;
161  } else if ((*tmpName) == "UNKNOWN_OBJECT") {
162  curType = UNKNOWN_TYPE;
163  } else {
164  curType = COMPLEX_TYPE;
165  }
166  // Delete temporary string.
167  delete tmpName;
168  tmpName = 0;
169 
170  return curType;
171 }
172 
175 {
176  if(!fCurCls) {
177  fCurCls = this->IsA();
178  }
179 }
180 
183 {
184  InitCurClass();
185  if(!fMemberList) {
186  fMemberList = fCurCls->GetListOfDataMembers();
187  }
188 }
189 
192 {
193  InitCurClass();
194  if(!fMethodList) {
195  fMethodList = fCurCls->GetListOfMethods();
196  }
197 }
198 
206 TMethod* FairTSQLObject::GetMethod(std::string const& methodName)
207 {
208  InitMethodList();
209  TMethod* mt = (TMethod*) fMethodList->FindObject(methodName.c_str());
210  return (mt);
211 }
212 
219 std::string* FairTSQLObject::GetMethodPrototype(std::string const& methodName)
220 {
221  InitMethodList();
222  TMethod* mt = (TMethod*) fMethodList->FindObject(methodName.c_str());
223 
224  std::string* out;
225 
226  if(mt) {
227  out = new std::string(mt->GetPrototype());
228  } else {
229  out = new std::string("UNKNOWN_METHOD");
230  }
231  return out;
232 }
233 
240 std::string* FairTSQLObject::GetMethodReturnTypeName(std::string const& methodName)
241 {
242  return GetMethodReturnTypeName(methodName.c_str());
243 }
244 
251 std::string* FairTSQLObject::GetMethodReturnTypeName(char const* methodName)
252 {
253  InitMethodList();
254  TMethod* mt = (TMethod*) fMethodList->FindObject(methodName);
255 
256  std::string* out;
257 
258  if(mt) {
259  out = new std::string(mt->GetReturnTypeName());
260  } else {
261  out = new std::string("UNKNOWN_METHOD");
262  }
263  return out;
264 }
265 
273 TMethodCall* FairTSQLObject::GetDataMemberGetter(std::string const& mName)
274 {
275  TMethodCall* ret = 0;// Temporary object
276  TClass& curcls = GetCurCls();
277  TDataMember* mem = curcls.GetDataMember(mName.c_str());
278 
279  if(mem) {
280  ret = mem->GetterMethod();
281  }
282  return ret;
283 }
284 
293 {
294  // Find object type
296 
297  // Create return value and set the type
298  FairDBObjectMemberValue* returnVal = new FairDBObjectMemberValue(type);
299  //(*returnVal).type = type;
300 
301  // Get the getter method.
302  TMethodCall* getMeth = GetDataMemberGetter(mName);
303 
304  if( (!getMeth) || (!getMeth->IsValid()) ) {
305  std::cerr << "<ERROR> Could not initialize getter method for "<< mName
306  << " Type is set to UNKNOWN_TYPE;" << std::endl;
307  (*returnVal).type = UNKNOWN_TYPE;
308  }
309 
310  std::string typeName = ", Type = ";
311  // Cast the object
312  char* tmpChar = 0;
313  long tmpLong = 0;
314  double tmpDouble = 0.00;
315 
316  switch( (*returnVal).type ) {
317  case CHAR:
318  typeName += "CHAR \n";
319  getMeth->Execute(this, "", &tmpChar);
320  (*returnVal).c_val = (*tmpChar);
321  break;
322  case INT:
323  typeName += "INT \n";
324  getMeth->Execute(this, "", tmpLong);
325  (*returnVal).i_val = static_cast<int>(tmpLong);
326  break;
327  case UINT:
328  typeName += "UNSIGNED INT \n";
329  getMeth->Execute(this, "", tmpLong);
330  (*returnVal).Ui_Val = tmpLong;
331  break;
332  case FLOAT:
333  typeName += "FLOAT \n";
334  getMeth->Execute(this, "", tmpDouble);
335  (*returnVal).f_val = static_cast<float>(tmpDouble);
336  break;
337  case DOUBLE:
338  typeName += "DOUBLE \n";
339  getMeth->Execute(this, "", tmpDouble);
340  (*returnVal).d_val = tmpDouble;
341  break;
342  case INT_ARRAY:
343  typeName += "INT_ARRAY \n";
344  getMeth->Execute(this, "", &tmpChar);
345  //(*returnVal).I_Ar_val = (TArrayI*)(tmpChar);
346  (*returnVal).I_Ar_val = reinterpret_cast<TArrayI*>(tmpChar);
347  break;
348  case INT_ARRAY_PTR:
349  typeName += "INT_ARRAY* \n";
350  getMeth->Execute(this, "", &tmpChar);
351  //(*returnVal).I_Ar_val = (TArrayI*)(tmpChar);
352  (*returnVal).I_Ar_val = reinterpret_cast<TArrayI*>(tmpChar);
353  break;
354  case FLOAT_ARRAY:
355  typeName += "FLOAT_ARRAY \n";
356  getMeth->Execute(this, "", &tmpChar);
357  //(*returnVal).F_Ar_val = (TArrayF*)(tmpChar);
358  (*returnVal).F_Ar_val = reinterpret_cast<TArrayF*>(tmpChar);
359  break;
360  case FLOAT_ARRAY_PTR:
361  typeName += "FLOAT_ARRAY* \n";
362  getMeth->Execute(this, "", &tmpChar);
363  //(*returnVal).F_Ar_val = (TArrayF*)(tmpChar);
364  (*returnVal).F_Ar_val = reinterpret_cast<TArrayF*>(tmpChar);
365  break;
366  case DOUBLE_ARRAY:
367  typeName += "DOUBLE_ARRAY \n";
368  getMeth->Execute(this, "", &tmpChar);
369  //(*returnVal).D_Ar_val = (TArrayD*)(tmpChar);
370  (*returnVal).D_Ar_val = reinterpret_cast<TArrayD*>(tmpChar);
371  break;
372  case DOUBLE_ARRAY_PTR:
373  typeName += "DOUBLE_ARRAY* \n";
374  getMeth->Execute(this, "", &tmpChar);
375  //(*returnVal).D_Ar_val = (TArrayD*)(tmpChar);
376  (*returnVal).D_Ar_val = reinterpret_cast<TArrayD*>(tmpChar);
377  break;
378  case COMPLEX_TYPE:
379  typeName += "COMPLEX_TYPE \n";
380  std::cerr << "<Warning> Type = COMPLEX_TYPE. Not implemented yet.\n";
381  break;
382  default:
383  typeName += "UNKNOWN_TYPE \n";
384  std::cerr << "<ERROR> Type = UNKNOWN_TYPE. Do not know how to deal with this one. \n";
385  }
386  std::cout << "Par Name = " << mName << typeName;
387  return returnVal;
388 }