]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/offline/AliHLTTPCOfflineTrackerCalibComponent.cxx
eliminating further private copy of AliMagF and cleaning the header file includes...
[u/mrichter/AliRoot.git] / HLT / TPCLib / offline / AliHLTTPCOfflineTrackerCalibComponent.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: Jacek Otwinowski <J.Otwinowski@gsi.de>                *
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   AliHLTTPCOfflineTrackerCalibComponent.cxx
19     @author Jacek Otwinowski & Matthias Richter
20     @date   
21     @brief  Wrapper component to the TPC offline tracker (ONLY CALIBRATION)
22 */
23
24 #include "AliHLTTPCOfflineTrackerCalibComponent.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 #include "AliTPCReconstructor.h"
34 #include "AliTPCParam.h"
35 #include "AliTPCRecoParam.h"
36 #include "AliTPCParamSR.h"
37 #include "AliTPCtrackerMI.h"
38 #include "AliTPCClustersRow.h"
39 #include "AliTPCseed.h"
40 #include "AliESDEvent.h"
41 #include "AliHLTTPCDefinitions.h"
42
43 /** ROOT macro for the implementation of ROOT specific class methods */
44 ClassImp(AliHLTTPCOfflineTrackerCalibComponent)
45
46 AliHLTTPCOfflineTrackerCalibComponent::AliHLTTPCOfflineTrackerCalibComponent() : AliHLTProcessor(),
47 fGeometryFileName(""),
48 fTPCGeomParam(0),
49 fTracker(0),
50 fESD(0)
51 {
52   // Default constructor
53   fGeometryFileName = getenv("ALICE_ROOT");
54   fGeometryFileName += "/HLT/TPCLib/offline/geometry.root";
55 }
56
57 AliHLTTPCOfflineTrackerCalibComponent::~AliHLTTPCOfflineTrackerCalibComponent()
58 {
59   // see header file for class documentation
60 }
61
62 const char* AliHLTTPCOfflineTrackerCalibComponent::GetComponentID()
63 {
64   // see header file for class documentation
65   return "TPCOfflineTrackerCalib";
66 }
67
68 void AliHLTTPCOfflineTrackerCalibComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
69 {
70   // get input data type
71   list.push_back(kAliHLTDataTypeTObjArray|kAliHLTDataOriginTPC/*AliHLTTPCDefinitions::fgkOfflineClustersDataType*/);
72 }
73
74 AliHLTComponentDataType AliHLTTPCOfflineTrackerCalibComponent::GetOutputDataType()
75 {
76   // create output data type
77   //return kAliHLTDataTypeESDObject|kAliHLTDataOriginTPC/*AliHLTTPCDefinitions::fgkOfflineTrackSegmentsDataType*/;
78   return kAliHLTDataTypeTObjArray|kAliHLTDataOriginTPC;
79 }
80
81 void AliHLTTPCOfflineTrackerCalibComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
82 {
83   // get output data size
84   constBase = 2000000;
85   inputMultiplier = 1;
86 }
87
88 AliHLTComponent* AliHLTTPCOfflineTrackerCalibComponent::Spawn()
89 {
90   // create instance of the component
91   return new AliHLTTPCOfflineTrackerCalibComponent;
92 }
93
94 int AliHLTTPCOfflineTrackerCalibComponent::DoInit( int argc, const char** argv )
95 {
96   // init configuration 
97   //
98   int iResult=0;
99 #ifdef HAVE_NOT_TPCOFFLINE_REC
100   HLTFatal("AliRoot version > v4-13-Release required");
101   return -ENOSYS;
102 #endif
103
104   TString argument="";
105   TString configuration=""; 
106   int bMissingParam=0;
107
108   // loop over input parameters
109   for (int i=0; i<argc && iResult>=0; i++) {
110     argument=argv[i];
111     if (argument.IsNull()) continue;
112
113     if (argument.CompareTo("-geometry")==0) {
114       if ((bMissingParam=(++i>=argc))) break;
115
116       HLTInfo("got \'-geometry\' argument: %s", argv[i]);
117       fGeometryFileName = argv[i];
118       HLTInfo("Geometry file is: %s", fGeometryFileName.c_str());
119
120       // the remaining arguments are treated as configuration
121     } else {
122       if (!configuration.IsNull()) configuration+=" ";
123       configuration+=argument;
124     }
125   } // end loop
126
127   if (bMissingParam) {
128     HLTError("missing parameter for argument %s", argument.Data());
129     iResult=-EINVAL;
130   }
131
132   if (iResult>=0 && !configuration.IsNull()) {
133     iResult=Configure(configuration.Data());
134   } else {
135     iResult=Reconfigure(NULL, NULL);
136   }
137
138   //
139   // initialisation
140   //
141  
142   // Load geometry
143   AliGeomManager::LoadGeometry(fGeometryFileName.c_str());
144   if((AliGeomManager::GetGeometry()) == 0) {
145     HLTError("Cannot load geometry from file %s",fGeometryFileName.c_str());
146     iResult=-EINVAL;
147   }
148
149   // TPC reconstruction parameters
150   AliTPCRecoParam * tpcRecoParam = AliTPCRecoParam::GetHLTParam();
151   if(tpcRecoParam) {
152     tpcRecoParam->SetClusterSharing(kTRUE);
153
154     AliTPCReconstructor tpcReconstructor;
155     tpcReconstructor.SetRecoParam(tpcRecoParam);
156   }
157  
158   // TPC geometry parameters
159   fTPCGeomParam = new AliTPCParamSR;
160   if (fTPCGeomParam) {
161     fTPCGeomParam->ReadGeoMatrices();
162   }
163
164   // Init tracker
165   fTracker = new AliTPCtrackerMI(fTPCGeomParam);
166
167   // AliESDEvent event needed by AliTPCtrackerMI
168   // output of the component
169   fESD = new AliESDEvent();
170   if (fESD) {
171     fESD->CreateStdContent();
172   }
173
174   if (!fTracker || !fESD || !fTPCGeomParam) {
175     HLTError("failed creating internal objects");
176     iResult=-ENOMEM;
177   }
178
179   if (iResult>=0) {
180     // read the default CDB entries
181     iResult=Reconfigure(NULL, NULL);
182   }
183
184   return iResult;
185 }
186
187 int AliHLTTPCOfflineTrackerCalibComponent::DoDeinit()
188 {
189   // deinit configuration
190
191   if(fTPCGeomParam) delete fTPCGeomParam; fTPCGeomParam = 0; 
192   if(fTracker) delete fTracker; fTracker = 0; 
193   if(fESD) delete fESD; fESD = 0;
194
195   return 0;
196 }
197
198 int AliHLTTPCOfflineTrackerCalibComponent::DoEvent( const AliHLTComponentEventData& /*evtData*/, AliHLTComponentTriggerData& /*trigData*/)
199 {
200   // tracker function
201   HLTInfo("DoEvent processing data");
202
203   int iResult=0;
204   TClonesArray *clusterArray=0;
205   TObjArray *seedArray=0;
206   int slice, patch;
207
208   const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTObjArray|kAliHLTDataOriginTPC); 
209   if(!pBlock) {
210      HLTError("Cannot get first data block 0x%08x ",pBlock);
211      iResult=-ENOMEM; return iResult;
212   }
213   int minSlice=AliHLTTPCDefinitions::GetMinSliceNr(pBlock->fSpecification);
214   int maxSlice=AliHLTTPCDefinitions::GetMaxSliceNr(pBlock->fSpecification);
215   int minPatch=AliHLTTPCDefinitions::GetMinPatchNr(pBlock->fSpecification);
216   int maxPatch=AliHLTTPCDefinitions::GetMaxPatchNr(pBlock->fSpecification);  
217
218   if (fTracker && fESD) {
219       // loop over input data blocks: TClonesArrays of clusters
220       for (TObject *pObj = (TObject *)GetFirstInputObject(kAliHLTDataTypeTObjArray|kAliHLTDataOriginTPC/*AliHLTTPCDefinitions::fgkOfflineClustersDataType*/,"TClonesArray",0);
221          pObj !=0 && iResult>=0;
222          pObj = (TObject *)GetNextInputObject(0)) {
223       clusterArray = dynamic_cast<TClonesArray*>(pObj);
224       if (!clusterArray) continue;
225
226       HLTInfo("load %d clusters from block %s 0x%08x", clusterArray->GetEntries(), DataType2Text(GetDataType(pObj)).c_str(), GetSpecification(pObj));
227       slice=AliHLTTPCDefinitions::GetMinSliceNr(GetSpecification(pObj));
228       patch=AliHLTTPCDefinitions::GetMinPatchNr(GetSpecification(pObj));
229
230       if(slice < minSlice) minSlice=slice;
231       if(slice > maxSlice) maxSlice=slice;
232       if(patch < minPatch) minPatch=patch;
233       if(patch > maxPatch) maxPatch=patch;
234 #ifndef HAVE_NOT_TPCOFFLINE_REC
235       fTracker->LoadClusters(clusterArray);
236 #endif //HAVE_NOT_TPCOFFLINE_REC
237  
238     clusterArray->Delete();
239     }// end loop over input objects
240
241 #ifndef HAVE_NOT_TPCOFFLINE_REC
242     // Load outer sectors
243       fTracker->LoadOuterSectors();
244     // Load inner sectors
245       fTracker->LoadInnerSectors();
246 #endif
247
248     // set magnetic field for the ESD, assumes correct initialization of
249     // the field map
250     fESD->SetMagneticField(AliTracker::GetBz());
251   
252     // run tracker
253     fTracker->Clusters2Tracks(fESD);
254
255     // get TPC seeds
256     seedArray = fTracker->GetSeeds();
257
258     Int_t nTracks = fESD->GetNumberOfTracks();
259     HLTInfo("Number TPC tracks %d", nTracks);
260
261     // calculate specification from the specification of input data blocks
262     AliHLTUInt32_t iSpecification = AliHLTTPCDefinitions::EncodeDataSpecification( minSlice, maxSlice, minPatch, maxPatch );
263     HLTInfo("minSlice %d, maxSlice %d, minPatch %d, maxPatch %d", minSlice, maxSlice, minPatch, maxPatch);
264
265     // send data
266     if(seedArray) PushBack(seedArray, kAliHLTDataTypeTObjArray|kAliHLTDataOriginTPC, iSpecification);
267
268     // delete seeds
269     if(seedArray) seedArray->Delete();
270
271     // unload clusters
272     fTracker->UnloadClusters();
273
274     // reset ESDs and ESDs friends
275     fESD->Reset();
276
277   } else {
278     HLTError("component not initialized");
279     iResult=-ENOMEM;
280   }
281
282   return iResult;
283 }
284
285 int AliHLTTPCOfflineTrackerCalibComponent::Configure(const char* arguments)
286 {
287   // see header file for class documentation
288   int iResult=0;
289   if (!arguments) return iResult;
290
291   TString allArgs=arguments;
292   TString argument;
293   int bMissingParam=0;
294
295   TObjArray* pTokens=allArgs.Tokenize(" ");
296   if (pTokens) {
297     for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
298       argument=((TObjString*)pTokens->At(i))->GetString();
299       if (argument.IsNull()) continue;
300
301       if (argument.CompareTo("-solenoidBz")==0) {
302         if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
303         HLTWarning("argument -solenoidBz is deprecated, magnetic field set up globally (%f)", GetBz());
304         continue;
305       } else {
306         HLTError("unknown argument %s", argument.Data());
307         iResult=-EINVAL;
308         break;
309       }
310     }
311     delete pTokens;
312   }
313   if (bMissingParam) {
314     HLTError("missing parameter for argument %s", argument.Data());
315     iResult=-EINVAL;
316   }
317   return iResult;
318 }
319
320 int AliHLTTPCOfflineTrackerCalibComponent::Reconfigure(const char* cdbEntry, const char* chainId)
321 {
322   // see header file for class documentation
323   int iResult=0;
324   const char* path=kAliHLTCDBSolenoidBz;
325   const char* defaultNotify="";
326   if (cdbEntry) {
327     path=cdbEntry;
328     defaultNotify=" (default)";
329   }
330   if (path) {
331     if (chainId) {} // just to get rid of warning, can not comment argument due to debug message
332     HLTDebug("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
333     AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
334     if (pEntry) {
335       TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
336       if (pString) {
337         HLTDebug("received configuration object string: \'%s\'", pString->GetString().Data());
338         iResult=Configure(pString->GetString().Data());
339       } else {
340         HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
341       }
342     } else {
343       HLTError("can not fetch object \"%s\" from CDB", path);
344     }
345   }
346   
347   return iResult;
348 }