source: trunk/MagicSoft/Mars/mbase/MTaskInteractive.cc@ 7929

Last change on this file since 7929 was 7184, checked in by tbretz, 19 years ago
*** empty log message ***
File size: 4.4 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, 6/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2003
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MTaskInteractive
28//
29// If you want to create a new task inside a macro you will have to compile
30// your macro using macro.C++, because the root interpreter cannot use
31// uncompiled classes. To workaround this problem you can write simple
32// funcions (which can be handled by CINT) and use MTaskInteractive.
33//
34// This is a simple way to develop new code in a macro without need
35// to compile it.
36//
37// Example:
38// Int_t Process()
39// {
40// gLog << "Processing..." << endl;
41// return kTRUE;
42// }
43//
44// void main()
45// {
46// MTaskInteractive task;
47// task.SetProcess(Process);
48// MTaskList list;
49// list.AddToList(&task);
50// }
51//
52//
53// Input Containers:
54// -/-
55//
56// Output Containers:
57// -/-
58//
59/////////////////////////////////////////////////////////////////////////////
60#include "MTaskInteractive.h"
61
62#include <Api.h>
63#include <TMethodCall.h>
64
65#include "MLog.h"
66#include "MLogManip.h"
67
68ClassImp(MTaskInteractive);
69
70using namespace std;
71
72// --------------------------------------------------------------------------
73//
74// Default Constructor. Takes name and title of the interactive task
75//
76MTaskInteractive::MTaskInteractive(const char *name, const char *title) :
77 fPreProcess(NULL), fProcess(NULL), fPostProcess(NULL), fReInit(NULL)
78{
79 fName = name ? name : "MTaskInteractive";
80 fTitle = title ? title : "Interactive task";
81
82 fCall[0] = 0;
83 fCall[1] = 0;
84 fCall[2] = 0;
85 fCall[3] = 0;
86}
87
88// --------------------------------------------------------------------------
89//
90// Destructor. Free all resources.
91//
92MTaskInteractive::~MTaskInteractive()
93{
94 Free(0);
95 Free(1);
96 Free(2);
97 Free(3);
98}
99
100// --------------------------------------------------------------------------
101//
102// Calls the function and returns its return value.
103// Called by PreProcess, Process, PostProcess and ReInit.
104//
105inline Int_t MTaskInteractive::Return(Int_t no, void *params)
106{
107 // Static function called when SetFCN is called in interactive mode
108 if (!fCall[no])
109 {
110 gLog << err << dbginf << "Return(" << no << ") - TMethodCall not set." << endl;
111 return kFALSE;
112 }
113
114 Long_t result;
115 fCall[no]->SetParamPtrs(params);
116 fCall[no]->Execute(result);
117
118 return result;
119}
120
121// --------------------------------------------------------------------------
122//
123// Generalized function to set the functions of your interactive task.
124// Called by SetPreProcess, SetProcess, SetPostProcess and SetReInit
125//
126Bool_t MTaskInteractive::Set(void *fcn, Int_t no, const char *params)
127{
128 // this function is called by CINT instead of the function above
129 if (!fcn)
130 return kFALSE;
131
132 char *funcname = G__p2f2funcname(fcn);
133 if (!funcname)
134 return kFALSE;
135
136 Free(no);
137
138 fCall[no] = new TMethodCall;
139 fCall[no]->InitWithPrototype(funcname, params);
140
141 gLog << inf << GetDescriptor() << ": Using " << funcname << " as ";
142 switch (no)
143 {
144 case 0:
145 gLog << "PreProcess";
146 break;
147 case 1:
148 gLog << "Process";
149 break;
150 case 2:
151 gLog << "PostProcess";
152 break;
153 case 3:
154 gLog << "ReInit";
155 break;
156
157 }
158 gLog << "-function." << endl;
159
160 return kTRUE;
161}
162
163// --------------------------------------------------------------------------
164//
165//
166//
167void MTaskInteractive::Free(Int_t no)
168{
169 if (!fCall[no])
170 return;
171 delete fCall[no];
172 fCall[no] = 0;
173}
Note: See TracBrowser for help on using the repository browser.