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