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, TObjArray::Class());
66 fCalibJobs = new TObjArray(0);
67 fCalibJobs->SetOwner(kTRUE);
70 AliTPCAnalysisTaskcalib::~AliTPCAnalysisTaskcalib() {
74 printf("AliTPCAnalysisTaskcalib::~AliTPCAnalysisTaskcalib");
78 void AliTPCAnalysisTaskcalib::Exec(Option_t *) {
81 // Loop over tracks and call Process function
83 //Printf("ERROR: fESD not available");
86 fESDfriend=static_cast<AliESDfriend*>(fESD->FindListObject("AliESDfriend"));
87 Int_t n=fESD->GetNumberOfTracks();
90 //Printf("ERROR: fESDfriend not available");
93 if (fESDfriend->TestSkipBit()) return;
95 Int_t run = fESD->GetRunNumber();
96 for (Int_t i=0;i<n;++i) {
97 AliESDfriendTrack *friendTrack=fESDfriend->GetTrack(i);
98 AliESDtrack *track=fESD->GetTrack(i);
99 TObject *calibObject=0;
101 if (!friendTrack) continue;
102 for (Int_t j=0;(calibObject=friendTrack->GetCalibObject(j));++j)
103 if ((seed=dynamic_cast<AliTPCseed*>(calibObject)))
105 if (track) Process(track, run);
109 PostData(0,fCalibJobs);
112 void AliTPCAnalysisTaskcalib::ConnectInputData(Option_t *) {
116 TTree* tree=dynamic_cast<TTree*>(GetInputData(0));
118 //Printf("ERROR: Could not read chain from input slot 0");
121 AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
123 //Printf("ERROR: Could not get ESDInputHandler");
126 fESD = esdH->GetEvent();
127 //Printf("*** CONNECTED NEW EVENT ****");
132 void AliTPCAnalysisTaskcalib::CreateOutputObjects() {
136 //OpenFile(0, "RECREATE");
138 PostData(0,fCalibJobs);
141 void AliTPCAnalysisTaskcalib::Terminate(Option_t */*option*/) {
145 AliTPCcalibBase *job=0;
146 Int_t njobs = fCalibJobs->GetEntriesFast();
147 for (Int_t i=0;i<njobs;i++){
148 job = (AliTPCcalibBase*)fCalibJobs->UncheckedAt(i);
149 if (job) job->Terminate();
154 void AliTPCAnalysisTaskcalib::FinishTaskOutput()
157 // According description in AliAnalisysTask this method is call
158 // on the slaves before sending data
161 if(!fDebugOutputPath.IsNull()) {
162 RegisterDebugOutput();
168 void AliTPCAnalysisTaskcalib::Process(AliESDEvent *event) {
172 AliTPCcalibBase *job=0;
173 Int_t njobs = fCalibJobs->GetEntriesFast();
174 for (Int_t i=0;i<njobs;i++){
175 job = (AliTPCcalibBase*)fCalibJobs->UncheckedAt(i);
177 job->UpdateEventInfo(event);
178 if (job->AcceptTrigger())
184 void AliTPCAnalysisTaskcalib::Process(AliTPCseed *track) {
188 AliTPCcalibBase *job=0;
189 Int_t njobs = fCalibJobs->GetEntriesFast();
190 for (Int_t i=0;i<njobs;i++){
191 job = (AliTPCcalibBase*)fCalibJobs->UncheckedAt(i);
193 if (job->AcceptTrigger())
198 void AliTPCAnalysisTaskcalib::Process(AliESDtrack *track, Int_t run) {
202 AliTPCcalibBase *job=0;
203 Int_t njobs = fCalibJobs->GetEntriesFast();
204 for (Int_t i=0;i<njobs;i++){
205 job = (AliTPCcalibBase*)fCalibJobs->UncheckedAt(i);
207 if (job->AcceptTrigger())
208 job->Process(track,run);
212 Long64_t AliTPCAnalysisTaskcalib::Merge(TCollection *li) {
213 TIterator *i=fCalibJobs->MakeIterator();
214 AliTPCcalibBase *job;
216 while ((job=dynamic_cast<AliTPCcalibBase*>(i->Next())))
221 void AliTPCAnalysisTaskcalib::Analyze() {
223 // Analyze the content of the task
225 AliTPCcalibBase *job=0;
226 Int_t njobs = fCalibJobs->GetEntriesFast();
227 for (Int_t i=0;i<njobs;i++){
228 job = (AliTPCcalibBase*)fCalibJobs->UncheckedAt(i);
229 if (job) job->Analyze();
234 void AliTPCAnalysisTaskcalib::RegisterDebugOutput(){
238 AliTPCcalibBase *job=0;
239 Int_t njobs = fCalibJobs->GetEntriesFast();
240 for (Int_t i=0;i<njobs;i++){
241 job = (AliTPCcalibBase*)fCalibJobs->UncheckedAt(i);
242 if (job) job->RegisterDebugOutput(fDebugOutputPath.Data());
244 TString dsName=GetName();
246 TFile fff(dsName.Data(),"recreate");
247 fCalibJobs->Write("TPCCalib",TObject::kSingleKey);
250 // store - copy debug output to the destination position
251 // currently ONLY for local copy
252 TString dsName2=fDebugOutputPath.Data();
253 gSystem->MakeDirectory(dsName2.Data());
254 dsName2+=gSystem->HostName();
255 gSystem->MakeDirectory(dsName2.Data());
258 dsName2+=Int_t(s.GetNanoSec());
260 gSystem->MakeDirectory(dsName2.Data());
262 AliInfo(Form("copy %s\t%s\n",dsName.Data(),dsName2.Data()));
263 printf("copy %s\t%s\n",dsName.Data(),dsName2.Data());
264 TFile::Cp(dsName.Data(),dsName2.Data());