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

Last change on this file since 1305 was 1304, checked in by tbretz, 23 years ago
*** empty log message ***
File size: 5.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@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// If you want to add a new member to the list call this function with the
145// pointer to the member to be added.
146//
147Bool_t MDataList::AddToList(MData *member)
148{
149 if (!member)
150 return kTRUE;
151
152 if (fMembers.FindObject(member))
153 {
154 *fLog << warn << dbginf << "Filter already existing... skipped." << endl;
155 return kTRUE;
156 }
157
158 fMembers.Add(member);
159
160 return kTRUE;
161}
162
163Bool_t MDataList::PreProcess(const MParList *plist)
164{
165 TIter Next(&fMembers);
166
167 MData *member=NULL;
168
169 //
170 // loop over all members
171 //
172 while ((member=(MData*)Next()))
173 if (!member->PreProcess(plist))
174 {
175 *fLog << err << "Error - Preprocessing Data Member ";
176 *fLog << member->GetName() << " in " << fName << endl;
177 return kFALSE;
178 }
179
180 return kTRUE;
181}
182
183
184// --------------------------------------------------------------------------
185//
186// If you want to use a verbose output ("and") instead of a symbolic ("&")
187// one the option string must conatin a "v"
188//
189void MDataList::Print(Option_t *opt) const
190{
191 *fLog << all << "(";
192
193 TIter Next(&fMembers);
194
195 TObject *member=Next();
196
197 //
198 // loop over all members
199 //
200 if (!member)
201 {
202 *fLog << "<empty>)" << flush;
203 return;
204 }
205
206 member->Print();
207
208 while ((member=Next()))
209 {
210 switch (fSign)
211 {
212 case kENone:
213 break;
214
215 case kEPlus:
216 *fLog << "+";
217 break;
218
219 case kEMinus:
220 *fLog << "-";
221 break;
222
223 case kEMult:
224 *fLog << "*";
225 break;
226
227 case kEDiv:
228 *fLog << "/";
229 break;
230 }
231
232 member->Print();
233 }
234
235 *fLog << ")" << flush;
236}
237
Note: See TracBrowser for help on using the repository browser.