]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/macros/alieve_init.C
3a1ef7d963acb6e6309964f828d12cac1b169a70
[u/mrichter/AliRoot.git] / EVE / macros / alieve_init.C
1 // $Id$
2 // Main authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 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 /// \ingroup evemacros
11 /// \file alieve_init.C
12
13 void alieve_init(const TString& cdburi = "",
14                  const TString& path   = ".", Int_t event=0,
15                  const Text_t* esdfile = 0,
16                  const Text_t* aodfile = 0,
17                  const Text_t* rawfile = 0,
18                  Bool_t assert_runloader = kFALSE,
19                  Bool_t assert_esd       = kFALSE,
20                  Bool_t assert_aod       = kFALSE,
21                  Bool_t assert_raw       = kFALSE)
22 {
23   if (cdburi.IsNull() && ! AliCDBManager::Instance()->IsDefaultStorageSet())
24   {
25     gEnv->SetValue("Root.Stacktrace", "no");
26     Fatal("alieve_init.C", "OCDB path MUST be specified as the first argument.");
27   }
28
29   Info("alieve_init", "Adding standard macros.");
30   TString  hack = gSystem->pwd(); // Problem with TGFileBrowser cding
31   alieve_init_import_macros();
32   gSystem->cd(hack);
33
34   TEveUtil::AssertMacro("VizDB_scan.C");
35
36   gSystem->ProcessEvents();
37
38   AliEveEventManager::SetFilesPath(path);
39   
40   AliEveEventManager::SetESDFileName(esdfile);
41   AliEveEventManager::SetRawFileName(rawfile);
42   AliEveEventManager::SetCdbUri(cdburi);
43   AliEveEventManager::SetAssertElements(assert_runloader, assert_esd,
44                                         assert_aod, assert_raw);
45
46   // Open event
47   if (path.BeginsWith("alien:") || ! cdburi.BeginsWith("local:"))
48   {
49     if (gGrid != 0)
50     {
51       Info("alieve_init", "TGrid already initializied. Skiping checks and initialization.");
52     }
53     else
54     {
55       Info("alieve_init", "AliEn requested - connecting.");
56       if (gSystem->Getenv("GSHELL_ROOT") == 0)
57       {
58         Error("alieve_init", "AliEn environment not initialized. Aborting.");
59         gSystem->Exit(1);
60       }
61       if (TGrid::Connect("alien") == 0)
62       {
63         Error("alieve_init", "TGrid::Connect() failed. Aborting.");
64         gSystem->Exit(1);
65       }
66     }
67   }
68
69   Info("alieve_init", "Opening event %d from '%s' ...", event, path.Data());
70   TString name("Event"); // CINT has trouble with direct "Event".
71   new AliEveEventManager(name, event);
72   gEve->AddEvent(AliEveEventManager::GetMaster());
73 }
74
75 void alieve_init_import_macros()
76 {
77   // Put macros in the list of browsables, add a macro browser to
78   // top-level GUI.
79
80   TString macdir("$(ALICE_ROOT)/EVE/alice-macros");
81   gSystem->ExpandPathName(macdir);
82
83   TFolder* f = gEve->GetMacroFolder();
84   void* dirhandle = gSystem->OpenDirectory(macdir.Data());
85   if (dirhandle != 0)
86   {
87     char* filename;
88     TPMERegexp re("\\.C$");
89     TObjArray names;
90     while ((filename = gSystem->GetDirEntry(dirhandle)) != 0)
91     {
92       if (re.Match(filename))
93         names.AddLast(new TObjString(filename));
94     }
95     names.Sort();
96
97     for (Int_t ii=0; ii<names.GetEntries(); ++ii)
98     {
99       TObjString * si = (TObjString*) names.At(ii);
100        f->Add(new TEveMacro(Form("%s/%s", macdir.Data(), (si->GetString()).Data())));
101     }
102   }
103   gSystem->FreeDirectory(dirhandle);
104
105   gROOT->GetListOfBrowsables()->Add(new TSystemDirectory(macdir.Data(), macdir.Data()));
106
107   {
108     TEveBrowser   *br = gEve->GetBrowser();
109     TGFileBrowser *fb = 0;
110     fb = br->GetFileBrowser();
111     fb->GotoDir(macdir);
112     {
113       br->StartEmbedding(0);
114       fb = br->MakeFileBrowser();
115       fb->BrowseObj(f);
116       fb->Show();
117       br->StopEmbedding();
118       br->SetTabTitle("Macros", 0);
119       br->SetTab(0, 0);
120     }
121   }
122 }