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

Last change on this file since 1439 was 1348, checked in by tbretz, 22 years ago
*** empty log message ***
File size: 5.6 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//
206void MDataList::Print(Option_t *opt) const
207{
208 *fLog << "(";
209
210 TIter Next(&fMembers);
211
212 TObject *member=Next();
213
214 //
215 // loop over all members
216 //
217 if (!member)
218 {
219 *fLog << "<empty>)" << flush;
220 return;
221 }
222
223 member->Print();
224
225 while ((member=Next()))
226 {
227 switch (fSign)
228 {
229 case kENone:
230 break;
231
232 case kEPlus:
233 *fLog << "+";
234 break;
235
236 case kEMinus:
237 *fLog << "-";
238 break;
239
240 case kEMult:
241 *fLog << "*";
242 break;
243
244 case kEDiv:
245 *fLog << "/";
246 break;
247 }
248
249 member->Print();
250 }
251
252 *fLog << ")" << flush;
253}
254
Note: See TracBrowser for help on using the repository browser.