source: trunk/MagicSoft/Mars/mbase/MEvtLoop.cc@ 967

Last change on this file since 967 was 967, checked in by tbretz, 23 years ago
*** empty log message ***
File size: 7.9 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 12/2000 (tbretz@uni-sw.gwdg.de)
19!
20! Copyright: MAGIC Software Development, 2000-2001
21!
22!
23\* ======================================================================== */
24
25
26//////////////////////////////////////////////////////////////////////////////
27// //
28// MEvtLoop //
29// //
30// This class is the core of each event processing. //
31// First you must set the parameter list to use. The parameter list //
32// must contain the task list (MTaskList) to use. The name of the task //
33// list can be specified if you call Eventloop. The standard name is //
34// "MTaskList". The name you specify must match the name of the MTaskList //
35// object. //
36// //
37// If you call Eventloop first all PreProcess functions - with the //
38// parameter list as an argument - of the tasks in the task list are //
39// executed. If one of them returns kFALSE then the execution is stopped. //
40// If the preprocessing was ok. The Process funtion of the tasks are //
41// as long as one function returns kSTOP. Only the tasks which are marked //
42// marked as "All" or with a string which matches the MInputStreamID of //
43// MTaskList are executed. If one tasks returns kCONTINUE the pending //
44// tasks in the list are skipped and the execution in continued with //
45// the first one in the list. //
46// Afterwards the PostProcess functions are executed. //
47// //
48// //
49// Maybe we can add a TProgressMeter sometimes later to be able to show //
50// the progress graphically... //
51// //
52// //
53//////////////////////////////////////////////////////////////////////////////
54#include "MEvtLoop.h"
55
56#include <iostream.h>
57
58#include <TStopwatch.h>
59
60#include "MLog.h"
61#include "MLogManip.h"
62
63#include "MParList.h"
64#include "MTaskList.h"
65
66ClassImp(MEvtLoop);
67
68
69//!
70//! Maybe we can add a static parameter list to MEvtLoop
71//! Also we can derive MEvtLoop from MTaskList to have a static tasklist, too
72//!
73
74// --------------------------------------------------------------------------
75//
76// default constructor - emty
77//
78MEvtLoop::MEvtLoop() : fParList(NULL)
79{
80}
81
82// --------------------------------------------------------------------------
83//
84// default destructor - emty
85//
86MEvtLoop::~MEvtLoop()
87{
88 if (TestBit(kIsOwner) && fParList)
89 delete fParList;
90}
91
92// --------------------------------------------------------------------------
93//
94// if you set the Eventloop as owner the destructor of the given parameter
95// list is calles by the destructor of MEvtLoop, otherwise not.
96//
97inline void MEvtLoop::SetOwner(Bool_t enable=kTRUE)
98{
99 enable ? SetBit(kIsOwner) : ResetBit(kIsOwner);
100}
101
102// --------------------------------------------------------------------------
103//
104// The proprocessing part of the eventloop. Be careful, this is
105// for developers or use in special jobs only!
106//
107Bool_t MEvtLoop::PreProcess(const char *tlist)
108{
109 //
110 // check if the needed parameter list is set.
111 //
112 if (!fParList)
113 {
114 *fLog << dbginf << "Parlist not initialized." << endl;
115 return kFALSE;
116 }
117
118 //
119 // check for the existance of the specified task list
120 // the default name is "MTaskList"
121 //
122 fTaskList = (MTaskList*)fParList->FindObject(tlist);
123 if (!fTaskList)
124 {
125 *fLog << dbginf << "Cannot find tasklist '" << tlist << "' in parameter list." << endl;
126 return kFALSE;
127 }
128
129 if (fLog != &gLog)
130 fParList ->SetLogStream(fLog);
131
132 //
133 // execute the preprocess of all tasks
134 // connect the different tasks with the right containers in
135 // the parameter list
136 //
137 if (!fTaskList->PreProcess(fParList))
138 {
139 *fLog << "Error detected while PreProcessing" << endl;
140 return kFALSE;
141 }
142
143 *fLog << endl;
144
145 return kTRUE;
146}
147
148// --------------------------------------------------------------------------
149//
150// The processing part of the eventloop. Be careful, this is
151// for developers or use in special jobs only!
152//
153void MEvtLoop::Process(Int_t maxcnt) const
154{
155 //
156 // loop over all events and process all tasks for
157 // each event
158 //
159 *fLog << "Eventloop running (";
160
161 if (maxcnt<0)
162 *fLog << "all";
163 else
164 *fLog << dec << maxcnt;
165
166 *fLog << " events)..." << flush;
167
168 Int_t dummy = maxcnt<0 ? 0 : maxcnt;
169
170 //
171 // start a stopwatch
172 //
173 TStopwatch clock;
174 clock.Start();
175
176 //
177 // This is the MAIN EVENTLOOP which processes the data
178 // if maxcnt<0 the number of processed events is counted
179 // else only maxcnt events are processed
180 //
181 if (maxcnt<0)
182 // process first and increment if sucessfull
183 while (fTaskList->Process()) dummy++;
184 else
185 // check for number and break if unsuccessfull
186 while (dummy-- && fTaskList->Process());
187
188 //
189 // stop stop-watch, print results
190 //
191 clock.Stop();
192
193 *fLog << "Ready!" << endl << endl;
194
195 clock.Print();
196
197 *fLog << dec << endl << "CPU - "
198 << "Time: " << clock.CpuTime() << "s"
199 << " for " << (maxcnt<0?dummy:maxcnt) << " Events"
200 << " --> " << (maxcnt<0?dummy:maxcnt)/clock.CpuTime() << " Events/s"
201 << endl;
202 *fLog << "Total - "
203 << "Time: " << clock.RealTime() << "s"
204 << " for " << (maxcnt<0?dummy:maxcnt) << " Events"
205 << " --> " << (maxcnt<0?dummy:maxcnt)/clock.RealTime() << " Events/s"
206 << endl << endl;
207}
208
209// --------------------------------------------------------------------------
210//
211// The postprocessing part of the eventloop. Be careful, this is
212// for developers or use in special jobs only!
213//
214Bool_t MEvtLoop::PostProcess() const
215{
216 //
217 // execute the post process of all tasks
218 //
219 return fTaskList->PostProcess();
220}
221
222// --------------------------------------------------------------------------
223//
224// See class description above.
225//
226Bool_t MEvtLoop::Eventloop(Int_t maxcnt, const char *tlist)
227{
228 Bool_t rc = PreProcess();
229
230 //
231 // If all Tasks were PreProcesses successfully start Processing.
232 //
233 if (rc)
234 Process(maxcnt);
235
236 //
237 // Now postprocess all tasks. Only successfully preprocessed tasks are
238 // postprocessed. If the Postprocessing of one task fail return an error.
239 //
240 if (!PostProcess())
241 return kFALSE;
242
243 //
244 // If postprocessing of all preprocessed tasks was sucefully return rc.
245 // This gives an error in case the preprocessing has failed already.
246 // Otherwise the eventloop is considered: successfully.
247 //
248 return rc;
249}
250
Note: See TracBrowser for help on using the repository browser.