1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 ///////////////////////////////////////////////////////////////////////////////
19 // ANALYSIS task to perrorm TPC calibration //
22 ///////////////////////////////////////////////////////////////////////////////
23 #include "AliTPCAnalysisTaskcalib.h"
25 #include "AliTPCcalibBase.h"
26 #include "AliESDEvent.h"
27 #include "AliESDfriend.h"
28 #include "AliESDtrack.h"
29 #include "AliESDfriendTrack.h"
30 #include "AliTPCseed.h"
31 #include "AliESDInputHandler.h"
32 #include "AliAnalysisManager.h"
35 #include "TTimeStamp.h"
37 ClassImp(AliTPCAnalysisTaskcalib)
40 AliTPCAnalysisTaskcalib::AliTPCAnalysisTaskcalib()
48 // default constructor
54 AliTPCAnalysisTaskcalib::AliTPCAnalysisTaskcalib(const char *name)
55 :AliAnalysisTask(name,""),
64 DefineInput(0, TChain::Class());
65 DefineOutput(0, AliTPCcalibBase::Class());
66 DefineOutput(1, AliTPCcalibBase::Class());
67 DefineOutput(2, AliTPCcalibBase::Class());
68 DefineOutput(3, AliTPCcalibBase::Class());
69 DefineOutput(4, AliTPCcalibBase::Class());
70 DefineOutput(5, AliTPCcalibBase::Class());
71 fCalibJobs = new TObjArray(0);
72 fCalibJobs->SetOwner(kTRUE);
75 AliTPCAnalysisTaskcalib::~AliTPCAnalysisTaskcalib() {
79 printf("AliTPCAnalysisTaskcalib::~AliTPCAnalysisTaskcalib");
83 void AliTPCAnalysisTaskcalib::Exec(Option_t *) {
86 // Loop over tracks and call Process function
88 //Printf("ERROR: fESD not available");
91 fESDfriend=static_cast<AliESDfriend*>(fESD->FindListObject("AliESDfriend"));
92 Int_t n=fESD->GetNumberOfTracks();
95 //Printf("ERROR: fESDfriend not available");
98 if (fESDfriend->TestSkipBit()) return;
100 Int_t run = fESD->GetRunNumber();
101 for (Int_t i=0;i<n;++i) {
102 AliESDfriendTrack *friendTrack=fESDfriend->GetTrack(i);
103 AliESDtrack *track=fESD->GetTrack(i);
104 TObject *calibObject=0;
106 if (!friendTrack) continue;
107 for (Int_t j=0;(calibObject=friendTrack->GetCalibObject(j));++j)
108 if ((seed=dynamic_cast<AliTPCseed*>(calibObject)))
110 if (track) Process(track, run);
116 void AliTPCAnalysisTaskcalib::ConnectInputData(Option_t *) {
120 TTree* tree=dynamic_cast<TTree*>(GetInputData(0));
122 //Printf("ERROR: Could not read chain from input slot 0");
125 AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
127 //Printf("ERROR: Could not get ESDInputHandler");
130 fESD = esdH->GetEvent();
131 //Printf("*** CONNECTED NEW EVENT ****");
136 void AliTPCAnalysisTaskcalib::CreateOutputObjects() {
140 //OpenFile(0, "RECREATE");
142 for (Int_t i=0; i<fCalibJobs->GetEntries(); i++)
144 if (fCalibJobs->At(i))
145 PostData(i,(AliTPCcalibBase*)fCalibJobs->At(i));
149 void AliTPCAnalysisTaskcalib::Terminate(Option_t */*option*/) {
153 AliTPCcalibBase *job=0;
154 Int_t njobs = fCalibJobs->GetEntriesFast();
155 for (Int_t i=0;i<njobs;i++){
156 job = (AliTPCcalibBase*)fCalibJobs->UncheckedAt(i);
157 if (job) job->Terminate();
162 void AliTPCAnalysisTaskcalib::FinishTaskOutput()
165 // According description in AliAnalisysTask this method is call
166 // on the slaves before sending data
169 if(!fDebugOutputPath.IsNull()) {
170 RegisterDebugOutput();
176 void AliTPCAnalysisTaskcalib::Process(AliESDEvent *event) {
180 AliTPCcalibBase *job=0;
181 Int_t njobs = fCalibJobs->GetEntriesFast();
182 for (Int_t i=0;i<njobs;i++){
183 job = (AliTPCcalibBase*)fCalibJobs->UncheckedAt(i);
185 job->UpdateEventInfo(event);
186 if (job->AcceptTrigger())
192 void AliTPCAnalysisTaskcalib::Process(AliTPCseed *track) {
196 AliTPCcalibBase *job=0;
197 Int_t njobs = fCalibJobs->GetEntriesFast();
198 for (Int_t i=0;i<njobs;i++){
199 job = (AliTPCcalibBase*)fCalibJobs->UncheckedAt(i);
201 if (job->AcceptTrigger())
206 void AliTPCAnalysisTaskcalib::Process(AliESDtrack *track, Int_t run) {
210 AliTPCcalibBase *job=0;
211 Int_t njobs = fCalibJobs->GetEntriesFast();
212 for (Int_t i=0;i<njobs;i++){
213 job = (AliTPCcalibBase*)fCalibJobs->UncheckedAt(i);
215 if (job->AcceptTrigger())
216 job->Process(track,run);
220 Long64_t AliTPCAnalysisTaskcalib::Merge(TCollection *li) {
221 TIterator *i=fCalibJobs->MakeIterator();
222 AliTPCcalibBase *job;
224 while ((job=dynamic_cast<AliTPCcalibBase*>(i->Next())))
229 void AliTPCAnalysisTaskcalib::Analyze() {
231 // Analyze the content of the task
233 AliTPCcalibBase *job=0;
234 Int_t njobs = fCalibJobs->GetEntriesFast();
235 for (Int_t i=0;i<njobs;i++){
236 job = (AliTPCcalibBase*)fCalibJobs->UncheckedAt(i);
237 if (job) job->Analyze();
242 void AliTPCAnalysisTaskcalib::RegisterDebugOutput(){
246 AliTPCcalibBase *job=0;
247 Int_t njobs = fCalibJobs->GetEntriesFast();
248 for (Int_t i=0;i<njobs;i++){
249 job = (AliTPCcalibBase*)fCalibJobs->UncheckedAt(i);
250 if (job) job->RegisterDebugOutput(fDebugOutputPath.Data());
252 TString dsName=GetName();
254 TFile fff(dsName.Data(),"recreate");
255 fCalibJobs->Write("TPCCalib",TObject::kSingleKey);
258 // store - copy debug output to the destination position
259 // currently ONLY for local copy
260 TString dsName2=fDebugOutputPath.Data();
261 gSystem->MakeDirectory(dsName2.Data());
262 dsName2+=gSystem->HostName();
263 gSystem->MakeDirectory(dsName2.Data());
266 dsName2+=Int_t(s.GetNanoSec());
268 gSystem->MakeDirectory(dsName2.Data());
270 AliInfo(Form("copy %s\t%s\n",dsName.Data(),dsName2.Data()));
271 printf("copy %s\t%s\n",dsName.Data(),dsName2.Data());
272 TFile::Cp(dsName.Data(),dsName2.Data());