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

Last change on this file since 1476 was 1474, checked in by tbretz, 22 years ago
*** empty log message ***
File size: 4.9 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// obj is a pointer to the instance of your class from which the data
66// should be requested. TMethodCall (s. root dox) is a pointer
67// to a TMethodCall object which should be the getter function for
68// the data you want to get.
69//
70MDataMember::MDataMember(MParContainer *obj, const TString call)
71{
72 fObject = obj;
73 fCall = obj->GetterMethod(call);
74}
75
76// --------------------------------------------------------------------------
77//
78// returns the value you requested
79//
80Double_t MDataMember::GetValue() const
81{
82 if (!fCall)
83 {
84 *fLog << err << "No TMethodCall for " << fName << " of ";
85 *fLog << fObject->GetName() << " available... returning 0." << endl;
86 return 0;
87 }
88
89 switch (fCall->ReturnType())
90 {
91 case TMethodCall::kLong:
92 Long_t l;
93 fCall->Execute(fObject, l);
94 return (Double_t)l;
95
96 case TMethodCall::kDouble:
97 Double_t v;
98 fCall->Execute(fObject, v);
99 return v;
100
101 default:
102 *fLog << err << "DataMember " << fName << " of ";
103 *fLog << fObject->GetName() << " neither int nor float... returning 0." << endl;
104 return 0;
105 }
106}
107
108// --------------------------------------------------------------------------
109//
110// If a string was given PreProcess try to resolv the object name and
111// tries to get it from the parlist. And also tries to resolve
112// the data member (variable) name you requested and tries to get a
113// corresponding TMethodCall from the root Dictionary.
114// Remark: If your Data Member is called fDataMember the corresponding
115// getter Method in your class must be calles fDataMember
116//
117Bool_t MDataMember::PreProcess(const MParList *plist)
118{
119 if (fCall)
120 return kTRUE;
121
122 TString cname(fName);
123 TString mname(fName);
124
125 const char *dot = strrchr(cname, '.');
126
127 if (dot)
128 {
129 const int pos = dot-cname;
130
131 cname.Remove(pos);
132 mname.Remove(0, pos+1);
133 }
134
135 fObject = (MParContainer*)plist->FindObject(cname);
136 if (!fObject)
137 {
138 *fLog << err << "Object '" << cname << "' not in parameter list... aborting." << endl;
139 return kFALSE;
140 }
141
142 fCall = fObject->GetterMethod(mname);
143
144 return fCall ? kTRUE : kFALSE;
145}
146
147// --------------------------------------------------------------------------
148//
149// Returns the ready-to-save flag of the data member container
150//
151Bool_t MDataMember::IsReadyToSave() const
152{
153 return IsValid() ? fObject->IsReadyToSave() : kFALSE;
154}
155
156// --------------------------------------------------------------------------
157//
158// Print the name of the data member without an CR.
159//
160/*
161void MDataMember::Print(Option_t *opt) const
162{
163 *fLog << fName << flush;
164}
165*/
166
167TString MDataMember::GetRule() const
168{
169 return fName;
170}
Note: See TracBrowser for help on using the repository browser.