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

Last change on this file since 905 was 887, checked in by tbretz, 23 years ago
*** empty log message ***
File size: 6.3 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#include "MEvtLoop.h"
50
51#include <iostream.h>
52
53#include <TStopwatch.h>
54
55#include "MLog.h"
56#include "MLogManip.h"
57
58#include "MParList.h"
59#include "MTaskList.h"
60
61ClassImp(MEvtLoop);
62
63
64//!
65//! Maybe we can add a static parameter list to MEvtLoop
66//! Also we can derive MEvtLoop from MTaskList to have a static tasklist, too
67//!
68
69// --------------------------------------------------------------------------
70//
71// default constructor - emty
72//
73MEvtLoop::MEvtLoop() : fParList(NULL)
74{
75}
76
77// --------------------------------------------------------------------------
78//
79// default destructor - emty
80//
81MEvtLoop::~MEvtLoop()
82{
83}
84
85// --------------------------------------------------------------------------
86//
87// The proprocessing part of the eventloop. Be careful, this is
88// for developers use only!
89//
90Bool_t MEvtLoop::PreProcess(const char *tlist)
91{
92 //
93 // check if the needed parameter list is set.
94 //
95 if (!fParList)
96 {
97 *fLog << dbginf << "Parlist not initialized." << endl;
98 return kFALSE;
99 }
100
101 //
102 // check for the existance of the specified task list
103 // the default name is "MTaskList"
104 //
105 fTaskList = (MTaskList*)fParList->FindObject(tlist);
106 if (!fTaskList)
107 {
108 *fLog << dbginf << "Cannot find tasklist '" << tlist << "' in parameter list." << endl;
109 return kFALSE;
110 }
111
112 if (fLog != &gLog)
113 fParList ->SetLogStream(fLog);
114
115 //
116 // execute the preprocess of all tasks
117 // connect the different tasks with the right containers in
118 // the parameter list
119 //
120 if (!fTaskList->PreProcess(fParList))
121 {
122 *fLog << "Error detected while PreProcessing" << endl;
123 return kFALSE;
124 }
125
126 *fLog << endl;
127
128 return kTRUE;
129}
130
131// --------------------------------------------------------------------------
132//
133// The processing part of the eventloop. Be careful, this is
134// for developers use only!
135//
136void MEvtLoop::Process(Int_t maxcnt) const
137{
138 //
139 // loop over all events and process all tasks for
140 // each event
141 //
142 *fLog << "Eventloop running (";
143
144 if (maxcnt<0)
145 *fLog << "all";
146 else
147 *fLog << dec << maxcnt;
148
149 *fLog << " events)..." << flush;
150
151 Int_t dummy = maxcnt<0 ? 0 : maxcnt;
152
153 //
154 // start a stopwatch
155 //
156 TStopwatch clock;
157 clock.Start();
158
159 //
160 // This is the MAIN EVENTLOOP which processes the data
161 // if maxcnt<0 the number of processed events is counted
162 // else only maxcnt events are processed
163 //
164 if (maxcnt<0)
165 // process first and increment if sucessfull
166 while (fTaskList->Process()) dummy++;
167 else
168 // check for number and break if unsuccessfull
169 while (dummy-- && fTaskList->Process());
170
171 //
172 // stop stop-watch, print results
173 //
174 clock.Stop();
175
176 *fLog << "Ready!" << endl << endl;
177
178 clock.Print();
179
180 *fLog << dec << endl
181 << "Time: " << clock.CpuTime() << "s"
182 << " for " << (maxcnt<0?dummy:maxcnt) << " Events"
183 << " --> " << (maxcnt<0?dummy:maxcnt)/clock.CpuTime() << " Events/s"
184 << endl << endl;
185}
186
187// --------------------------------------------------------------------------
188//
189// The postprocessing part of the eventloop. Be careful, this is
190// for developers use only!
191//
192Bool_t MEvtLoop::PostProcess() const
193{
194 //
195 // execute the post process of all tasks
196 //
197 return fTaskList->PostProcess();
198}
199
200// --------------------------------------------------------------------------
201//
202// See class description above.
203//
204Bool_t MEvtLoop::Eventloop(Int_t maxcnt, const char *tlist)
205{
206 Bool_t rc = PreProcess();
207
208 if (rc)
209 Process(maxcnt);
210
211 if (!PostProcess())
212 return kFALSE;
213
214 return rc;
215}
216
Note: See TracBrowser for help on using the repository browser.