]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TRD/AliHLTTRDTrackerComponent.cxx
initial HLT-TRD commit
[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
33 #include "AliCDBManager.h"
34 #include "AliTRDclusterizerV1HLT.h"
35 #include "AliTRDReconstructor.h"
36 #include "AliESD.h"
37 #include "AliTRDtrackerHLT.h"
38
39 #include "AliTRDCalibraFillHisto.h"
40
41 #include "AliTRDcluster.h"
42 #include "TObjArray.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
49 AliHLTTRDTrackerComponent gAliHLTTRDTrackerComponent;
50
51 ClassImp(AliHLTTRDTrackerComponent);
52     
53 AliHLTTRDTrackerComponent::AliHLTTRDTrackerComponent()
54 {
55   fOutputPercentage = 100; // By default we copy to the output exactly what we got as input
56
57   fStrorageDBpath = "local://$ALICE_ROOT";
58   fCDB = AliCDBManager::Instance();
59   //fCDB->SetDefaultStorage(fStrorageDBpath.c_str());
60   fCDB->SetRun(0);
61
62   fGeometryFileName = getenv("ALICE_ROOT");
63   fGeometryFileName += "/HLT/TRD/geometry.root";
64 }
65
66 AliHLTTRDTrackerComponent::~AliHLTTRDTrackerComponent()
67 {
68 }
69
70 const char* AliHLTTRDTrackerComponent::GetComponentID()
71 {
72   return "TRDTracker"; // The ID of this component
73 }
74
75 void AliHLTTRDTrackerComponent::GetInputDataTypes( vector<AliHLTComponent_DataType>& list)
76 {
77   list.clear(); // We do not have any requirements for our input data type(s).
78   list.push_back( AliHLTTRDDefinitions::gkClusterDataType );
79 }
80
81 AliHLTComponent_DataType AliHLTTRDTrackerComponent::GetOutputDataType()
82 {
83   return AliHLTTRDDefinitions::gkClusterDataType;
84 }
85
86 void AliHLTTRDTrackerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
87 {
88   constBase = 0;
89   inputMultiplier = ((double)fOutputPercentage)/100.0;
90 }
91
92 // Spawn function, return new instance of this class
93 AliHLTComponent* AliHLTTRDTrackerComponent::Spawn()
94 {
95   return new AliHLTTRDTrackerComponent;
96 };
97
98 int AliHLTTRDTrackerComponent::DoInit( int argc, const char** argv )
99 {
100   // perform initialization. We check whether our relative output size is specified in the arguments.
101   fOutputPercentage = 100;
102   int i = 0;
103   char* cpErr;
104   while ( i < argc )
105     {
106       Logging( kHLTLogDebug, "HLT::TRDTracker::DoInit", "Arguments", "argv[%d] == %s", i, argv[i] );
107       if ( !strcmp( argv[i], "output_percentage" ) )
108         {
109           if ( i+1>=argc )
110             {
111               Logging(kHLTLogError, "HLT::TRDTracker::DoInit", "Missing Argument", "Missing output_percentage parameter");
112               return ENOTSUP;
113             }
114           Logging( kHLTLogDebug, "HLT::TRDTracker::DoInit", "Arguments", "argv[%d+1] == %s", i, argv[i+1] );
115           fOutputPercentage = strtoul( argv[i+1], &cpErr, 0 );
116           if ( *cpErr )
117             {
118               Logging(kHLTLogError, "HLT::TRDTracker::DoInit", "Wrong Argument", "Cannot convert output_percentage parameter '%s'", argv[i+1] );
119               return EINVAL;
120             }
121           Logging( kHLTLogInfo, "HLT::TRDTracker::DoInit", "Output percentage set", "Output percentage set to %lu %%", fOutputPercentage );
122           i += 2;
123           continue;
124         }
125
126       if ( strcmp( argv[i], "-cdb" ) == 0)
127         {
128           if ( i+1 >= argc )
129             {
130               Logging(kHLTLogError, "HLT::TRDTracker::DoInit", "Missing Argument", "Missing -cdb argument");
131               return ENOTSUP;         
132             }
133           fStrorageDBpath = argv[i+1];
134           Logging( kHLTLogInfo, "HLT::TRDTracker::DoInit", "DB storage set", "DB storage is %s", fStrorageDBpath.c_str() );       
135           fCDB->SetDefaultStorage(fStrorageDBpath.c_str());
136           i += 2;
137           continue;
138         }      
139
140       if ( strcmp( argv[i], "-geometry" ) == 0)
141         {
142           if ( i+1 >= argc )
143             {
144               Logging(kHLTLogError, "HLT::TRDTracker::DoInit", "Missing Argument", "Missing -geometry argument");
145               return ENOTSUP;         
146             }
147           fGeometryFileName = argv[i+1];
148           Logging( kHLTLogInfo, "HLT::TRDTracker::DoInit", "GeomFile storage set", "GeomFile storage is %s", 
149                    fGeometryFileName.c_str() );   
150           i += 2;
151           continue;
152         }      
153
154       Logging(kHLTLogError, "HLT::TRDTracker::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
155       return EINVAL;
156     }
157
158   fClusterizer = new AliTRDclusterizerV1HLT("TRCclusterizer", "TRCclusterizer");
159
160   fGeometryFile = TFile::Open(fGeometryFileName.c_str());
161   if (fGeometryFile)
162     {
163       fGeoManager = (TGeoManager *)fGeometryFile->Get("Geometry");
164       fTracker = new AliTRDtrackerHLT(fGeometryFile);
165     }
166   else
167     {
168       Logging(kHLTLogError, "HLT::TRDTracker::DoInit", "fGeometryFile", "Unable to open file. FATAL!");
169       return -1;
170     }
171
172   AliTRDCalibraFillHisto *calibra = AliTRDCalibraFillHisto::Instance();
173   if (calibra == 0)
174     {
175       Logging(kHLTLogError, "HLT::TRDTracker::DoInit", "Calibration Histos", "::Instance failed");
176       return -1;      
177     }
178   else
179     {
180       calibra->SetMITracking(kTRUE);
181       calibra->Init2Dhistos();
182     }
183
184   return 0;
185 }
186
187 int AliHLTTRDTrackerComponent::DoDeinit()
188 {
189   delete fClusterizer;
190   fClusterizer = 0;
191
192   delete fTracker;
193   fTracker = 0;
194   
195   if (fGeometryFile)
196     {
197       fGeometryFile->Close();
198       delete fGeometryFile;
199     }
200
201   AliTRDCalibraFillHisto *calibra = AliTRDCalibraFillHisto::Instance();
202   if (calibra)
203     {
204       calibra->Write2d();
205       calibra->Destroy();
206     }
207
208   return 0;
209 }
210
211 int AliHLTTRDTrackerComponent::DoEvent( const AliHLTComponentEventData & evtData,
212                                         AliHLTComponentTriggerData & trigData )
213 {
214   Logging( kHLTLogInfo, "HLT::TRDTracker::DoEvent", "Output percentage set", "Output percentage set to %lu %%", fOutputPercentage );
215   Logging( kHLTLogInfo, "HLT::TRDTracker::DoEvent", "BLOCKS", "NofBlocks %lu", evtData.fBlockCnt );
216
217   AliHLTUInt32_t fDblock_Specification = 0;
218
219   AliHLTComponentBlockData *dblock = (AliHLTComponentBlockData *)GetFirstInputBlock( AliHLTTRDDefinitions::gkClusterDataType );
220   if (dblock != 0)
221     {
222       fDblock_Specification = dblock->fSpecification;
223     }
224   else
225     {
226       Logging( kHLTLogWarning, "HLT::TRDTracker::DoEvent", "DATAIN", "First Input Block not found! 0x%x", dblock);
227       return -1;
228     }
229
230   int ibForce = 0;
231   TObject *tobjin = (TObject *)GetFirstInputObject( AliHLTTRDDefinitions::gkClusterDataType, "TObjArray", ibForce);
232   Logging( kHLTLogInfo, "HLT::TRDTracker::DoEvent", "1stBLOCK", "Pointer = 0x%x", tobjin);
233
234 //   int iTotalClusterCounter = 0;
235   while (tobjin != 0)
236     {
237       TObjArray *clusters = (TObjArray *)tobjin;
238       if (clusters != 0)
239         {
240           //put back to the clusterizers tree
241           Int_t iSuggestedDet = -1; // take the det number from the first cluster
242           Bool_t kInsert = kFALSE;
243           if (clusters->GetEntries() > 0)
244             {
245               AliTRDcluster *cl = (AliTRDcluster*)clusters->At(0);
246               iSuggestedDet = cl->GetDetector();
247               kInsert = fClusterizer->InsertClusters(clusters, iSuggestedDet);      
248               Logging( kHLTLogInfo, "HLT::TRDTracker::DoEvent", "TOTREE", "Result = %d", kInsert);        
249             }
250             
251           Logging( kHLTLogInfo, "HLT::TRDTracker::DoEvent", "CLUSTERS", "Pointer = 0x%x", clusters);      
252 //        //dump the clusters to the log files
253 //        for (Int_t ic = 0; ic < clusters->GetEntries(); ic++)
254 //          {
255 //            AliTRDcluster *cl = (AliTRDcluster*)clusters->At(ic);
256 //            Logging( kHLTLogInfo, "HLT::TRDTracker::DoEvent", "CLUSTER", "%d : %d : Q = %1.2f", 
257 //                     iTotalClusterCounter, ic, cl->GetQ());         
258 //            iTotalClusterCounter++;
259 //          }
260           
261           //Pass the data further...
262           //PushBack(clusters, AliHLTTRDDefinitions::gkClusterDataType, fDblock_Specification);
263         }
264       else
265         {
266           Logging( kHLTLogError, "HLT::TRDTracker::DoEvent", "CLUSTERS", "Pointer = 0x%x", clusters);     
267         }
268
269       tobjin = (TObject *)GetNextInputObject( ibForce );
270       Logging( kHLTLogInfo, "HLT::TRDTracker::DoEvent", "nextBLOCK", "Pointer = 0x%x", tobjin);
271
272     }
273
274   Int_t iNclusters = fClusterizer->GetNclusters();
275   Logging( kHLTLogInfo, "HLT::TRDTracker::DoEvent", "COUNT", "N of Clusters = %d", iNclusters);
276   fTracker->LoadClusters(fClusterizer->GetClusterTree());
277
278   AliTRDReconstructor::SetSeedingOn(kTRUE);
279
280   AliESD *esd = new AliESD();
281
282   //fTracker->MakeSeedsMI(3, 5, esd);
283   fTracker->PropagateBack(esd);
284
285   //here transport the esd tracks further
286   //no receiver defined yet(!)
287   delete esd;
288   return 0;
289 }