]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TRD/AliHLTTRDTrackerComponent.cxx
naming, eff C++
[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
30 #include "AliHLTTRDTrackerComponent.h"
31 #include "AliHLTTRDDefinitions.h"
32 #include "AliCDBManager.h"
33
34 #include "AliTRDclusterizerV1HLT.h"
35 #include "AliTRDReconstructor.h"
36 #include "AliESDEvent.h"
37 #include "AliTRDtrackerHLT.h"
38 #include "AliTRDCalibraFillHisto.h"
39 #include "AliMagFMaps.h"
40 #include "AliTRDcluster.h"
41 #include "TObjArray.h"
42
43 #include <cstdlib>
44 #include <cerrno>
45 #include <string>
46
47 // this is a global object used for automatic component registration, do not use this
48 AliHLTTRDTrackerComponent gAliHLTTRDTrackerComponent;
49
50 ClassImp(AliHLTTRDTrackerComponent);
51     
52 AliHLTTRDTrackerComponent::AliHLTTRDTrackerComponent()
53   : AliHLTProcessor()
54   , fOutputPercentage(100) // By default we copy to the output exactly what we got as input  
55   , fStrorageDBpath("local://$ALICE_ROOT")
56   , fCDB(NULL)
57   , fField(NULL)
58   , fGeometryFileName("")
59   , fGeometryFile(NULL)
60   , fGeoManager(NULL)
61   , fTracker(NULL)
62 {
63   // Default constructor
64   fCDB = AliCDBManager::Instance();
65   //fCDB->SetDefaultStorage(fStrorageDBpath.c_str());
66   fCDB->SetRun(0);
67
68   fGeometryFileName = getenv("ALICE_ROOT");
69   fGeometryFileName += "/HLT/TRD/geometry.root";
70 }
71
72 AliHLTTRDTrackerComponent::~AliHLTTRDTrackerComponent()
73 {
74   // Destructor
75 }
76
77 const char* AliHLTTRDTrackerComponent::GetComponentID()
78 {
79   // Return the component ID const char *
80   return "TRDTracker"; // The ID of this component
81 }
82
83 void AliHLTTRDTrackerComponent::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
90 AliHLTComponent_DataType AliHLTTRDTrackerComponent::GetOutputDataType()
91 {
92   // Get the output data type
93   return AliHLTTRDDefinitions::fgkClusterDataType;
94 }
95
96 void AliHLTTRDTrackerComponent::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
104 AliHLTComponent* AliHLTTRDTrackerComponent::Spawn()
105 {
106   // Spawn function, return new instance of this class
107   return new AliHLTTRDTrackerComponent;
108 };
109
110 int AliHLTTRDTrackerComponent::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   while ( i < argc )
117     {
118       Logging( kHLTLogDebug, "HLT::TRDTracker::DoInit", "Arguments", "argv[%d] == %s", i, argv[i] );
119       if ( !strcmp( argv[i], "output_percentage" ) )
120         {
121           if ( i+1>=argc )
122             {
123               Logging(kHLTLogError, "HLT::TRDTracker::DoInit", "Missing Argument", "Missing output_percentage parameter");
124               return ENOTSUP;
125             }
126           Logging( kHLTLogDebug, "HLT::TRDTracker::DoInit", "Arguments", "argv[%d+1] == %s", i, argv[i+1] );
127           fOutputPercentage = strtoul( argv[i+1], &cpErr, 0 );
128           if ( *cpErr )
129             {
130               Logging(kHLTLogError, "HLT::TRDTracker::DoInit", "Wrong Argument", "Cannot convert output_percentage parameter '%s'", argv[i+1] );
131               return EINVAL;
132             }
133           Logging( kHLTLogInfo, "HLT::TRDTracker::DoInit", "Output percentage set", "Output percentage set to %lu %%", fOutputPercentage );
134           i += 2;
135           continue;
136         }
137
138       if ( strcmp( argv[i], "-cdb" ) == 0)
139         {
140           if ( i+1 >= argc )
141             {
142               Logging(kHLTLogError, "HLT::TRDTracker::DoInit", "Missing Argument", "Missing -cdb argument");
143               return ENOTSUP;         
144             }
145           fStrorageDBpath = argv[i+1];
146           Logging( kHLTLogInfo, "HLT::TRDTracker::DoInit", "DB storage set", "DB storage is %s", fStrorageDBpath.c_str() );       
147           fCDB->SetDefaultStorage(fStrorageDBpath.c_str());
148           i += 2;
149           continue;
150         }      
151
152       if ( strcmp( argv[i], "-geometry" ) == 0)
153         {
154           if ( i+1 >= argc )
155             {
156               Logging(kHLTLogError, "HLT::TRDTracker::DoInit", "Missing Argument", "Missing -geometry argument");
157               return ENOTSUP;         
158             }
159           fGeometryFileName = argv[i+1];
160           Logging( kHLTLogInfo, "HLT::TRDTracker::DoInit", "GeomFile storage set", "GeomFile storage is %s", 
161                    fGeometryFileName.c_str() );   
162           i += 2;
163           continue;
164         }      
165
166       Logging(kHLTLogError, "HLT::TRDTracker::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
167       return EINVAL;
168     }
169
170   fClusterizer = new AliTRDclusterizerV1HLT("TRCclusterizer", "TRCclusterizer");
171
172   //init alifield map - temporarly fixed - should come from a DB
173   fField = new AliMagFMaps("Maps","Maps", 2, 1., 10., 1);
174   if (fField)
175     AliTracker::SetFieldMap(fField,1);
176   else
177     Logging(kHLTLogError, "HLT::TRDTracker::DoInit", "Field", "Unable to init the field");
178     
179   fGeometryFile = TFile::Open(fGeometryFileName.c_str());
180   if (fGeometryFile)
181     {
182       fGeoManager = (TGeoManager *)fGeometryFile->Get("Geometry");
183       fTracker = new AliTRDtrackerHLT(fGeometryFile);
184     }
185   else
186     {
187       Logging(kHLTLogError, "HLT::TRDTracker::DoInit", "fGeometryFile", "Unable to open file. FATAL!");
188       return -1;
189     }
190
191   AliTRDCalibraFillHisto *calibra = AliTRDCalibraFillHisto::Instance();
192   if (calibra == 0)
193     {
194       Logging(kHLTLogError, "HLT::TRDTracker::DoInit", "Calibration Histos", "::Instance failed");
195       return -1;      
196     }
197   else
198     {
199       calibra->SetMITracking(kTRUE);
200       calibra->Init2Dhistos();
201     }
202
203   return 0;
204 }
205
206 int AliHLTTRDTrackerComponent::DoDeinit()
207 {
208   // Deinitialization of the component
209
210   delete fClusterizer;
211   fClusterizer = 0;
212
213   delete fField;
214   fField = 0;
215
216   delete fTracker;
217   fTracker = 0;
218   
219   if (fGeometryFile)
220     {
221       fGeometryFile->Close();
222       delete fGeometryFile;
223       fGeometryFile = 0;
224     }
225
226   AliTRDCalibraFillHisto *calibra = AliTRDCalibraFillHisto::Instance();
227   if (calibra)
228     {
229       // should not write in here!
230       calibra->Write2d();
231       calibra->Destroy();
232     }
233
234   return 0;
235 }
236
237 int AliHLTTRDTrackerComponent::DoEvent( const AliHLTComponentEventData & evtData,
238                                         AliHLTComponentTriggerData & trigData )
239 {
240   // Process an event
241   
242   Logging( kHLTLogInfo, "HLT::TRDTracker::DoEvent", "Output percentage set", "Output percentage set to %lu %%", fOutputPercentage );
243   Logging( kHLTLogInfo, "HLT::TRDTracker::DoEvent", "BLOCKS", "NofBlocks %lu", evtData.fBlockCnt );
244
245   AliHLTUInt32_t fDblock_Specification = 0;
246
247   AliHLTComponentBlockData *dblock = (AliHLTComponentBlockData *)GetFirstInputBlock( AliHLTTRDDefinitions::fgkClusterDataType );
248   if (dblock != 0)
249     {
250       fDblock_Specification = dblock->fSpecification;
251     }
252   else
253     {
254       Logging( kHLTLogWarning, "HLT::TRDTracker::DoEvent", "DATAIN", "First Input Block not found! 0x%x", dblock);
255       return -1;
256     }
257
258   int ibForce = 0;
259   TObject *tobjin = (TObject *)GetFirstInputObject( AliHLTTRDDefinitions::fgkClusterDataType, "TObjArray", ibForce);
260   Logging( kHLTLogInfo, "HLT::TRDTracker::DoEvent", "1stBLOCK", "Pointer = 0x%x", tobjin);
261
262 //   int iTotalClusterCounter = 0;
263   while (tobjin != 0)
264     {
265       TObjArray *clusters = (TObjArray *)tobjin;
266       if (clusters != 0)
267         {
268           //put back to the clusterizers tree
269           Int_t iSuggestedDet = -1; // take the det number from the first cluster
270           Bool_t kInsert = kFALSE;
271           if (clusters->GetEntries() > 0)
272             {
273               AliTRDcluster *cl = (AliTRDcluster*)clusters->At(0);
274               iSuggestedDet = cl->GetDetector();
275               kInsert = fClusterizer->InsertClusters(clusters, iSuggestedDet);      
276               Logging( kHLTLogInfo, "HLT::TRDTracker::DoEvent", "TOTREE", "Result = %d", kInsert);        
277             }
278             
279           Logging( kHLTLogInfo, "HLT::TRDTracker::DoEvent", "CLUSTERS", "Pointer = 0x%x", clusters);      
280 //        //dump the clusters to the log files
281 //        for (Int_t ic = 0; ic < clusters->GetEntries(); ic++)
282 //          {
283 //            AliTRDcluster *cl = (AliTRDcluster*)clusters->At(ic);
284 //            Logging( kHLTLogInfo, "HLT::TRDTracker::DoEvent", "CLUSTER", "%d : %d : Q = %1.2f", 
285 //                     iTotalClusterCounter, ic, cl->GetQ());         
286 //            iTotalClusterCounter++;
287 //          }
288           
289           //Pass the data further...
290           //PushBack(clusters, AliHLTTRDDefinitions::fgkClusterDataType, fDblock_Specification);
291         }
292       else
293         {
294           Logging( kHLTLogError, "HLT::TRDTracker::DoEvent", "CLUSTERS", "Pointer = 0x%x", clusters);     
295         }
296
297       tobjin = (TObject *)GetNextInputObject( ibForce );
298       Logging( kHLTLogInfo, "HLT::TRDTracker::DoEvent", "nextBLOCK", "Pointer = 0x%x", tobjin);
299
300     }
301
302   Int_t iNclusters = fClusterizer->GetNclusters();
303   Logging( kHLTLogInfo, "HLT::TRDTracker::DoEvent", "COUNT", "N of Clusters = %d", iNclusters);
304   fTracker->LoadClusters(fClusterizer->GetClusterTree());
305
306   AliTRDReconstructor::SetSeedingOn(kTRUE);
307
308   AliESDEvent *esd = new AliESDEvent();
309   esd->CreateStdContent();
310   //fTracker->MakeSeedsMI(3, 5, esd);
311   fTracker->PropagateBack(esd);
312
313   //here transport the esd tracks further
314   //no receiver defined yet(!)
315   delete esd;
316   return 0;
317 }