]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCAnalysisTaskcalib.cxx
Bugfix: lowercase b should be upper case B for component id: TPCClusterFinder32Bit
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCAnalysisTaskcalib.cxx
1 // $Id$
2 /**************************************************************************
3  * This file is property of and copyright by the ALICE HLT Project        * 
4  * ALICE Experiment at CERN, All rights reserved.                         *
5  *                                                                        *
6  * Primary Authors: Kalliopi Kanaki <Kalliopi.Kanaki@ift.uib.no>          *
7  *                  for The ALICE HLT Project.                            *
8  *                                                                        *
9  * Permission to use, copy, modify and distribute this software and its   *
10  * documentation strictly for non-commercial purposes is hereby granted   *
11  * without fee, provided that the above copyright notice appears in all   *
12  * copies and that both the copyright notice and this permission notice   *
13  * appear in the supporting documentation. The authors make no claims     *
14  * about the suitability of this software for any purpose. It is          *
15  * provided "as is" without express or implied warranty.                  *
16  **************************************************************************/
17
18 /** @file   AliHLTTPCAnalysisTaskcalib.cxx
19     @author Kalliopi Kanaki
20     @date   
21     @brief  
22 */
23
24 // see header file for class documentation
25 // or
26 // refer to README to build package
27 // or
28 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt   
29
30 #if __GNUC__>= 3
31 using namespace std;
32 #endif
33
34 #include "AliHLTTPCAnalysisTaskcalib.h"
35 #include "AliTPCcalibBase.h"
36 #include "AliESDEvent.h"
37 #include "AliESDfriend.h"
38 #include "AliESDtrack.h"
39 #include "AliESDfriendTrack.h"
40 #include "AliTPCseed.h"
41
42 #include "AliESDInputHandler.h"
43 #include "AliAnalysisManager.h"
44
45 #include "TFile.h"
46 #include "TSystem.h"
47 #include "TTimeStamp.h"
48 #include "TChain.h"
49
50 ClassImp(AliHLTTPCAnalysisTaskcalib)
51
52 AliHLTTPCAnalysisTaskcalib::AliHLTTPCAnalysisTaskcalib()
53    :
54    AliTPCAnalysisTaskcalib(),
55    fCalibJobs(0),
56    fESD(0),
57    fESDfriend(0),
58    fDebugOutputPath()
59 {
60   //
61   // default constructor
62   // 
63 }
64
65
66 AliHLTTPCAnalysisTaskcalib::AliHLTTPCAnalysisTaskcalib(const char *name) 
67    :
68    AliTPCAnalysisTaskcalib(name),
69    fCalibJobs(0),
70    fESD(0),
71    fESDfriend(0),
72    fDebugOutputPath()
73 {
74   //
75   // Constructor
76   //
77   DefineInput(0, TChain::Class());
78   DefineOutput(0, TObjArray::Class());
79   fCalibJobs = new TObjArray(0);
80   fCalibJobs->SetOwner(kTRUE);
81 }
82
83 AliHLTTPCAnalysisTaskcalib::~AliHLTTPCAnalysisTaskcalib() {
84   //
85   // destructor
86   //
87   printf("AliHLTTPCAnalysisTaskcalib::~AliHLTTPCAnalysisTaskcalib");
88   fCalibJobs->Delete();
89 }
90
91 void AliHLTTPCAnalysisTaskcalib::Exec(Option_t *) {
92   //
93   // Exec function
94   // Loop over tracks and call  Process function
95   if (!fESD) {
96     //Printf("ERROR: fESD not available");
97     return;
98   }
99   fESDfriend=static_cast<AliESDfriend*>(fESD->FindListObject("AliESDfriend"));
100   if (!fESDfriend) {
101     //Printf("ERROR: fESDfriend not available");
102     return;
103   }
104   Int_t n=fESD->GetNumberOfTracks();
105   Process(fESD);
106   Int_t run = fESD->GetRunNumber();
107   for (Int_t i=0;i<n;++i) {
108     AliESDfriendTrack *friendTrack=fESDfriend->GetTrack(i);
109     AliESDtrack *track=fESD->GetTrack(i);
110     TObject *calibObject=0;
111     AliTPCseed *seed=0;
112     if (!friendTrack) continue;
113     for (Int_t j=0;(calibObject=friendTrack->GetCalibObject(j));++j)
114       if ((seed=dynamic_cast<AliTPCseed*>(calibObject)))
115         break;
116     if (track) Process(track, run);
117     if (seed)
118       Process(seed);
119   }
120   PostData(0,fCalibJobs);
121 }
122
123 void AliHLTTPCAnalysisTaskcalib::ConnectInputData(Option_t *) {
124   //
125   //
126   //
127   TTree* tree=dynamic_cast<TTree*>(GetInputData(0));
128   if (!tree) {
129     //Printf("ERROR: Could not read chain from input slot 0");
130   } 
131   else {
132     AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
133     if (!esdH) {
134       //Printf("ERROR: Could not get ESDInputHandler");
135     } 
136     else {
137       fESD = esdH->GetEvent();
138       //Printf("*** CONNECTED NEW EVENT ****");
139     }
140   }
141 }
142
143 void AliHLTTPCAnalysisTaskcalib::CreateOutputObjects() {
144   //
145   //
146   //
147   OpenFile(0, "RECREATE");
148 }
149 void AliHLTTPCAnalysisTaskcalib::Terminate(Option_t */*option*/) {
150   //
151   // Terminate
152   //
153   AliTPCcalibBase *job=0;
154   Int_t njobs = fCalibJobs->GetEntriesFast();
155   for (Int_t i=0;i<njobs;i++){
156     job = (AliTPCcalibBase*)fCalibJobs->UncheckedAt(i);
157     if (job) job->Terminate();
158   }
159   
160 }
161
162 void AliHLTTPCAnalysisTaskcalib::FinishTaskOutput()
163 {
164   //
165   // According description in AliAnalisysTask this method is call 
166   // on the slaves before sending data
167   //
168   Terminate("slave");
169   RegisterDebugOutput();
170   
171 }
172
173
174 void AliHLTTPCAnalysisTaskcalib::Process(AliESDEvent *event) {
175   //
176   // Process ESD event
177   //
178   AliTPCcalibBase *job=0;
179    
180   Int_t njobs = fCalibJobs->GetEntriesFast(); 
181   for(Int_t i=0;i<njobs;i++){
182       job = (AliTPCcalibBase*)fCalibJobs->UncheckedAt(i);
183       if(job){
184          job->UpdateEventInfo(event);
185          if(job->AcceptTrigger()) job->Process(event);
186       }
187   }
188 }
189
190 void AliHLTTPCAnalysisTaskcalib::Process(AliTPCseed *track) {
191   //
192   // Process TPC track
193   //
194   AliTPCcalibBase *job=0;
195   Int_t njobs = fCalibJobs->GetEntriesFast();
196   for (Int_t i=0;i<njobs;i++){
197     job = (AliTPCcalibBase*)fCalibJobs->UncheckedAt(i);
198     if (job)  
199       if (job->AcceptTrigger())
200         job->Process(track);
201   }
202 }
203
204 void AliHLTTPCAnalysisTaskcalib::Process(AliESDtrack *track, Int_t run) {
205   //
206   // Process ESD track
207   //
208   AliTPCcalibBase *job=0;
209   Int_t njobs = fCalibJobs->GetEntriesFast();
210   for (Int_t i=0;i<njobs;i++){
211     job = (AliTPCcalibBase*)fCalibJobs->UncheckedAt(i);
212     if (job) 
213       if (job->AcceptTrigger())
214         job->Process(track,run);
215   }
216 }
217
218 Long64_t AliHLTTPCAnalysisTaskcalib::Merge(TCollection *li) {
219   TIterator *i=fCalibJobs->MakeIterator();
220   AliTPCcalibBase *job;
221   Long64_t n=0;
222   while ((job=dynamic_cast<AliTPCcalibBase*>(i->Next())))
223     n+=job->Merge(li);
224   return n;
225 }
226
227 void AliHLTTPCAnalysisTaskcalib::Analyze() {
228   //
229   // Analyze the content of the task
230   //
231   AliTPCcalibBase *job=0;
232   Int_t njobs = fCalibJobs->GetEntriesFast();
233   for (Int_t i=0;i<njobs;i++){
234     job = (AliTPCcalibBase*)fCalibJobs->UncheckedAt(i);
235     if (job) job->Analyze();
236   }
237 }
238
239
240 void AliHLTTPCAnalysisTaskcalib::RegisterDebugOutput(){
241   //
242   //
243   //
244   AliTPCcalibBase *job=0;
245   Int_t njobs = fCalibJobs->GetEntriesFast();
246   for (Int_t i=0;i<njobs;i++){
247     job = (AliTPCcalibBase*)fCalibJobs->UncheckedAt(i);
248     if (job) job->RegisterDebugOutput(fDebugOutputPath.Data());
249   }
250   TFile fff("CalibObjects.root","recreate");
251   fCalibJobs->Write("TPCCalib",TObject::kSingleKey);
252   fff.Close();
253   //
254   // store  - copy debug output to the destination position
255   // currently ONLY for local copy
256   TString dsName="CalibObjects.root";
257   TString dsName2=fDebugOutputPath.Data();
258   gSystem->MakeDirectory(dsName2.Data());
259   dsName2+=gSystem->HostName();
260   gSystem->MakeDirectory(dsName2.Data());
261   dsName2+="/";
262   TTimeStamp s;
263   dsName2+=Int_t(s.GetNanoSec());
264   dsName2+="/";
265   gSystem->MakeDirectory(dsName2.Data());
266   dsName2+=dsName;
267   AliInfo(Form("copy %s\t%s\n",dsName.Data(),dsName2.Data()));
268   printf("copy %s\t%s\n",dsName.Data(),dsName2.Data());
269   TFile::Cp(dsName.Data(),dsName2.Data());
270
271 }