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

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