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

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