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

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