]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/offline/AliHLTTPCOfflineTrackerComponent.cxx
Adding several checks in order to compile HLT libraries with older AliRoot versions
[u/mrichter/AliRoot.git] / HLT / TPCLib / offline / AliHLTTPCOfflineTrackerComponent.cxx
1 // $Id$
2
3 //**************************************************************************
4 //* This file is property of and copyright by the ALICE HLT Project        * 
5 //* ALICE Experiment at CERN, All rights reserved.                         *
6 //*                                                                        *
7 //* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no>        *
8 //*                                                                        *
9 //* Permission to use, copy, modify and distribute this software and its   *
10 //* documentation strictly for non-commercial purposes is hereby granted   *
11 //* without fee, provided that the above copyright notice appears in all   *
12 //* copies and that both the copyright notice and this permission notice   *
13 //* appear in the supporting documentation. The authors make no claims     *
14 //* about the suitability of this software for any purpose. It is          *
15 //* provided "as is" without express or implied warranty.                  *
16 //**************************************************************************
17
18 /** @file   AliHLTTPCOfflineTrackerComponent.cxx
19     @author Jacek Otwinowski & Matthias Richter
20     @date   
21     @brief  Wrapper component to the TPC offline tracker
22 */
23
24 #include "AliHLTTPCOfflineTrackerComponent.h"
25 #include "TString.h"
26 #include "TClonesArray.h"
27 #include "TObjArray.h"
28 #include "TObjString.h"
29 #include "AliVParticle.h"
30 #include "AliCDBManager.h"
31 #include "AliCDBEntry.h"
32 #include "AliGeomManager.h"
33 #ifndef HAVE_NOT_ALIMAGF30848
34 #include "AliMagF.h"
35 #else // keeping the <30489 code for backward compatibility, to be merged at some point
36 #include "AliMagFMaps.h"
37 #endif
38 #include "AliTPCReconstructor.h"
39 #include "AliTPCParam.h"
40 #include "AliTPCRecoParam.h"
41 #include "AliTPCParamSR.h"
42 #include "AliTPCtrackerMI.h"
43 #include "AliTPCClustersRow.h"
44 #include "AliTPCseed.h"
45 #include "AliESDEvent.h"
46 #include "AliHLTTPCDefinitions.h"
47
48 /** ROOT macro for the implementation of ROOT specific class methods */
49 ClassImp(AliHLTTPCOfflineTrackerComponent)
50
51 AliHLTTPCOfflineTrackerComponent::AliHLTTPCOfflineTrackerComponent() : AliHLTProcessor(),
52 fGeometryFileName(""),
53 fTPCGeomParam(0),
54 fTracker(0),
55 fESD(0)
56 {
57   // Default constructor
58   fGeometryFileName = getenv("ALICE_ROOT");
59   fGeometryFileName += "/HLT/TPCLib/offline/geometry.root";
60 }
61
62 AliHLTTPCOfflineTrackerComponent::~AliHLTTPCOfflineTrackerComponent()
63 {
64   // see header file for class documentation
65 }
66
67 const char* AliHLTTPCOfflineTrackerComponent::GetComponentID()
68 {
69   // see header file for class documentation
70   return "TPCOfflineTracker";
71 }
72
73 void AliHLTTPCOfflineTrackerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
74 {
75   // get input data type
76   list.push_back(kAliHLTDataTypeTObjArray|kAliHLTDataOriginTPC/*AliHLTTPCDefinitions::fgkOfflineClustersDataType*/);
77 }
78
79 AliHLTComponentDataType AliHLTTPCOfflineTrackerComponent::GetOutputDataType()
80 {
81   // create output data type
82   return kAliHLTDataTypeESDObject|kAliHLTDataOriginTPC/*AliHLTTPCDefinitions::fgkOfflineTrackSegmentsDataType*/;
83 }
84
85 void AliHLTTPCOfflineTrackerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
86 {
87   // get output data size
88   constBase = 2000000;
89   inputMultiplier = 1;
90 }
91
92 AliHLTComponent* AliHLTTPCOfflineTrackerComponent::Spawn()
93 {
94   // create instance of the component
95   return new AliHLTTPCOfflineTrackerComponent;
96 }
97
98 int AliHLTTPCOfflineTrackerComponent::DoInit( int argc, const char** argv )
99 {
100   // init configuration 
101   //
102   int iResult=0;
103 #ifdef HAVE_NOT_TPCOFFLINE_REC
104   HLTFatal("AliRoot version > v4-13-Release required");
105   return -ENOSYS;
106 #endif
107
108   TString argument="";
109   TString configuration=""; 
110   int bMissingParam=0;
111
112   // loop over input parameters
113   for (int i=0; i<argc && iResult>=0; i++) {
114     argument=argv[i];
115     if (argument.IsNull()) continue;
116
117     if (argument.CompareTo("-geometry")==0) {
118       if ((bMissingParam=(++i>=argc))) break;
119
120       HLTInfo("got \'-geometry\' argument: %s", argv[i]);
121       fGeometryFileName = argv[i];
122       HLTInfo("Geometry file is: %s", fGeometryFileName.c_str());
123
124       // the remaining arguments are treated as configuration
125     } else {
126       if (!configuration.IsNull()) configuration+=" ";
127       configuration+=argument;
128     }
129   } // end loop
130
131   if (bMissingParam) {
132     HLTError("missing parameter for argument %s", argument.Data());
133     iResult=-EINVAL;
134   }
135
136   if (iResult>=0 && !configuration.IsNull()) {
137     iResult=Configure(configuration.Data());
138   } else {
139     iResult=Reconfigure(NULL, NULL);
140   }
141
142   //
143   // initialisation
144   //
145  
146   // Load geometry
147   AliGeomManager::LoadGeometry(fGeometryFileName.c_str());
148   if((AliGeomManager::GetGeometry()) == 0) {
149     HLTError("Cannot load geometry from file %s",fGeometryFileName.c_str());
150     iResult=-EINVAL;
151   }
152
153   // TPC reconstruction parameters
154   AliTPCRecoParam * tpcRecoParam = AliTPCRecoParam::GetHLTParam();
155   if(tpcRecoParam) {
156     tpcRecoParam->SetClusterSharing(kTRUE);
157
158     AliTPCReconstructor tpcReconstructor;
159     tpcReconstructor.SetRecoParam(tpcRecoParam);
160   }
161  
162   // TPC geometry parameters
163   fTPCGeomParam = new AliTPCParamSR;
164   if (fTPCGeomParam) {
165     fTPCGeomParam->ReadGeoMatrices();
166   }
167
168   // Init tracker
169   fTracker = new AliTPCtrackerMI(fTPCGeomParam);
170
171   // AliESDEvent event needed by AliTPCtrackerMI
172   // output of the component
173   fESD = new AliESDEvent();
174   if (fESD) {
175     fESD->CreateStdContent();
176   }
177
178   if (!fTracker || !fESD || !fTPCGeomParam) {
179     HLTError("failed creating internal objects");
180     iResult=-ENOMEM;
181   }
182
183   if (iResult>=0) {
184     // read the default CDB entries
185     iResult=Reconfigure(NULL, NULL);
186   }
187
188   return iResult;
189 }
190
191 int AliHLTTPCOfflineTrackerComponent::DoDeinit()
192 {
193   // deinit configuration
194
195   if(fTPCGeomParam) delete fTPCGeomParam; fTPCGeomParam = 0; 
196   if(fTracker) delete fTracker; fTracker = 0; 
197   if(fESD) delete fESD; fESD = 0;
198
199   return 0;
200 }
201
202 int AliHLTTPCOfflineTrackerComponent::DoEvent( const AliHLTComponentEventData& /*evtData*/, AliHLTComponentTriggerData& /*trigData*/)
203 {
204   // tracker function
205   HLTInfo("DoEvent processing data");
206
207   int iResult=0;
208   TClonesArray *clusterArray=0;
209   int slice, patch;
210
211   const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTObjArray|kAliHLTDataOriginTPC); 
212   if(!pBlock) {
213      HLTError("Cannot get first data block 0x%08x ",pBlock);
214      iResult=-ENOMEM; return iResult;
215   }
216   int minSlice=AliHLTTPCDefinitions::GetMinSliceNr(pBlock->fSpecification);
217   int maxSlice=AliHLTTPCDefinitions::GetMaxSliceNr(pBlock->fSpecification);
218   int minPatch=AliHLTTPCDefinitions::GetMinPatchNr(pBlock->fSpecification);
219   int maxPatch=AliHLTTPCDefinitions::GetMaxPatchNr(pBlock->fSpecification);  
220
221   if (fTracker && fESD) {
222       // loop over input data blocks: TClonesArrays of clusters
223       for (TObject *pObj = (TObject *)GetFirstInputObject(kAliHLTDataTypeTObjArray|kAliHLTDataOriginTPC/*AliHLTTPCDefinitions::fgkOfflineClustersDataType*/,"TClonesArray",0);
224          pObj !=0 && iResult>=0;
225          pObj = (TObject *)GetNextInputObject(0)) {
226       clusterArray = dynamic_cast<TClonesArray*>(pObj);
227       if (!clusterArray) continue;
228
229       HLTInfo("load %d clusters from block %s 0x%08x", clusterArray->GetEntries(), DataType2Text(GetDataType(pObj)).c_str(), GetSpecification(pObj));
230       slice=AliHLTTPCDefinitions::GetMinSliceNr(GetSpecification(pObj));
231       patch=AliHLTTPCDefinitions::GetMinPatchNr(GetSpecification(pObj));
232
233       if(slice < minSlice) minSlice=slice;
234       if(slice > maxSlice) maxSlice=slice;
235       if(patch < minPatch) minPatch=patch;
236       if(patch > maxPatch) maxPatch=patch;
237 #ifndef HAVE_NOT_TPCOFFLINE_REC
238       fTracker->LoadClusters(clusterArray);
239 #endif //HAVE_NOT_TPCOFFLINE_REC
240  
241     clusterArray->Delete();
242     }// end loop over input objects
243
244 #ifndef HAVE_NOT_TPCOFFLINE_REC
245     // Load outer sectors
246       fTracker->LoadOuterSectors();
247     // Load inner sectors
248       fTracker->LoadInnerSectors();
249 #endif
250
251     // set magnetic field for the ESD, assumes correct initialization of
252     // the field map
253     fESD->SetMagneticField(AliTracker::GetBz());
254   
255     // run tracker
256     fTracker->Clusters2Tracks(fESD);
257
258     // unload clusters
259     fTracker->UnloadClusters();
260
261     Int_t nTracks = fESD->GetNumberOfTracks();
262     HLTInfo("Number TPC tracks %d", nTracks);
263
264     // calculate specification from the specification of input data blocks
265     AliHLTUInt32_t iSpecification = AliHLTTPCDefinitions::EncodeDataSpecification( minSlice, maxSlice, minPatch, maxPatch );
266     HLTInfo("minSlice %d, maxSlice %d, minPatch %d, maxPatch %d", minSlice, maxSlice, minPatch, maxPatch);
267
268     // send data
269     PushBack(fESD, kAliHLTDataTypeESDObject|kAliHLTDataOriginTPC, iSpecification);
270
271     // reset ESDs and ESDs friends
272     fESD->Reset();
273
274   } else {
275     HLTError("component not initialized");
276     iResult=-ENOMEM;
277   }
278
279   return iResult;
280 }
281
282 int AliHLTTPCOfflineTrackerComponent::Configure(const char* arguments)
283 {
284   // see header file for class documentation
285   int iResult=0;
286   if (!arguments) return iResult;
287
288   TString allArgs=arguments;
289   TString argument;
290   int bMissingParam=0;
291
292   TObjArray* pTokens=allArgs.Tokenize(" ");
293   if (pTokens) {
294     for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
295       argument=((TObjString*)pTokens->At(i))->GetString();
296       if (argument.IsNull()) continue;
297
298       if (argument.CompareTo("-solenoidBz")==0) {
299 #ifndef HAVE_NOT_ALIMAGF30848
300         if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
301         // TODO: Matthias 2009-05-08 this changes below look weird to me
302         // maybe this was not correctly done by Federico in r 30849
303         float SolenoidBz=((TObjString*)pTokens->At(i))->GetString().Atof();
304         if (SolenoidBz<kAlmost0Field) SolenoidBz=kAlmost0Field;
305         float factor=SolenoidBz/5;
306         //
307         AliMagF::BMap_t map = AliMagF::k5kG;
308         if (SolenoidBz<3.) {
309           map=AliMagF::k2kG;
310           factor=SolenoidBz/2;
311         } /*else if (SolenoidBz>=3. && SolenoidBz<4.5) {
312           map=AliMagFMaps::k4kG;
313           factor=SolenoidBz/4;
314           }
315         else {
316           map=AliMagFMaps::k5kG;
317           factor=SolenoidBz/5;
318           } */
319         // the magnetic field map is not supposed to change
320         // field initialization should be done once in the beginning
321         // TODO: does the factor need adjustment?
322         const AliMagF* currentMap = (AliMagF*)TGeoGlobalMagField::Instance()->GetField();
323         if (!currentMap) {
324           AliMagF* field = new AliMagF("MagneticFieldMap", "BMap", 2, 1., 1., 10., map);
325           TGeoGlobalMagField::Instance()->SetField(field);
326           HLTInfo("Solenoid Field set to: %f map %d", SolenoidBz, map);
327         } else if (currentMap->GetMapType()!=map) {
328           HLTWarning("omitting request to override field map %d with %d", currentMap->GetMapType(), map);
329         }
330 #else // keeping the <30489 code for backward compatibility, to be merged at some point
331         if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
332         // TODO: check if there is common functionality in the AliMagF* classes
333         float SolenoidBz=((TObjString*)pTokens->At(i))->GetString().Atof();
334         if (SolenoidBz<kAlmost0Field) SolenoidBz=kAlmost0Field;
335         float factor=1.;
336         int map=AliMagFMaps::k2kG;
337         if (SolenoidBz<3.) {
338           map=AliMagFMaps::k2kG;
339           factor=SolenoidBz/2;
340         } else if (SolenoidBz>=3. && SolenoidBz<4.5) {
341           map=AliMagFMaps::k4kG;
342           factor=SolenoidBz/4;
343         } else {
344           map=AliMagFMaps::k5kG;
345           factor=SolenoidBz/5;
346         }
347         // the magnetic field map is not supposed to change
348         // field initialization should be done once in the beginning
349         // TODO: does the factor need adjustment?
350         const AliMagF* currentMap=AliTracker::GetFieldMap();
351         if (!currentMap) {
352           AliMagFMaps* field = new AliMagFMaps("Maps","Maps", 2, 1., 10., map);
353           AliTracker::SetFieldMap(field,kFALSE);
354           HLTInfo("Solenoid Field set to: %f map %d", SolenoidBz, map);
355         } else if (currentMap->Map()!=map) {
356           HLTWarning("omitting request to override field map %s with %s", currentMap->Map(), map);
357         }
358 #endif
359         continue;
360       } else {
361         HLTError("unknown argument %s", argument.Data());
362         iResult=-EINVAL;
363         break;
364       }
365     }
366     delete pTokens;
367   }
368   if (bMissingParam) {
369     HLTError("missing parameter for argument %s", argument.Data());
370     iResult=-EINVAL;
371   }
372   return iResult;
373 }
374
375 int AliHLTTPCOfflineTrackerComponent::Reconfigure(const char* cdbEntry, const char* chainId)
376 {
377   // see header file for class documentation
378   int iResult=0;
379   const char* path=kAliHLTCDBSolenoidBz;
380   const char* defaultNotify="";
381   if (cdbEntry) {
382     path=cdbEntry;
383     defaultNotify=" (default)";
384   }
385   if (path) {
386     if (chainId) {} // just to get rid of warning, can not comment argument due to debug message
387     HLTDebug("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
388     AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
389     if (pEntry) {
390       TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
391       if (pString) {
392         HLTDebug("received configuration object string: \'%s\'", pString->GetString().Data());
393         iResult=Configure(pString->GetString().Data());
394       } else {
395         HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
396       }
397     } else {
398       HLTError("can not fetch object \"%s\" from CDB", path);
399     }
400   }
401   
402   return iResult;
403 }