]> git.uio.no Git - u/mrichter/AliRoot.git/blame - 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
CommitLineData
1ac82ce6 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
1726bb2d 19 @author Jacek Otwinowski & Matthias Richter
1ac82ce6 20 @date
21 @brief Wrapper component to the TPC offline tracker
22*/
23
24#include "AliHLTTPCOfflineTrackerComponent.h"
25#include "TString.h"
89c2e505 26#include "TClonesArray.h"
1ac82ce6 27#include "TObjArray.h"
28#include "TObjString.h"
e642ae99 29#include "AliVParticle.h"
30#include "AliCDBManager.h"
31#include "AliCDBEntry.h"
32#include "AliGeomManager.h"
a553c904 33#ifndef HAVE_NOT_ALIMAGF30848
f7a1cc68 34#include "AliMagF.h"
a553c904 35#else // keeping the <30489 code for backward compatibility, to be merged at some point
36#include "AliMagFMaps.h"
37#endif
89c2e505 38#include "AliTPCReconstructor.h"
aa40a4a1 39#include "AliTPCParam.h"
89c2e505 40#include "AliTPCRecoParam.h"
aa40a4a1 41#include "AliTPCParamSR.h"
42#include "AliTPCtrackerMI.h"
43#include "AliTPCClustersRow.h"
89c2e505 44#include "AliTPCseed.h"
aa40a4a1 45#include "AliESDEvent.h"
46#include "AliHLTTPCDefinitions.h"
1ac82ce6 47
48/** ROOT macro for the implementation of ROOT specific class methods */
49ClassImp(AliHLTTPCOfflineTrackerComponent)
50
aa40a4a1 51AliHLTTPCOfflineTrackerComponent::AliHLTTPCOfflineTrackerComponent() : AliHLTProcessor(),
e642ae99 52fGeometryFileName(""),
aa40a4a1 53fTPCGeomParam(0),
54fTracker(0),
0e442a0a 55fESD(0)
1ac82ce6 56{
e642ae99 57 // Default constructor
58 fGeometryFileName = getenv("ALICE_ROOT");
59 fGeometryFileName += "/HLT/TPCLib/offline/geometry.root";
1ac82ce6 60}
61
62AliHLTTPCOfflineTrackerComponent::~AliHLTTPCOfflineTrackerComponent()
63{
64 // see header file for class documentation
65}
66
67const char* AliHLTTPCOfflineTrackerComponent::GetComponentID()
68{
69 // see header file for class documentation
70 return "TPCOfflineTracker";
71}
72
73void AliHLTTPCOfflineTrackerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
74{
aa40a4a1 75 // get input data type
76 list.push_back(kAliHLTDataTypeTObjArray|kAliHLTDataOriginTPC/*AliHLTTPCDefinitions::fgkOfflineClustersDataType*/);
1ac82ce6 77}
78
79AliHLTComponentDataType AliHLTTPCOfflineTrackerComponent::GetOutputDataType()
80{
aa40a4a1 81 // create output data type
82 return kAliHLTDataTypeESDObject|kAliHLTDataOriginTPC/*AliHLTTPCDefinitions::fgkOfflineTrackSegmentsDataType*/;
1ac82ce6 83}
84
85void AliHLTTPCOfflineTrackerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
86{
aa40a4a1 87 // get output data size
88 constBase = 2000000;
e642ae99 89 inputMultiplier = 1;
1ac82ce6 90}
91
92AliHLTComponent* AliHLTTPCOfflineTrackerComponent::Spawn()
93{
aa40a4a1 94 // create instance of the component
1ac82ce6 95 return new AliHLTTPCOfflineTrackerComponent;
96}
97
98int AliHLTTPCOfflineTrackerComponent::DoInit( int argc, const char** argv )
99{
aa40a4a1 100 // init configuration
101 //
1ac82ce6 102 int iResult=0;
c03e064d 103#ifdef HAVE_NOT_TPCOFFLINE_REC
104 HLTFatal("AliRoot version > v4-13-Release required");
105 return -ENOSYS;
aa40a4a1 106#endif
1ac82ce6 107
108 TString argument="";
109 TString configuration="";
110 int bMissingParam=0;
e642ae99 111
112 // loop over input parameters
1ac82ce6 113 for (int i=0; i<argc && iResult>=0; i++) {
114 argument=argv[i];
115 if (argument.IsNull()) continue;
116
e642ae99 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
1ac82ce6 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
e642ae99 142 //
143 // initialisation
144 //
1b56c057 145
e642ae99 146 // Load geometry
e642ae99 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 }
89c2e505 152
153 // TPC reconstruction parameters
89c2e505 154 AliTPCRecoParam * tpcRecoParam = AliTPCRecoParam::GetHLTParam();
155 if(tpcRecoParam) {
1b56c057 156 tpcRecoParam->SetClusterSharing(kTRUE);
157
7e88424f 158 AliTPCReconstructor tpcReconstructor;
159 tpcReconstructor.SetRecoParam(tpcRecoParam);
89c2e505 160 }
e642ae99 161
aa40a4a1 162 // TPC geometry parameters
163 fTPCGeomParam = new AliTPCParamSR;
164 if (fTPCGeomParam) {
165 fTPCGeomParam->ReadGeoMatrices();
166 }
167
e642ae99 168 // Init tracker
aa40a4a1 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();
488581c1 176 }
177
aa40a4a1 178 if (!fTracker || !fESD || !fTPCGeomParam) {
179 HLTError("failed creating internal objects");
180 iResult=-ENOMEM;
181 }
182
e642ae99 183 if (iResult>=0) {
184 // read the default CDB entries
185 iResult=Reconfigure(NULL, NULL);
186 }
187
1ac82ce6 188 return iResult;
189}
190
191int AliHLTTPCOfflineTrackerComponent::DoDeinit()
192{
aa40a4a1 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
1ac82ce6 199 return 0;
200}
201
202int AliHLTTPCOfflineTrackerComponent::DoEvent( const AliHLTComponentEventData& /*evtData*/, AliHLTComponentTriggerData& /*trigData*/)
203{
aa40a4a1 204 // tracker function
205 HLTInfo("DoEvent processing data");
1ac82ce6 206
aa40a4a1 207 int iResult=0;
89c2e505 208 TClonesArray *clusterArray=0;
e642ae99 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);
aa40a4a1 220
221 if (fTracker && fESD) {
89c2e505 222 // loop over input data blocks: TClonesArrays of clusters
dcb8a00c 223 for (TObject *pObj = (TObject *)GetFirstInputObject(kAliHLTDataTypeTObjArray|kAliHLTDataOriginTPC/*AliHLTTPCDefinitions::fgkOfflineClustersDataType*/,"TClonesArray",0);
aa40a4a1 224 pObj !=0 && iResult>=0;
225 pObj = (TObject *)GetNextInputObject(0)) {
89c2e505 226 clusterArray = dynamic_cast<TClonesArray*>(pObj);
aa40a4a1 227 if (!clusterArray) continue;
aa40a4a1 228
89c2e505 229 HLTInfo("load %d clusters from block %s 0x%08x", clusterArray->GetEntries(), DataType2Text(GetDataType(pObj)).c_str(), GetSpecification(pObj));
e642ae99 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;
c03e064d 237#ifndef HAVE_NOT_TPCOFFLINE_REC
aa40a4a1 238 fTracker->LoadClusters(clusterArray);
c03e064d 239#endif //HAVE_NOT_TPCOFFLINE_REC
89c2e505 240
241 clusterArray->Delete();
aa40a4a1 242 }// end loop over input objects
243
89c2e505 244#ifndef HAVE_NOT_TPCOFFLINE_REC
245 // Load outer sectors
246 fTracker->LoadOuterSectors();
247 // Load inner sectors
248 fTracker->LoadInnerSectors();
249#endif
250
488581c1 251 // set magnetic field for the ESD, assumes correct initialization of
252 // the field map
253 fESD->SetMagneticField(AliTracker::GetBz());
89c2e505 254
aa40a4a1 255 // run tracker
256 fTracker->Clusters2Tracks(fESD);
1726bb2d 257
1726bb2d 258 // unload clusters
aa40a4a1 259 fTracker->UnloadClusters();
260
261 Int_t nTracks = fESD->GetNumberOfTracks();
0e442a0a 262 HLTInfo("Number TPC tracks %d", nTracks);
aa40a4a1 263
e642ae99 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);
aa40a4a1 267
e642ae99 268 // send data
269 PushBack(fESD, kAliHLTDataTypeESDObject|kAliHLTDataOriginTPC, iSpecification);
aa40a4a1 270
89c2e505 271 // reset ESDs and ESDs friends
aa40a4a1 272 fESD->Reset();
e642ae99 273
aa40a4a1 274 } else {
275 HLTError("component not initialized");
276 iResult=-ENOMEM;
277 }
278
279 return iResult;
1ac82ce6 280}
281
282int 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
e642ae99 298 if (argument.CompareTo("-solenoidBz")==0) {
a553c904 299#ifndef HAVE_NOT_ALIMAGF30848
1ac82ce6 300 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
a553c904 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
e642ae99 303 float SolenoidBz=((TObjString*)pTokens->At(i))->GetString().Atof();
304 if (SolenoidBz<kAlmost0Field) SolenoidBz=kAlmost0Field;
f7a1cc68 305 float factor=SolenoidBz/5;
306 //
307 AliMagF::BMap_t map = AliMagF::k5kG;
e642ae99 308 if (SolenoidBz<3.) {
f7a1cc68 309 map=AliMagF::k2kG;
e642ae99 310 factor=SolenoidBz/2;
f7a1cc68 311 } /*else if (SolenoidBz>=3. && SolenoidBz<4.5) {
e642ae99 312 map=AliMagFMaps::k4kG;
313 factor=SolenoidBz/4;
f7a1cc68 314 }
315 else {
e642ae99 316 map=AliMagFMaps::k5kG;
317 factor=SolenoidBz/5;
f7a1cc68 318 } */
e642ae99 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?
f7a1cc68 322 const AliMagF* currentMap = (AliMagF*)TGeoGlobalMagField::Instance()->GetField();
e642ae99 323 if (!currentMap) {
f7a1cc68 324 AliMagF* field = new AliMagF("MagneticFieldMap", "BMap", 2, 1., 1., 10., map);
325 TGeoGlobalMagField::Instance()->SetField(field);
e642ae99 326 HLTInfo("Solenoid Field set to: %f map %d", SolenoidBz, map);
f7a1cc68 327 } else if (currentMap->GetMapType()!=map) {
328 HLTWarning("omitting request to override field map %d with %d", currentMap->GetMapType(), map);
e642ae99 329 }
a553c904 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
e642ae99 359 continue;
1ac82ce6 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
e642ae99 375int AliHLTTPCOfflineTrackerComponent::Reconfigure(const char* cdbEntry, const char* chainId)
1ac82ce6 376{
377 // see header file for class documentation
378 int iResult=0;
e642ae99 379 const char* path=kAliHLTCDBSolenoidBz;
380 const char* defaultNotify="";
381 if (cdbEntry) {
382 path=cdbEntry;
383 defaultNotify=" (default)";
384 }
385 if (path) {
73449074 386 if (chainId) {} // just to get rid of warning, can not comment argument due to debug message
e642ae99 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
1ac82ce6 402 return iResult;
403}