]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TRD/AliHLTTRDTrackerComponent.cxx
fix mem leak and compiler warning
[u/mrichter/AliRoot.git] / HLT / TRD / AliHLTTRDTrackerComponent.cxx
1 // $Id$
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   AliHLTTRDTrackerComponent.cxx
20     @author Timm Steinbeck, Matthias Richter
21     @date   
22     @brief  A TRDTracker processing component for the HLT. */
23
24 #if __GNUC__ >= 3
25 using namespace std;
26 #endif
27
28 #include "TFile.h"
29 #include "TChain.h"
30
31 #include "AliHLTTRDTrackerComponent.h"
32 #include "AliHLTTRDDefinitions.h"
33 #include "AliCDBManager.h"
34
35 #include "AliTRDReconstructor.h"
36 #include "AliTRDrecoParam.h"
37 #include "AliESDEvent.h"
38 //#include "AliTRDtrackerHLT.h"
39 #include "AliTRDtracker.h"
40 #include "AliTRDCalibraFillHisto.h"
41 #include "AliMagFMaps.h"
42 #include "AliTRDcluster.h"
43 #include "AliESDfriend.h"
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
49 AliHLTTRDTrackerComponent gAliHLTTRDTrackerComponent;
50
51 ClassImp(AliHLTTRDTrackerComponent);
52     
53 AliHLTTRDTrackerComponent::AliHLTTRDTrackerComponent()
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)
62   , fTracker(NULL)
63 {
64   // Default constructor
65
66   fGeometryFileName = getenv("ALICE_ROOT");
67   fGeometryFileName += "/HLT/TRD/geometry.root";
68 }
69
70 AliHLTTRDTrackerComponent::~AliHLTTRDTrackerComponent()
71 {
72   // Destructor
73 }
74
75 const char* AliHLTTRDTrackerComponent::GetComponentID()
76 {
77   // Return the component ID const char *
78   return "TRDTracker"; // The ID of this component
79 }
80
81 void AliHLTTRDTrackerComponent::GetInputDataTypes( vector<AliHLTComponent_DataType>& list)
82 {
83   // Get the list of input data  
84   list.clear(); // We do not have any requirements for our input data type(s).
85   list.push_back( AliHLTTRDDefinitions::fgkClusterDataType );
86 }
87
88 AliHLTComponent_DataType AliHLTTRDTrackerComponent::GetOutputDataType()
89 {
90   // Get the output data type
91   return AliHLTTRDDefinitions::fgkClusterDataType;
92 }
93
94 void AliHLTTRDTrackerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
95 {
96   // Get the output data size
97   constBase = 0;
98   inputMultiplier = ((double)fOutputPercentage)/100.0;
99 }
100
101 // Spawn function, return new instance of this class
102 AliHLTComponent* AliHLTTRDTrackerComponent::Spawn()
103 {
104   // Spawn function, return new instance of this class
105   return new AliHLTTRDTrackerComponent;
106 };
107
108 int AliHLTTRDTrackerComponent::DoInit( int argc, const char** argv )
109 {
110   // perform initialization. We check whether our relative output size is specified in the arguments.
111   fOutputPercentage = 100;
112   int i = 0;
113   char* cpErr;
114   while ( i < argc )
115     {
116       Logging( kHLTLogDebug, "HLT::TRDTracker::DoInit", "Arguments", "argv[%d] == %s", i, argv[i] );
117       if ( !strcmp( argv[i], "output_percentage" ) )
118         {
119           if ( i+1>=argc )
120             {
121               Logging(kHLTLogError, "HLT::TRDTracker::DoInit", "Missing Argument", "Missing output_percentage parameter");
122               return ENOTSUP;
123             }
124           Logging( kHLTLogDebug, "HLT::TRDTracker::DoInit", "Arguments", "argv[%d+1] == %s", i, argv[i+1] );
125           fOutputPercentage = strtoul( argv[i+1], &cpErr, 0 );
126           if ( *cpErr )
127             {
128               Logging(kHLTLogError, "HLT::TRDTracker::DoInit", "Wrong Argument", "Cannot convert output_percentage parameter '%s'", argv[i+1] );
129               return EINVAL;
130             }
131           Logging( kHLTLogInfo, "HLT::TRDTracker::DoInit", "Output percentage set", "Output percentage set to %lu %%", fOutputPercentage );
132           i += 2;
133           continue;
134         }
135
136       if ( strcmp( argv[i], "-cdb" ) == 0)
137         {
138           if ( i+1 >= argc )
139             {
140               Logging(kHLTLogError, "HLT::TRDTracker::DoInit", "Missing Argument", "Missing -cdb argument");
141               return ENOTSUP;         
142             }
143           fStrorageDBpath = argv[i+1];
144           Logging( kHLTLogInfo, "HLT::TRDTracker::DoInit", "DB storage set", "DB storage is %s", fStrorageDBpath.c_str() );       
145           i += 2;
146           continue;
147         }      
148
149       if ( strcmp( argv[i], "-geometry" ) == 0)
150         {
151           if ( i+1 >= argc )
152             {
153               Logging(kHLTLogError, "HLT::TRDTracker::DoInit", "Missing Argument", "Missing -geometry argument");
154               return ENOTSUP;         
155             }
156           fGeometryFileName = argv[i+1];
157           Logging( kHLTLogInfo, "HLT::TRDTracker::DoInit", "GeomFile storage set", "GeomFile storage is %s", 
158                    fGeometryFileName.c_str() );   
159           i += 2;
160           continue;
161         }      
162
163       Logging(kHLTLogError, "HLT::TRDTracker::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
164       return EINVAL;
165     }
166
167   //init alifield map - temporarly fixed - should come from a DB
168   fField = new AliMagFMaps("Maps","Maps", 2, 1., 10., 1);
169   if (fField)
170     AliTracker::SetFieldMap(fField,1);
171   else
172     Logging(kHLTLogError, "HLT::TRDTracker::DoInit", "Field", "Unable to init the field");
173
174   fCDB = AliCDBManager::Instance();
175   if (!fCDB)
176     {
177       Logging(kHLTLogError, "HLT::TRDCalibration::DoInit", "Could not get CDB instance", "fCDB 0x%x", fCDB);
178     }
179   else
180     {
181       fCDB->SetRun(0); // THIS HAS TO BE RETRIEVED !!!
182       fCDB->SetDefaultStorage(fStrorageDBpath.c_str());
183       Logging(kHLTLogDebug, "HLT::TRDCalibration::DoInit", "CDB instance", "fCDB 0x%x", fCDB);
184     }
185     
186   fGeometryFile = TFile::Open(fGeometryFileName.c_str());
187   if (fGeometryFile)
188     {
189       fGeoManager = (TGeoManager *)fGeometryFile->Get("Geometry");
190       //fTracker = new AliTRDtrackerHLT(fGeometryFile);
191         AliTRDrecoParam *fPars = AliTRDrecoParam::GetLowFluxParam();
192                         //AB 10.Jul.08 - Memory leak - please consider a better strategy on HLT
193       AliTRDReconstructor *fReconstructor = new AliTRDReconstructor();
194       fReconstructor->SetRecoParam(fPars);
195                         fReconstructor->SetOption("sa,!cw");
196                         fReconstructor->SetStreamLevel(0);
197       fTracker = new AliTRDtracker(fGeometryFile);
198       fTracker->SetReconstructor(fReconstructor);
199     }
200   else
201     {
202       Logging(kHLTLogError, "HLT::TRDTracker::DoInit", "fGeometryFile", "Unable to open file. FATAL!");
203       return -1;
204     }
205
206   AliTRDCalibraFillHisto *calibra = AliTRDCalibraFillHisto::Instance();
207   if (calibra == 0)
208     {
209       Logging(kHLTLogError, "HLT::TRDTracker::DoInit", "Calibration Histos", "::Instance failed");
210       return -1;      
211     }
212   else
213     {
214       calibra->Init2Dhistos();
215     }
216
217   return 0;
218 }
219
220 int AliHLTTRDTrackerComponent::DoDeinit()
221 {
222   // Deinitialization of the component
223
224   delete fField;
225   fField = 0;
226
227   delete fTracker;
228   fTracker = 0;
229   
230   if (fGeometryFile)
231     {
232       fGeometryFile->Close();
233       delete fGeometryFile;
234       fGeometryFile = 0;
235     }
236
237   AliTRDCalibraFillHisto *calibra = AliTRDCalibraFillHisto::Instance();
238   if (calibra)
239     {
240       // should not write in here!
241       calibra->Write2d();
242       Logging( kHLTLogInfo, "HLT::TRDTracker::DoDeinit", "CALIBRA", "before destroy");
243       calibra->Destroy();
244       Logging( kHLTLogInfo, "HLT::TRDTracker::DoDeinit", "CALIBRA", "after destroy");
245     }
246
247   return 0;
248 }
249
250 int AliHLTTRDTrackerComponent::DoEvent( const AliHLTComponentEventData & evtData,
251                                         AliHLTComponentTriggerData & trigData )
252 {
253   // Process an event
254   
255   Logging( kHLTLogInfo, "HLT::TRDTracker::DoEvent", "Output percentage set", "Output percentage set to %lu %%", fOutputPercentage );
256   Logging( kHLTLogInfo, "HLT::TRDTracker::DoEvent", "BLOCKS", "NofBlocks %lu", evtData.fBlockCnt );
257
258   AliHLTUInt32_t dBlockSpecification = 0;
259
260   //implement a usage of the following
261 //   AliHLTUInt32_t triggerDataStructSize = trigData.fStructSize;
262 //   AliHLTUInt32_t triggerDataSize = trigData.fDataSize;
263 //   void *triggerData = trigData.fData;
264   Logging( kHLTLogDebug, "HLT::TRDTracker::DoEvent", "Trigger data received", 
265            "Struct size %d Data size %d Data location 0x%x", trigData.fStructSize, trigData.fDataSize, (UInt_t*)trigData.fData);
266
267   AliHLTComponentBlockData *dblock = (AliHLTComponentBlockData *)GetFirstInputBlock( AliHLTTRDDefinitions::fgkClusterDataType );
268   if (dblock != 0)
269     {
270       dBlockSpecification = dblock->fSpecification;
271     }
272   else
273     {
274       Logging( kHLTLogWarning, "HLT::TRDTracker::DoEvent", "DATAIN", "First Input Block not found! 0x%x", dblock);
275       return -1;
276     }
277
278   int ibForce = 0;
279   TObject *tobjin = (TObject *)GetFirstInputObject( AliHLTTRDDefinitions::fgkClusterDataType, "TTree", ibForce);
280   Logging( kHLTLogInfo, "HLT::TRDTracker::DoEvent", "1stBLOCK", "Pointer = 0x%x", tobjin);
281
282   TTree *clusterTree = (TTree*)tobjin;
283   if (!clusterTree)
284     {
285       Logging( kHLTLogWarning, "HLT::TRDTracker::DoEvent", "DATAIN", "First Input Block not a tree! 0x%x", tobjin);
286       return -1;
287     }
288
289   Logging( kHLTLogInfo, "HLT::TRDTracker::DoEvent", "1stBLOCK", "Pointer = 0x%x Name = %s", clusterTree, clusterTree->GetName());
290
291   while (tobjin != 0)
292     {
293       if (clusterTree)
294         {
295           Logging( kHLTLogInfo, "HLT::TRDTracker::DoEvent", "CLUSTERS", "Pointer = 0x%x Name = %s", clusterTree, clusterTree->GetName());
296           Int_t iNentries = clusterTree->GetEntries();
297           Logging( kHLTLogInfo, "HLT::TRDTracker::DoEvent", "COUNT", "N of tree entries = %d", iNentries);
298           fTracker->LoadClusters(clusterTree);
299         }
300       else
301         {
302           Logging( kHLTLogError, "HLT::TRDTracker::DoEvent", "CLUSTERS", "Tree Pointer = 0x%x", clusterTree);
303         }
304
305       tobjin = (TObject *)GetNextInputObject( ibForce );
306       Logging( kHLTLogInfo, "HLT::TRDTracker::DoEvent", "nextBLOCK", "Pointer = 0x%x", tobjin);
307       clusterTree = (TTree*)tobjin;
308     }
309
310   fTracker->SetAddTRDseeds();
311
312   AliESDfriend *esdFriend = new AliESDfriend();
313
314   AliESDEvent *esd = new AliESDEvent();
315   esd->CreateStdContent();
316   fTracker->PropagateBack(esd);
317   fTracker->RefitInward(esd);
318   fTracker->Clusters2Tracks(esd);
319
320   esd->GetESDfriend(esdFriend);
321   //here transport the esd tracks further
322
323   Int_t nTracks = esd->GetNumberOfTracks();
324   Int_t nTRDTracks = esd->GetNumberOfTrdTracks();
325   Logging( kHLTLogInfo, "HLT::TRDTracker::DoEvent", "DONE", "Number of tracks %d Number of TRD tracks %d", nTracks, nTRDTracks);
326
327 //   AliTRDCalibraFillHisto *calibra = AliTRDCalibraFillHisto::Instance();
328 //   calibra->Init2Dhistostrack();
329
330   for (Int_t it = 0; it < nTracks; it++)
331     {
332       AliESDtrack* track = esd->GetTrack(it);
333
334 //       Int_t nCalibObjects = 0;
335 //       Int_t idx = 0;
336 //       while (track->GetCalibObject(idx) != 0)
337 //      {
338 //        nCalibObjects++;
339 //        idx++;
340 //      }
341 //       Logging( kHLTLogInfo, "HLT::TRDTracker::DoEvent", "DONE", "Track 0x%x NcalibObjects %d", track, nCalibObjects);
342
343       Logging( kHLTLogInfo, "HLT::TRDTracker::DoEvent", "DONE", "Track %d 0x%x Pt %1.2f", it, track, track->Pt());
344       PushBack(track, AliHLTTRDDefinitions::fgkTRDSATracksDataType, ++dBlockSpecification);
345 //       if (calibra->GetMItracking())
346 //      {
347 //        calibra->UpdateHistograms(track);
348 //      }
349     }
350
351   //PushBack(esd, AliHLTTRDDefinitions::fgkTRDSAEsdDataType, dBlockSpecification);
352   //PushBack(esdFriend, AliHLTTRDDefinitions::fgkTRDSAEsdDataType, dBlockSpecification);
353
354   //no receiver defined yet(!)
355   //Logging( kHLTLogInfo, "HLT::TRDTracker::DoEvent", "DONE", "now deleting");
356   delete esd;
357   delete esdFriend;
358
359   //Logging( kHLTLogInfo, "HLT::TRDTracker::DoEvent", "DONE", "after delete esd");
360   delete clusterTree;
361
362   //Logging( kHLTLogInfo, "HLT::TRDTracker::DoEvent", "DONE", "after delete clusterTree");
363   return 0;
364 }