addtional DSC alias from Tomek
[u/mrichter/AliRoot.git] / HLT / global / AliHLTGlobalEsdConverterComponent.cxx
CommitLineData
a1408c4b 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//* for The ALICE HLT 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 AliHLTGlobalEsdConverterComponent.cxx
20 @author Matthias Richter
21 @date
22 @brief Global ESD converter component.
23*/
24
25// see header file for class documentation
26// or
27// refer to README to build package
28// or
29// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
30
31#include <cassert>
32#include "AliHLTGlobalEsdConverterComponent.h"
33#include "AliHLTGlobalBarrelTrack.h"
34#include "AliHLTExternalTrackParam.h"
093b64dc 35#include "AliHLTTrackMCLabel.h"
a1408c4b 36#include "AliESDEvent.h"
37#include "AliESDtrack.h"
38#include "AliCDBEntry.h"
39#include "AliCDBManager.h"
40#include "TTree.h"
41#include "TList.h"
42
43/** ROOT macro for the implementation of ROOT specific class methods */
44ClassImp(AliHLTGlobalEsdConverterComponent)
45
46AliHLTGlobalEsdConverterComponent::AliHLTGlobalEsdConverterComponent()
47 : AliHLTProcessor()
48 , fESD(NULL)
49 , fSolenoidBz(5)
50 , fWriteTree(0)
093b64dc 51 , fVerbosity(0)
a1408c4b 52{
53 // see header file for class documentation
54 // or
55 // refer to README to build package
56 // or
57 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
58}
59
60AliHLTGlobalEsdConverterComponent::~AliHLTGlobalEsdConverterComponent()
61{
62 // see header file for class documentation
63 if (fESD) delete fESD;
64 fESD=NULL;
65}
66
67int AliHLTGlobalEsdConverterComponent::Configure(const char* arguments)
68{
69 // see header file for class documentation
70 int iResult=0;
71 if (!arguments) return iResult;
72
73 TString allArgs=arguments;
74 TString argument;
75 int bMissingParam=0;
76
77 TObjArray* pTokens=allArgs.Tokenize(" ");
78 if (pTokens) {
79 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
80 argument=((TObjString*)pTokens->At(i))->GetString();
81 if (argument.IsNull()) continue;
82
83 if (argument.CompareTo("-solenoidBz")==0) {
84 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
85 HLTInfo("Magnetic Field set to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
86 fSolenoidBz=((TObjString*)pTokens->At(i))->GetString().Atof();
87 continue;
88 } else {
89 HLTError("unknown argument %s", argument.Data());
90 iResult=-EINVAL;
91 break;
92 }
93 }
94 delete pTokens;
95 }
96 if (bMissingParam) {
97 HLTError("missing parameter for argument %s", argument.Data());
98 iResult=-EINVAL;
99 }
100
101 return iResult;
102}
103
104int AliHLTGlobalEsdConverterComponent::Reconfigure(const char* cdbEntry, const char* chainId)
105{
106 // see header file for class documentation
107 int iResult=0;
108 const char* path=kAliHLTCDBSolenoidBz;
109 const char* defaultNotify="";
110 if (cdbEntry) {
111 path=cdbEntry;
112 defaultNotify=" (default)";
113 }
114 if (path) {
115 HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
116 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
117 if (pEntry) {
118 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
119 if (pString) {
120 HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
121 iResult=Configure(pString->GetString().Data());
122 } else {
123 HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
124 }
125 } else {
126 HLTError("can not fetch object \"%s\" from CDB", path);
127 }
128 }
129
130 return iResult;
131}
132
133void AliHLTGlobalEsdConverterComponent::GetInputDataTypes(AliHLTComponentDataTypeList& list)
134{
135 // see header file for class documentation
136 list.push_back(kAliHLTDataTypeTrack);
137 list.push_back(kAliHLTDataTypeTrackMC);
138}
139
140AliHLTComponentDataType AliHLTGlobalEsdConverterComponent::GetOutputDataType()
141{
142 // see header file for class documentation
7a9de6d1 143 return kAliHLTDataTypeESDObject|kAliHLTDataOriginOut;
a1408c4b 144}
145
146void AliHLTGlobalEsdConverterComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
147{
148 // see header file for class documentation
149 constBase=2000000;
150 inputMultiplier=10.0;
151}
152
153int AliHLTGlobalEsdConverterComponent::DoInit(int argc, const char** argv)
154{
155 // see header file for class documentation
156 int iResult=0;
157 TString argument="";
158 int bMissingParam=0;
159 for (int i=0; i<argc && iResult>=0; i++) {
160 argument=argv[i];
161 if (argument.IsNull()) continue;
162
163 // -notree
164 if (argument.CompareTo("-notree")==0) {
165 fWriteTree=0;
166
167 // -tree
168 } else if (argument.CompareTo("-tree")==0) {
169 fWriteTree=1;
170
171 } else {
172 HLTError("unknown argument %s", argument.Data());
173 break;
174 }
175 }
176 if (bMissingParam) {
177 HLTError("missing parameter for argument %s", argument.Data());
178 iResult=-EINVAL;
179 }
180
181 if (iResult>=0) {
182 iResult=Reconfigure(NULL, NULL);
183 }
184
185 if (iResult>=0) {
186 fESD = new AliESDEvent;
187 if (fESD) {
188 fESD->CreateStdContent();
189 } else {
190 iResult=-ENOMEM;
191 }
192 }
193
194 return iResult;
195}
196
197int AliHLTGlobalEsdConverterComponent::DoDeinit()
198{
199 // see header file for class documentation
200 if (fESD) delete fESD;
201 fESD=NULL;
202
203 return 0;
204}
205
206int AliHLTGlobalEsdConverterComponent::DoEvent(const AliHLTComponentEventData& /*evtData*/,
207 AliHLTComponentTriggerData& /*trigData*/)
208{
209 // see header file for class documentation
210 int iResult=0;
211 if (!fESD) return -ENODEV;
212
213 AliESDEvent* pESD = fESD;
214
215 pESD->Reset();
216 pESD->SetMagneticField(fSolenoidBz);
217
218 TTree* pTree = NULL;
219 if (fWriteTree)
220 pTree = new TTree("esdTree", "Tree with HLT ESD objects");
221
222 if (pTree) {
223 pTree->SetDirectory(0);
224 }
225
226 if ((iResult=ProcessBlocks(pTree, pESD))>0) {
227 // TODO: set the specification correctly
228 if (pTree) {
229 // the esd structure is written to the user info and is
230 // needed in te ReadFromTree method to read all objects correctly
231 pTree->GetUserInfo()->Add(pESD);
232 pESD->WriteToTree(pTree);
7a9de6d1 233 iResult=PushBack(pTree, kAliHLTDataTypeESDTree|kAliHLTDataOriginOut, 0);
a1408c4b 234 } else {
7a9de6d1 235 iResult=PushBack(pESD, kAliHLTDataTypeESDObject|kAliHLTDataOriginOut, 0);
a1408c4b 236 }
237 }
238 if (pTree) {
239 // clear user info list to prevent objects from being deleted
240 pTree->GetUserInfo()->Clear();
241 delete pTree;
242 }
243 return iResult;
244}
245
246int AliHLTGlobalEsdConverterComponent::ProcessBlocks(TTree* pTree, AliESDEvent* pESD)
247{
248 // see header file for class documentation
249
250 int iResult=0;
251 int iAddedDataBlocks=0;
252
253 // Barrel tracking
254
255 // in the first attempt this component reads the TPC tracks and updates in the
256 // second step from the ITS tracks
093b64dc 257
258
259 // first read MC information (if present)
260 std::map<int,int> mcLabels;
261
262 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrackMC|kAliHLTDataOriginTPC);
263 pBlock!=NULL; pBlock=GetNextInputBlock()) {
264 AliHLTTrackMCData* dataPtr = reinterpret_cast<AliHLTTrackMCData*>( pBlock->fPtr );
265 if (sizeof(AliHLTTrackMCData)+dataPtr->fCount*sizeof(AliHLTTrackMCLabel)==pBlock->fSize) {
266 for( unsigned int il=0; il<dataPtr->fCount; il++ ){
267 AliHLTTrackMCLabel &lab = dataPtr->fLabels[il];
268 mcLabels[lab.fTrackID] = lab.fMCLabel;
269 }
270 } else {
271 HLTWarning("data mismatch in block %s (0x%08x): count %d, size %d -> ignoring track MC information",
272 DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification,
273 dataPtr->fCount, pBlock->fSize);
274 }
275 }
276
cd60a73f 277 // convert the TPC tracks to ESD tracks
a1408c4b 278 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack|kAliHLTDataOriginTPC);
279 pBlock!=NULL; pBlock=GetNextInputBlock()) {
280 vector<AliHLTGlobalBarrelTrack> tracks;
281 if ((iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracks))>0) {
282 for (vector<AliHLTGlobalBarrelTrack>::iterator element=tracks.begin();
283 element!=tracks.end(); element++) {
284 Float_t points[4] = {
285 element->GetX(),
286 element->GetY(),
287 element->GetLastPointX(),
288 element->GetLastPointY()
289 };
093b64dc 290
291 Int_t mcLabel = -1;
292 if( mcLabels.find(element->TrackID())!=mcLabels.end() )
293 mcLabel = mcLabels[element->TrackID()];
294 element->SetLabel( mcLabel );
295
a1408c4b 296 AliESDtrack iotrack;
297 iotrack.UpdateTrackParams(&(*element),AliESDtrack::kTPCin);
298 iotrack.SetTPCPoints(points);
299
300 pESD->AddTrack(&iotrack);
093b64dc 301 if (fVerbosity>0) element->Print();
a1408c4b 302 }
093b64dc 303 HLTInfo("converted %d track(s) to AliESDtrack and added to ESD", tracks.size());
a1408c4b 304 iAddedDataBlocks++;
305 } else if (iResult<0) {
093b64dc 306 HLTError("can not extract tracks from data block of type %s (specification %08x) of size %d: error %d",
307 DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification, pBlock->fSize, iResult);
a1408c4b 308 }
309 }
310
cd60a73f 311 // now update ESD tracks with the ITS info
af3250a3 312 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack|kAliHLTDataOriginITS);
cd60a73f 313 pBlock!=NULL; pBlock=GetNextInputBlock()) {
314 vector<AliHLTGlobalBarrelTrack> tracks;
315 if ((iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracks))>0) {
316 for (vector<AliHLTGlobalBarrelTrack>::iterator element=tracks.begin();
317 element!=tracks.end(); element++) {
318 int ncl=0;
319 const UInt_t* pointsArray=element->GetPoints();
320 for( unsigned il=0; il<element->GetNumberOfPoints(); il++ ){
321 // TODO: check what needs to be done with the clusters
322 if( pointsArray[il]<~(UInt_t)0 ) {/*tITS.SetClusterIndex(ncl, tr.fClusterIds[il]);*/}
323 ncl++;
a1408c4b 324 }
cd60a73f 325 //tITS.SetNumberOfClusters( ncl );
326 int tpcID=element->TrackID();
327 // the ITS tracker assigns the TPC track used as seed for a certain track to
328 // the trackID
329 if( tpcID<0 || tpcID>=pESD->GetNumberOfTracks()) continue;
330
331 AliESDtrack *tESD = pESD->GetTrack( tpcID );
332 if( tESD ) tESD->UpdateTrackParams( &(*element), AliESDtrack::kITSin );
a1408c4b 333 }
cd60a73f 334 }
335 }
a1408c4b 336
337 // primary vertex & V0's
cd60a73f 338 /*
a1408c4b 339 //AliHLTVertexer vertexer;
340 //vertexer.SetESD( pESD );
341 //vertexer.FindPrimaryVertex();
342 //vertexer.FindV0s();
343 */
344 if (iAddedDataBlocks>0 && pTree) {
cd60a73f 345 pTree->Fill();
a1408c4b 346 }
347
348 if (iResult>=0) iResult=iAddedDataBlocks;
349 return iResult;
350}