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

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