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

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