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