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