ChangeLog and version no updated
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCEsdWriterComponent.cxx
CommitLineData
3cde846d 1// @(#) $Id$
2
3/** @file AliHLTTPCEsdWriterComponent.cxx
4 @author Matthias Richter
5 @date
6 @brief Writer component to store tracks of the HLT TPC conformal
7 mapping tracker in the AliESD format
8
9 */
10#include "AliHLTTPCEsdWriterComponent.h"
11#include "AliESD.h"
12#include "TTree.h"
13#include "AliHLTTPCTrack.h"
14#include "AliHLTTPCTrackArray.h"
15#include "AliHLTTPCTrackletDataFormat.h"
16#include "AliHLTTPCDefinitions.h"
17
18/** global instance for component registration */
19AliHLTTPCEsdWriterComponent gTPCEsdWriter;
20
21/** ROOT macro for the implementation of ROOT specific class methods */
22ClassImp(AliHLTTPCEsdWriterComponent)
23
24AliHLTTPCEsdWriterComponent::AliHLTTPCEsdWriterComponent()
25 :
26 fTree(NULL),
27 fESD(NULL)
28{
29}
30
31AliHLTTPCEsdWriterComponent::~AliHLTTPCEsdWriterComponent()
32{
33}
34
35int AliHLTTPCEsdWriterComponent::InitWriter()
36{
37 int iResult=0;
38 fESD = new AliESD;
39 if (fESD) {
40 fTree = new TTree("esdTree", "Tree with HLT ESD objects");
41 if (fTree) {
42 fTree->Branch("ESD", "AliESD", &fESD);
43 }
44 delete fESD;
45 fESD=NULL;
46 }
47 if (fTree==NULL) {
48 iResult=-ENOMEM;
49 }
50 return iResult;
51}
52
53int AliHLTTPCEsdWriterComponent::CloseWriter()
54{
55 int iResult=0;
56 if (fTree) {
57 WriteObject(kAliHLTVoidEventID, fTree);
58 TTree* pTree=fTree;
59 fTree=NULL;
60 delete pTree;
61 } else {
62 HLTWarning("not initialized");
63 }
64 AliHLTRootFileWriterComponent::CloseWriter();
65}
66
67int AliHLTTPCEsdWriterComponent::DumpEvent( const AliHLTComponentEventData& evtData,
68 const AliHLTComponentBlockData* blocks,
69 AliHLTComponentTriggerData& trigData )
70{
71 int iResult=0;
72 TTree* pTree=fTree;
73 if (pTree) {
74 fESD = new AliESD;
75 if (fESD) {
76 AliESD* pESD=fESD;
77
78 const AliHLTComponentBlockData* iter = NULL;
3cde846d 79 AliHLTTPCTrackletData* inPtr=NULL;
80
81 for (int ndx=0; ndx<evtData.fBlockCnt && iResult>=0; ndx++) {
82 iter = blocks+ndx;
83 if ( iter->fDataType == AliHLTTPCDefinitions::gkTrackSegmentsDataType ) {
4fdaad1e 84 Int_t minslice=AliHLTTPCDefinitions::GetMinSliceNr(iter->fSpecification);
85 Int_t maxslice=AliHLTTPCDefinitions::GetMaxSliceNr(iter->fSpecification);
86 //HLTDebug("dataspec %#x minslice %d", iter->fSpecification, minslice);
87 if (minslice >=0 && minslice<36) {
88 if (minslice!=maxslice) {
89 HLTWarning("data from multiple sectors in one block: "
90 "possible missmatch in treatment of local coordinate system");
91 }
92 AliHLTTPCTrackArray tracks;
93 inPtr=(AliHLTTPCTrackletData*)iter->fPtr;
94 HLTDebug("reading block %d (slice %d): %d tracklets", ndx, minslice, inPtr->fTrackletCnt);
95 tracks.FillTracks(inPtr->fTrackletCnt, inPtr->fTracklets, minslice, 0/*don't rotate*/);
96 if ((iResult=Tracks2ESD(&tracks, pESD))>=0) {
3cde846d 97 }
98 } else {
4fdaad1e 99 HLTError("invalid sector number");
100 iResult=-EBADF;
3cde846d 101 }
102 }
103 }
4fdaad1e 104 if (iResult>=0) {
105 pTree->Fill();
106 }
3cde846d 107
108 fESD=NULL;
109 delete pESD;
110 } else {
111 iResult=-ENOMEM;
112 }
113 }
114 return iResult;
115}
116
117int AliHLTTPCEsdWriterComponent::ScanArgument(int argc, const char** argv)
118{
119 int iResult=AliHLTRootFileWriterComponent::ScanArgument(argc, argv);
120 return iResult;
121}
122
123int AliHLTTPCEsdWriterComponent::Tracks2ESD(AliHLTTPCTrackArray* pTracks, AliESD* pESD)
124{
125 int iResult=0;
126 if (pTracks && pESD) {
127 HLTDebug("converting %d tracks from track array", pTracks->GetNTracks());
128 for (int i=0; i<pTracks->GetNTracks() && iResult>=0; i++) {
129 AliHLTTPCTrack* pTrack=(*pTracks)[i];
130 if (pTrack) {
04dbc9e4 131 //HLTDebug("convert track %d", i);
132 //pTrack->Print();
3cde846d 133 int iLocal=pTrack->Convert2AliKalmanTrack();
134 if (iLocal>=0) {
135 AliESDtrack iotrack;
136 iotrack.UpdateTrackParams(pTrack,AliESDtrack::kTPCin);
137 iotrack.SetTPCPoints(pTrack->GetPoints());
138 pESD->AddTrack(&iotrack);
139 } else {
140 HLTError("conversion to AliKalmanTrack failed for track %d of %d", i, pTracks->GetNTracks());
141 }
142 } else {
143 HLTError("internal missmatch in array");
144 iResult=-EFAULT;
145 }
146 }
147
148 } else {
149 iResult=-EINVAL;
150 }
151 return iResult;
152}