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

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