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