]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliESDInputHandlerRP.cxx
EffC++ warnings corrected.
[u/mrichter/AliRoot.git] / STEER / AliESDInputHandlerRP.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: AliESDInputHandler.cxx 24521 2008-03-14 16:43:54Z morsch $ */
17
18 //-------------------------------------------------------------------------
19 //     Event handler for ESD input reading the RecPoint Trees in parallel
20 //     Author: Andreas Morsch, CERN
21 //-------------------------------------------------------------------------
22
23 #include <TTree.h>
24 #include <TList.h>
25 #include <TFile.h>
26 #include <TString.h>
27 #include <TObjString.h>
28 #include <TProcessID.h>
29
30 #include "AliESDInputHandlerRP.h"
31 #include "AliESDEvent.h"
32 #include "AliESD.h"
33 #include "AliLog.h"
34
35 ClassImp(AliESDInputHandlerRP)
36
37 //______________________________________________________________________________
38 AliESDInputHandlerRP::AliESDInputHandlerRP() :
39     AliESDInputHandler(),
40     fRTrees(new TList()),
41     fRFiles(new TList()),
42     fDirR(0),
43     fEventNumber(-1),
44     fNEvent(-1),
45     fFileNumber(0),
46     fEventsPerFile(0),
47     fExtension(""),
48     fPathName(new TString("./"))
49 {
50   // default constructor
51 }
52
53 //______________________________________________________________________________
54 AliESDInputHandlerRP::~AliESDInputHandlerRP() 
55 {
56   // destructor
57 }
58
59 //______________________________________________________________________________
60 AliESDInputHandlerRP::AliESDInputHandlerRP(const char* name, const char* title):
61     AliESDInputHandler(name, title),
62     fRTrees(new TList()),
63     fRFiles(new TList()),
64     fDirR(0),
65     fEventNumber(-1),
66     fNEvent(-1),
67     fFileNumber(0),
68     fEventsPerFile(0),
69     fExtension(""),
70     fPathName(new TString("./"))
71 {
72     // Constructor
73 }
74
75 Bool_t AliESDInputHandlerRP::Init(Option_t* opt)
76 {
77     //
78     // Initialize input
79     //
80     if (!(strcmp(opt, "proof")) || !(strcmp(opt, "local"))) return kTRUE;
81     //
82     TFile* file;
83     
84     file = TFile::Open(Form("%sTPC.RecPoints.root", fPathName->Data()));
85     if (!file) AliFatal(Form("AliESDInputHandlerRP: TPC.RecPoints.root not found in %s ! \n", fPathName->Data()));
86     fRFiles->Add(file);
87     fEventsPerFile = file->GetNkeys() - file->GetNProcessIDs();
88     // Reset the event number
89     fEventNumber      = -1;
90     fFileNumber       =  0;
91     fNEvent           =  fTree->GetEntries();
92     
93     printf("AliESDInputHandler::Init() %d\n",__LINE__);
94     return kTRUE;
95 }
96
97 Bool_t AliESDInputHandlerRP::BeginEvent(Long64_t entry)
98 {
99     // Begin the next event
100     // Delegate to base class
101     AliESDInputHandler::BeginEvent(entry);
102 //
103     if (entry == -1) {
104         fEventNumber++;
105         entry = fEventNumber;
106     } else {
107         fEventNumber = entry;
108     }
109     
110     if (entry >= fNEvent) {
111         AliWarning(Form("AliESDInputHandlerRP: Event number out of range %5d %5d\n", entry, fNEvent));
112         return kFALSE;
113     }
114     return LoadEvent(entry);
115 }
116
117 Bool_t AliESDInputHandlerRP::LoadEvent(Int_t iev)
118 {
119     // Load the event number iev
120     //
121     // Calculate the file number
122     Int_t inew  = iev / fEventsPerFile;
123     if (inew != fFileNumber) {
124         fFileNumber = inew;
125         if (!OpenFile(fFileNumber)){
126             return kFALSE;
127         }
128     }
129     // Folder name
130     char folder[20];
131     sprintf(folder, "Event%d", iev);
132     // Tree R
133     TFile* file = (TFile*) (fRFiles->At(0));
134     
135     file->GetObject(folder, fDirR);
136     if (!fDirR) {
137         AliWarning(Form("AliESDInputHandlerRP: Event #%5d not found\n", iev));
138         return kFALSE;
139     }
140     
141     TTree* tree;
142     fDirR ->GetObject("TreeR", tree);
143     fRTrees->Add(tree);
144     tree->ls();
145     
146     return kTRUE;
147 }
148
149 Bool_t AliESDInputHandlerRP::OpenFile(Int_t i)
150 {
151     // Open file i
152     Bool_t ok = kTRUE;
153     if (i > 0) {
154         fExtension = Form("%d", i);
155     } else {
156         fExtension = "";
157     }
158     
159     fRFiles->Delete();
160     TFile* file;
161     file = TFile::Open(Form("%sTPC.RecPoints%s.root", fPathName->Data(), fExtension));
162     if (!file) {
163         AliFatal(Form("AliESDInputHandlerRP: TPC.RecPoints.root not found in %s ! \n", fPathName->Data()));
164         ok = kFALSE;
165     }
166     return ok;
167 }
168
169 Bool_t AliESDInputHandlerRP::Notify(const char *path)
170 {
171   // Notify about directory change
172   // The directory is taken from the 'path' argument
173   // Reconnect trees
174     TString fileName(path);
175     if(fileName.Contains("AliESDs.root")){
176         fileName.ReplaceAll("AliESDs.root", "");
177     }
178
179     *fPathName = fileName;
180
181     printf("AliESDInputHandlerRP::Notify() Path: %s\n", fPathName->Data());
182     
183     ResetIO();
184     InitIO("");
185
186     return kTRUE;
187 }
188
189 Bool_t AliESDInputHandlerRP::FinishEvent()
190 {
191     // Clean-up after each event
192     delete fDirR;  fDirR = 0;
193     AliESDInputHandler::FinishEvent();
194     return kTRUE;
195 }
196
197 void AliESDInputHandlerRP::ResetIO()
198 {
199 // Delete trees and files
200     fRTrees->Delete();
201     fRFiles->Delete();
202     fExtension="";
203 }