source: trunk/MagicSoft/Mars/mdata/MDataMember.cc@ 1327

Last change on this file since 1327 was 1327, checked in by tbretz, 23 years ago
*** empty log message ***
File size: 4.0 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC Analysis and Reconstruction
5! * Software. It is distributed to you in the hope that it can be a useful
6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
7! * It is distributed WITHOUT ANY WARRANTY.
8! *
9! * Permission to use, copy, modify and distribute this software and its
10! * documentation for any purpose is hereby granted without fee,
11! * provided that the above copyright notice appear in all copies and
12! * that both that copyright notice and this permission notice appear
13! * in supporting documentation. It is provided "as is" without express
14! * or implied warranty.
15! *
16!
17!
18! Author(s): Thomas Bretz 04/2002 <mailto:tbretz@uni-sw.gwdg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2002
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MDataMember
28//
29// This objects corresponds to the data member of another object.
30// You can either specify the object as a string, eg "MHillas.fWidth"
31// where MHillas is the name of the container in the parameterlist
32// and fWidth is it's data member, or you can specify it by giving
33// the pointer corresponding to the instance of your object and
34// a TMethodCall pointer corresponding to the Member function returning
35// the requested value.
36//
37/////////////////////////////////////////////////////////////////////////////
38
39#include "MDataMember.h"
40
41#include <TMethodCall.h>
42
43#include "MLog.h"
44#include "MLogManip.h"
45
46#include "MParList.h"
47
48ClassImp(MDataMember);
49
50// --------------------------------------------------------------------------
51//
52// obj is a pointer to the instance of your class from which the data
53// should be requested. TMethodCall (s. root dox) is a pointer
54// to a TMethodCall object which should be the getter function for
55// the data you want to get.
56//
57MDataMember::MDataMember(MParContainer *obj, TMethodCall *call)
58{
59 fObject = obj;
60 fCall = call;
61}
62
63// --------------------------------------------------------------------------
64//
65// returns the value you requested
66//
67Double_t MDataMember::GetValue() const
68{
69 if (!fCall)
70 return 0;
71
72 switch (fCall->ReturnType())
73 {
74 case TMethodCall::kLong:
75 Long_t l;
76 fCall->Execute(fObject, l);
77 return (Double_t)l;
78
79 case TMethodCall::kDouble:
80 Double_t v;
81 fCall->Execute(fObject, v);
82 return v;
83
84 default:
85 *fLog << err << "DataMember " << fName << " of ";
86 *fLog << fObject->GetName() << " neither int nor float... abort." << endl;
87 return 0;
88 }
89}
90
91// --------------------------------------------------------------------------
92//
93// If a string was given PreProcess try to resolv the object name and
94// tries to get it from the parlist. And also tries to resolve
95// the data member (variable) name you requested and tries to get a
96// corresponding TMethodCall from the root Dictionary.
97// Remark: If your Data Member is called fDataMember the corresponding
98// getter Method in your class must be calles fDataMember
99//
100Bool_t MDataMember::PreProcess(const MParList *plist)
101{
102 if (fCall)
103 return kTRUE;
104
105 TString cname(fName);
106 TString mname(fName);
107
108 const char *dot = strrchr(cname, '.');
109
110 if (dot)
111 {
112 const int pos = dot-cname;
113
114 cname.Remove(pos);
115 mname.Remove(0, pos+1);
116 }
117
118 fObject = (MParContainer*)plist->FindObject(cname);
119 if (!fObject)
120 {
121 *fLog << err << "Object '" << cname << "' not in parameter list... aborting." << endl;
122 return kFALSE;
123 }
124
125 fCall = fObject->GetterMethod(mname);
126
127 return fCall ? kTRUE : kFALSE;
128}
129
130// --------------------------------------------------------------------------
131//
132// Print the name of the data member without an CR.
133//
134void MDataMember::Print(Option_t *opt) const
135{
136 *fLog << fName << flush;
137}
138
Note: See TracBrowser for help on using the repository browser.