]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVE/EveBase/AliEveMacroExecutor.cxx
new years resolution
[u/mrichter/AliRoot.git] / EVE / EveBase / AliEveMacroExecutor.cxx
CommitLineData
f6afd0e1 1// @(#)root/eve:$Id$
2// Author: Matevz Tadel 2007
3
4/**************************************************************************
5 * Copyright(c) 1998-2008, ALICE Experiment at CERN, all rights reserved. *
6 * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for *
7 * full copyright notice. *
8 **************************************************************************/
9
10#include "AliEveMacroExecutor.h"
11#include "AliEveMacro.h"
12#include "AliEveEventManager.h"
13
14#include <TEveUtil.h>
15#include <TList.h>
16#include <TROOT.h>
17
18//______________________________________________________________________________
f6afd0e1 19//
68ca2fe7 20// Contains a list of AliEveMacros.
21// The macros are added via AddMacro() and are owned by the executor.
22// The macros can be executed via ExecMacros().
23// They are executed in order in which they are registered.
f6afd0e1 24
25ClassImp(AliEveMacroExecutor)
26
27//______________________________________________________________________________
28AliEveMacroExecutor::AliEveMacroExecutor() :
29 TObject(),
30 fMacros(new TList)
31{
32 // Constructor.
33
34 fMacros->SetOwner(kTRUE);
35}
36
37//______________________________________________________________________________
38AliEveMacroExecutor::~AliEveMacroExecutor()
39{
40 // Destructor.
41
42 delete fMacros;
43}
44
45/******************************************************************************/
46
47void AliEveMacroExecutor::AddMacro(AliEveMacro* mac)
48{
49 // Add a new macro. Ownership transfered to the executor.
50
51 static const TEveException kEH("AliEveMacroExecutor::AddMacro ");
52
53 const TString mname = mac->GetMacro();
54 if ( ! mname.IsNull() && TEveUtil::CheckMacro(mname) == kFALSE)
55 {
56 TEveUtil::LoadMacro(mname);
57 }
58 fMacros->Add(mac);
59}
60
7b2d546e 61AliEveMacro* AliEveMacroExecutor::FindMacro(const TString& func)
62{
63 // Find macro with given function name (it is supposed to be unique).
64 // Returns 0 if not found.
65
66 TIter next(fMacros);
67 AliEveMacro* mac;
68 while ((mac = (AliEveMacro*) next()))
69 {
70 if (mac->GetFunc() == func)
71 return mac;
72 }
73 return 0;
74}
75
f6afd0e1 76/******************************************************************************/
77
78#include "Api.h"
79#include "TInterpreter.h"
80
81void AliEveMacroExecutor::ExecMacros()
82{
83 // Execute registered macros.
84
85 TIter next(fMacros);
86 AliEveMacro* mac;
87 while ((mac = (AliEveMacro*) next()))
88 {
89 // printf ("macro '%s'; func '%s'; args '%s'\n", mac->GetMacro().Data(), mac->GetFunc().Data(), mac->GetArgs().Data());
90
68ca2fe7 91 mac->ResetExecState();
92
f6afd0e1 93 if (mac->GetActive() == kFALSE || mac->GetFunc().IsNull())
94 {
95 continue;
96 }
97
68ca2fe7 98 if ((mac->RequiresRunLoader() && ! AliEveEventManager::HasRunLoader()) ||
99 (mac->RequiresESD() && ! AliEveEventManager::HasESD()) ||
100 (mac->RequiresESDfriend() && ! AliEveEventManager::HasESDfriend()) ||
101 (mac->RequiresRawReader() && ! AliEveEventManager::HasRawReader()))
f6afd0e1 102 {
68ca2fe7 103 mac->SetExecNoData();
104 continue;
f6afd0e1 105 }
106
107 TString cmd(mac->FormForExec());
108 try
109 {
68ca2fe7 110 Long_t result = 0;
111 TInterpreter::EErrorCode error = TInterpreter::kNoError;
112
113 result = gInterpreter->ProcessLine(cmd, &error);
114
f6afd0e1 115 // Try to fix broken cint state? Code taken form pyroot.
68ca2fe7 116 if (G__get_return(0) > G__RETURN_NORMAL)
117 {
118 printf ("*** FIXING CINT STATE AFTER RETURN ***\n");
119 G__security_recover(0);
120 }
121
122 if (error)
123 {
124 mac->SetExecError();
125 Error("ExecMacros", "Executing %s::%s, CINT error ... hopefully recovered.",
126 mac->GetMacro().Data(), cmd.Data());
127 }
128 else
f6afd0e1 129 {
68ca2fe7 130 TEveElement *el = (TEveElement*) result;
131 TObject *obj = dynamic_cast<TObject*>(el);
132 if (el != 0 && obj == 0)
133 {
134 Warning("ExecMacros", "Executing %s::%s, returned TEveElement seems bad, setting it to 0.",
135 mac->GetMacro().Data(), cmd.Data());
136 el = 0;
137 }
138 mac->SetExecOK(el);
f6afd0e1 139 }
140 }
141 catch(TEveException& exc)
142 {
68ca2fe7 143 mac->SetExecException(exc);
144
145 // Try to fix broken cint state? Code taken form pyroot.
146 if (G__get_return(0) > G__RETURN_NORMAL)
147 {
148 printf ("*** FIXING CINT STATE AFTER EXCEPTION ***\n");
149 G__security_recover(0);
150 }
151
f6afd0e1 152 Error("ExecMacros", "Executing %s::%s, caught exception: '%s'.",
153 mac->GetMacro().Data(), cmd.Data(), exc.Data());
154 }
f6afd0e1 155 }
156}