]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliESDInputHandler.cxx
Adding VZERO track references (Brigitte)
[u/mrichter/AliRoot.git] / STEER / AliESDInputHandler.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id$ */
17
18 //-------------------------------------------------------------------------
19 //     Event handler for ESD input 
20 //     Author: Andreas Morsch, CERN
21 //-------------------------------------------------------------------------
22
23 #include <TTree.h>
24 #include <TChain.h>
25 #include <TFile.h>
26 #include <TArchiveFile.h>
27 #include <TObjArray.h>
28 #include <TSystem.h>
29 #include <TString.h>
30 #include <TObjString.h>
31 #include <TProcessID.h>
32
33 #include "AliESDInputHandler.h"
34 #include "AliESDEvent.h"
35 #include "AliESD.h"
36 #include "AliRunTag.h"
37 #include "AliEventTag.h"
38 #include "AliLog.h"
39
40 ClassImp(AliESDInputHandler)
41
42 //______________________________________________________________________________
43 AliESDInputHandler::AliESDInputHandler() :
44   AliInputEventHandler(),
45   fEvent(0x0),
46   fBranches(""),
47   fBranchesOn(""),
48   fAnalysisType(0),
49   fNEvents(0),
50   fUseTags(kFALSE),
51   fChainT(0),
52   fTreeT(0),
53   fRunTag(0)
54 {
55   // default constructor
56 }
57
58 //______________________________________________________________________________
59 AliESDInputHandler::~AliESDInputHandler() 
60 {
61   //  destructor
62   //  delete fEvent;
63 }
64
65 //______________________________________________________________________________
66 AliESDInputHandler::AliESDInputHandler(const char* name, const char* title):
67     AliInputEventHandler(name, title), fEvent(0x0), fBranches(""), fBranchesOn(""), fAnalysisType(0),
68      fUseTags(kFALSE), fChainT(0), fTreeT(0), fRunTag(0)
69 {
70     // Constructor
71 }
72
73 Bool_t AliESDInputHandler::Init(TTree* tree,  Option_t* opt)
74 {
75     // Initialisation necessary for each new tree 
76     fAnalysisType = opt;
77     fTree         = tree;
78     
79     if (!fTree) return kFALSE;
80     // Get pointer to ESD event
81     SwitchOffBranches();
82     SwitchOnBranches();
83     
84     if (fEvent) {
85       delete fEvent;
86       fEvent = 0;
87     }
88     fEvent = new AliESDEvent();
89
90     fEvent->ReadFromTree(fTree);
91     fNEvents = fTree->GetEntries();
92     return kTRUE;
93 }
94
95 Bool_t AliESDInputHandler::BeginEvent(Long64_t /*entry*/)
96 {
97     // Copy from old to new format if necessary
98   AliESD* old = ((AliESDEvent*) fEvent)->GetAliESDOld();
99   if (old) {
100         ((AliESDEvent*)fEvent)->CopyFromOldESD();
101         old->Reset();
102   }
103   return kTRUE;
104 }
105
106 Bool_t  AliESDInputHandler::FinishEvent()
107 {
108     // Finish the event 
109     if(fEvent)fEvent->Reset();
110     return kTRUE;
111
112
113 Bool_t AliESDInputHandler::Notify(const char* path)
114 {
115     // Notify a directory change
116     AliInfo(Form("Directory change %s \n", path));
117     //
118     if (!fUseTags) return (kTRUE);
119     
120     Bool_t zip = kFALSE;
121     
122     TString fileName(path);
123     if(fileName.Contains("#AliESDs.root")){
124         fileName.ReplaceAll("#AliESDs.root", "");
125         zip = kTRUE;
126     } 
127     else if (fileName.Contains("AliESDs.root")){
128         fileName.ReplaceAll("AliESDs.root", "");
129     }
130     else if(fileName.Contains("#AliAOD.root")){
131         fileName.ReplaceAll("#AliAOD.root", "");
132         zip = kTRUE;
133     }
134     else if(fileName.Contains("AliAOD.root")){
135         fileName.ReplaceAll("AliAOD.root", "");
136     }
137     else if(fileName.Contains("#galice.root")){
138         // For running with galice and kinematics alone...
139         fileName.ReplaceAll("#galice.root", "");
140         zip = kTRUE;
141     }
142     else if(fileName.Contains("galice.root")){
143         // For running with galice and kinematics alone...
144         fileName.ReplaceAll("galice.root", "");
145     }
146
147     
148     TString pathName("./");
149     if (fileName.Length() != 0) {
150         pathName = fileName;
151     }
152     
153     printf("AliESDInputHandler::Notify() Path: %s\n", pathName.Data());
154     
155     if (fRunTag) {
156         fRunTag->Clear();
157     } else {
158         fRunTag = new AliRunTag();
159     }
160     
161     delete fTreeT; fTreeT = 0;
162
163     if (fChainT) {
164         delete fChainT;
165         fChainT = 0;
166     }
167     
168     if (!fChainT) {
169         fChainT = new TChain("T");
170     }
171     
172
173
174     const char* tagPattern = "ESD.tag.root";
175     const char* name = 0x0;
176     TString tagFilename;
177     if (zip) {
178         TFile* file = TFile::Open(fileName.Data());
179         TArchiveFile* arch = file->GetArchive();
180         TObjArray* arr = arch->GetMembers();
181         TIter next(arr);
182         
183         while ((file = (TFile*) next())) {
184             name = file->GetName();
185             if (strstr(name,tagPattern)) { 
186                 tagFilename = pathName.Data();
187                 tagFilename += "#";
188                 tagFilename += name;
189                 fChainT->Add(tagFilename);  
190                 AliInfo(Form("Adding %s to tag chain \n", tagFilename.Data()));
191             }//pattern check
192         } // archive file loop
193     } else {
194         void * dirp = gSystem->OpenDirectory(pathName.Data());
195         while((name = gSystem->GetDirEntry(dirp))) {
196             if (strstr(name,tagPattern)) { 
197                 tagFilename = pathName.Data();
198                 tagFilename += "/";
199                 tagFilename += name;
200                 fChainT->Add(tagFilename);  
201                 AliInfo(Form("Adding %s to tag chain \n", tagFilename.Data()));
202             }//pattern check
203         }//directory loop
204     }
205     fChainT->SetBranchAddress("AliTAG",&fRunTag);
206     fChainT->GetEntry(0);
207     return kTRUE;
208 }
209
210
211 void AliESDInputHandler::SwitchOffBranches() const {
212   //
213   // Switch of branches on user request
214     TObjArray * tokens = fBranches.Tokenize(" ");
215     Int_t ntok = tokens->GetEntries();
216     for (Int_t i = 0; i < ntok; i++)  {
217         TString str = ((TObjString*) tokens->At(i))->GetString();
218         if (str.Length() == 0)
219             continue;
220         fTree->SetBranchStatus(Form("%s%s%s","*", str.Data(), "*"), 0);
221         AliInfo(Form("Branch %s switched off \n", str.Data()));
222     }
223 }
224
225 void AliESDInputHandler::SwitchOnBranches() const {
226   //
227   // Switch of branches on user request
228   TObjArray * tokens = fBranchesOn.Tokenize(" ");
229   Int_t ntok = tokens->GetEntries();
230
231   for (Int_t i = 0; i < ntok; i++)  {
232       TString str = ((TObjString*) tokens->At(i))->GetString();
233       if (str.Length() == 0)
234           continue;
235       fTree->SetBranchStatus(Form("%s%s%s","*", str.Data(), "*"), 1);
236       AliInfo(Form("Branch %s switched on \n", str.Data()));
237   }
238 }