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

Last change on this file since 19345 was 19273, checked in by tbretz, 6 years ago
A lot of code became obsolete with root 6.
File size: 4.5 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@physik.rwth-aachen.de>
19!
20! Copyright: MAGIC Software Development, 2000-2018
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#include <TMethodCall.h>
65#endif
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#if ROOT_VERSION_CODE < ROOT_VERSION(6,00,00)
85 fCall[0] = 0;
86 fCall[1] = 0;
87 fCall[2] = 0;
88 fCall[3] = 0;
89#endif
90}
91
92// --------------------------------------------------------------------------
93//
94// Destructor. Free all resources.
95//
96MTaskInteractive::~MTaskInteractive()
97{
98 Free(0);
99 Free(1);
100 Free(2);
101 Free(3);
102}
103
104#if ROOT_VERSION_CODE < ROOT_VERSION(6,00,00)
105// --------------------------------------------------------------------------
106//
107// Calls the function and returns its return value.
108// Called by PreProcess, Process, PostProcess and ReInit.
109//
110inline Int_t MTaskInteractive::Return(Int_t no, void *params)
111{
112 // Static function called when SetFCN is called in interactive mode
113 if (!fCall[no])
114 {
115 gLog << err << dbginf << "Return(" << no << ") - TMethodCall not set." << endl;
116 return kFALSE;
117 }
118
119 Long_t result;
120 fCall[no]->SetParamPtrs(params);
121 fCall[no]->Execute(result);
122
123 return result;
124}
125
126// --------------------------------------------------------------------------
127//
128// Generalized function to set the functions of your interactive task.
129// Called by SetPreProcess, SetProcess, SetPostProcess and SetReInit
130//
131Bool_t MTaskInteractive::Set(void *fcn, Int_t no, const char *params)
132{
133 // this function is called by CINT instead of the function above
134 if (!fcn)
135 return kFALSE;
136
137 char *funcname = G__p2f2funcname(fcn);
138 if (!funcname)
139 return kFALSE;
140
141 Free(no);
142
143 fCall[no] = new TMethodCall;
144 fCall[no]->InitWithPrototype(funcname, params);
145
146 gLog << inf << GetDescriptor() << ": Using " << funcname << " as ";
147 switch (no)
148 {
149 case 0:
150 gLog << "PreProcess";
151 break;
152 case 1:
153 gLog << "Process";
154 break;
155 case 2:
156 gLog << "PostProcess";
157 break;
158 case 3:
159 gLog << "ReInit";
160 break;
161
162 }
163 gLog << "-function." << endl;
164
165 return kTRUE;
166}
167
168// --------------------------------------------------------------------------
169//
170//
171//
172void MTaskInteractive::Free(Int_t no)
173{
174 if (!fCall[no])
175 return;
176 delete fCall[no];
177 fCall[no] = 0;
178}
179#endif
Note: See TracBrowser for help on using the repository browser.