]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDReconstructor.cxx
Additiona fix for bug #63491: High virtual memory consumption in the TRD clusterizati...
[u/mrichter/AliRoot.git] / TRD / AliTRDReconstructor.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 /* $Id$ */
17
18 ///////////////////////////////////////////////////////////////////////////////
19 //                                                                           //
20 // Class for TRD reconstruction                                              //
21 //                                                                           //
22 ///////////////////////////////////////////////////////////////////////////////
23
24 #include <TObjString.h>
25 #include <TObjArray.h>
26 #include <TTreeStream.h>
27 #include <TDirectory.h>
28
29 #include "AliRawReader.h"
30
31 #include "AliTRDReconstructor.h"
32 #include "AliTRDclusterizer.h"
33 #include "AliTRDrawData.h"
34 #include "AliTRDrawStreamBase.h"
35 #include "AliTRDdigitsManager.h"
36 #include "AliTRDtrackerV1.h"
37
38 #define SETFLG(n,f) ((n) |= f)
39 #define CLRFLG(n,f) ((n) &= ~f)
40
41 ClassImp(AliTRDReconstructor)
42
43 TClonesArray *AliTRDReconstructor::fgClusters = NULL;
44 TClonesArray *AliTRDReconstructor::fgTracklets = NULL;
45 Char_t const * AliTRDReconstructor::fgSteerNames[kNsteer] = {
46   "DigitsConversion       "
47  ,"Write Clusters         "
48  ,"Write Online Tracklets "
49  ,"Stand Alone Tracking   "
50  ,"HLT Mode               "
51  ,"Process Online Tracklets"
52  ,"Debug Streaming        "
53 };
54 Char_t const * AliTRDReconstructor::fgSteerFlags[kNsteer] = {
55   "dc"// digits conversion [false]
56  ,"cw"// write clusters [true]
57  ,"tw"// write online tracklets [false]
58  ,"sa"// track seeding (stand alone tracking) [true]
59  ,"hlt"// HLT reconstruction [false]
60  ,"tp"// also use online tracklets for reconstruction [false]
61  ,"deb"// Write debug stream [false]
62 };
63 Char_t const * AliTRDReconstructor::fgTaskNames[AliTRDrecoParam::kTRDreconstructionTasks] = {
64   "Clusterizer"
65  ,"Tracker"
66  ,"PID"
67 };
68 Char_t const * AliTRDReconstructor::fgTaskFlags[AliTRDrecoParam::kTRDreconstructionTasks] = {
69   "cl"
70  ,"tr"
71  ,"pd"
72 };
73 Int_t AliTRDReconstructor::fgNTimeBins = -1;
74
75 //_____________________________________________________________________________
76 AliTRDReconstructor::AliTRDReconstructor()
77   :AliReconstructor()
78   ,fSteerParam(0)
79   ,fClusterizer(NULL)
80 {
81   // setting default "ON" steering parameters
82   // owner of debug streamers 
83   SETFLG(fSteerParam, kOwner);
84   // write clusters [cw]
85   SETFLG(fSteerParam, kWriteClusters);
86   // track seeding (stand alone tracking) [sa]
87   SETFLG(fSteerParam, kSeeding);
88
89   memset(fDebugStream, 0, sizeof(TTreeSRedirector *) * AliTRDrecoParam::kTRDreconstructionTasks);
90 }
91
92 //_____________________________________________________________________________
93 AliTRDReconstructor::~AliTRDReconstructor()
94 {
95   //
96   // Destructor
97   //
98
99   if(fgClusters) {
100     fgClusters->Delete();
101     delete fgClusters;
102     fgClusters = NULL;
103   }
104   if(fgTracklets) {
105     fgTracklets->Delete();
106     delete fgTracklets;
107     fgTracklets = NULL;
108   }
109   if(fSteerParam&kOwner){
110     for(Int_t itask = 0; itask < AliTRDrecoParam::kTRDreconstructionTasks; itask++)
111       if(fDebugStream[itask]) delete fDebugStream[itask];
112   }
113   if(fClusterizer){
114     delete fClusterizer;
115     fClusterizer = NULL;
116   }
117 }
118
119
120 //_____________________________________________________________________________
121 void AliTRDReconstructor::Init(){
122   //
123   // Init Options
124   //
125   SetOption(GetOption());
126   Options(fSteerParam);
127
128   if(!fClusterizer){
129     fClusterizer = new AliTRDclusterizer(fgTaskNames[AliTRDrecoParam::kClusterizer], fgTaskNames[AliTRDrecoParam::kClusterizer]);
130     fClusterizer->SetReconstructor(this);
131   }
132   
133   // Make Debug Streams when Debug Streaming
134   if(IsDebugStreaming()){
135     for(Int_t task = 0; task < AliTRDrecoParam::kTRDreconstructionTasks; task++){
136       TDirectory *savedir = gDirectory;
137       fDebugStream[task] = new TTreeSRedirector(Form("TRD.Debug%s.root", fgTaskNames[task]));
138       savedir->cd();
139       SETFLG(fSteerParam, kOwner);
140     }
141   }
142 }
143
144 //_____________________________________________________________________________
145 void AliTRDReconstructor::ConvertDigits(AliRawReader *rawReader
146               , TTree *digitsTree) const
147 {
148   //
149   // Convert raw data digits into digit objects in a root tree
150   //
151
152   //AliInfo("Convert raw data digits into digit objects [RawReader -> Digit TTree]");
153
154   AliTRDrawData rawData;
155   rawReader->Reset();
156   rawReader->Select("TRD");
157   rawData.OpenOutput();
158   AliTRDrawStreamBase::SetRawStreamVersion(GetRecoParam()->GetRawStreamVersion()->Data());
159   AliTRDdigitsManager *manager = rawData.Raw2Digits(rawReader);
160   manager->MakeBranch(digitsTree);
161   manager->WriteDigits();
162   delete manager;
163
164 }
165
166 //_____________________________________________________________________________
167 void AliTRDReconstructor::Reconstruct(AliRawReader *rawReader
168                                     , TTree *clusterTree) const
169 {
170   //
171   // Reconstruct clusters
172   //
173
174   //AliInfo("Reconstruct TRD clusters from RAW data [RawReader -> Cluster TTree]");
175
176
177   rawReader->Reset();
178   rawReader->Select("TRD");
179   AliTRDrawStreamBase::SetRawStreamVersion(GetRecoParam()->GetRawStreamVersion()->Data());
180
181   if(!fClusterizer){
182     AliFatal("Clusterizer not available!");
183     return;
184   }
185
186   fClusterizer->ResetRecPoints();
187
188   fClusterizer->OpenOutput(clusterTree);
189   fClusterizer->OpenTrackletOutput();
190   fClusterizer->SetUseLabels(kFALSE);
191   fClusterizer->Raw2ClustersChamber(rawReader);
192   
193   if(IsWritingClusters()) return;
194
195   // take over ownership of clusters
196   fgClusters = fClusterizer->RecPoints();
197   fClusterizer->SetClustersOwner(kFALSE);
198
199   // take over ownership of online tracklets
200   fgTracklets = fClusterizer->TrackletsArray();
201   fClusterizer->SetTrackletsOwner(kFALSE);
202
203   fgNTimeBins = fClusterizer->GetNTimeBins();
204 }
205
206 //_____________________________________________________________________________
207 void AliTRDReconstructor::Reconstruct(TTree *digitsTree
208                                     , TTree *clusterTree) const
209 {
210   //
211   // Reconstruct clusters
212   //
213
214   //AliInfo("Reconstruct TRD clusters from Digits [Digit TTree -> Cluster TTree]");
215   
216   if(!fClusterizer){
217     AliFatal("Clusterizer not available!");
218     return;
219   }
220
221   fClusterizer->ResetRecPoints();
222
223   fClusterizer->OpenOutput(clusterTree);
224   fClusterizer->ReadDigits(digitsTree);
225   fClusterizer->MakeClusters();
226
227   if(IsWritingClusters()) return;
228
229   // take over ownership of clusters
230   fgClusters = fClusterizer->RecPoints();
231   fClusterizer->SetClustersOwner(kFALSE);
232
233   // take over ownership of online tracklets
234   fgTracklets = fClusterizer->TrackletsArray();
235   fClusterizer->SetTrackletsOwner(kFALSE);
236
237   fgNTimeBins = fClusterizer->GetNTimeBins();
238 }
239
240 //_____________________________________________________________________________
241 AliTracker *AliTRDReconstructor::CreateTracker() const
242 {
243   //
244   // Create a TRD tracker
245   //
246
247   //return new AliTRDtracker(NULL);
248   AliTRDtrackerV1 *tracker = new AliTRDtrackerV1();
249   tracker->SetReconstructor(this);
250   return tracker;
251
252 }
253
254 //_____________________________________________________________________________
255 void AliTRDReconstructor::FillESD(TTree* /*digitsTree*/
256         , TTree* /*clusterTree*/
257         , AliESDEvent* /*esd*/) const
258 {
259   //
260   // Fill ESD
261   //
262
263 }
264
265 //_____________________________________________________________________________
266 void AliTRDReconstructor::SetOption(Option_t *opt)
267 {
268   //
269   // Read option string into the steer param.
270   //
271
272   AliReconstructor::SetOption(opt);
273
274   TString s(opt);
275   TObjArray *opar = s.Tokenize(",");
276   for(Int_t ipar=0; ipar<opar->GetEntriesFast(); ipar++){
277     Bool_t processed = kFALSE;
278     TString sopt(((TObjString*)(*opar)[ipar])->String());
279     for(Int_t iopt=0; iopt<kNsteer; iopt++){
280       if(!sopt.Contains(fgSteerFlags[iopt])) continue;
281       SETFLG(fSteerParam, BIT(iopt));
282       if(sopt.Contains("!")) CLRFLG(fSteerParam, BIT(iopt));
283       processed = kTRUE;
284       break;    
285     }
286     if(processed) continue;
287
288     AliWarning(Form("Unknown option flag %s.", sopt.Data()));
289   }
290 }
291
292 //_____________________________________________________________________________
293 void AliTRDReconstructor::Options(UInt_t steer)
294 {
295   //
296   // Print the options
297   //
298
299   for(Int_t iopt=0; iopt<kNsteer; iopt++){
300     AliDebugGeneral("AliTRDReconstructor", 1, Form(" %s[%s]%s", fgSteerNames[iopt], fgSteerFlags[iopt], steer ?(((steer>>iopt)&1)?" : ON":" : OFF"):""));
301   }
302 }
303