]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG0/AliSelectorRL.cxx
class with static analysis helper functions
[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 {
23   //
24   // Constructor. Initialization of pointers
25   //
26 }
27
28 AliSelectorRL::~AliSelectorRL()
29 {
30   //
31   // Destructor
32   //
33
34   // histograms are in the output list and deleted when the output
35   // list is deleted by the TSelector dtor
36 }
37
38 Bool_t AliSelectorRL::Notify()
39 {
40   // Calls base class Notify
41   // On top of that run loader is closed, because we change the input file
42
43   if (AliSelector::Notify() == kFALSE)
44     return kFALSE;
45
46   DeleteRunLoader();
47
48   return kTRUE;
49 }
50
51 Bool_t AliSelectorRL::Process(Long64_t entry)
52 {
53   // Call the baseclass Process and set event number in runLoader (if loaded)
54
55   if (AliSelector::Process(entry) == kFALSE)
56     return kFALSE;
57
58   if (fRunLoader)
59     fRunLoader->GetEvent(entry);
60
61   return kTRUE;
62 }
63
64 void AliSelectorRL::SlaveTerminate()
65 {
66   // removes runloader
67
68   AliSelector::SlaveTerminate();
69
70   DeleteRunLoader();
71 }
72
73 AliRunLoader* AliSelectorRL::GetRunLoader()
74 {
75   // Returns AliRun instance corresponding to current ESD active in fTree
76   // Loads galice.root, the file is identified by replacing "AliESDs" to
77   // "galice" in the file path of the ESD file. This is a hack, to be changed!
78
79   if (!fRunLoader)
80   {
81     if (!fTree->GetCurrentFile())
82       return 0;
83
84     TString fileName(fTree->GetCurrentFile()->GetName());
85     fileName.ReplaceAll("AliESDs", "galice");
86
87     fRunLoader = AliRunLoader::Open(fileName);
88     if (!fRunLoader)
89       return 0;
90
91     fRunLoader->LoadgAlice();
92     fRunLoader->GetEvent(fTree->GetTree()->GetReadEntry());
93   }
94
95   return fRunLoader;
96 }
97
98 void AliSelectorRL::DeleteRunLoader()
99 {
100   //
101   // deletes the runloader
102   //
103
104   if (fRunLoader)
105   {
106     fRunLoader->Delete();
107     fRunLoader = 0;
108   }
109 }
110
111 AliHeader* AliSelectorRL::GetHeader()
112 {
113   // Returns header retrieved from RunLoader
114
115   AliRunLoader* runLoader = GetRunLoader();
116   if (!runLoader)
117     return 0;
118
119   if (runLoader->GetHeader() == 0)
120     runLoader->LoadHeader();
121
122   return runLoader->GetHeader();
123 }
124
125 AliStack* AliSelectorRL::GetStack()
126 {
127   // Returns stack retrieved from RunLoader
128
129   AliRunLoader* runLoader = GetRunLoader();
130   if (!runLoader)
131     return 0;
132
133   if (runLoader->Stack() == 0)
134     runLoader->LoadKinematics();
135
136   return runLoader->Stack();
137 }