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

Last change on this file since 1727 was 1709, checked in by wittek, 22 years ago
*** empty log message ***
File size: 5.6 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@astro.uni-wuerzburg.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 // The following change has to be checked :
125 // In order that fCall is initialized properly
126 // the original statement "if (fCall)" is replaced by the statement
127 if (fCall && !fObject)
128 return kTRUE;
129
130 TString cname(fDataMember);
131 TString mname(fDataMember);
132
133 const char *dot = strrchr(cname, '.');
134
135 if (dot)
136 {
137 const int pos = dot-cname;
138
139 cname.Remove(pos);
140 mname.Remove(0, pos+1);
141 }
142
143 fObject = (MParContainer*)plist->FindObject(cname);
144 if (!fObject)
145 {
146 *fLog << err << "Object '" << cname << "' not in parameter list... aborting." << endl;
147 return kFALSE;
148 }
149
150 fCall = fObject->GetterMethod(mname);
151
152 return fCall ? kTRUE : kFALSE;
153}
154
155// --------------------------------------------------------------------------
156//
157// Returns the ready-to-save flag of the data member container
158//
159Bool_t MDataMember::IsReadyToSave() const
160{
161 return IsValid() ? fObject->IsReadyToSave() : kFALSE;
162}
163
164// --------------------------------------------------------------------------
165//
166// Print the name of the data member without an CR.
167//
168/*
169void MDataMember::Print(Option_t *opt) const
170{
171 *fLog << fName << flush;
172}
173*/
174
175// --------------------------------------------------------------------------
176//
177// Builds a rule which cn be used in a MDataChain to describe this object
178//
179TString MDataMember::GetRule() const
180{
181 return fDataMember;
182}
183
184// --------------------------------------------------------------------------
185//
186// Returns the data member.
187// This is mainly used in MTask::AddToBranchList
188//
189TString MDataMember::GetDataMember() const
190{
191 return fDataMember;
192}
Note: See TracBrowser for help on using the repository browser.