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 |
|
---|
68 | ClassImp(MTaskInteractive);
|
---|
69 |
|
---|
70 | using namespace std;
|
---|
71 |
|
---|
72 | // --------------------------------------------------------------------------
|
---|
73 | //
|
---|
74 | //
|
---|
75 | MTaskInteractive::MTaskInteractive(const char *name, const char *title) :
|
---|
76 | fPreProcess(NULL), fProcess(NULL), fPostProcess(NULL)
|
---|
77 | {
|
---|
78 | fName = name ? name : "MTaskInteractive";
|
---|
79 | fTitle = title ? title : "Interactive task";
|
---|
80 |
|
---|
81 | fCall[0] = 0;
|
---|
82 | fCall[1] = 0;
|
---|
83 | fCall[2] = 0;
|
---|
84 | }
|
---|
85 |
|
---|
86 | MTaskInteractive::~MTaskInteractive()
|
---|
87 | {
|
---|
88 | Free(0);
|
---|
89 | Free(1);
|
---|
90 | Free(2);
|
---|
91 | }
|
---|
92 |
|
---|
93 | inline Int_t MTaskInteractive::Return(Int_t no, void *params)
|
---|
94 | {
|
---|
95 | // Static function called when SetFCN is called in interactive mode
|
---|
96 | if (!fCall[no])
|
---|
97 | {
|
---|
98 | gLog << err << dbginf << "Return(" << no << ") - TMethodCall not set." << endl;
|
---|
99 | return kFALSE;
|
---|
100 | }
|
---|
101 |
|
---|
102 | Long_t result;
|
---|
103 | fCall[no]->SetParamPtrs(params);
|
---|
104 | fCall[no]->Execute(result);
|
---|
105 |
|
---|
106 | return result;
|
---|
107 | }
|
---|
108 |
|
---|
109 | Bool_t MTaskInteractive::Set(void *fcn, Int_t no, const char *params)
|
---|
110 | {
|
---|
111 | // this function is called by CINT instead of the function above
|
---|
112 | if (!fcn)
|
---|
113 | return kFALSE;
|
---|
114 |
|
---|
115 | char *funcname = G__p2f2funcname(fcn);
|
---|
116 | if (!funcname)
|
---|
117 | return kFALSE;
|
---|
118 |
|
---|
119 | Free(no);
|
---|
120 |
|
---|
121 | fCall[no] = new TMethodCall;
|
---|
122 | fCall[no]->InitWithPrototype(funcname, params);
|
---|
123 |
|
---|
124 | gLog << inf << GetDescriptor() << ": Using " << funcname << " as ";
|
---|
125 | switch (no)
|
---|
126 | {
|
---|
127 | case 0:
|
---|
128 | gLog << "Pre";
|
---|
129 | break;
|
---|
130 | case 2:
|
---|
131 | gLog << "Post";
|
---|
132 | break;
|
---|
133 |
|
---|
134 | }
|
---|
135 | gLog << "Process-function." << endl;
|
---|
136 |
|
---|
137 | return kTRUE;
|
---|
138 | }
|
---|
139 |
|
---|
140 | void MTaskInteractive::Free(Int_t no)
|
---|
141 | {
|
---|
142 | if (!fCall[no])
|
---|
143 | return;
|
---|
144 | delete fCall[no];
|
---|
145 | fCall[no] = 0;
|
---|
146 | }
|
---|