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