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

Last change on this file since 5723 was 4513, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 4.2 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)
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}
86
87// --------------------------------------------------------------------------
88//
89// Destructor. Free all resources.
90//
91MTaskInteractive::~MTaskInteractive()
92{
93 Free(0);
94 Free(1);
95 Free(2);
96}
97
98// --------------------------------------------------------------------------
99//
100// Calls the function and returns its return value.
101// Called by PreProcess, Process, PostProcess and ReInit.
102//
103inline Int_t MTaskInteractive::Return(Int_t no, void *params)
104{
105 // Static function called when SetFCN is called in interactive mode
106 if (!fCall[no])
107 {
108 gLog << err << dbginf << "Return(" << no << ") - TMethodCall not set." << endl;
109 return kFALSE;
110 }
111
112 Long_t result;
113 fCall[no]->SetParamPtrs(params);
114 fCall[no]->Execute(result);
115
116 return result;
117}
118
119// --------------------------------------------------------------------------
120//
121// Generalized function to set the functions of your interactive task.
122// Called by SetPreProcess, SetProcess, SetPostProcess and SetReInit
123//
124Bool_t MTaskInteractive::Set(void *fcn, Int_t no, const char *params)
125{
126 // this function is called by CINT instead of the function above
127 if (!fcn)
128 return kFALSE;
129
130 char *funcname = G__p2f2funcname(fcn);
131 if (!funcname)
132 return kFALSE;
133
134 Free(no);
135
136 fCall[no] = new TMethodCall;
137 fCall[no]->InitWithPrototype(funcname, params);
138
139 gLog << inf << GetDescriptor() << ": Using " << funcname << " as ";
140 switch (no)
141 {
142 case 0:
143 gLog << "Pre";
144 break;
145 case 2:
146 gLog << "Post";
147 break;
148
149 }
150 gLog << "Process-function." << endl;
151
152 return kTRUE;
153}
154
155// --------------------------------------------------------------------------
156//
157//
158//
159void MTaskInteractive::Free(Int_t no)
160{
161 if (!fCall[no])
162 return;
163 delete fCall[no];
164 fCall[no] = 0;
165}
Note: See TracBrowser for help on using the repository browser.