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

Last change on this file since 3544 was 2206, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 3.3 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// Input Containers:
38// -/-
39//
40// Output Containers:
41// -/-
42//
43/////////////////////////////////////////////////////////////////////////////
44#include "MTaskInteractive.h"
45
46#include <Api.h>
47#include <TMethodCall.h>
48
49#include "MLog.h"
50#include "MLogManip.h"
51
52ClassImp(MTaskInteractive);
53
54using namespace std;
55
56// --------------------------------------------------------------------------
57//
58//
59MTaskInteractive::MTaskInteractive(const char *name, const char *title) :
60 fPreProcess(NULL), fProcess(NULL), fPostProcess(NULL)
61{
62 fName = name ? name : "MTaskInteractive";
63 fTitle = title ? title : "Interactive task";
64
65 fCall[0] = 0;
66 fCall[1] = 0;
67 fCall[2] = 0;
68}
69
70MTaskInteractive::~MTaskInteractive()
71{
72 Free(0);
73 Free(1);
74 Free(2);
75}
76
77inline Int_t MTaskInteractive::Return(Int_t no, void *params)
78{
79 // Static function called when SetFCN is called in interactive mode
80 if (!fCall[no])
81 {
82 gLog << err << dbginf << "Return(" << no << ") - TMethodCall not set." << endl;
83 return kFALSE;
84 }
85
86 Long_t result;
87 fCall[no]->SetParamPtrs(params);
88 fCall[no]->Execute(result);
89
90 return result;
91}
92
93Bool_t MTaskInteractive::Set(void *fcn, Int_t no, const char *params)
94{
95 // this function is called by CINT instead of the function above
96 if (!fcn)
97 return kFALSE;
98
99 char *funcname = G__p2f2funcname(fcn);
100 if (!funcname)
101 return kFALSE;
102
103 Free(no);
104
105 fCall[no] = new TMethodCall;
106 fCall[no]->InitWithPrototype(funcname, params);
107
108 gLog << inf << GetDescriptor() << ": Using " << funcname << " as ";
109 switch (no)
110 {
111 case 0:
112 gLog << "Pre";
113 break;
114 case 2:
115 gLog << "Post";
116 break;
117
118 }
119 gLog << "Process-function." << endl;
120
121 return kTRUE;
122}
123
124void MTaskInteractive::Free(Int_t no)
125{
126 if (!fCall[no])
127 return;
128 delete fCall[no];
129 fCall[no] = 0;
130}
Note: See TracBrowser for help on using the repository browser.