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

Last change on this file since 603 was 599, checked in by tbretz, 24 years ago
*** empty log message ***
File size: 4.6 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 "MParList.h"
31#include "MTaskList.h"
32
33ClassImp(MEvtLoop)
34
35MEvtLoop::MEvtLoop() : fParlist(NULL)
36{
37}
38
39MEvtLoop::~MEvtLoop()
40{
41}
42
43void MEvtLoop::SetParList(MParList *p)
44{
45 fParlist = p;
46}
47
48Bool_t MEvtLoop::PreProcess(const char *tlist)
49{
50 //
51 // The proprocessing part of the eventloop. Be careful, this is
52 // for developers use only!
53 //
54
55 //
56 // check if the needed parameter list is set.
57 //
58 if (!fParlist)
59 {
60 cout << "MEvtLoop::Eventloop - Error: Parlist not initialized." << endl;
61 return kFALSE;
62 }
63
64 //
65 // check for the existance of the specified task list
66 // the default name is "MTaskList"
67 //
68 fTaskList = (MTaskList*)fParlist->FindObject(tlist);
69 if (!fTaskList)
70 {
71 cout << "MEvtLoop::Eventloop - Error: Cannot find tasklist '" << tlist << "' in parameter list." << endl;
72 return kFALSE;
73 }
74
75 //
76 // execute the preprocess of all tasks
77 // connect the different tasks with the right containers in
78 // the parameter list
79 //
80 if (!fTaskList->PreProcess(fParlist))
81 {
82 cout << "Error detected while PreProcessing" << endl;
83 return kFALSE;
84 }
85
86 return kTRUE;
87}
88
89void MEvtLoop::Process(Int_t maxcnt) const
90{
91 //
92 // The processing part of the eventloop. Be careful, this is
93 // for developers use only!
94 //
95
96 //
97 // loop over all events and process all tasks for
98 // each event
99 //
100 cout << endl << "Eventloop running (";
101
102 if (maxcnt<0)
103 cout << "all";
104 else
105 cout << dec << maxcnt;
106
107 cout << " events)..." << flush;
108
109 Int_t dummy = maxcnt<0 ? 0 : maxcnt;
110
111 //
112 // start a stopwatch
113 //
114 TStopwatch clock;
115 clock.Start();
116
117 //
118 // This is the MAIN EVENTLOOP which processes the data
119 // if maxcnt<0 the number of processed events is counted
120 // else only maxcnt events are processed
121 //
122 if (maxcnt<0)
123 while (fTaskList->Process() && ++dummy);
124 else
125 while (fTaskList->Process() && dummy--);
126
127 //
128 // stop stop-watch, print results
129 //
130 clock.Stop();
131
132 cout << "Ready!" << endl << endl;
133
134 clock.Print();
135
136 cout << dec << endl
137 << "Time: " << clock.CpuTime() << "s"
138 << " for " << (maxcnt<0?dummy:maxcnt) << " Events"
139 << " --> " << (maxcnt<0?dummy:maxcnt)/clock.CpuTime() << " Events/s"
140 << endl << endl;
141
142}
143
144void MEvtLoop::PostProcess() const
145{
146 //
147 // The postprocessing part of the eventloop. Be careful, this is
148 // for developers use only!
149 //
150
151 //
152 // execute the post process of all tasks
153 //
154 fTaskList->PostProcess();
155}
156
157void MEvtLoop::Eventloop(Int_t maxcnt, const char *tlist)
158{
159 // See class description above.
160
161 if (!PreProcess(tlist))
162 return;
163
164 Process(maxcnt);
165
166 PostProcess();
167}
168
Note: See TracBrowser for help on using the repository browser.