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

Last change on this file since 646 was 606, checked in by tbretz, 24 years ago
*** empty log message ***
File size: 4.7 KB
Line 
1/////////////////////////////////////////////////////////////////////////////
2// //
3// MEvtLoop //
4// //
5// This class is the core of each event processing. //
6// First you must set the parameter list to use. The parameter list //
7// must contain the task list (MTaskList) to use. The name of the task //
8// list can be specified if you call Eventloop. The standard name is //
9// "MTaskList". The name you specify must match the name of the MTaskList //
10// object. //
11// //
12// If you call Eventloop first all PreProcess functions - with the //
13// parameter list as an argument - of the tasks in the task list are //
14// executed. If one of them returns kFALSE then the execution is stopped. //
15// If the preprocessing was ok. The Process funtion of the tasks are //
16// as long as one function returns kSTOP. Only the tasks which are marked //
17// marked as "All" or with a string which matches the MInputStreamID of //
18// MTaskList are executed. If one tasks returns kCONTINUE the pending //
19// tasks in the list are skipped and the execution in continued with //
20// the first one in the list. //
21// Afterwards the PostProcess functions are executed. //
22// //
23/////////////////////////////////////////////////////////////////////////////
24#include "MEvtLoop.h"
25
26#include <iostream.h>
27
28#include <TStopwatch.h>
29
30#include "MLog.h"
31#include "MParList.h"
32#include "MTaskList.h"
33
34ClassImp(MEvtLoop)
35
36MEvtLoop::MEvtLoop() : fParList(NULL)
37{
38}
39
40MEvtLoop::~MEvtLoop()
41{
42}
43
44Bool_t MEvtLoop::PreProcess(const char *tlist)
45{
46 //
47 // The proprocessing part of the eventloop. Be careful, this is
48 // for developers use only!
49 //
50
51 //
52 // check if the needed parameter list is set.
53 //
54 if (!fParList)
55 {
56 *fLog << "MEvtLoop::Eventloop - Error: Parlist not initialized." << endl;
57 return kFALSE;
58 }
59
60 //
61 // check for the existance of the specified task list
62 // the default name is "MTaskList"
63 //
64 fTaskList = (MTaskList*)fParList->FindObject(tlist);
65 if (!fTaskList)
66 {
67 *fLog << "MEvtLoop::Eventloop - Error: Cannot find tasklist '" << tlist << "' in parameter list." << endl;
68 return kFALSE;
69 }
70
71 if (fLog != &gLog)
72 {
73 fParList ->SetLogStream(fLog);
74 fTaskList->SetLogStream(fLog);
75 }
76
77 //
78 // execute the preprocess of all tasks
79 // connect the different tasks with the right containers in
80 // the parameter list
81 //
82 if (!fTaskList->PreProcess(fParList))
83 {
84 *fLog << "Error detected while PreProcessing" << endl;
85 return kFALSE;
86 }
87
88 *fLog << endl;
89
90 return kTRUE;
91}
92
93void MEvtLoop::Process(Int_t maxcnt) const
94{
95 //
96 // The processing part of the eventloop. Be careful, this is
97 // for developers use only!
98 //
99
100 //
101 // loop over all events and process all tasks for
102 // each event
103 //
104 *fLog << "Eventloop running (";
105
106 if (maxcnt<0)
107 *fLog << "all";
108 else
109 *fLog << dec << maxcnt;
110
111 *fLog << " events)..." << flush;
112
113 Int_t dummy = maxcnt<0 ? 0 : maxcnt;
114
115 //
116 // start a stopwatch
117 //
118 TStopwatch clock;
119 clock.Start();
120
121 //
122 // This is the MAIN EVENTLOOP which processes the data
123 // if maxcnt<0 the number of processed events is counted
124 // else only maxcnt events are processed
125 //
126 if (maxcnt<0)
127 while (fTaskList->Process() && ++dummy);
128 else
129 while (fTaskList->Process() && dummy--);
130
131 //
132 // stop stop-watch, print results
133 //
134 clock.Stop();
135
136 *fLog << "Ready!" << endl << endl;
137
138 clock.Print();
139
140 *fLog << dec << endl
141 << "Time: " << clock.CpuTime() << "s"
142 << " for " << (maxcnt<0?dummy:maxcnt) << " Events"
143 << " --> " << (maxcnt<0?dummy:maxcnt)/clock.CpuTime() << " Events/s"
144 << endl << endl;
145
146}
147
148void MEvtLoop::PostProcess() const
149{
150 //
151 // The postprocessing part of the eventloop. Be careful, this is
152 // for developers use only!
153 //
154
155 //
156 // execute the post process of all tasks
157 //
158 fTaskList->PostProcess();
159}
160
161void MEvtLoop::Eventloop(Int_t maxcnt, const char *tlist)
162{
163 // See class description above.
164
165 if (!PreProcess(tlist))
166 return;
167
168 Process(maxcnt);
169
170 PostProcess();
171}
172
Note: See TracBrowser for help on using the repository browser.