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

Last change on this file since 1339 was 1334, checked in by tbretz, 24 years ago
*** empty log message ***
File size: 4.1 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 {
71 *fLog << err << "No TMethodCall for " << fName << " of ";
72 *fLog << fObject->GetName() << " available... returning 0." << endl;
73 return 0;
74 }
75
76 switch (fCall->ReturnType())
77 {
78 case TMethodCall::kLong:
79 Long_t l;
80 fCall->Execute(fObject, l);
81 return (Double_t)l;
82
83 case TMethodCall::kDouble:
84 Double_t v;
85 fCall->Execute(fObject, v);
86 return v;
87
88 default:
89 *fLog << err << "DataMember " << fName << " of ";
90 *fLog << fObject->GetName() << " neither int nor float... returning 0." << endl;
91 return 0;
92 }
93}
94
95// --------------------------------------------------------------------------
96//
97// If a string was given PreProcess try to resolv the object name and
98// tries to get it from the parlist. And also tries to resolve
99// the data member (variable) name you requested and tries to get a
100// corresponding TMethodCall from the root Dictionary.
101// Remark: If your Data Member is called fDataMember the corresponding
102// getter Method in your class must be calles fDataMember
103//
104Bool_t MDataMember::PreProcess(const MParList *plist)
105{
106 if (fCall)
107 return kTRUE;
108
109 TString cname(fName);
110 TString mname(fName);
111
112 const char *dot = strrchr(cname, '.');
113
114 if (dot)
115 {
116 const int pos = dot-cname;
117
118 cname.Remove(pos);
119 mname.Remove(0, pos+1);
120 }
121
122 fObject = (MParContainer*)plist->FindObject(cname);
123 if (!fObject)
124 {
125 *fLog << err << "Object '" << cname << "' not in parameter list... aborting." << endl;
126 return kFALSE;
127 }
128
129 fCall = fObject->GetterMethod(mname);
130
131 return fCall ? kTRUE : kFALSE;
132}
133
134// --------------------------------------------------------------------------
135//
136// Print the name of the data member without an CR.
137//
138void MDataMember::Print(Option_t *opt) const
139{
140 *fLog << fName << flush;
141}
142
Note: See TracBrowser for help on using the repository browser.