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

Last change on this file since 3421 was 2557, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 7.8 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
38using namespace std;
39
40// --------------------------------------------------------------------------
41//
42// Default Constructor. Not for usage!
43//
44MDataList::MDataList()
45{
46 fSign = kENone;
47
48 gROOT->GetListOfCleanups()->Add(&fMembers);
49 fMembers.SetBit(kMustCleanup);
50}
51
52// --------------------------------------------------------------------------
53//
54// Constructor.
55//
56// Specify the operation which is used to evaluate the
57// result of this list.
58//
59// Options:
60// *, /, -, +
61//
62MDataList::MDataList(char type)
63{
64 switch (type)
65 {
66 case '*':
67 fSign = kEMult;
68 return;
69 case '/':
70 fSign = kEDiv;
71 return;
72 case '-':
73 fSign = kEMinus;
74 return;
75 case '+':
76 fSign = kEPlus;
77 return;
78 case '%':
79 fSign = kEModul;
80 return;
81 default:
82 fSign = kENone;
83 }
84
85 gROOT->GetListOfCleanups()->Add(&fMembers);
86 fMembers.SetBit(kMustCleanup);
87}
88
89// --------------------------------------------------------------------------
90//
91// CopyConstructor
92//
93MDataList::MDataList(MDataList &ts)
94{
95 fMembers.AddAll(&ts.fMembers);
96 fSign = ts.fSign;
97}
98
99// --------------------------------------------------------------------------
100//
101// Evaluates and returns the result of the member list.
102// The expression is evaluated step by step, eg:
103// ((member[0] # member[1]) # member[3]) # member[4])
104// The '#' stands for the boolean operation which is specified in
105// the constructor.
106//
107Double_t MDataList::GetValue() const
108{
109 TIter Next(&fMembers);
110
111 MData *member=(MData*)Next();
112
113 if (!member)
114 return kTRUE;
115
116 Double_t val = member->GetValue();
117
118 //
119 // loop over all members
120 //
121 switch (fSign)
122 {
123 case kENone:
124 return 0;
125
126 case kEPlus:
127 while ((member=(MData*)Next()))
128 val += member->GetValue();
129 break;
130
131 case kEMinus:
132 while ((member=(MData*)Next()))
133 val -= member->GetValue();
134 break;
135
136 case kEMult:
137 while ((member=(MData*)Next()))
138 val *= member->GetValue();
139 break;
140
141 case kEDiv:
142 while ((member=(MData*)Next()))
143 {
144 Double_t d = member->GetValue();
145 if (d==0)
146 {
147 *fLog << warn << "Warning: Division by zero (" << member->GetName() << ")" << endl;
148 return 0;
149 }
150 val /= d;
151 }
152 break;
153
154 case kEModul:
155 while ((member=(MData*)Next()))
156 {
157 Double_t d = member->GetValue();
158 if (d==0)
159 {
160 *fLog << warn << "Warning: Modulo division by zero (" << member->GetName() << ")" << endl;
161 return 0;
162 }
163 val = fmod(val, d);
164 }
165 break;
166 }
167 return val;
168}
169
170// --------------------------------------------------------------------------
171//
172// Checks whether at least one member has the ready-to-save flag.
173//
174Bool_t MDataList::IsReadyToSave() const
175{
176 TIter Next(&fMembers);
177
178 MData *data = NULL;
179
180 while ((data=(MData*)Next()))
181 if (data->IsReadyToSave())
182 return kTRUE;
183
184 return kFALSE;
185}
186
187// --------------------------------------------------------------------------
188//
189// If you want to add a new member to the list call this function with the
190// pointer to the member to be added.
191//
192Bool_t MDataList::AddToList(MData *member)
193{
194 if (!member)
195 return kTRUE;
196
197 if (fMembers.FindObject(member))
198 {
199 *fLog << warn << dbginf << "Filter already existing... skipped." << endl;
200 return kTRUE;
201 }
202
203 member->SetBit(kMustCleanup);
204 fMembers.Add(member);
205
206 return kTRUE;
207}
208
209// --------------------------------------------------------------------------
210//
211// PreProcesses all members in the list
212//
213Bool_t MDataList::PreProcess(const MParList *plist)
214{
215 TIter Next(&fMembers);
216
217 MData *member=NULL;
218
219 //
220 // loop over all members
221 //
222 while ((member=(MData*)Next()))
223 if (!member->PreProcess(plist))
224 {
225 *fLog << err << "Error - Preprocessing Data Member ";
226 *fLog << member->GetName() << " in " << fName << endl;
227 return kFALSE;
228 }
229
230 return kTRUE;
231}
232
233
234// --------------------------------------------------------------------------
235//
236// If you want to use a verbose output ("and") instead of a symbolic ("&")
237// one the option string must conatin a "v"
238//
239/*
240void MDataList::Print(Option_t *opt) const
241{
242 *fLog << "(";
243
244 TIter Next(&fMembers);
245
246 TObject *member=Next();
247
248 //
249 // loop over all members
250 //
251 if (!member)
252 {
253 *fLog << "<empty>)" << flush;
254 return;
255 }
256
257 member->Print();
258
259 while ((member=Next()))
260 {
261 switch (fSign)
262 {
263 case kENone:
264 break;
265
266 case kEPlus:
267 *fLog << "+";
268 break;
269
270 case kEMinus:
271 *fLog << "-";
272 break;
273
274 case kEMult:
275 *fLog << "*";
276 break;
277
278 case kEDiv:
279 *fLog << "/";
280 break;
281 }
282
283 member->Print();
284 }
285
286 *fLog << ")" << flush;
287 }
288 */
289
290// --------------------------------------------------------------------------
291//
292// Builds a rule from all the list members. This is a rule which could
293// be used to rebuild the list using the constructor of a MDataChain
294//
295TString MDataList::GetRule() const
296{
297 TIter Next(&fMembers);
298
299 MData *member=(MData*)Next();
300
301 //
302 // loop over all members
303 //
304 if (!member)
305 return "(<empty>)";
306
307 TString str = "(";
308
309 str += member->GetRule();
310
311 while ((member=(MData*)Next()))
312 {
313 switch (fSign)
314 {
315 case kENone:
316 break;
317
318 case kEPlus:
319 str += "+";
320 break;
321
322 case kEMinus:
323 str += "-";
324 break;
325
326 case kEMult:
327 str += "*";
328 break;
329
330 case kEDiv:
331 str += "/";
332 break;
333
334 case kEModul:
335 str += "%";
336 break;
337 }
338
339 str += member->GetRule();
340 }
341
342 str += ")";
343
344 return str;
345}
346
347// --------------------------------------------------------------------------
348//
349// Return a comma seperated list of all data members used in the chain.
350// This is mainly used in MTask::AddToBranchList
351//
352TString MDataList::GetDataMember() const
353{
354 TString str;
355
356 TIter Next(&fMembers);
357
358 MData *member=(MData*)Next();
359
360 if (!member->GetDataMember().IsNull())
361 str += member->GetDataMember();
362
363 while ((member=(MData*)Next()))
364 {
365 if (!member->GetDataMember().IsNull())
366 {
367 str += ",";
368 str += member->GetDataMember();
369 }
370 }
371
372 return str;
373}
Note: See TracBrowser for help on using the repository browser.