source: trunk/MagicSoft/Mars/mdata/MDataList.cc@ 2124

Last change on this file since 2124 was 1574, checked in by tbretz, 22 years ago
*** empty log message ***
File size: 7.2 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// MDataList
28//
29/////////////////////////////////////////////////////////////////////////////
30
31#include "MDataList.h"
32
33#include "MLog.h"
34#include "MLogManip.h"
35
36ClassImp(MDataList);
37
38// --------------------------------------------------------------------------
39//
40// Default Constructor. Not for usage!
41//
42MDataList::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//
57MDataList::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//
82MDataList::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//
96Double_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//
150Bool_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//
168Bool_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// --------------------------------------------------------------------------
185//
186// PreProcesses all members in the list
187//
188Bool_t MDataList::PreProcess(const MParList *plist)
189{
190 TIter Next(&fMembers);
191
192 MData *member=NULL;
193
194 //
195 // loop over all members
196 //
197 while ((member=(MData*)Next()))
198 if (!member->PreProcess(plist))
199 {
200 *fLog << err << "Error - Preprocessing Data Member ";
201 *fLog << member->GetName() << " in " << fName << endl;
202 return kFALSE;
203 }
204
205 return kTRUE;
206}
207
208
209// --------------------------------------------------------------------------
210//
211// If you want to use a verbose output ("and") instead of a symbolic ("&")
212// one the option string must conatin a "v"
213//
214/*
215void MDataList::Print(Option_t *opt) const
216{
217 *fLog << "(";
218
219 TIter Next(&fMembers);
220
221 TObject *member=Next();
222
223 //
224 // loop over all members
225 //
226 if (!member)
227 {
228 *fLog << "<empty>)" << flush;
229 return;
230 }
231
232 member->Print();
233
234 while ((member=Next()))
235 {
236 switch (fSign)
237 {
238 case kENone:
239 break;
240
241 case kEPlus:
242 *fLog << "+";
243 break;
244
245 case kEMinus:
246 *fLog << "-";
247 break;
248
249 case kEMult:
250 *fLog << "*";
251 break;
252
253 case kEDiv:
254 *fLog << "/";
255 break;
256 }
257
258 member->Print();
259 }
260
261 *fLog << ")" << flush;
262 }
263 */
264
265// --------------------------------------------------------------------------
266//
267// Builds a rule from all the list members. This is a rule which could
268// be used to rebuild the list using the constructor of a MDataChain
269//
270TString MDataList::GetRule() const
271{
272 TIter Next(&fMembers);
273
274 MData *member=(MData*)Next();
275
276 //
277 // loop over all members
278 //
279 if (!member)
280 return "(<empty>)";
281
282 TString str = "(";
283
284 str += member->GetRule();
285
286 while ((member=(MData*)Next()))
287 {
288 switch (fSign)
289 {
290 case kENone:
291 break;
292
293 case kEPlus:
294 str += "+";
295 break;
296
297 case kEMinus:
298 str += "-";
299 break;
300
301 case kEMult:
302 str += "*";
303 break;
304
305 case kEDiv:
306 str += "/";
307 break;
308 }
309
310 str += member->GetRule();
311 }
312
313 str += ")";
314
315 return str;
316}
317
318// --------------------------------------------------------------------------
319//
320// Return a comma seperated list of all data members used in the chain.
321// This is mainly used in MTask::AddToBranchList
322//
323TString MDataList::GetDataMember() const
324{
325 TString str;
326
327 TIter Next(&fMembers);
328
329 MData *member=(MData*)Next();
330
331 if (!member->GetDataMember().IsNull())
332 str += member->GetDataMember();
333
334 while ((member=(MData*)Next()))
335 {
336 if (!member->GetDataMember().IsNull())
337 {
338 str += ",";
339 str += member->GetDataMember();
340 }
341 }
342
343 return str;
344}
Note: See TracBrowser for help on using the repository browser.