| 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 |
|
|---|
| 33 | ClassImp(MEvtLoop)
|
|---|
| 34 |
|
|---|
| 35 | MEvtLoop::MEvtLoop() : fParlist(NULL)
|
|---|
| 36 | {
|
|---|
| 37 | }
|
|---|
| 38 |
|
|---|
| 39 | MEvtLoop::~MEvtLoop()
|
|---|
| 40 | {
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 | void MEvtLoop::SetParList(MParList *p)
|
|---|
| 44 | {
|
|---|
| 45 | fParlist = p;
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | void MEvtLoop::Eventloop(Int_t maxcnt, const char *ftasks)
|
|---|
| 49 | {
|
|---|
| 50 | // See class description above.
|
|---|
| 51 |
|
|---|
| 52 | //
|
|---|
| 53 | // check if the needed parameter list is set.
|
|---|
| 54 | //
|
|---|
| 55 | if (!fParlist)
|
|---|
| 56 | {
|
|---|
| 57 | cout << "MEvtLoop::Eventloop - Error: Parlist not initialized." << endl;
|
|---|
| 58 | return;
|
|---|
| 59 | }
|
|---|
| 60 |
|
|---|
| 61 | //
|
|---|
| 62 | // check for the existance of the specified task list
|
|---|
| 63 | // the default name is "MTaskList"
|
|---|
| 64 | //
|
|---|
| 65 | MTaskList *tasks = (MTaskList*)fParlist->FindObject(ftasks);
|
|---|
| 66 | if (!tasks)
|
|---|
| 67 | {
|
|---|
| 68 | cout << "MEvtLoop::Eventloop - Error: Cannot find tasklist '" << ftasks << "' in parameter list." << endl;
|
|---|
| 69 | return;
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | //
|
|---|
| 73 | // execute the preprocess of all tasks
|
|---|
| 74 | // connect the different tasks with the right containers in
|
|---|
| 75 | // the parameter list
|
|---|
| 76 | //
|
|---|
| 77 | if (!tasks->PreProcess(fParlist))
|
|---|
| 78 | {
|
|---|
| 79 | cout << "Error detected while PreProcessing" << endl;
|
|---|
| 80 | return;
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | //
|
|---|
| 84 | // loop over all events and process all tasks for
|
|---|
| 85 | // each event
|
|---|
| 86 | //
|
|---|
| 87 | cout << endl << "Eventloop running (";
|
|---|
| 88 |
|
|---|
| 89 | if (maxcnt<0)
|
|---|
| 90 | cout << "all";
|
|---|
| 91 | else
|
|---|
| 92 | cout << dec << maxcnt;
|
|---|
| 93 |
|
|---|
| 94 | cout << " events)..." << flush;
|
|---|
| 95 |
|
|---|
| 96 | Int_t dummy = maxcnt<0 ? 0 : maxcnt;
|
|---|
| 97 |
|
|---|
| 98 | //
|
|---|
| 99 | // start a stopwatch
|
|---|
| 100 | //
|
|---|
| 101 | TStopwatch clock;
|
|---|
| 102 | clock.Start();
|
|---|
| 103 |
|
|---|
| 104 | //
|
|---|
| 105 | // This is the MAIN EVENTLOOP which processes the data
|
|---|
| 106 | // if maxcnt<0 the number of processed events is counted
|
|---|
| 107 | // else only maxcnt events are processed
|
|---|
| 108 | //
|
|---|
| 109 | if (maxcnt<0)
|
|---|
| 110 | while (tasks->Process() && ++dummy);
|
|---|
| 111 | else
|
|---|
| 112 | while (tasks->Process() && dummy--);
|
|---|
| 113 |
|
|---|
| 114 | //
|
|---|
| 115 | // stop stop-watch, print results
|
|---|
| 116 | //
|
|---|
| 117 | clock.Stop();
|
|---|
| 118 |
|
|---|
| 119 | cout << "Ready!" << endl << endl;
|
|---|
| 120 |
|
|---|
| 121 | clock.Print();
|
|---|
| 122 |
|
|---|
| 123 | cout << dec << endl
|
|---|
| 124 | << "Time: " << clock.CpuTime() << "s"
|
|---|
| 125 | << " for " << (maxcnt<0?dummy:maxcnt) << " Events"
|
|---|
| 126 | << " --> " << (maxcnt<0?dummy:maxcnt)/clock.CpuTime() << " Events/s"
|
|---|
| 127 | << endl << endl;
|
|---|
| 128 |
|
|---|
| 129 | //
|
|---|
| 130 | // execute the post process of all tasks
|
|---|
| 131 | //
|
|---|
| 132 | tasks->PostProcess();
|
|---|
| 133 | }
|
|---|
| 134 |
|
|---|