]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliSelectorRL.cxx
Adding AliSelector, AliSelectorRL to ESD, STEER that can be used as base classes
[u/mrichter/AliRoot.git] / STEER / 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   {
62     if (fRunLoader->GetEvent(entry) != 0)
63       return kFALSE;
64   }
65
66   return kTRUE;
67 }
68
69 void AliSelectorRL::SlaveTerminate()
70 {
71   // removes runloader
72
73   AliSelector::SlaveTerminate();
74
75   DeleteRunLoader();
76 }
77
78 AliRunLoader* AliSelectorRL::GetRunLoader()
79 {
80   // Returns AliRun instance corresponding to current ESD active in fTree
81   // Loads galice.root, the file is identified by replacing "AliESDs" to
82   // "galice" in the file path of the ESD file. 
83
84   if (!fRunLoader)
85   {
86     if (!fTree->GetCurrentFile())
87       return 0;
88
89     TString fileName(fTree->GetCurrentFile()->GetName());
90     fileName.ReplaceAll("AliESDs", "galice");
91
92     // temporary workaround for PROOF bug #18505
93     fileName.ReplaceAll("#galice.root#galice.root", "#galice.root");
94
95     fRunLoader = AliRunLoader::Open(fileName);
96     if (!fRunLoader)
97       return 0;
98
99     fRunLoader->GetEvent(fTree->GetTree()->GetReadEntry());
100   }
101
102   return fRunLoader;
103 }
104
105 void AliSelectorRL::DeleteRunLoader()
106 {
107   //
108   // deletes the runloader
109   //
110
111   if (fRunLoader)
112   {
113     fRunLoader->Delete();
114     fRunLoader = 0;
115   }
116
117   fKinematicsLoaded = kFALSE;
118   fHeaderLoaded = kFALSE;
119 }
120
121 AliHeader* AliSelectorRL::GetHeader()
122 {
123   // Returns header retrieved from RunLoader
124
125   AliRunLoader* runLoader = GetRunLoader();
126   if (!runLoader)
127     return 0;
128
129   if (fHeaderLoaded == kFALSE)
130     if (runLoader->LoadHeader() != 0)
131       return 0;
132
133   fHeaderLoaded = kTRUE;
134
135   return runLoader->GetHeader();
136 }
137
138 AliStack* AliSelectorRL::GetStack()
139 {
140   // Returns stack retrieved from RunLoader
141
142   AliRunLoader* runLoader = GetRunLoader();
143   if (!runLoader)
144     return 0;
145
146   if (fKinematicsLoaded == kFALSE)
147     if (runLoader->LoadKinematics() != 0)
148       return 0;
149
150   fKinematicsLoaded = kTRUE;
151
152   return runLoader->Stack();
153 }