]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliESDInputHandler.cxx
datamember added in AliGeomManager with number of alignable volumes per subdetector...
[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   fUseTags(kFALSE),
50   fChainT(0),
51   fTreeT(0),
52   fRunTag(0)
53 {
54   // default constructor
55 }
56
57 //______________________________________________________________________________
58 AliESDInputHandler::~AliESDInputHandler() 
59 {
60   //  destructor
61   //  delete fEvent;
62 }
63
64 //______________________________________________________________________________
65 AliESDInputHandler::AliESDInputHandler(const char* name, const char* title):
66     AliInputEventHandler(name, title), fEvent(0x0), fBranches(""), fBranchesOn(""), fAnalysisType(0),
67      fUseTags(kFALSE), fChainT(0), fTreeT(0), fRunTag(0)
68 {
69     // Constructor
70 }
71
72 Bool_t AliESDInputHandler::Init(TTree* tree,  Option_t* opt)
73 {
74     // Initialisation necessary for each new tree 
75     fAnalysisType = opt;
76     fTree         = tree;
77     
78     if (!fTree) return kFALSE;
79     // Get pointer to ESD event
80     SwitchOffBranches();
81     SwitchOnBranches();
82     
83     if (fEvent) {
84       delete fEvent;
85       fEvent = 0;
86     }
87     fEvent = new AliESDEvent();
88
89     fEvent->ReadFromTree(fTree);
90     return kTRUE;
91 }
92
93 Bool_t AliESDInputHandler::BeginEvent(Long64_t /*entry*/)
94 {
95     // Copy from old to new format if necessary
96   AliESD* old = ((AliESDEvent*) fEvent)->GetAliESDOld();
97   if (old) {
98         ((AliESDEvent*)fEvent)->CopyFromOldESD();
99         old->Reset();
100   }
101   return kTRUE;
102 }
103
104 Bool_t  AliESDInputHandler::FinishEvent()
105 {
106     // Finish the event 
107     if(fEvent)fEvent->Reset();
108     return kTRUE;
109
110
111 Bool_t AliESDInputHandler::Notify(const char* path)
112 {
113     // Notify a directory change
114     AliInfo(Form("Directory change %s \n", path));
115     //
116     if (!fUseTags) return (kTRUE);
117     
118     Bool_t zip = kFALSE;
119     
120     TString fileName(path);
121     if(fileName.Contains("#AliESDs.root")){
122         fileName.ReplaceAll("#AliESDs.root", "");
123         zip = kTRUE;
124     } 
125     else if (fileName.Contains("AliESDs.root")){
126         fileName.ReplaceAll("AliESDs.root", "");
127     }
128     else if(fileName.Contains("#AliAOD.root")){
129         fileName.ReplaceAll("#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         fileName.ReplaceAll("#galice.root", "");
138         zip = kTRUE;
139     }
140     else if(fileName.Contains("galice.root")){
141         // For running with galice and kinematics alone...
142         fileName.ReplaceAll("galice.root", "");
143     }
144
145     
146     TString* pathName = new TString("./");
147     *pathName = fileName;
148     printf("AliESDInputHandler::Notify() Path: %s\n", pathName->Data());
149     
150     if (fRunTag) {
151         fRunTag->Clear();
152     } else {
153         fRunTag = new AliRunTag();
154     }
155     
156     delete fTreeT; fTreeT = 0;
157
158     if (fChainT) {
159         delete fChainT;
160         fChainT = 0;
161     }
162     
163     if (!fChainT) {
164         fChainT = new TChain("T");
165     }
166     
167
168
169     const char* tagPattern = "ESD.tag.root";
170     const char* name = 0x0;
171     TString tagFilename;
172     if (zip) {
173         TFile* file = TFile::Open(fileName.Data());
174         TArchiveFile* arch = file->GetArchive();
175         TObjArray* arr = arch->GetMembers();
176         TIter next(arr);
177         
178         while ((file = (TFile*) next())) {
179             name = file->GetName();
180             if (strstr(name,tagPattern)) { 
181                 tagFilename = pathName->Data();
182                 tagFilename += "#";
183                 tagFilename += name;
184                 fChainT->Add(tagFilename);  
185                 AliInfo(Form("Adding %s to tag chain \n", tagFilename.Data()));
186             }//pattern check
187         } // archive file loop
188     } else {
189         void * dirp = gSystem->OpenDirectory(pathName->Data());
190         while((name = gSystem->GetDirEntry(dirp))) {
191             if (strstr(name,tagPattern)) { 
192                 tagFilename = pathName->Data();
193                 tagFilename += "/";
194                 tagFilename += name;
195                 fChainT->Add(tagFilename);  
196                 AliInfo(Form("Adding %s to tag chain \n", tagFilename.Data()));
197             }//pattern check
198         }//directory loop
199     }
200     fChainT->SetBranchAddress("AliTAG",&fRunTag);
201     fChainT->GetEntry(0);
202     return kTRUE;
203 }
204
205
206 void AliESDInputHandler::SwitchOffBranches() const {
207   //
208   // Switch of branches on user request
209     TObjArray * tokens = fBranches.Tokenize(" ");
210     Int_t ntok = tokens->GetEntries();
211     for (Int_t i = 0; i < ntok; i++)  {
212         TString str = ((TObjString*) tokens->At(i))->GetString();
213         if (str.Length() == 0)
214             continue;
215         fTree->SetBranchStatus(Form("%s%s%s","*", str.Data(), "*"), 0);
216         AliInfo(Form("Branch %s switched off \n", str.Data()));
217     }
218 }
219
220 void AliESDInputHandler::SwitchOnBranches() const {
221   //
222   // Switch of branches on user request
223   TObjArray * tokens = fBranchesOn.Tokenize(" ");
224   Int_t ntok = tokens->GetEntries();
225
226   for (Int_t i = 0; i < ntok; i++)  {
227       TString str = ((TObjString*) tokens->At(i))->GetString();
228       if (str.Length() == 0)
229           continue;
230       fTree->SetBranchStatus(Form("%s%s%s","*", str.Data(), "*"), 1);
231       AliInfo(Form("Branch %s switched on \n", str.Data()));
232   }
233 }