]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVE/EveBase/AliEveMacroExecutor.cxx
Prototype implementation of tags for macro selection.
[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//______________________________________________________________________________
19// Full description of AliEveMacroExecutor
20//
21
22ClassImp(AliEveMacroExecutor)
23
24//______________________________________________________________________________
25AliEveMacroExecutor::AliEveMacroExecutor() :
26 TObject(),
27 fMacros(new TList)
28{
29 // Constructor.
30
31 fMacros->SetOwner(kTRUE);
32}
33
34//______________________________________________________________________________
35AliEveMacroExecutor::~AliEveMacroExecutor()
36{
37 // Destructor.
38
39 delete fMacros;
40}
41
42/******************************************************************************/
43
44void AliEveMacroExecutor::AddMacro(AliEveMacro* mac)
45{
46 // Add a new macro. Ownership transfered to the executor.
47
48 static const TEveException kEH("AliEveMacroExecutor::AddMacro ");
49
50 const TString mname = mac->GetMacro();
51 if ( ! mname.IsNull() && TEveUtil::CheckMacro(mname) == kFALSE)
52 {
53 TEveUtil::LoadMacro(mname);
54 }
55 fMacros->Add(mac);
56}
57
7b2d546e 58AliEveMacro* AliEveMacroExecutor::FindMacro(const TString& func)
59{
60 // Find macro with given function name (it is supposed to be unique).
61 // Returns 0 if not found.
62
63 TIter next(fMacros);
64 AliEveMacro* mac;
65 while ((mac = (AliEveMacro*) next()))
66 {
67 if (mac->GetFunc() == func)
68 return mac;
69 }
70 return 0;
71}
72
f6afd0e1 73/******************************************************************************/
74
75#include "Api.h"
76#include "TInterpreter.h"
77
78void AliEveMacroExecutor::ExecMacros()
79{
80 // Execute registered macros.
81
82 TIter next(fMacros);
83 AliEveMacro* mac;
84 while ((mac = (AliEveMacro*) next()))
85 {
86 // printf ("macro '%s'; func '%s'; args '%s'\n", mac->GetMacro().Data(), mac->GetFunc().Data(), mac->GetArgs().Data());
87
88 if (mac->GetActive() == kFALSE || mac->GetFunc().IsNull())
89 {
90 continue;
91 }
92
93 switch (mac->GetSources())
94 {
95 case AliEveMacro::kRunLoader:
96 if ( ! AliEveEventManager::HasRunLoader())
97 continue;
98 break;
99 case AliEveMacro::kESD:
100 if ( ! AliEveEventManager::HasESD())
101 continue;
102 break;
103 case AliEveMacro::kESDfriend:
104 if ( ! AliEveEventManager::HasESDfriend())
105 continue;
106 break;
107 case AliEveMacro::kRawReader:
108 if ( ! AliEveEventManager::HasRawReader())
109 continue;
110 break;
111 default:
112 break;
113 }
114
115 TString cmd(mac->FormForExec());
116 try
117 {
118 gInterpreter->ProcessLine(cmd);
119 // Try to fix broken cint state? Code taken form pyroot.
120 if ( G__get_return( 0 ) > G__RETURN_NORMAL )
121 {
122 printf ("***INFIXING***\n");
123 G__security_recover( 0 ); // 0 ensures silence
124 }
125 }
126 catch(TEveException& exc)
127 {
128 Error("ExecMacros", "Executing %s::%s, caught exception: '%s'.",
129 mac->GetMacro().Data(), cmd.Data(), exc.Data());
130 }
131
132 // Try to fix broken cint state? Code taken form pyroot.
133 if ( G__get_return( 0 ) > G__RETURN_NORMAL )
134 {
135 printf ("***POSTFIXING****\n");
136 G__security_recover( 0 ); // 0 ensures silence
137 }
138 }
139}