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