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 <mailto: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 <TSystem.h>
|
---|
59 | #include <TStopwatch.h>
|
---|
60 | #include <TGProgressBar.h>
|
---|
61 |
|
---|
62 | #include "MLog.h"
|
---|
63 | #include "MLogManip.h"
|
---|
64 |
|
---|
65 | #include "MParList.h"
|
---|
66 | #include "MTaskList.h"
|
---|
67 |
|
---|
68 | ClassImp(MEvtLoop);
|
---|
69 |
|
---|
70 |
|
---|
71 | //!
|
---|
72 | //! Maybe we can add a static parameter list to MEvtLoop
|
---|
73 | //! Also we can derive MEvtLoop from MTaskList to have a static tasklist, too
|
---|
74 | //!
|
---|
75 |
|
---|
76 | // --------------------------------------------------------------------------
|
---|
77 | //
|
---|
78 | // default constructor - emty
|
---|
79 | //
|
---|
80 | MEvtLoop::MEvtLoop() : fParList(NULL), fProgress(NULL)
|
---|
81 | {
|
---|
82 | }
|
---|
83 |
|
---|
84 | // --------------------------------------------------------------------------
|
---|
85 | //
|
---|
86 | // default destructor - emty
|
---|
87 | //
|
---|
88 | MEvtLoop::~MEvtLoop()
|
---|
89 | {
|
---|
90 | if (TestBit(kIsOwner) && fParList)
|
---|
91 | delete fParList;
|
---|
92 | }
|
---|
93 |
|
---|
94 | // --------------------------------------------------------------------------
|
---|
95 | //
|
---|
96 | // if you set the Eventloop as owner the destructor of the given parameter
|
---|
97 | // list is calles by the destructor of MEvtLoop, otherwise not.
|
---|
98 | //
|
---|
99 | void MEvtLoop::SetOwner(Bool_t enable)
|
---|
100 | {
|
---|
101 | enable ? SetBit(kIsOwner) : ResetBit(kIsOwner);
|
---|
102 | }
|
---|
103 |
|
---|
104 | // --------------------------------------------------------------------------
|
---|
105 | //
|
---|
106 | // The proprocessing part of the eventloop. Be careful, this is
|
---|
107 | // for developers or use in special jobs only!
|
---|
108 | //
|
---|
109 | Bool_t MEvtLoop::PreProcess(const char *tlist)
|
---|
110 | {
|
---|
111 | //
|
---|
112 | // check if the needed parameter list is set.
|
---|
113 | //
|
---|
114 | if (!fParList)
|
---|
115 | {
|
---|
116 | *fLog << err << dbginf << "Parlist not initialized." << endl;
|
---|
117 | return kFALSE;
|
---|
118 | }
|
---|
119 |
|
---|
120 | //
|
---|
121 | // check for the existance of the specified task list
|
---|
122 | // the default name is "MTaskList"
|
---|
123 | //
|
---|
124 | fTaskList = (MTaskList*)fParList->FindObject(tlist);
|
---|
125 | if (!fTaskList)
|
---|
126 | {
|
---|
127 | *fLog << err << dbginf << "Cannot find tasklist '" << tlist << "' in parameter list." << endl;
|
---|
128 | return kFALSE;
|
---|
129 | }
|
---|
130 |
|
---|
131 | if (fLog != &gLog)
|
---|
132 | fParList ->SetLogStream(fLog);
|
---|
133 |
|
---|
134 | //
|
---|
135 | // execute the preprocess of all tasks
|
---|
136 | // connect the different tasks with the right containers in
|
---|
137 | // the parameter list
|
---|
138 | //
|
---|
139 | if (!fTaskList->PreProcess(fParList))
|
---|
140 | {
|
---|
141 | *fLog << err << "Error detected while PreProcessing" << endl;
|
---|
142 | return kFALSE;
|
---|
143 | }
|
---|
144 |
|
---|
145 | *fLog << endl;
|
---|
146 |
|
---|
147 | return kTRUE;
|
---|
148 | }
|
---|
149 |
|
---|
150 | // --------------------------------------------------------------------------
|
---|
151 | //
|
---|
152 | // The processing part of the eventloop. Be careful, this is
|
---|
153 | // for developers or use in special jobs only!
|
---|
154 | //
|
---|
155 | void MEvtLoop::Process(Int_t maxcnt) const
|
---|
156 | {
|
---|
157 | //
|
---|
158 | // loop over all events and process all tasks for
|
---|
159 | // each event
|
---|
160 | //
|
---|
161 | *fLog << all <<"Eventloop running (";
|
---|
162 |
|
---|
163 | if (maxcnt<0)
|
---|
164 | *fLog << "all";
|
---|
165 | else
|
---|
166 | *fLog << dec << maxcnt;
|
---|
167 |
|
---|
168 | *fLog << " events)..." << flush;
|
---|
169 |
|
---|
170 | if (fProgress && maxcnt>0)
|
---|
171 | fProgress->SetRange(0, maxcnt);
|
---|
172 |
|
---|
173 | Int_t dummy = maxcnt<0 ? 0 : maxcnt;
|
---|
174 |
|
---|
175 | //
|
---|
176 | // start a stopwatch
|
---|
177 | //
|
---|
178 | TStopwatch clock;
|
---|
179 | clock.Start();
|
---|
180 |
|
---|
181 | //
|
---|
182 | // This is the MAIN EVENTLOOP which processes the data
|
---|
183 | // if maxcnt<0 the number of processed events is counted
|
---|
184 | // else only maxcnt events are processed
|
---|
185 | //
|
---|
186 | if (maxcnt<0)
|
---|
187 | // process first and increment if sucessfull
|
---|
188 | if (fProgress)
|
---|
189 | while (fTaskList->Process())
|
---|
190 | {
|
---|
191 | fProgress->SetPosition(++dummy);
|
---|
192 | #if ROOT_VERSION_CODE < ROOT_VERSION(3,02,06)
|
---|
193 | gSystem->ProcessEvents();
|
---|
194 | #else
|
---|
195 | gClient->ProcessEventsFor(fProgress);
|
---|
196 | #endif
|
---|
197 | }
|
---|
198 | else
|
---|
199 | while (fTaskList->Process()) dummy++;
|
---|
200 | else
|
---|
201 | // check for number and break if unsuccessfull
|
---|
202 | if (fProgress)
|
---|
203 | while (dummy-- && fTaskList->Process())
|
---|
204 | {
|
---|
205 | fProgress->SetPosition(maxcnt - dummy);
|
---|
206 | #if ROOT_VERSION_CODE < ROOT_VERSION(3,02,06)
|
---|
207 | gSystem->ProcessEvents();
|
---|
208 | #else
|
---|
209 | gClient->ProcessEventsFor(fProgress);
|
---|
210 | #endif
|
---|
211 | }
|
---|
212 | else
|
---|
213 | while (dummy-- && fTaskList->Process());
|
---|
214 |
|
---|
215 | //
|
---|
216 | // stop stop-watch, print results
|
---|
217 | //
|
---|
218 | clock.Stop();
|
---|
219 |
|
---|
220 | *fLog << all << "Ready!" << endl << endl;
|
---|
221 |
|
---|
222 | *fLog << dec << endl << "CPU - "
|
---|
223 | << "Time: " << clock.CpuTime() << "s"
|
---|
224 | << " for " << (maxcnt<0?dummy:maxcnt) << " Events"
|
---|
225 | << " --> " << (maxcnt<0?dummy:maxcnt)/clock.CpuTime() << " Events/s"
|
---|
226 | << endl;
|
---|
227 | *fLog << "Real - "
|
---|
228 | << "Time: " << clock.RealTime() << "s"
|
---|
229 | << " for " << (maxcnt<0?dummy:maxcnt) << " Events"
|
---|
230 | << " --> " << (maxcnt<0?dummy:maxcnt)/clock.RealTime() << " Events/s"
|
---|
231 | << endl << endl;
|
---|
232 | }
|
---|
233 |
|
---|
234 | // --------------------------------------------------------------------------
|
---|
235 | //
|
---|
236 | // The postprocessing part of the eventloop. Be careful, this is
|
---|
237 | // for developers or use in special jobs only!
|
---|
238 | //
|
---|
239 | Bool_t MEvtLoop::PostProcess() const
|
---|
240 | {
|
---|
241 | //
|
---|
242 | // execute the post process of all tasks
|
---|
243 | //
|
---|
244 | return fTaskList->PostProcess();
|
---|
245 | }
|
---|
246 |
|
---|
247 | // --------------------------------------------------------------------------
|
---|
248 | //
|
---|
249 | // See class description above.
|
---|
250 | //
|
---|
251 | Bool_t MEvtLoop::Eventloop(Int_t maxcnt, const char *tlist)
|
---|
252 | {
|
---|
253 | Bool_t rc = PreProcess();
|
---|
254 |
|
---|
255 | //
|
---|
256 | // If all Tasks were PreProcesses successfully start Processing.
|
---|
257 | //
|
---|
258 | if (rc)
|
---|
259 | Process(maxcnt);
|
---|
260 |
|
---|
261 | //
|
---|
262 | // Now postprocess all tasks. Only successfully preprocessed tasks are
|
---|
263 | // postprocessed. If the Postprocessing of one task fail return an error.
|
---|
264 | //
|
---|
265 | if (!PostProcess())
|
---|
266 | return kFALSE;
|
---|
267 |
|
---|
268 | //
|
---|
269 | // If postprocessing of all preprocessed tasks was sucefully return rc.
|
---|
270 | // This gives an error in case the preprocessing has failed already.
|
---|
271 | // Otherwise the eventloop is considered: successfully.
|
---|
272 | //
|
---|
273 | return rc;
|
---|
274 | }
|
---|
275 |
|
---|