]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG0/AliSelectorRL.cxx
temporary workaround for PROOF bug #18505
[u/mrichter/AliRoot.git] / PWG0 / AliSelectorRL.cxx
1 /* $Id$ */
2
3 #include "AliSelectorRL.h"
4
5 #include <AliLog.h>
6 #include <AliRunLoader.h>
7
8 #include <TTree.h>
9 #include <TFile.h>
10
11 //
12 // This selector depends on the RunLoader, therefore to use it you have to have the whole AliRoot available
13 // The benefit is that you can use the RunLoader to access everything in the data structure
14 // If you only have the ESD library use AliSelector instead
15 //
16
17 ClassImp(AliSelectorRL)
18
19 AliSelectorRL::AliSelectorRL() :
20   AliSelector(),
21   fRunLoader(0),
22   fKinematicsLoaded(kFALSE),
23   fHeaderLoaded(kFALSE)
24 {
25   //
26   // Constructor. Initialization of pointers
27   //
28 }
29
30 AliSelectorRL::~AliSelectorRL()
31 {
32   //
33   // Destructor
34   //
35
36   // histograms are in the output list and deleted when the output
37   // list is deleted by the TSelector dtor
38 }
39
40 Bool_t AliSelectorRL::Notify()
41 {
42   // Calls base class Notify
43   // On top of that run loader is closed, because we change the input file
44
45   if (AliSelector::Notify() == kFALSE)
46     return kFALSE;
47
48   DeleteRunLoader();
49
50   return kTRUE;
51 }
52
53 Bool_t AliSelectorRL::Process(Long64_t entry)
54 {
55   // Call the baseclass Process and set event number in runLoader (if loaded)
56
57   if (AliSelector::Process(entry) == kFALSE)
58     return kFALSE;
59
60   if (fRunLoader)
61     fRunLoader->GetEvent(entry);
62
63   return kTRUE;
64 }
65
66 void AliSelectorRL::SlaveTerminate()
67 {
68   // removes runloader
69
70   AliSelector::SlaveTerminate();
71
72   DeleteRunLoader();
73 }
74
75 AliRunLoader* AliSelectorRL::GetRunLoader()
76 {
77   // Returns AliRun instance corresponding to current ESD active in fTree
78   // Loads galice.root, the file is identified by replacing "AliESDs" to
79   // "galice" in the file path of the ESD file. This is a hack, to be changed!
80
81   if (!fRunLoader)
82   {
83     if (!fTree->GetCurrentFile())
84       return 0;
85
86     TString fileName(fTree->GetCurrentFile()->GetName());
87     fileName.ReplaceAll("AliESDs", "galice");
88
89     // temporary workaround for PROOF bug #18505
90     fileName.ReplaceAll("#galice.root#galice.root", "#galice.root");
91
92     fRunLoader = AliRunLoader::Open(fileName);
93     if (!fRunLoader)
94       return 0;
95
96     if (fRunLoader->LoadgAlice() != 0)
97     {
98       delete fRunLoader;
99       fRunLoader = 0;
100       return 0;
101     }
102     fRunLoader->GetEvent(fTree->GetTree()->GetReadEntry());
103   }
104
105   return fRunLoader;
106 }
107
108 void AliSelectorRL::DeleteRunLoader()
109 {
110   //
111   // deletes the runloader
112   //
113
114   if (fRunLoader)
115   {
116     fRunLoader->Delete();
117     fRunLoader = 0;
118   }
119
120   fKinematicsLoaded = kFALSE;
121   fHeaderLoaded = kFALSE;
122 }
123
124 AliHeader* AliSelectorRL::GetHeader()
125 {
126   // Returns header retrieved from RunLoader
127
128   AliRunLoader* runLoader = GetRunLoader();
129   if (!runLoader)
130     return 0;
131
132   if (fHeaderLoaded == kFALSE)
133     if (runLoader->LoadHeader() != 0)
134       return 0;
135
136   fHeaderLoaded = kTRUE;
137
138   return runLoader->GetHeader();
139 }
140
141 AliStack* AliSelectorRL::GetStack()
142 {
143   // Returns stack retrieved from RunLoader
144
145   AliRunLoader* runLoader = GetRunLoader();
146   if (!runLoader)
147     return 0;
148
149   if (fKinematicsLoaded == kFALSE)
150     if (runLoader->LoadKinematics() != 0)
151       return 0;
152
153   fKinematicsLoaded = kTRUE;
154
155   return runLoader->Stack();
156 }