EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EicPOD.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file EicPOD.cc
1 
2 #include <TROOT.h>
3 #include <TClass.h>
4 #include <TRealData.h>
5 #include <TDataMember.h>
6 
7 #include <EicPOD.h>
8 
9 // ---------------------------------------------------------------------------------------
10 
11 //
12 // Follow the logic of EicGeoParData::Print(); do not care about performance here;
13 //
14 
15 int EicPOD::SetDoubleVariable(const char *vname, double value) const
16 {
17  // Well, assume it is either 'double' or 'Double_t';
18  auto addr = GetVariableOffset(vname, "Double_t");
19  if (!addr) {
20  addr = GetVariableOffset(vname, "double");
21 
22  if (!addr) return -1;
23  } //if
24 
25  *(Double_t*)addr = value;
26 
27  return 0;
28 } // EicPOD::SetDoubleVariable()
29 
30 double EicPOD::GetDoubleVariable(const char *vname) const
31 {
32  auto addr = GetVariableOffset(vname, "Double_t");
33  if (!addr) addr = GetVariableOffset(vname, "double");
34 
35  return (addr ? *(Double_t*)addr : 0.0);
36 } // EicPOD::GetDoubleVariable()
37 
38 // ---------------------------------------------------------------------------------------
39 
40 int EicPOD::SetTStringVariable(const char *vname, const char *value) const
41 {
42  auto addr = GetVariableOffset(vname, "TString");
43  if (!addr) return -1;
44 
45  *(TString*)addr = value;
46 
47  return 0;
48 } // EicPOD::SetTStringVariable()
49 
50 const TString *EicPOD::GetTStringVariable(const char *vname) const
51 {
52  auto addr = GetVariableOffset(vname, "TString");
53 
54  return (addr ? (TString*)addr : 0);
55 } // EicPOD::GetTStringVariable()
56 
57 // ---------------------------------------------------------------------------------------
58 
59 char *EicPOD::GetVariableOffset(const char *vname, const char *vtype) const
60 {
61  TList *dataList = gROOT->GetClass(ClassName())->GetListOfRealData();
62  TIter next(dataList);
63 
64  TRealData *data;
65  while ((data=(TRealData*)next())) {
66  TDataMember *member = data->GetDataMember();
67 
68  if (!strcmp(data->GetName(), vname) &&
69  !strcmp(member->GetFullTypeName(), vtype))
70  return (char*)this + member->GetOffset();
71  } //while
72 
73  return 0;
74 } // EicPOD::GetVariableOffset()
75 
76 // ---------------------------------------------------------------------------------------
77