]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliESDInputHandler.cxx
The total mult in V0 became float number.
[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 static Option_t *gESDDataType = "ESD";
43
44 //______________________________________________________________________________
45 AliESDInputHandler::AliESDInputHandler() :
46   AliInputEventHandler(),
47   fEvent(0x0),
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), fAnalysisType(0),
68      fNEvents(0), 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         zip = kTRUE;
125     } 
126     else if (fileName.Contains("AliESDs.root")){
127         fileName.ReplaceAll("AliESDs.root", "");
128     }
129     else if(fileName.Contains("#AliAOD.root")){
130         zip = kTRUE;
131     }
132     else if(fileName.Contains("AliAOD.root")){
133         fileName.ReplaceAll("AliAOD.root", "");
134     }
135     else if(fileName.Contains("#galice.root")){
136         // For running with galice and kinematics alone...
137         zip = kTRUE;
138     }
139     else if(fileName.Contains("galice.root")){
140         // For running with galice and kinematics alone...
141         fileName.ReplaceAll("galice.root", "");
142     }
143
144     
145     TString pathName("./");
146     if (fileName.Length() != 0) {
147         pathName = fileName;
148     }
149     
150     printf("AliESDInputHandler::Notify() Path: %s\n", pathName.Data());
151     
152     if (fRunTag) {
153         fRunTag->Clear();
154     } else {
155         fRunTag = new AliRunTag();
156     }
157     
158     delete fTreeT; fTreeT = 0;
159
160     if (fChainT) {
161         delete fChainT;
162         fChainT = 0;
163     }
164     
165     if (!fChainT) {
166         fChainT = new TChain("T");
167     }
168     
169
170
171     const char* tagPattern = "ESD.tag.root";
172     const char* name = 0x0;
173     TString tagFilename;
174     if (zip) {
175         TFile* file = fTree->GetCurrentFile();
176         TArchiveFile* arch = file->GetArchive();
177         TObjArray* arr = arch->GetMembers();
178         TIter next(arr);
179         
180         while ((file = (TFile*) next())) {
181             name = file->GetName();
182             if (strstr(name,tagPattern)) { 
183                 tagFilename = pathName.Data();
184                 tagFilename += "#";
185                 tagFilename += name;
186                 fChainT->Add(tagFilename);  
187                 AliInfo(Form("Adding %s to tag chain \n", tagFilename.Data()));
188             }//pattern check
189         } // archive file loop
190     } else {
191         void * dirp = gSystem->OpenDirectory(pathName.Data());
192         while((name = gSystem->GetDirEntry(dirp))) {
193             if (strstr(name,tagPattern)) { 
194                 tagFilename = pathName.Data();
195                 tagFilename += "/";
196                 tagFilename += name;
197                 fChainT->Add(tagFilename);  
198                 AliInfo(Form("Adding %s to tag chain \n", tagFilename.Data()));
199             }//pattern check
200         }//directory loop
201     }
202     fChainT->SetBranchAddress("AliTAG",&fRunTag);
203     fChainT->GetEntry(0);
204     return kTRUE;
205 }
206
207
208
209 Option_t *AliESDInputHandler::GetDataType() const
210 {
211 // Returns handled data type.
212    return gESDDataType;
213 }