]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/TRD/AliHLTTRDTrackerV1Component.cxx
fix mem leak and compiler warning
[u/mrichter/AliRoot.git] / HLT / TRD / AliHLTTRDTrackerV1Component.cxx
CommitLineData
0e339ac7 1// $Id: AliHLTTRDTrackerV1Component.cxx 23618 2008-01-29 13:07:38Z hristov $
2
3/**************************************************************************
4 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5 * *
6 * Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
7 * Timm Steinbeck <timm@kip.uni-heidelberg.de> *
8 * for The ALICE Off-line Project. *
9 * *
10 * Permission to use, copy, modify and distribute this software and its *
11 * documentation strictly for non-commercial purposes is hereby granted *
12 * without fee, provided that the above copyright notice appears in all *
13 * copies and that both the copyright notice and this permission notice *
14 * appear in the supporting documentation. The authors make no claims *
15 * about the suitability of this software for any purpose. It is *
16 * provided "as is" without express or implied warranty. *
17 **************************************************************************/
18
19/** @file AliHLTTRDTrackerV1Component.cxx
20 @author Timm Steinbeck, Matthias Richter
21 @date
22 @brief A TRDTrackerV1 processing component for the HLT. */
23
24#if __GNUC__ >= 3
25using namespace std;
26#endif
27
28#include "AliHLTTRDTrackerV1Component.h"
29#include "AliHLTTRDDefinitions.h"
30
31#include "TFile.h"
32#include "TChain.h"
33
34#include "AliCDBManager.h"
35#include "AliESDEvent.h"
36#include "AliMagFMaps.h"
37#include "AliESDfriend.h"
38
39#include "AliTRDReconstructor.h"
40#include "AliTRDtrackerV1.h"
41#include "AliTRDcluster.h"
42#include "AliTRDrecoParam.h"
43
44#include <cstdlib>
45#include <cerrno>
46#include <string>
47
48// this is a global object used for automatic component registration, do not use this
49AliHLTTRDTrackerV1Component gAliHLTTRDTrackerV1Component;
50
51ClassImp(AliHLTTRDTrackerV1Component);
52
53AliHLTTRDTrackerV1Component::AliHLTTRDTrackerV1Component()
54 : AliHLTProcessor()
55 , fOutputPercentage(100) // By default we copy to the output exactly what we got as input
56 , fStrorageDBpath("local://$ALICE_ROOT")
57 , fCDB(NULL)
58 , fField(NULL)
59 , fGeometryFileName("")
60 , fGeometryFile(NULL)
61 , fGeoManager(NULL)
0d66dbf5 62 , fReconstructor(NULL)
0e339ac7 63 , fTracker(NULL)
64 , fRecoParam(NULL)
65{
66 // Default constructor
67
68 fGeometryFileName = getenv("ALICE_ROOT");
69 fGeometryFileName += "/HLT/TRD/geometry.root";
70}
71
72AliHLTTRDTrackerV1Component::~AliHLTTRDTrackerV1Component()
73{
74 // Destructor
75}
76
77const char* AliHLTTRDTrackerV1Component::GetComponentID()
78{
79 // Return the component ID const char *
80 return "TRDTrackerV1"; // The ID of this component
81}
82
83void AliHLTTRDTrackerV1Component::GetInputDataTypes( vector<AliHLTComponent_DataType>& list)
84{
85 // Get the list of input data
86 list.clear(); // We do not have any requirements for our input data type(s).
87 list.push_back( AliHLTTRDDefinitions::fgkClusterDataType );
88}
89
90AliHLTComponent_DataType AliHLTTRDTrackerV1Component::GetOutputDataType()
91{
92 // Get the output data type
93 return AliHLTTRDDefinitions::fgkClusterDataType;
94}
95
96void AliHLTTRDTrackerV1Component::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
97{
98 // Get the output data size
99 constBase = 0;
100 inputMultiplier = ((double)fOutputPercentage)/100.0;
101}
102
103// Spawn function, return new instance of this class
104AliHLTComponent* AliHLTTRDTrackerV1Component::Spawn()
105{
106 // Spawn function, return new instance of this class
107 return new AliHLTTRDTrackerV1Component;
108};
109
110int AliHLTTRDTrackerV1Component::DoInit( int argc, const char** argv )
111{
112 // perform initialization. We check whether our relative output size is specified in the arguments.
113 fOutputPercentage = 100;
114 int i = 0;
115 char* cpErr;
116
117 Int_t iRecoParamType = -1; // default will be the low flux
118 Int_t iNtimeBins = -1; // number of time bins for the tracker to use
119 Int_t iMagneticField = -1; // magnetic field: 0==OFF and 1==ON
120
121 while ( i < argc )
122 {
123 Logging( kHLTLogDebug, "HLT::TRDTrackerV1::DoInit", "Arguments", "argv[%d] == %s", i, argv[i] );
124 if ( !strcmp( argv[i], "output_percentage" ) )
125 {
126 if ( i+1>=argc )
127 {
128 Logging(kHLTLogError, "HLT::TRDTrackerV1::DoInit", "Missing Argument", "Missing output_percentage parameter");
129 return ENOTSUP;
130 }
131 Logging( kHLTLogDebug, "HLT::TRDTrackerV1::DoInit", "Arguments", "argv[%d+1] == %s", i, argv[i+1] );
132 fOutputPercentage = strtoul( argv[i+1], &cpErr, 0 );
133 if ( *cpErr )
134 {
135 Logging(kHLTLogError, "HLT::TRDTrackerV1::DoInit", "Wrong Argument", "Cannot convert output_percentage parameter '%s'", argv[i+1] );
136 return EINVAL;
137 }
138 Logging( kHLTLogInfo, "HLT::TRDTrackerV1::DoInit", "Output percentage set", "Output percentage set to %lu %%", fOutputPercentage );
139 i += 2;
140 continue;
141 }
142
143 if ( !strcmp( argv[i], "-NTimeBins" ) )
144 {
145 if ( i+1>=argc )
146 {
147 HLTError("Missing -NTimeBins parameter");
148 return ENOTSUP;
149 }
150 HLTDebug("Arguments", "argv[%d+1] == %s", i, argv[i+1] );
151 iNtimeBins = strtoul( argv[i+1], &cpErr, 0 );
152 if ( *cpErr )
153 {
154 HLTError("Wrong Argument. Cannot convert -NTimeBins parameter '%s'", argv[i+1] );
155 return EINVAL;
156 }
157 i += 2;
158 continue;
159 }
160
161 if ( strcmp( argv[i], "-cdb" ) == 0)
162 {
163 if ( i+1 >= argc )
164 {
165 Logging(kHLTLogError, "HLT::TRDTrackerV1::DoInit", "Missing Argument", "Missing -cdb argument");
166 return ENOTSUP;
167 }
168 fStrorageDBpath = argv[i+1];
169 Logging( kHLTLogInfo, "HLT::TRDTrackerV1::DoInit", "DB storage set", "DB storage is %s", fStrorageDBpath.c_str() );
170 i += 2;
171 continue;
172 }
173
174 if ( strcmp( argv[i], "-geometry" ) == 0)
175 {
176 if ( i+1 >= argc )
177 {
178 Logging(kHLTLogError, "HLT::TRDTrackerV1::DoInit", "Missing Argument", "Missing -geometry argument");
179 return ENOTSUP;
180 }
181 fGeometryFileName = argv[i+1];
182 Logging( kHLTLogInfo, "HLT::TRDTrackerV1::DoInit", "GeomFile storage set", "GeomFile storage is %s",
183 fGeometryFileName.c_str() );
184 i += 2;
185 continue;
186 }
187
188 // the flux parametrizations
189 if ( strcmp( argv[i], "-lowflux" ) == 0)
190 {
191 iRecoParamType = 0;
192 HLTDebug("Low flux reco selected.");
193 i++;
194 continue;
195 }
196
197 if ( strcmp( argv[i], "-highflux" ) == 0)
198 {
199 iRecoParamType = 1;
200 HLTDebug("Low flux reco selected.");
201 i++;
202 continue;
203 }
204
205 if ( strcmp( argv[i], "-magnetic_field_ON" ) == 0)
206 {
207 iMagneticField = 1;
208 i++;
209 continue;
210 }
211
212 if ( strcmp( argv[i], "-magnetic_field_OFF" ) == 0)
213 {
214 iMagneticField = 0;
215 i++;
216 continue;
217 }
218
219 Logging(kHLTLogError, "HLT::TRDTrackerV1::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
220 return EINVAL;
221 }
222
223 // THE "REAL" INIT COMES HERE
224 // offline condition data base
225 fCDB = AliCDBManager::Instance();
226 if (!fCDB)
227 {
228 Logging(kHLTLogError, "HLT::TRDCalibration::DoInit", "Could not get CDB instance", "fCDB 0x%x", fCDB);
229 return -1;
230 }
231 else
232 {
233 fCDB->SetRun(0); // THIS HAS TO BE RETRIEVED !!!
234 fCDB->SetDefaultStorage(fStrorageDBpath.c_str());
235 Logging(kHLTLogDebug, "HLT::TRDCalibration::DoInit", "CDB instance", "fCDB 0x%x", fCDB);
236 }
237
238 // check if the N of time bins make sense
239 if (iNtimeBins <= 0)
240 {
241 HLTError("Sorry. Tracker needs number of time bins. At the moment you have to provide it with -NTimeBins <value>. The simulation always had 24 and the real data 30. Take your pick. Make sure the information is correct. Ask offline to implement how to propagate this information into clusters/cluster tree.");
242 return -1;
243 }
244
245 if (iNtimeBins < 24 || iNtimeBins > 30)
246 {
247 HLTWarning("The number of time bins seems to be strange = %d. But okay. Let's try it...", iNtimeBins);
248 }
249
250 HLTDebug("The number of time bins = %d.", iNtimeBins);
251 AliTRDtrackerV1::SetNTimeBins(iNtimeBins);
252
253 // !!!! THIS IS IMPORTANT
254 // init alifield map - temporarly via parameter - should come from a DB or DCS ?
255 // !!!!
256 if (iMagneticField < 0)
257 {
258 iMagneticField = 0;
259 HLTWarning("No magnetic field switch stated. Use -magnetic_field_ON or -magnetic_field_OFF flag. Defaulting to OFF = NO MAGNETIC FIELD");
260 }
261
262 if (iMagneticField == 0)
263 {
264 // magnetic field OFF
265 fField = new AliMagFMaps("Maps","Maps", 2, 0., 10., 1);
266 HLTDebug("Magnetic field is OFF.");
267 }
268
269 if (iMagneticField == 1)
270 {
271 // magnetic field ON
272 fField = new AliMagFMaps("Maps","Maps", 2, 1., 10., 1);
273 HLTDebug("Magnetic field is ON.");
274 }
275
276 if (fField == 0)
277 {
278 HLTError("Unable to init the field. Trouble at this point.");
279 return -1;
280 }
281
282 // kTRUE sets the map uniform
283 AliTracker::SetFieldMap(fField,kTRUE);
284
285 // reconstruction parameters
286 if (iRecoParamType < 0 || iRecoParamType > 1)
287 {
288 HLTWarning("No reco param selected. Use -lowflux or -highflux flag. Defaulting to low flux.");
289 iRecoParamType = 0;
290 }
291
292 if (iRecoParamType == 0)
293 {
294 fRecoParam = AliTRDrecoParam::GetLowFluxParam();
295 HLTDebug("Low flux params init.");
296 }
297
298 if (iRecoParamType == 1)
299 {
300 fRecoParam = AliTRDrecoParam::GetHighFluxParam();
301 HLTDebug("High flux params init.");
302 }
303
304 if (fRecoParam == 0)
305 {
306 HLTError("No reco params initialized. Sniffing big trouble!");
307 return -1;
308 }
309
9fa37a91 310 // this is important in case we want to ::PropagateBack - see the TrackerV1.cxx
0d66dbf5 311 //fRecoParam->SetSeeding(kTRUE);
9fa37a91 312 // no debug stream -> no debug files! on HLT
0d66dbf5 313 //fRecoParam->SetStreamLevel(0);
9fa37a91 314
0d66dbf5 315 //AliTRDReconstructor reconstructor; reconstructor.SetRecoParam(fRecoParam);
316 // AB 10.Jul.08
317 // temporary until recoParam in the OCDB
318 fReconstructor = new AliTRDReconstructor();
319 fReconstructor->SetRecoParam(fRecoParam);
320 fReconstructor->SetStreamLevel(0); // default value
321 fReconstructor->SetOption("sa,!cw");
322
0e339ac7 323 // geometry:
324 // for some unknown at this point reason (30th of April 2008)
325 // the TrackerV1 initializes new TRDgeometry in the constructor
326 // we avoid it here
327 fGeometryFile = 0;
328 // fGeometryFile = TFile::Open(fGeometryFileName.c_str());
329 // if (fGeometryFile)
330 // {
331 // fGeoManager = (TGeoManager *)fGeometryFile->Get("Geometry");
332 // // for the old tracker we would do this:
333 // fTracker = new AliTRDtracker(fGeometryFile);
334 // }
335 // else
336 // {
337 // Logging(kHLTLogError, "HLT::TRDTrackerV1::DoInit", "fGeometryFile", "Unable to open file. FATAL!");
338 // return -1;
339 // }
340
341 // create the tracker
342 fTracker = new AliTRDtrackerV1();
0d66dbf5 343 fTracker->SetReconstructor(fReconstructor);
0e339ac7 344 HLTDebug("TRDTracker at 0x%x", fTracker);
345
346 if (fTracker == 0)
347 {
348 HLTError("Unable to create the tracker!");
349 // do we want a smarter return value here? probably yes
350 // answering your own questions is stupid but maybe helpful... ;)
351 return -1;
352 }
353
0e339ac7 354 return 0;
355}
356
357int AliHLTTRDTrackerV1Component::DoDeinit()
358{
359 // Deinitialization of the component
360
361 delete fField;
362 fField = 0;
363
364 delete fTracker;
365 fTracker = 0;
366
0d66dbf5 367 // AB 10.Jul.08
368 delete fReconstructor;
369 fReconstructor = 0x0;
370
0e339ac7 371 if (fGeometryFile)
372 {
373 fGeometryFile->Close();
374 delete fGeometryFile;
375 fGeometryFile = 0;
376 }
377
378 return 0;
379}
380
381int AliHLTTRDTrackerV1Component::DoEvent( const AliHLTComponentEventData & evtData,
382 AliHLTComponentTriggerData & trigData )
383{
384 // Process an event
385
386 Logging( kHLTLogInfo, "HLT::TRDTrackerV1::DoEvent", "Output percentage set", "Output percentage set to %lu %%", fOutputPercentage );
387 Logging( kHLTLogInfo, "HLT::TRDTrackerV1::DoEvent", "BLOCKS", "NofBlocks %lu", evtData.fBlockCnt );
388
389 AliHLTUInt32_t dBlockSpecification = 0;
390
391 //implement a usage of the following
392 // AliHLTUInt32_t triggerDataStructSize = trigData.fStructSize;
393 // AliHLTUInt32_t triggerDataSize = trigData.fDataSize;
394 // void *triggerData = trigData.fData;
395 Logging( kHLTLogDebug, "HLT::TRDTrackerV1::DoEvent", "Trigger data received",
396 "Struct size %d Data size %d Data location 0x%x", trigData.fStructSize, trigData.fDataSize, (UInt_t*)trigData.fData);
397
398 AliHLTComponentBlockData *dblock = (AliHLTComponentBlockData *)GetFirstInputBlock( AliHLTTRDDefinitions::fgkClusterDataType );
399 if (dblock != 0)
400 {
401 dBlockSpecification = dblock->fSpecification;
402 }
403 else
404 {
405 Logging( kHLTLogWarning, "HLT::TRDTrackerV1::DoEvent", "DATAIN", "First Input Block not found! 0x%x", dblock);
406 return -1;
407 }
408
409 int ibForce = 0;
410
411 TObject *tobjin = (TObject *)GetFirstInputObject( AliHLTTRDDefinitions::fgkClusterDataType, "TTree", ibForce);
412 Logging( kHLTLogInfo, "HLT::TRDTrackerV1::DoEvent", "1stBLOCK", "Pointer = 0x%x", tobjin);
413
414 TTree *clusterTree = (TTree*)tobjin;
415 if (!clusterTree)
416 {
417 Logging( kHLTLogWarning, "HLT::TRDTrackerV1::DoEvent", "DATAIN", "First Input Block not a tree! 0x%x", tobjin);
418 return -1;
419 }
420
421 Logging( kHLTLogInfo, "HLT::TRDTrackerV1::DoEvent", "1stBLOCK", "Pointer = 0x%x Name = %s", clusterTree, clusterTree->GetName());
422
423 while (tobjin != 0)
424 {
425 if (clusterTree)
426 {
427 Logging( kHLTLogInfo, "HLT::TRDTrackerV1::DoEvent", "CLUSTERS", "Pointer = 0x%x Name = %s", clusterTree, clusterTree->GetName());
428 Int_t iNentries = clusterTree->GetEntries();
429 Logging( kHLTLogInfo, "HLT::TRDTrackerV1::DoEvent", "COUNT", "N of tree entries = %d", iNentries);
430 fTracker->LoadClusters(clusterTree);
431 }
432 else
433 {
434 Logging( kHLTLogError, "HLT::TRDTrackerV1::DoEvent", "CLUSTERS", "Tree Pointer = 0x%x", clusterTree);
435 }
436
437 tobjin = (TObject *)GetNextInputObject( ibForce );
438 Logging( kHLTLogInfo, "HLT::TRDTrackerV1::DoEvent", "nextBLOCK", "Pointer = 0x%x", tobjin);
439 clusterTree = (TTree*)tobjin;
440 }
441
442 // maybe it is not so smart to create it each event? clear is enough ?
443 AliESDEvent *esd = new AliESDEvent();
444 esd->CreateStdContent();
445
446 fTracker->Clusters2Tracks(esd);
447 // not necessary...
448 //fTracker->PropagateBack(esd);
449
450 //here transport the esd tracks further
451 Int_t nTracks = esd->GetNumberOfTracks();
452 Int_t nTRDTracks = esd->GetNumberOfTrdTracks();
453 HLTInfo("Number of tracks %d Number of TRD tracks %d", nTracks, nTRDTracks);
454 //esd->Print();
455 PushBack(esd, AliHLTTRDDefinitions::fgkTRDSAEsdDataType);
456
457 // extract the friend ?
458 // AliESDfriend *esdFriend = new AliESDfriend();
459 // esd->GetESDfriend(esdFriend);
460 // PushBack(esdFriend, AliHLTTRDDefinitions::fgkTRDSAEsdDataType);
461 // delete esdFriend;
462
463 //HLTInfo("now deleting");
464 delete esd;
465
466 delete clusterTree;
467 fTracker->UnloadClusters();
468
469 HLTDebug("Event done.");
470 return 0;
471}
472
473///////////////////////////////
474/*
475 consider transporting TRD tracks only as they might have signigicantly smaller size... on the other hand you will need to prodece ESDs at some point...
476
477// this is for ESDtrack
478// for (Int_t it = 0; it < nTracks; it++)
479// {
480// AliESDtrack* track = esd->GetTrack(it);
481// HLTInfo("Track %d 0x%x Pt %1.2f", it, track, track->Pt());
482// //PushBack(track, AliHLTTRDDefinitions::fgkTRDSATracksDataType, ++dBlockSpecification);
483// PushBack(track, AliHLTTRDDefinitions::fgkTRDSATracksDataType);
484// }
485
486// one can do similar things with the TRDtrack
487esd->GetNumberOfTrdTracks();
488and then
489for (i;;)
490AliESDTrdTrack *trdtrack = esd->GetTrdTrack(i)
491*/
492