3cde846d |
1 | // @(#) $Id$ |
2 | |
2a083ac4 |
3 | /************************************************************************** |
9be2600f |
4 | * This file is property of and copyright by the ALICE HLT Project * |
5 | * ALICE Experiment at CERN, All rights reserved. * |
2a083ac4 |
6 | * * |
9be2600f |
7 | * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> * |
8 | * for The ALICE HLT Project. * |
2a083ac4 |
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 | |
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 |
24 | |
25 | */ |
26 | #include "AliHLTTPCEsdWriterComponent.h" |
af885e0f |
27 | #include "AliESDEvent.h" |
d523f52c |
28 | #include "AliESDtrack.h" |
3cde846d |
29 | #include "TTree.h" |
30 | #include "AliHLTTPCTrack.h" |
31 | #include "AliHLTTPCTrackArray.h" |
32 | #include "AliHLTTPCTrackletDataFormat.h" |
33 | #include "AliHLTTPCDefinitions.h" |
34 | |
35 | /** global instance for component registration */ |
36 | AliHLTTPCEsdWriterComponent gTPCEsdWriter; |
37 | |
38 | /** ROOT macro for the implementation of ROOT specific class methods */ |
39 | ClassImp(AliHLTTPCEsdWriterComponent) |
40 | |
41 | AliHLTTPCEsdWriterComponent::AliHLTTPCEsdWriterComponent() |
42 | : |
43 | fTree(NULL), |
44 | fESD(NULL) |
45 | { |
2a083ac4 |
46 | // see header file for class documentation |
47 | // or |
48 | // refer to README to build package |
49 | // or |
50 | // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt |
3cde846d |
51 | } |
52 | |
53 | AliHLTTPCEsdWriterComponent::~AliHLTTPCEsdWriterComponent() |
54 | { |
2a083ac4 |
55 | // see header file for class documentation |
3cde846d |
56 | } |
57 | |
58 | int AliHLTTPCEsdWriterComponent::InitWriter() |
59 | { |
2a083ac4 |
60 | // see header file for class documentation |
3cde846d |
61 | int iResult=0; |
af885e0f |
62 | fESD = new AliESDEvent; |
3cde846d |
63 | if (fESD) { |
76e61c6e |
64 | fESD->CreateStdContent(); |
3cde846d |
65 | fTree = new TTree("esdTree", "Tree with HLT ESD objects"); |
66 | if (fTree) { |
af885e0f |
67 | fESD->WriteToTree(fTree); |
3cde846d |
68 | } |
3cde846d |
69 | } |
70 | if (fTree==NULL) { |
71 | iResult=-ENOMEM; |
72 | } |
73 | return iResult; |
74 | } |
75 | |
76 | int AliHLTTPCEsdWriterComponent::CloseWriter() |
77 | { |
2a083ac4 |
78 | // see header file for class documentation |
3cde846d |
79 | int iResult=0; |
80 | if (fTree) { |
81 | WriteObject(kAliHLTVoidEventID, fTree); |
82 | TTree* pTree=fTree; |
83 | fTree=NULL; |
84 | delete pTree; |
85 | } else { |
86 | HLTWarning("not initialized"); |
87 | } |
2a083ac4 |
88 | iResult=AliHLTRootFileWriterComponent::CloseWriter(); |
89 | return iResult; |
3cde846d |
90 | } |
91 | |
92 | int AliHLTTPCEsdWriterComponent::DumpEvent( const AliHLTComponentEventData& evtData, |
93 | const AliHLTComponentBlockData* blocks, |
5d2abf3b |
94 | AliHLTComponentTriggerData& /*trigData*/ ) |
3cde846d |
95 | { |
2a083ac4 |
96 | // see header file for class documentation |
3cde846d |
97 | int iResult=0; |
98 | TTree* pTree=fTree; |
99 | if (pTree) { |
3cde846d |
100 | if (fESD) { |
af885e0f |
101 | AliESDEvent* pESD=fESD; |
3cde846d |
102 | |
103 | const AliHLTComponentBlockData* iter = NULL; |
3cde846d |
104 | AliHLTTPCTrackletData* inPtr=NULL; |
de554e07 |
105 | int bIsTrackSegs=0; |
3cde846d |
106 | |
2a083ac4 |
107 | for (int ndx=0; ndx<(int)evtData.fBlockCnt && iResult>=0; ndx++) { |
3cde846d |
108 | iter = blocks+ndx; |
96bda103 |
109 | if ( (bIsTrackSegs=(iter->fDataType == AliHLTTPCDefinitions::fgkTrackSegmentsDataType))==1 || |
110 | iter->fDataType == AliHLTTPCDefinitions::fgkTracksDataType ) { |
4fdaad1e |
111 | Int_t minslice=AliHLTTPCDefinitions::GetMinSliceNr(iter->fSpecification); |
112 | Int_t maxslice=AliHLTTPCDefinitions::GetMaxSliceNr(iter->fSpecification); |
de554e07 |
113 | if (bIsTrackSegs==0) { |
114 | // slice parameter and data specification ignored, tracks already in global coordinates |
b09663cd |
115 | minslice=-1; |
116 | maxslice=-1; |
de554e07 |
117 | } |
4fdaad1e |
118 | //HLTDebug("dataspec %#x minslice %d", iter->fSpecification, minslice); |
b09663cd |
119 | if (minslice >=-1 && minslice<36) { |
4fdaad1e |
120 | if (minslice!=maxslice) { |
121 | HLTWarning("data from multiple sectors in one block: " |
122 | "possible missmatch in treatment of local coordinate system"); |
123 | } |
124 | AliHLTTPCTrackArray tracks; |
125 | inPtr=(AliHLTTPCTrackletData*)iter->fPtr; |
126 | HLTDebug("reading block %d (slice %d): %d tracklets", ndx, minslice, inPtr->fTrackletCnt); |
127 | tracks.FillTracks(inPtr->fTrackletCnt, inPtr->fTracklets, minslice, 0/*don't rotate*/); |
128 | if ((iResult=Tracks2ESD(&tracks, pESD))>=0) { |
3cde846d |
129 | } |
130 | } else { |
4fdaad1e |
131 | HLTError("invalid sector number"); |
132 | iResult=-EBADF; |
3cde846d |
133 | } |
134 | } |
135 | } |
4fdaad1e |
136 | if (iResult>=0) { |
137 | pTree->Fill(); |
138 | } |
3cde846d |
139 | |
af885e0f |
140 | fESD->Reset(); |
3cde846d |
141 | } else { |
142 | iResult=-ENOMEM; |
143 | } |
144 | } |
145 | return iResult; |
146 | } |
147 | |
148 | int AliHLTTPCEsdWriterComponent::ScanArgument(int argc, const char** argv) |
149 | { |
2a083ac4 |
150 | // see header file for class documentation |
3cde846d |
151 | int iResult=AliHLTRootFileWriterComponent::ScanArgument(argc, argv); |
152 | return iResult; |
153 | } |
154 | |
af885e0f |
155 | int AliHLTTPCEsdWriterComponent::Tracks2ESD(AliHLTTPCTrackArray* pTracks, AliESDEvent* pESD) |
3cde846d |
156 | { |
2a083ac4 |
157 | // see header file for class documentation |
3cde846d |
158 | int iResult=0; |
159 | if (pTracks && pESD) { |
160 | HLTDebug("converting %d tracks from track array", pTracks->GetNTracks()); |
161 | for (int i=0; i<pTracks->GetNTracks() && iResult>=0; i++) { |
162 | AliHLTTPCTrack* pTrack=(*pTracks)[i]; |
163 | if (pTrack) { |
04dbc9e4 |
164 | //HLTDebug("convert track %d", i); |
165 | //pTrack->Print(); |
3cde846d |
166 | int iLocal=pTrack->Convert2AliKalmanTrack(); |
167 | if (iLocal>=0) { |
168 | AliESDtrack iotrack; |
169 | iotrack.UpdateTrackParams(pTrack,AliESDtrack::kTPCin); |
170 | iotrack.SetTPCPoints(pTrack->GetPoints()); |
171 | pESD->AddTrack(&iotrack); |
172 | } else { |
173 | HLTError("conversion to AliKalmanTrack failed for track %d of %d", i, pTracks->GetNTracks()); |
174 | } |
175 | } else { |
176 | HLTError("internal missmatch in array"); |
177 | iResult=-EFAULT; |
178 | } |
179 | } |
180 | |
181 | } else { |
182 | iResult=-EINVAL; |
183 | } |
184 | return iResult; |
185 | } |