]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TPC/AliTPCAnalysisTaskcalib.cxx
Setting Id keyword property.
[u/mrichter/AliRoot.git] / TPC / AliTPCAnalysisTaskcalib.cxx
CommitLineData
73d51118 1/**************************************************************************
2 * Copyright(c) 1998-1999, 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
17///////////////////////////////////////////////////////////////////////////////
18// //
fc492d0d 19// ANALYSIS task to perrorm TPC calibration //
20
73d51118 21// //
22///////////////////////////////////////////////////////////////////////////////
23#include "AliTPCAnalysisTaskcalib.h"
24#include "TChain.h"
25#include "AliTPCcalibBase.h"
26#include "AliESDEvent.h"
27#include "AliESDfriend.h"
f7f33dec 28#include "AliESDtrack.h"
73d51118 29#include "AliESDfriendTrack.h"
30#include "AliTPCseed.h"
31#include "AliESDInputHandler.h"
32#include "AliAnalysisManager.h"
679480d0 33#include "TFile.h"
34#include "TSystem.h"
35#include "TTimeStamp.h"
73d51118 36
37ClassImp(AliTPCAnalysisTaskcalib)
38
f7f33dec 39
40AliTPCAnalysisTaskcalib::AliTPCAnalysisTaskcalib()
41 :AliAnalysisTask(),
42 fCalibJobs(0),
43 fESD(0),
44 fESDfriend(0),
5647625c 45 fDebugOutputPath("")
f7f33dec 46{
47 //
48 // default constructor
49 //
50
51}
52
53
73d51118 54AliTPCAnalysisTaskcalib::AliTPCAnalysisTaskcalib(const char *name)
55 :AliAnalysisTask(name,""),
56 fCalibJobs(0),
0db06ea6 57 fESD(0),
f7f33dec 58 fESDfriend(0),
5647625c 59 fDebugOutputPath("")
73d51118 60{
61 //
62 // Constructor
63 //
64 DefineInput(0, TChain::Class());
65 DefineOutput(0, TObjArray::Class());
f7f33dec 66 fCalibJobs = new TObjArray(0);
42a48f93 67 fCalibJobs->SetOwner(kTRUE);
73d51118 68}
69
70AliTPCAnalysisTaskcalib::~AliTPCAnalysisTaskcalib() {
71 //
72 // destructor
73 //
f7f33dec 74 printf("AliTPCAnalysisTaskcalib::~AliTPCAnalysisTaskcalib");
edb92719 75 fCalibJobs->Delete();
73d51118 76}
77
78void AliTPCAnalysisTaskcalib::Exec(Option_t *) {
79 //
80 // Exec function
81 // Loop over tracks and call Process function
82 if (!fESD) {
2acad464 83 //Printf("ERROR: fESD not available");
73d51118 84 return;
85 }
86 fESDfriend=static_cast<AliESDfriend*>(fESD->FindListObject("AliESDfriend"));
87 if (!fESDfriend) {
2acad464 88 //Printf("ERROR: fESDfriend not available");
73d51118 89 return;
90 }
91 Int_t n=fESD->GetNumberOfTracks();
f7f33dec 92 Process(fESD);
5822e507 93 Int_t run = fESD->GetRunNumber();
73d51118 94 for (Int_t i=0;i<n;++i) {
95 AliESDfriendTrack *friendTrack=fESDfriend->GetTrack(i);
f7f33dec 96 AliESDtrack *track=fESD->GetTrack(i);
0db06ea6 97 TObject *calibObject=0;
73d51118 98 AliTPCseed *seed=0;
1f3b7de0 99 if (!friendTrack) continue;
0db06ea6 100 for (Int_t j=0;(calibObject=friendTrack->GetCalibObject(j));++j)
101 if ((seed=dynamic_cast<AliTPCseed*>(calibObject)))
73d51118 102 break;
5822e507 103 if (track) Process(track, run);
73d51118 104 if (seed)
105 Process(seed);
106 }
c51653e8 107 PostData(0,fCalibJobs);
73d51118 108}
109
110void AliTPCAnalysisTaskcalib::ConnectInputData(Option_t *) {
111 //
112 //
113 //
114 TTree* tree=dynamic_cast<TTree*>(GetInputData(0));
115 if (!tree) {
2acad464 116 //Printf("ERROR: Could not read chain from input slot 0");
73d51118 117 }
118 else {
119 AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
120 if (!esdH) {
2acad464 121 //Printf("ERROR: Could not get ESDInputHandler");
73d51118 122 }
123 else {
124 fESD = esdH->GetEvent();
684602c8 125 //Printf("*** CONNECTED NEW EVENT ****");
73d51118 126 }
127 }
128}
129
130void AliTPCAnalysisTaskcalib::CreateOutputObjects() {
131 //
132 //
133 //
54b8f8e1 134 //OpenFile(0, "RECREATE");
77d31cb8 135
136 PostData(0,fCalibJobs);
73d51118 137}
77d31cb8 138
0db06ea6 139void AliTPCAnalysisTaskcalib::Terminate(Option_t */*option*/) {
7eaa723e 140 //
08825fb4 141 // Terminate
7eaa723e 142 //
08825fb4 143 AliTPCcalibBase *job=0;
f7f33dec 144 Int_t njobs = fCalibJobs->GetEntriesFast();
08825fb4 145 for (Int_t i=0;i<njobs;i++){
f7f33dec 146 job = (AliTPCcalibBase*)fCalibJobs->UncheckedAt(i);
08825fb4 147 if (job) job->Terminate();
7eaa723e 148 }
42a48f93 149
73d51118 150}
151
f7f33dec 152void AliTPCAnalysisTaskcalib::FinishTaskOutput()
153{
154 //
155 // According description in AliAnalisysTask this method is call
156 // on the slaves before sending data
157 //
158 Terminate("slave");
5647625c 159 if(!fDebugOutputPath.IsNull()) {
160 RegisterDebugOutput();
161 }
679480d0 162
f7f33dec 163}
164
165
73d51118 166void AliTPCAnalysisTaskcalib::Process(AliESDEvent *event) {
08825fb4 167 //
168 // Process ESD event
169 //
170 AliTPCcalibBase *job=0;
f7f33dec 171 Int_t njobs = fCalibJobs->GetEntriesFast();
08825fb4 172 for (Int_t i=0;i<njobs;i++){
f7f33dec 173 job = (AliTPCcalibBase*)fCalibJobs->UncheckedAt(i);
42a48f93 174 if (job) {
175 job->UpdateEventInfo(event);
c51653e8 176 if (job->AcceptTrigger())
177 job->Process(event);
42a48f93 178 }
08825fb4 179 }
73d51118 180}
181
182void AliTPCAnalysisTaskcalib::Process(AliTPCseed *track) {
08825fb4 183 //
184 // Process TPC track
185 //
186 AliTPCcalibBase *job=0;
f7f33dec 187 Int_t njobs = fCalibJobs->GetEntriesFast();
08825fb4 188 for (Int_t i=0;i<njobs;i++){
f7f33dec 189 job = (AliTPCcalibBase*)fCalibJobs->UncheckedAt(i);
c51653e8 190 if (job)
191 if (job->AcceptTrigger())
192 job->Process(track);
f7f33dec 193 }
194}
195
5822e507 196void AliTPCAnalysisTaskcalib::Process(AliESDtrack *track, Int_t run) {
f7f33dec 197 //
198 // Process ESD track
199 //
200 AliTPCcalibBase *job=0;
201 Int_t njobs = fCalibJobs->GetEntriesFast();
202 for (Int_t i=0;i<njobs;i++){
203 job = (AliTPCcalibBase*)fCalibJobs->UncheckedAt(i);
c51653e8 204 if (job)
205 if (job->AcceptTrigger())
206 job->Process(track,run);
08825fb4 207 }
73d51118 208}
209
210Long64_t AliTPCAnalysisTaskcalib::Merge(TCollection *li) {
f7f33dec 211 TIterator *i=fCalibJobs->MakeIterator();
73d51118 212 AliTPCcalibBase *job;
213 Long64_t n=0;
0db06ea6 214 while ((job=dynamic_cast<AliTPCcalibBase*>(i->Next())))
73d51118 215 n+=job->Merge(li);
216 return n;
217}
218
219void AliTPCAnalysisTaskcalib::Analyze() {
08825fb4 220 //
221 // Analyze the content of the task
222 //
223 AliTPCcalibBase *job=0;
f7f33dec 224 Int_t njobs = fCalibJobs->GetEntriesFast();
08825fb4 225 for (Int_t i=0;i<njobs;i++){
f7f33dec 226 job = (AliTPCcalibBase*)fCalibJobs->UncheckedAt(i);
08825fb4 227 if (job) job->Analyze();
228 }
73d51118 229}
f7f33dec 230
231
232void AliTPCAnalysisTaskcalib::RegisterDebugOutput(){
233 //
234 //
235 //
236 AliTPCcalibBase *job=0;
237 Int_t njobs = fCalibJobs->GetEntriesFast();
238 for (Int_t i=0;i<njobs;i++){
239 job = (AliTPCcalibBase*)fCalibJobs->UncheckedAt(i);
240 if (job) job->RegisterDebugOutput(fDebugOutputPath.Data());
241 }
86cd06f0 242 TString dsName=GetName();
243 dsName+=".root";
244 TFile fff(dsName.Data(),"recreate");
c51653e8 245 fCalibJobs->Write("TPCCalib",TObject::kSingleKey);
679480d0 246 fff.Close();
247 //
248 // store - copy debug output to the destination position
249 // currently ONLY for local copy
679480d0 250 TString dsName2=fDebugOutputPath.Data();
251 gSystem->MakeDirectory(dsName2.Data());
252 dsName2+=gSystem->HostName();
253 gSystem->MakeDirectory(dsName2.Data());
254 dsName2+="/";
255 TTimeStamp s;
256 dsName2+=Int_t(s.GetNanoSec());
257 dsName2+="/";
258 gSystem->MakeDirectory(dsName2.Data());
259 dsName2+=dsName;
260 AliInfo(Form("copy %s\t%s\n",dsName.Data(),dsName2.Data()));
261 printf("copy %s\t%s\n",dsName.Data(),dsName2.Data());
262 TFile::Cp(dsName.Data(),dsName2.Data());
263
f7f33dec 264}