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 | // MDataList
|
---|
28 | //
|
---|
29 | /////////////////////////////////////////////////////////////////////////////
|
---|
30 |
|
---|
31 | #include "MDataList.h"
|
---|
32 |
|
---|
33 | #include "MLog.h"
|
---|
34 | #include "MLogManip.h"
|
---|
35 |
|
---|
36 | ClassImp(MDataList);
|
---|
37 |
|
---|
38 | // --------------------------------------------------------------------------
|
---|
39 | //
|
---|
40 | // Default Constructor. Not for usage!
|
---|
41 | //
|
---|
42 | MDataList::MDataList()
|
---|
43 | {
|
---|
44 | fSign = kENone;
|
---|
45 | }
|
---|
46 |
|
---|
47 | // --------------------------------------------------------------------------
|
---|
48 | //
|
---|
49 | // Constructor.
|
---|
50 | //
|
---|
51 | // Specify the operation which is used to evaluate the
|
---|
52 | // result of this list.
|
---|
53 | //
|
---|
54 | // Options:
|
---|
55 | // *, /, -, +
|
---|
56 | //
|
---|
57 | MDataList::MDataList(char type)
|
---|
58 | {
|
---|
59 | switch (type)
|
---|
60 | {
|
---|
61 | case '*':
|
---|
62 | fSign = kEMult;
|
---|
63 | return;
|
---|
64 | case '/':
|
---|
65 | fSign = kEDiv;
|
---|
66 | return;
|
---|
67 | case '-':
|
---|
68 | fSign = kEMinus;
|
---|
69 | return;
|
---|
70 | case '+':
|
---|
71 | fSign = kEPlus;
|
---|
72 | return;
|
---|
73 | default:
|
---|
74 | fSign = kENone;
|
---|
75 | }
|
---|
76 | }
|
---|
77 |
|
---|
78 | // --------------------------------------------------------------------------
|
---|
79 | //
|
---|
80 | // CopyConstructor
|
---|
81 | //
|
---|
82 | MDataList::MDataList(MDataList &ts)
|
---|
83 | {
|
---|
84 | fMembers.AddAll(&ts.fMembers);
|
---|
85 | fSign = ts.fSign;
|
---|
86 | }
|
---|
87 |
|
---|
88 | // --------------------------------------------------------------------------
|
---|
89 | //
|
---|
90 | // Evaluates and returns the result of the member list.
|
---|
91 | // The expression is evaluated step by step, eg:
|
---|
92 | // ((member[0] # member[1]) # member[3]) # member[4])
|
---|
93 | // The '#' stands for the boolean operation which is specified in
|
---|
94 | // the constructor.
|
---|
95 | //
|
---|
96 | Double_t MDataList::GetValue() const
|
---|
97 | {
|
---|
98 | TIter Next(&fMembers);
|
---|
99 |
|
---|
100 | MData *member=(MData*)Next();
|
---|
101 |
|
---|
102 | if (!member)
|
---|
103 | return kTRUE;
|
---|
104 |
|
---|
105 | Double_t val = member->GetValue();
|
---|
106 |
|
---|
107 | //
|
---|
108 | // loop over all members
|
---|
109 | //
|
---|
110 | switch (fSign)
|
---|
111 | {
|
---|
112 | case kENone:
|
---|
113 | return 0;
|
---|
114 |
|
---|
115 | case kEPlus:
|
---|
116 | while ((member=(MData*)Next()))
|
---|
117 | val += member->GetValue();
|
---|
118 | break;
|
---|
119 |
|
---|
120 | case kEMinus:
|
---|
121 | while ((member=(MData*)Next()))
|
---|
122 | val -= member->GetValue();
|
---|
123 | break;
|
---|
124 |
|
---|
125 | case kEMult:
|
---|
126 | while ((member=(MData*)Next()))
|
---|
127 | val *= member->GetValue();
|
---|
128 | break;
|
---|
129 |
|
---|
130 | case kEDiv:
|
---|
131 | while ((member=(MData*)Next()))
|
---|
132 | {
|
---|
133 | Double_t d = member->GetValue();
|
---|
134 | if (d==0)
|
---|
135 | {
|
---|
136 | *fLog << warn << "Warning: Division by zero (" << member->GetName() << ")" << endl;
|
---|
137 | return 0;
|
---|
138 | }
|
---|
139 | val /= d;
|
---|
140 | }
|
---|
141 | break;
|
---|
142 | }
|
---|
143 | return val;
|
---|
144 | }
|
---|
145 |
|
---|
146 | // --------------------------------------------------------------------------
|
---|
147 | //
|
---|
148 | // Checks whether at least one member has the ready-to-save flag.
|
---|
149 | //
|
---|
150 | Bool_t MDataList::IsReadyToSave() const
|
---|
151 | {
|
---|
152 | TIter Next(&fMembers);
|
---|
153 |
|
---|
154 | MData *data = NULL;
|
---|
155 |
|
---|
156 | while ((data=(MData*)Next()))
|
---|
157 | if (data->IsReadyToSave())
|
---|
158 | return kTRUE;
|
---|
159 |
|
---|
160 | return kFALSE;
|
---|
161 | }
|
---|
162 |
|
---|
163 | // --------------------------------------------------------------------------
|
---|
164 | //
|
---|
165 | // If you want to add a new member to the list call this function with the
|
---|
166 | // pointer to the member to be added.
|
---|
167 | //
|
---|
168 | Bool_t MDataList::AddToList(MData *member)
|
---|
169 | {
|
---|
170 | if (!member)
|
---|
171 | return kTRUE;
|
---|
172 |
|
---|
173 | if (fMembers.FindObject(member))
|
---|
174 | {
|
---|
175 | *fLog << warn << dbginf << "Filter already existing... skipped." << endl;
|
---|
176 | return kTRUE;
|
---|
177 | }
|
---|
178 |
|
---|
179 | fMembers.Add(member);
|
---|
180 |
|
---|
181 | return kTRUE;
|
---|
182 | }
|
---|
183 |
|
---|
184 | Bool_t MDataList::PreProcess(const MParList *plist)
|
---|
185 | {
|
---|
186 | TIter Next(&fMembers);
|
---|
187 |
|
---|
188 | MData *member=NULL;
|
---|
189 |
|
---|
190 | //
|
---|
191 | // loop over all members
|
---|
192 | //
|
---|
193 | while ((member=(MData*)Next()))
|
---|
194 | if (!member->PreProcess(plist))
|
---|
195 | {
|
---|
196 | *fLog << err << "Error - Preprocessing Data Member ";
|
---|
197 | *fLog << member->GetName() << " in " << fName << endl;
|
---|
198 | return kFALSE;
|
---|
199 | }
|
---|
200 |
|
---|
201 | return kTRUE;
|
---|
202 | }
|
---|
203 |
|
---|
204 |
|
---|
205 | // --------------------------------------------------------------------------
|
---|
206 | //
|
---|
207 | // If you want to use a verbose output ("and") instead of a symbolic ("&")
|
---|
208 | // one the option string must conatin a "v"
|
---|
209 | //
|
---|
210 | /*
|
---|
211 | void MDataList::Print(Option_t *opt) const
|
---|
212 | {
|
---|
213 | *fLog << "(";
|
---|
214 |
|
---|
215 | TIter Next(&fMembers);
|
---|
216 |
|
---|
217 | TObject *member=Next();
|
---|
218 |
|
---|
219 | //
|
---|
220 | // loop over all members
|
---|
221 | //
|
---|
222 | if (!member)
|
---|
223 | {
|
---|
224 | *fLog << "<empty>)" << flush;
|
---|
225 | return;
|
---|
226 | }
|
---|
227 |
|
---|
228 | member->Print();
|
---|
229 |
|
---|
230 | while ((member=Next()))
|
---|
231 | {
|
---|
232 | switch (fSign)
|
---|
233 | {
|
---|
234 | case kENone:
|
---|
235 | break;
|
---|
236 |
|
---|
237 | case kEPlus:
|
---|
238 | *fLog << "+";
|
---|
239 | break;
|
---|
240 |
|
---|
241 | case kEMinus:
|
---|
242 | *fLog << "-";
|
---|
243 | break;
|
---|
244 |
|
---|
245 | case kEMult:
|
---|
246 | *fLog << "*";
|
---|
247 | break;
|
---|
248 |
|
---|
249 | case kEDiv:
|
---|
250 | *fLog << "/";
|
---|
251 | break;
|
---|
252 | }
|
---|
253 |
|
---|
254 | member->Print();
|
---|
255 | }
|
---|
256 |
|
---|
257 | *fLog << ")" << flush;
|
---|
258 | }
|
---|
259 | */
|
---|
260 |
|
---|
261 | TString MDataList::GetRule() const
|
---|
262 | {
|
---|
263 | TIter Next(&fMembers);
|
---|
264 |
|
---|
265 | MData *member=(MData*)Next();
|
---|
266 |
|
---|
267 | //
|
---|
268 | // loop over all members
|
---|
269 | //
|
---|
270 | if (!member)
|
---|
271 | return "(<empty>)";
|
---|
272 |
|
---|
273 | TString str = "(";
|
---|
274 |
|
---|
275 | str += member->GetRule();
|
---|
276 |
|
---|
277 | while ((member=(MData*)Next()))
|
---|
278 | {
|
---|
279 | switch (fSign)
|
---|
280 | {
|
---|
281 | case kENone:
|
---|
282 | break;
|
---|
283 |
|
---|
284 | case kEPlus:
|
---|
285 | str += "+";
|
---|
286 | break;
|
---|
287 |
|
---|
288 | case kEMinus:
|
---|
289 | str += "-";
|
---|
290 | break;
|
---|
291 |
|
---|
292 | case kEMult:
|
---|
293 | str += "*";
|
---|
294 | break;
|
---|
295 |
|
---|
296 | case kEDiv:
|
---|
297 | str += "/";
|
---|
298 | break;
|
---|
299 | }
|
---|
300 |
|
---|
301 | str += member->GetRule();
|
---|
302 | }
|
---|
303 |
|
---|
304 | str += ")";
|
---|
305 |
|
---|
306 | return str;
|
---|
307 | }
|
---|