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