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

Last change on this file since 1287 was 1287, 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 *fLog << "Done." << endl;
161
162 return kTRUE;
163}
164
165Bool_t MDataList::PreProcess(const MParList *plist)
166{
167 TIter Next(&fMembers);
168
169 MData *member=NULL;
170
171 //
172 // loop over all members
173 //
174 while ((member=(MData*)Next()))
175 if (!member->PreProcess(plist))
176 {
177 *fLog << err << "Error - Preprocessing Data Member ";
178 *fLog << member->GetName() << " in " << fName << endl;
179 return kFALSE;
180 }
181
182 return kTRUE;
183}
184
185
186// --------------------------------------------------------------------------
187//
188// If you want to use a verbose output ("and") instead of a symbolic ("&")
189// one the option string must conatin a "v"
190//
191void MDataList::Print(Option_t *opt) const
192{
193 *fLog << all << "(";
194
195 TIter Next(&fMembers);
196
197 TObject *member=Next();
198
199 //
200 // loop over all members
201 //
202 if (!member)
203 {
204 *fLog << "<empty>)" << flush;
205 return;
206 }
207
208 member->Print();
209
210 while ((member=Next()))
211 {
212 switch (fSign)
213 {
214 case kENone:
215 break;
216
217 case kEPlus:
218 *fLog << "+";
219 break;
220
221 case kEMinus:
222 *fLog << "-";
223 break;
224
225 case kEMult:
226 *fLog << "*";
227 break;
228
229 case kEDiv:
230 *fLog << "/";
231 break;
232 }
233
234 member->Print();
235 }
236
237 *fLog << ")" << flush;
238}
239
Note: See TracBrowser for help on using the repository browser.