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

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