2 // Author: Matevz Tadel 2007
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 **************************************************************************/
10 #include "AliEveMacroExecutor.h"
11 #include "AliEveMacro.h"
12 #include "AliEveEventManager.h"
18 //______________________________________________________________________________
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.
25 ClassImp(AliEveMacroExecutor)
27 //______________________________________________________________________________
28 AliEveMacroExecutor::AliEveMacroExecutor() :
34 fMacros->SetOwner(kTRUE);
37 //______________________________________________________________________________
38 AliEveMacroExecutor::~AliEveMacroExecutor()
45 /******************************************************************************/
47 void AliEveMacroExecutor::AddMacro(AliEveMacro* mac)
49 // Add a new macro. Ownership transfered to the executor.
51 static const TEveException kEH("AliEveMacroExecutor::AddMacro ");
53 const TString mname = mac->GetMacro();
54 if ( ! mname.IsNull() && TEveUtil::CheckMacro(mname) == kFALSE)
56 TEveUtil::LoadMacro(mname);
61 AliEveMacro* AliEveMacroExecutor::FindMacro(const TString& func)
63 // Find macro with given function name (it is supposed to be unique).
64 // Returns 0 if not found.
68 while ((mac = (AliEveMacro*) next()))
70 if (mac->GetFunc() == func)
76 /******************************************************************************/
79 #include "TInterpreter.h"
81 void AliEveMacroExecutor::ExecMacros()
83 // Execute registered macros.
87 while ((mac = (AliEveMacro*) next()))
89 // printf ("macro '%s'; func '%s'; args '%s'\n", mac->GetMacro().Data(), mac->GetFunc().Data(), mac->GetArgs().Data());
91 mac->ResetExecState();
93 if (mac->GetActive() == kFALSE || mac->GetFunc().IsNull())
98 if ((mac->RequiresRunLoader() && ! AliEveEventManager::HasRunLoader()) ||
99 (mac->RequiresESD() && ! AliEveEventManager::HasESD()) ||
100 (mac->RequiresESDfriend() && ! AliEveEventManager::HasESDfriend()) ||
101 (mac->RequiresRawReader() && ! AliEveEventManager::HasRawReader()) ||
102 (mac->RequiresAOD() && ! AliEveEventManager::HasAOD()))
104 mac->SetExecNoData();
108 TString cmd(mac->FormForExec());
112 TInterpreter::EErrorCode error = TInterpreter::kNoError;
114 result = gInterpreter->ProcessLine(cmd, &error);
116 // Try to fix broken cint state? Code taken form pyroot.
117 if (G__get_return(0) > G__RETURN_NORMAL)
119 printf ("*** FIXING CINT STATE AFTER RETURN ***\n");
120 G__security_recover(0);
126 Error("ExecMacros", "Executing %s::%s, CINT error ... hopefully recovered.",
127 mac->GetMacro().Data(), cmd.Data());
131 TEveElement *el = (TEveElement*) result;
132 TObject *obj = dynamic_cast<TObject*>(el);
133 if (el != 0 && obj == 0)
135 Warning("ExecMacros", "Executing %s::%s, returned TEveElement seems bad, setting it to 0.",
136 mac->GetMacro().Data(), cmd.Data());
142 catch(TEveException& exc)
144 mac->SetExecException(exc);
146 // Try to fix broken cint state? Code taken form pyroot.
147 if (G__get_return(0) > G__RETURN_NORMAL)
149 printf ("*** FIXING CINT STATE AFTER EXCEPTION ***\n");
150 G__security_recover(0);
153 Error("ExecMacros", "Executing %s::%s, caught exception: '%s'.",
154 mac->GetMacro().Data(), cmd.Data(), exc.Data());