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