Avoid jumping of entries in data-selector window -- restore scrollbar position after...
[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()) ||
08b0f222 101 (mac->RequiresRawReader() && ! AliEveEventManager::HasRawReader()) ||
102 (mac->RequiresAOD() && ! AliEveEventManager::HasAOD()))
f6afd0e1 103 {
68ca2fe7 104 mac->SetExecNoData();
105 continue;
f6afd0e1 106 }
107
108 TString cmd(mac->FormForExec());
109 try
110 {
68ca2fe7 111 Long_t result = 0;
112 TInterpreter::EErrorCode error = TInterpreter::kNoError;
113
114 result = gInterpreter->ProcessLine(cmd, &error);
115
f6afd0e1 116 // Try to fix broken cint state? Code taken form pyroot.
68ca2fe7 117 if (G__get_return(0) > G__RETURN_NORMAL)
118 {
119 printf ("*** FIXING CINT STATE AFTER RETURN ***\n");
120 G__security_recover(0);
121 }
122
123 if (error)
124 {
125 mac->SetExecError();
126 Error("ExecMacros", "Executing %s::%s, CINT error ... hopefully recovered.",
127 mac->GetMacro().Data(), cmd.Data());
128 }
129 else
f6afd0e1 130 {
68ca2fe7 131 TEveElement *el = (TEveElement*) result;
132 TObject *obj = dynamic_cast<TObject*>(el);
133 if (el != 0 && obj == 0)
134 {
135 Warning("ExecMacros", "Executing %s::%s, returned TEveElement seems bad, setting it to 0.",
136 mac->GetMacro().Data(), cmd.Data());
137 el = 0;
138 }
139 mac->SetExecOK(el);
f6afd0e1 140 }
141 }
142 catch(TEveException& exc)
143 {
68ca2fe7 144 mac->SetExecException(exc);
145
146 // Try to fix broken cint state? Code taken form pyroot.
147 if (G__get_return(0) > G__RETURN_NORMAL)
148 {
149 printf ("*** FIXING CINT STATE AFTER EXCEPTION ***\n");
150 G__security_recover(0);
151 }
152
f6afd0e1 153 Error("ExecMacros", "Executing %s::%s, caught exception: '%s'.",
154 mac->GetMacro().Data(), cmd.Data(), exc.Data());
155 }
f6afd0e1 156 }
157}