]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/TPCLib/AliHLTTPCEsdWriterComponent.cxx
Changing the color of HLT tracks slightly to be distinguished from
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCEsdWriterComponent.cxx
CommitLineData
3cde846d 1// @(#) $Id$
2
c5123824 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//**************************************************************************
2a083ac4 18
3cde846d 19/** @file AliHLTTPCEsdWriterComponent.cxx
20 @author Matthias Richter
21 @date
22 @brief Writer component to store tracks of the HLT TPC conformal
23 mapping tracker in the AliESD format
c5123824 24*/
3cde846d 25
f32b83e1 26// see header file for class documentation
27// or
28// refer to README to build package
29// or
30// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
31
37513ae4 32#include <cassert>
3cde846d 33#include "AliHLTTPCEsdWriterComponent.h"
af885e0f 34#include "AliESDEvent.h"
d523f52c 35#include "AliESDtrack.h"
90c37647 36#include "AliCDBEntry.h"
37#include "AliCDBManager.h"
3cde846d 38#include "TTree.h"
62ff1e23 39#include "TList.h"
3cde846d 40#include "AliHLTTPCTrack.h"
41#include "AliHLTTPCTrackArray.h"
42#include "AliHLTTPCTrackletDataFormat.h"
43#include "AliHLTTPCDefinitions.h"
37513ae4 44#include "AliHLTTPCTransform.h"
be7c7c2b 45#include "AliHLTExternalTrackParam.h"
46#include "AliHLTKalmanTrack.h"
ae94e242 47#include "AliHLTTrackMCLabel.h"
48
deba5d85 49#include <vector>
3cde846d 50
3cde846d 51/** ROOT macro for the implementation of ROOT specific class methods */
52ClassImp(AliHLTTPCEsdWriterComponent)
53
54AliHLTTPCEsdWriterComponent::AliHLTTPCEsdWriterComponent()
90c37647 55 :
ae94e242 56 fSolenoidBz(0)
37513ae4 57{
58 // see header file for class documentation
59 // or
60 // refer to README to build package
61 // or
62 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
63}
64
65AliHLTTPCEsdWriterComponent::~AliHLTTPCEsdWriterComponent()
66{
67 // see header file for class documentation
68}
69
70AliHLTTPCEsdWriterComponent::AliWriter::AliWriter()
3cde846d 71 :
72 fTree(NULL),
37513ae4 73 fESD(NULL),
74 fBase(new AliHLTTPCEsdWriterComponent)
3cde846d 75{
2a083ac4 76 // see header file for class documentation
77 // or
78 // refer to README to build package
79 // or
80 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
3cde846d 81}
82
37513ae4 83AliHLTTPCEsdWriterComponent::AliWriter::~AliWriter()
84{
85 // see header file for class documentation
86 if (fBase) delete fBase;
87 fBase=NULL;
88}
89
90void AliHLTTPCEsdWriterComponent::AliWriter::GetInputDataTypes(AliHLTComponentDataTypeList& list)
3cde846d 91{
2a083ac4 92 // see header file for class documentation
37513ae4 93 list.push_back(AliHLTTPCDefinitions::fgkTrackSegmentsDataType);
8f471af0 94 list.push_back(AliHLTTPCDefinitions::fgkTracksDataType);
ae94e242 95 list.push_back( kAliHLTDataTypeTrack|kAliHLTDataOriginTPC );
3cde846d 96}
97
37513ae4 98int AliHLTTPCEsdWriterComponent::AliWriter::InitWriter()
3cde846d 99{
2a083ac4 100 // see header file for class documentation
3cde846d 101 int iResult=0;
af885e0f 102 fESD = new AliESDEvent;
3cde846d 103 if (fESD) {
76e61c6e 104 fESD->CreateStdContent();
3cde846d 105 fTree = new TTree("esdTree", "Tree with HLT ESD objects");
106 if (fTree) {
68f62aaa 107 fTree->SetDirectory(0);
af885e0f 108 fESD->WriteToTree(fTree);
3cde846d 109 }
3cde846d 110 }
111 if (fTree==NULL) {
112 iResult=-ENOMEM;
113 }
90c37647 114
115 if (iResult>=0) {
116 iResult=fBase->Reconfigure(NULL, NULL);
117 }
118
3cde846d 119 return iResult;
120}
121
37513ae4 122int AliHLTTPCEsdWriterComponent::AliWriter::CloseWriter()
3cde846d 123{
2a083ac4 124 // see header file for class documentation
3cde846d 125 int iResult=0;
126 if (fTree) {
62ff1e23 127 // the esd structure is written to the user info and is
128 // needed in te ReadFromTree method to read all objects correctly
129 if (fESD) fTree->GetUserInfo()->Add(fESD);
3cde846d 130 WriteObject(kAliHLTVoidEventID, fTree);
62ff1e23 131 fTree->GetUserInfo()->Clear();
3cde846d 132 TTree* pTree=fTree;
133 fTree=NULL;
134 delete pTree;
135 } else {
136 HLTWarning("not initialized");
137 }
62ff1e23 138
139 if (fESD) {
140 delete fESD;
141 }
2a083ac4 142 iResult=AliHLTRootFileWriterComponent::CloseWriter();
143 return iResult;
3cde846d 144}
145
37513ae4 146int AliHLTTPCEsdWriterComponent::AliWriter::DumpEvent( const AliHLTComponentEventData& evtData,
3cde846d 147 const AliHLTComponentBlockData* blocks,
5d2abf3b 148 AliHLTComponentTriggerData& /*trigData*/ )
3cde846d 149{
2a083ac4 150 // see header file for class documentation
3cde846d 151 int iResult=0;
152 TTree* pTree=fTree;
37513ae4 153 assert(fBase);
154 if (pTree && fBase) {
3cde846d 155 if (fESD) {
af885e0f 156 AliESDEvent* pESD=fESD;
3cde846d 157
37513ae4 158 iResult=fBase->ProcessBlocks(pTree, pESD, blocks, (int)evtData.fBlockCnt);
159
160 } else {
161 iResult=-ENOMEM;
162 }
163 }
164 return iResult;
165}
166
167int AliHLTTPCEsdWriterComponent::AliWriter::ScanArgument(int argc, const char** argv)
168{
169 // see header file for class documentation
170 int iResult=AliHLTRootFileWriterComponent::ScanArgument(argc, argv);
171 return iResult;
172}
173
174int AliHLTTPCEsdWriterComponent::ProcessBlocks(TTree* pTree, AliESDEvent* pESD,
175 const AliHLTComponentBlockData* blocks,
176 int nBlocks, int* pMinSlice,
177 int* pMaxSlice)
178{
179 // see header file for class documentation
eb30eb49 180
37513ae4 181 int iResult=0;
b94794a7 182 int iAddedDataBlocks=0;
ae94e242 183
a978c0d5 184 if (pESD && blocks) {
eb30eb49 185 pESD->Reset();
90c37647 186 pESD->SetMagneticField(fSolenoidBz);
3cde846d 187 const AliHLTComponentBlockData* iter = NULL;
de554e07 188 int bIsTrackSegs=0;
025ba4dc 189
ae94e242 190 // first read MC information (if present)
191
192 std::map<int,int> mcLabels;
193
37513ae4 194 for (int ndx=0; ndx<nBlocks && iResult>=0; ndx++) {
3cde846d 195 iter = blocks+ndx;
ae94e242 196 if(iter->fDataType == (kAliHLTDataTypeTrackMC|kAliHLTDataOriginTPC) ) {
197 AliHLTTrackMCData* dataPtr = ( AliHLTTrackMCData* )( iter->fPtr );
198 for( unsigned int il=0; il<dataPtr->fCount; il++ ){
199 AliHLTTrackMCLabel &lab = dataPtr->fLabels[il];
200 mcLabels[lab.fTrackID] = lab.fMCLabel;
27ed2b1e 201 }
deba5d85 202 }
025ba4dc 203 }
ae94e242 204
025ba4dc 205
206 // do the conversion of tracks
be7c7c2b 207
025ba4dc 208 for (int ndx=0; ndx<nBlocks && iResult>=0; ndx++) {
209 iter = blocks+ndx;
be7c7c2b 210
211 if( iter->fDataType == ( kAliHLTDataTypeTrack|kAliHLTDataOriginTPC ) ){
212 AliHLTTracksData* dataPtr = ( AliHLTTracksData* ) iter->fPtr;
213 int nTracks = dataPtr->fCount;
214 AliHLTExternalTrackParam* currOutTrack = dataPtr->fTracklets;
ae94e242 215
be7c7c2b 216 for( int itr=0; itr<nTracks; itr++ ){
217 AliHLTKalmanTrack t(*currOutTrack);
218 Float_t points[4] = {currOutTrack->fX, currOutTrack->fY, currOutTrack->fLastX, currOutTrack->fLastY };
ae94e242 219
220 Int_t mcLabel = -1;
221 if( mcLabels.find(currOutTrack->fTrackID)!=mcLabels.end() )
222 mcLabel = mcLabels[currOutTrack->fTrackID];
223
be7c7c2b 224 t.SetLabel( mcLabel );
225
226 AliESDtrack iotrack;
227 iotrack.UpdateTrackParams( &t,AliESDtrack::kTPCin);
228 iotrack.SetTPCPoints(points);
229 pESD->AddTrack(&iotrack);
230 unsigned int dSize = sizeof( AliHLTExternalTrackParam ) + currOutTrack->fNPoints * sizeof( unsigned int );
231 currOutTrack = ( AliHLTExternalTrackParam* )( (( Byte_t * )currOutTrack) + dSize );
232 }
ae94e242 233 iAddedDataBlocks++;
be7c7c2b 234 }
235
236
96bda103 237 if ( (bIsTrackSegs=(iter->fDataType == AliHLTTPCDefinitions::fgkTrackSegmentsDataType))==1 ||
238 iter->fDataType == AliHLTTPCDefinitions::fgkTracksDataType ) {
4fdaad1e 239 Int_t minslice=AliHLTTPCDefinitions::GetMinSliceNr(iter->fSpecification);
240 Int_t maxslice=AliHLTTPCDefinitions::GetMaxSliceNr(iter->fSpecification);
de554e07 241 if (bIsTrackSegs==0) {
242 // slice parameter and data specification ignored, tracks already in global coordinates
b09663cd 243 minslice=-1;
244 maxslice=-1;
37513ae4 245 if (pMinSlice) *pMinSlice=0;
246 if (pMaxSlice) *pMaxSlice=AliHLTTPCTransform::GetNSlice()-1;
247 } else {
248 if (pMinSlice && (*pMinSlice==-1 || *pMinSlice>minslice)) *pMinSlice=minslice;
249 if (pMaxSlice && (*pMaxSlice==-1 || *pMaxSlice<maxslice)) *pMaxSlice=maxslice;
de554e07 250 }
51df4d13 251 //HLTDebug("dataspec %#x minslice %d", iter->fSpecification, minslice);
37513ae4 252 if (minslice >=-1 && minslice<AliHLTTPCTransform::GetNSlice()) {
4fdaad1e 253 if (minslice!=maxslice) {
254 HLTWarning("data from multiple sectors in one block: "
c5123824 255 "possible mismatch in treatment of local coordinate system");
4fdaad1e 256 }
257 AliHLTTPCTrackArray tracks;
be7c7c2b 258 AliHLTTPCTrackletData* inPtr = (AliHLTTPCTrackletData*) iter->fPtr;
4fdaad1e 259 HLTDebug("reading block %d (slice %d): %d tracklets", ndx, minslice, inPtr->fTrackletCnt);
febeb705 260 if ((iResult=tracks.FillTracksChecked(inPtr->fTracklets, inPtr->fTrackletCnt, iter->fSize, minslice, 0/*don't rotate*/))>=0) {
be7c7c2b 261 if ((iResult=Tracks2ESD(&tracks, pESD ))>=0) {
b94794a7 262 iAddedDataBlocks++;
febeb705 263 }
3cde846d 264 }
265 } else {
4fdaad1e 266 HLTError("invalid sector number");
267 iResult=-EBADF;
3cde846d 268 }
6edb0fb5 269 }
270 }
271
51df4d13 272 if (iAddedDataBlocks>0 && pTree) {
4fdaad1e 273 pTree->Fill();
274 }
6edb0fb5 275
37513ae4 276 } else {
277 iResult=-EINVAL;
3cde846d 278 }
b94794a7 279 if (iResult>=0) iResult=iAddedDataBlocks;
3cde846d 280 return iResult;
281}
282
be7c7c2b 283
284int AliHLTTPCEsdWriterComponent::Tracks2ESD(AliHLTTPCTrackArray* pTracks, AliESDEvent* pESD )
3cde846d 285{
2a083ac4 286 // see header file for class documentation
3cde846d 287 int iResult=0;
6edb0fb5 288
eb30eb49 289 if (pTracks && pESD) {
deba5d85 290
3cde846d 291 for (int i=0; i<pTracks->GetNTracks() && iResult>=0; i++) {
292 AliHLTTPCTrack* pTrack=(*pTracks)[i];
293 if (pTrack) {
27ed2b1e 294
deba5d85 295 if( pTrack->Convert2AliKalmanTrack() ){
296 HLTError("conversion to AliKalmanTrack failed for track %d of %d", i, pTracks->GetNTracks());
297 continue;
298 }
eb30eb49 299
deba5d85 300 Float_t points[4] = {pTrack->GetFirstPointX(), pTrack->GetFirstPointY(), pTrack->GetLastPointX(), pTrack->GetLastPointY() };
eb30eb49 301
302 if(pTrack->GetSector() == -1){ // Set first and last points for global tracks
303 Double_t s = TMath::Sin( pTrack->GetAlpha() );
304 Double_t c = TMath::Cos( pTrack->GetAlpha() );
305 points[0] = pTrack->GetFirstPointX()*c + pTrack->GetFirstPointY()*s;
306 points[1] = -pTrack->GetFirstPointX()*s + pTrack->GetFirstPointY()*c;
307 points[2] = pTrack->GetLastPointX() *c + pTrack->GetLastPointY() *s;
308 points[3] = -pTrack->GetLastPointX() *s + pTrack->GetLastPointY() *c;
309 }
deba5d85 310
7467680a 311 AliESDtrack iotrack;
312 iotrack.UpdateTrackParams(pTrack,AliESDtrack::kTPCin);
313 iotrack.SetTPCPoints(points);
deba5d85 314
27ed2b1e 315 pESD->AddTrack(&iotrack);
3cde846d 316 } else {
c5123824 317 HLTError("internal mismatch in array");
3cde846d 318 iResult=-EFAULT;
319 }
320 }
321
322 } else {
323 iResult=-EINVAL;
324 }
325 return iResult;
326}
37513ae4 327
90c37647 328int AliHLTTPCEsdWriterComponent::Configure(const char* arguments)
329{
330 // see header file for class documentation
331 int iResult=0;
332 if (!arguments) return iResult;
333
334 TString allArgs=arguments;
335 TString argument;
336 int bMissingParam=0;
337
338 TObjArray* pTokens=allArgs.Tokenize(" ");
339 if (pTokens) {
340 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
341 argument=((TObjString*)pTokens->At(i))->GetString();
342 if (argument.IsNull()) continue;
343
344 if (argument.CompareTo("-solenoidBz")==0) {
345 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
346 HLTInfo("Magnetic Field set to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
347 fSolenoidBz=((TObjString*)pTokens->At(i))->GetString().Atof();
348 continue;
349 } else {
350 HLTError("unknown argument %s", argument.Data());
351 iResult=-EINVAL;
352 break;
353 }
354 }
355 delete pTokens;
356 }
357 if (bMissingParam) {
358 HLTError("missing parameter for argument %s", argument.Data());
359 iResult=-EINVAL;
360 }
361
362 return iResult;
363}
364
365int AliHLTTPCEsdWriterComponent::Reconfigure(const char* cdbEntry, const char* chainId)
366{
367 // see header file for class documentation
368 int iResult=0;
1ac82ce6 369 const char* path=kAliHLTCDBSolenoidBz;
90c37647 370 const char* defaultNotify="";
371 if (cdbEntry) {
372 path=cdbEntry;
373 defaultNotify=" (default)";
374 }
375 if (path) {
376 HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
377 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
378 if (pEntry) {
379 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
380 if (pString) {
381 HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
382 iResult=Configure(pString->GetString().Data());
383 } else {
384 HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
385 }
386 } else {
387 HLTError("can not fetch object \"%s\" from CDB", path);
388 }
389 }
390
391 return iResult;
392}
393
37513ae4 394AliHLTTPCEsdWriterComponent::AliConverter::AliConverter()
395 :
0f836349 396 fESD(NULL),
a978c0d5 397 fBase(new AliHLTTPCEsdWriterComponent),
51df4d13 398 fWriteTree(0)
37513ae4 399{
400 // see header file for class documentation
401 // or
402 // refer to README to build package
403 // or
51df4d13 404 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
405}
37513ae4 406
407AliHLTTPCEsdWriterComponent::AliConverter::~AliConverter()
408{
409 // see header file for class documentation
410 if (fBase) delete fBase;
411 fBase=NULL;
0f836349 412
413 if (fESD) delete fESD;
414 fESD=NULL;
37513ae4 415}
416
417void AliHLTTPCEsdWriterComponent::AliConverter::GetInputDataTypes(AliHLTComponentDataTypeList& list)
418{
419 // see header file for class documentation
420 list.push_back(AliHLTTPCDefinitions::fgkTrackSegmentsDataType);
8f471af0 421 list.push_back(AliHLTTPCDefinitions::fgkTracksDataType);
37513ae4 422}
423
424AliHLTComponentDataType AliHLTTPCEsdWriterComponent::AliConverter::GetOutputDataType()
425{
426 // see header file for class documentation
427 return kAliHLTDataTypeESDTree;
428}
429
430void AliHLTTPCEsdWriterComponent::AliConverter::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
431{
432 // see header file for class documentation
62ff1e23 433 constBase=2000000;
434 inputMultiplier=10.0;
37513ae4 435}
436
437int AliHLTTPCEsdWriterComponent::AliConverter::DoInit(int argc, const char** argv)
438{
439 // see header file for class documentation
a978c0d5 440 int iResult=0;
441 TString argument="";
442 int bMissingParam=0;
443 for (int i=0; i<argc && iResult>=0; i++) {
444 argument=argv[i];
445 if (argument.IsNull()) continue;
446
447 // -notree
448 if (argument.CompareTo("-notree")==0) {
449 fWriteTree=0;
450
451 // -tree
452 } else if (argument.CompareTo("-tree")==0) {
453 fWriteTree=1;
454
51df4d13 455 // -solenoidBz
456 } else if (argument.CompareTo("-solenoidBz")==0) {
eb30eb49 457 TString tmp="-solenoidBz ";
458 tmp+=argv[++i];
459 fBase->Configure(tmp.Data());
51df4d13 460 } else {
a978c0d5 461 HLTError("unknown argument %s", argument.Data());
462 break;
463 }
464 }
465 if (bMissingParam) {
466 HLTError("missing parameter for argument %s", argument.Data());
467 iResult=-EINVAL;
468 }
469
90c37647 470 if (iResult>=0) {
471 iResult=fBase->Reconfigure(NULL, NULL);
51df4d13 472 }
90c37647 473
a978c0d5 474 return iResult;
37513ae4 475}
476
477int AliHLTTPCEsdWriterComponent::AliConverter::DoDeinit()
478{
479 // see header file for class documentation
480 return 0;
481}
482
483int AliHLTTPCEsdWriterComponent::AliConverter::DoEvent(const AliHLTComponentEventData& evtData,
484 const AliHLTComponentBlockData* blocks,
485 AliHLTComponentTriggerData& /*trigData*/,
486 AliHLTUInt8_t* /*outputPtr*/,
53f79557 487 AliHLTUInt32_t& size,
37513ae4 488 AliHLTComponentBlockDataList& /*outputBlocks*/ )
51df4d13 489{
37513ae4 490 // see header file for class documentation
491 int iResult=0;
53f79557 492 // no direct writing to the output buffer
493 size=0;
494
37513ae4 495 assert(fBase);
0f836349 496 if (!fESD) {
497 fESD = new AliESDEvent;
498 if (fESD) {
499 fESD->CreateStdContent();
500 } else {
501 iResult=-ENOMEM;
502 }
503 }
504
505 AliESDEvent* pESD = fESD;
eb30eb49 506
37513ae4 507 if (pESD && fBase) {
eb30eb49 508
a978c0d5 509 TTree* pTree = NULL;
510 // TODO: Matthias 06.12.2007
511 // Tried to write the ESD directly instead to a tree, but this did not work
512 // out. Information in the ESD is different, needs investigation.
eb30eb49 513
a978c0d5 514 if (fWriteTree)
515 pTree = new TTree("esdTree", "Tree with HLT ESD objects");
eb30eb49 516
37513ae4 517 if (pTree) {
68f62aaa 518 pTree->SetDirectory(0);
a978c0d5 519 }
37513ae4 520
b94794a7 521 if ((iResult=fBase->ProcessBlocks(pTree, pESD, blocks, (int)evtData.fBlockCnt))>0) {
eb30eb49 522 // TODO: set the specification correctly
62ff1e23 523 if (pTree) {
524 // the esd structure is written to the user info and is
525 // needed in te ReadFromTree method to read all objects correctly
526 pTree->GetUserInfo()->Add(pESD);
10c15f49 527 pESD->WriteToTree(pTree);
37513ae4 528 iResult=PushBack(pTree, kAliHLTDataTypeESDTree|kAliHLTDataOriginTPC, 0);
62ff1e23 529 } else {
a978c0d5 530 iResult=PushBack(pESD, kAliHLTDataTypeESDObject|kAliHLTDataOriginTPC, 0);
62ff1e23 531 }
37513ae4 532 }
62ff1e23 533 if (pTree) {
534 // clear user info list to prevent objects from being deleted
535 pTree->GetUserInfo()->Clear();
a978c0d5 536 delete pTree;
62ff1e23 537 }
37513ae4 538 }
539 return iResult;
540}
541