source: trunk/Mars/mbase/MTaskInteractive.cc @ 19262

Last change on this file since 19262 was 19262, checked in by tbretz, 8 months ago
Not supported in root 6 until further debugging.
File size: 4.6 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#if ROOT_VERSION_CODE < ROOT_VERSION(6,00,00)
63#include <Api.h>
64#endif
65#include <TMethodCall.h>
66
67#include "MLog.h"
68#include "MLogManip.h"
69
70ClassImp(MTaskInteractive);
71
72using namespace std;
73
74// --------------------------------------------------------------------------
75//
76// Default Constructor. Takes name and title of the interactive task
77//
78MTaskInteractive::MTaskInteractive(const char *name, const char *title) :
79    fPreProcess(NULL), fProcess(NULL), fPostProcess(NULL), fReInit(NULL)
80{
81    fName  = name  ? name  : "MTaskInteractive";
82    fTitle = title ? title : "Interactive task";
83
84    fCall[0] = 0;
85    fCall[1] = 0;
86    fCall[2] = 0;
87    fCall[3] = 0;
88}
89
90// --------------------------------------------------------------------------
91//
92// Destructor. Free all resources.
93//
94MTaskInteractive::~MTaskInteractive()
95{
96    Free(0);
97    Free(1);
98    Free(2);
99    Free(3);
100}
101
102// --------------------------------------------------------------------------
103//
104// Calls the function and returns its return value.
105// Called by PreProcess, Process, PostProcess and ReInit.
106//
107inline Int_t MTaskInteractive::Return(Int_t no, void *params)
108{
109    // Static function called when SetFCN is called in interactive mode
110    if (!fCall[no])
111    {
112        gLog << err << dbginf << "Return(" << no << ") - TMethodCall not set." << endl;
113        return kFALSE;
114    }
115
116    Long_t result;
117    fCall[no]->SetParamPtrs(params);
118    fCall[no]->Execute(result);
119
120    return result;
121}
122
123// --------------------------------------------------------------------------
124//
125// Generalized function to set the functions of your interactive task.
126// Called by SetPreProcess, SetProcess, SetPostProcess and SetReInit
127//
128Bool_t MTaskInteractive::Set(void *fcn, Int_t no, const char *params)
129{
130#if ROOT_VERSION_CODE < ROOT_VERSION(6,00,00)
131    // this function is called by CINT instead of the function above
132    if (!fcn)
133        return kFALSE;
134
135    char *funcname = G__p2f2funcname(fcn);
136    if (!funcname)
137        return kFALSE;
138
139    Free(no);
140
141    fCall[no] = new TMethodCall;
142    fCall[no]->InitWithPrototype(funcname, params);
143
144    gLog << inf << GetDescriptor() << ": Using " << funcname << " as ";
145    switch (no)
146    {
147    case 0:
148        gLog << "PreProcess";
149        break;
150    case 1:
151        gLog << "Process";
152        break;
153    case 2:
154        gLog << "PostProcess";
155        break;
156    case 3:
157        gLog << "ReInit";
158        break;
159
160    }
161    gLog << "-function." << endl;
162
163    return kTRUE;
164#else
165    gLog << err << "MTaskInteractive::Set not yet supported for root 6." << endl;
166    return kFALSE;
167#endif
168}
169
170// --------------------------------------------------------------------------
171//
172//
173//
174void MTaskInteractive::Free(Int_t no)
175{
176    if (!fCall[no])
177        return;
178    delete fCall[no];
179    fCall[no] = 0;
180}
Note: See TracBrowser for help on using the repository browser.