AliTPCCalROC derives form TNamed (Marian, Lars)
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCEsdWriterComponent.cxx
CommitLineData
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 */
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"
3cde846d 36#include "TTree.h"
37#include "AliHLTTPCTrack.h"
38#include "AliHLTTPCTrackArray.h"
39#include "AliHLTTPCTrackletDataFormat.h"
40#include "AliHLTTPCDefinitions.h"
37513ae4 41#include "AliHLTTPCTransform.h"
3cde846d 42
3cde846d 43/** ROOT macro for the implementation of ROOT specific class methods */
44ClassImp(AliHLTTPCEsdWriterComponent)
45
46AliHLTTPCEsdWriterComponent::AliHLTTPCEsdWriterComponent()
37513ae4 47{
48 // see header file for class documentation
49 // or
50 // refer to README to build package
51 // or
52 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
53}
54
55AliHLTTPCEsdWriterComponent::~AliHLTTPCEsdWriterComponent()
56{
57 // see header file for class documentation
58}
59
60AliHLTTPCEsdWriterComponent::AliWriter::AliWriter()
3cde846d 61 :
62 fTree(NULL),
37513ae4 63 fESD(NULL),
64 fBase(new AliHLTTPCEsdWriterComponent)
3cde846d 65{
2a083ac4 66 // see header file for class documentation
67 // or
68 // refer to README to build package
69 // or
70 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
3cde846d 71}
72
37513ae4 73AliHLTTPCEsdWriterComponent::AliWriter::~AliWriter()
74{
75 // see header file for class documentation
76 if (fBase) delete fBase;
77 fBase=NULL;
78}
79
80void AliHLTTPCEsdWriterComponent::AliWriter::GetInputDataTypes(AliHLTComponentDataTypeList& list)
3cde846d 81{
2a083ac4 82 // see header file for class documentation
37513ae4 83 list.push_back(AliHLTTPCDefinitions::fgkTrackSegmentsDataType);
3cde846d 84}
85
37513ae4 86int AliHLTTPCEsdWriterComponent::AliWriter::InitWriter()
3cde846d 87{
2a083ac4 88 // see header file for class documentation
3cde846d 89 int iResult=0;
af885e0f 90 fESD = new AliESDEvent;
3cde846d 91 if (fESD) {
76e61c6e 92 fESD->CreateStdContent();
3cde846d 93 fTree = new TTree("esdTree", "Tree with HLT ESD objects");
94 if (fTree) {
af885e0f 95 fESD->WriteToTree(fTree);
3cde846d 96 }
3cde846d 97 }
98 if (fTree==NULL) {
99 iResult=-ENOMEM;
100 }
101 return iResult;
102}
103
37513ae4 104int AliHLTTPCEsdWriterComponent::AliWriter::CloseWriter()
3cde846d 105{
2a083ac4 106 // see header file for class documentation
3cde846d 107 int iResult=0;
108 if (fTree) {
109 WriteObject(kAliHLTVoidEventID, fTree);
110 TTree* pTree=fTree;
111 fTree=NULL;
112 delete pTree;
113 } else {
114 HLTWarning("not initialized");
115 }
2a083ac4 116 iResult=AliHLTRootFileWriterComponent::CloseWriter();
117 return iResult;
3cde846d 118}
119
37513ae4 120int AliHLTTPCEsdWriterComponent::AliWriter::DumpEvent( const AliHLTComponentEventData& evtData,
3cde846d 121 const AliHLTComponentBlockData* blocks,
5d2abf3b 122 AliHLTComponentTriggerData& /*trigData*/ )
3cde846d 123{
2a083ac4 124 // see header file for class documentation
3cde846d 125 int iResult=0;
126 TTree* pTree=fTree;
37513ae4 127 assert(fBase);
128 if (pTree && fBase) {
3cde846d 129 if (fESD) {
af885e0f 130 AliESDEvent* pESD=fESD;
3cde846d 131
37513ae4 132 iResult=fBase->ProcessBlocks(pTree, pESD, blocks, (int)evtData.fBlockCnt);
133
134 } else {
135 iResult=-ENOMEM;
136 }
137 }
138 return iResult;
139}
140
141int AliHLTTPCEsdWriterComponent::AliWriter::ScanArgument(int argc, const char** argv)
142{
143 // see header file for class documentation
144 int iResult=AliHLTRootFileWriterComponent::ScanArgument(argc, argv);
145 return iResult;
146}
147
148int AliHLTTPCEsdWriterComponent::ProcessBlocks(TTree* pTree, AliESDEvent* pESD,
149 const AliHLTComponentBlockData* blocks,
150 int nBlocks, int* pMinSlice,
151 int* pMaxSlice)
152{
153 // see header file for class documentation
154 int iResult=0;
155 if (pTree && pESD && blocks) {
3cde846d 156 const AliHLTComponentBlockData* iter = NULL;
3cde846d 157 AliHLTTPCTrackletData* inPtr=NULL;
de554e07 158 int bIsTrackSegs=0;
3cde846d 159
37513ae4 160 for (int ndx=0; ndx<nBlocks && iResult>=0; ndx++) {
3cde846d 161 iter = blocks+ndx;
96bda103 162 if ( (bIsTrackSegs=(iter->fDataType == AliHLTTPCDefinitions::fgkTrackSegmentsDataType))==1 ||
163 iter->fDataType == AliHLTTPCDefinitions::fgkTracksDataType ) {
4fdaad1e 164 Int_t minslice=AliHLTTPCDefinitions::GetMinSliceNr(iter->fSpecification);
165 Int_t maxslice=AliHLTTPCDefinitions::GetMaxSliceNr(iter->fSpecification);
de554e07 166 if (bIsTrackSegs==0) {
167 // slice parameter and data specification ignored, tracks already in global coordinates
b09663cd 168 minslice=-1;
169 maxslice=-1;
37513ae4 170 if (pMinSlice) *pMinSlice=0;
171 if (pMaxSlice) *pMaxSlice=AliHLTTPCTransform::GetNSlice()-1;
172 } else {
173 if (pMinSlice && (*pMinSlice==-1 || *pMinSlice>minslice)) *pMinSlice=minslice;
174 if (pMaxSlice && (*pMaxSlice==-1 || *pMaxSlice<maxslice)) *pMaxSlice=maxslice;
de554e07 175 }
4fdaad1e 176 //HLTDebug("dataspec %#x minslice %d", iter->fSpecification, minslice);
37513ae4 177 if (minslice >=-1 && minslice<AliHLTTPCTransform::GetNSlice()) {
4fdaad1e 178 if (minslice!=maxslice) {
179 HLTWarning("data from multiple sectors in one block: "
180 "possible missmatch in treatment of local coordinate system");
181 }
182 AliHLTTPCTrackArray tracks;
183 inPtr=(AliHLTTPCTrackletData*)iter->fPtr;
184 HLTDebug("reading block %d (slice %d): %d tracklets", ndx, minslice, inPtr->fTrackletCnt);
185 tracks.FillTracks(inPtr->fTrackletCnt, inPtr->fTracklets, minslice, 0/*don't rotate*/);
186 if ((iResult=Tracks2ESD(&tracks, pESD))>=0) {
3cde846d 187 }
188 } else {
4fdaad1e 189 HLTError("invalid sector number");
190 iResult=-EBADF;
3cde846d 191 }
192 }
193 }
4fdaad1e 194 if (iResult>=0) {
195 pTree->Fill();
196 }
3cde846d 197
37513ae4 198 pESD->Reset();
199
200 } else {
201 iResult=-EINVAL;
3cde846d 202 }
203 return iResult;
204}
205
af885e0f 206int AliHLTTPCEsdWriterComponent::Tracks2ESD(AliHLTTPCTrackArray* pTracks, AliESDEvent* pESD)
3cde846d 207{
2a083ac4 208 // see header file for class documentation
3cde846d 209 int iResult=0;
210 if (pTracks && pESD) {
211 HLTDebug("converting %d tracks from track array", pTracks->GetNTracks());
212 for (int i=0; i<pTracks->GetNTracks() && iResult>=0; i++) {
213 AliHLTTPCTrack* pTrack=(*pTracks)[i];
214 if (pTrack) {
04dbc9e4 215 //HLTDebug("convert track %d", i);
216 //pTrack->Print();
3cde846d 217 int iLocal=pTrack->Convert2AliKalmanTrack();
218 if (iLocal>=0) {
219 AliESDtrack iotrack;
220 iotrack.UpdateTrackParams(pTrack,AliESDtrack::kTPCin);
221 iotrack.SetTPCPoints(pTrack->GetPoints());
222 pESD->AddTrack(&iotrack);
223 } else {
224 HLTError("conversion to AliKalmanTrack failed for track %d of %d", i, pTracks->GetNTracks());
225 }
226 } else {
227 HLTError("internal missmatch in array");
228 iResult=-EFAULT;
229 }
230 }
231
232 } else {
233 iResult=-EINVAL;
234 }
235 return iResult;
236}
37513ae4 237
238AliHLTTPCEsdWriterComponent::AliConverter::AliConverter()
239 :
240 fBase(new AliHLTTPCEsdWriterComponent)
241{
242 // see header file for class documentation
243 // or
244 // refer to README to build package
245 // or
246 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
247}
248
249AliHLTTPCEsdWriterComponent::AliConverter::~AliConverter()
250{
251 // see header file for class documentation
252 if (fBase) delete fBase;
253 fBase=NULL;
254}
255
256void AliHLTTPCEsdWriterComponent::AliConverter::GetInputDataTypes(AliHLTComponentDataTypeList& list)
257{
258 // see header file for class documentation
259 list.push_back(AliHLTTPCDefinitions::fgkTrackSegmentsDataType);
260}
261
262AliHLTComponentDataType AliHLTTPCEsdWriterComponent::AliConverter::GetOutputDataType()
263{
264 // see header file for class documentation
265 return kAliHLTDataTypeESDTree;
266}
267
268void AliHLTTPCEsdWriterComponent::AliConverter::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
269{
270 // see header file for class documentation
271 constBase=1000000;
272 inputMultiplier=1.0;
273}
274
275int AliHLTTPCEsdWriterComponent::AliConverter::DoInit(int argc, const char** argv)
276{
277 // see header file for class documentation
278 return 0;
279}
280
281int AliHLTTPCEsdWriterComponent::AliConverter::DoDeinit()
282{
283 // see header file for class documentation
284 return 0;
285}
286
287int AliHLTTPCEsdWriterComponent::AliConverter::DoEvent(const AliHLTComponentEventData& evtData,
288 const AliHLTComponentBlockData* blocks,
289 AliHLTComponentTriggerData& /*trigData*/,
290 AliHLTUInt8_t* /*outputPtr*/,
291 AliHLTUInt32_t& /*size*/,
292 AliHLTComponentBlockDataList& /*outputBlocks*/ )
293{
294 // see header file for class documentation
295 int iResult=0;
296 assert(fBase);
297 AliESDEvent* pESD = new AliESDEvent;
298 if (pESD && fBase) {
299 pESD->CreateStdContent();
300 TTree* pTree = new TTree("esdTree", "Tree with HLT ESD objects");
301 if (pTree) {
302 pESD->WriteToTree(pTree);
303
304 if ((iResult=fBase->ProcessBlocks(pTree, pESD, blocks, (int)evtData.fBlockCnt))>=0) {
305 // TODO: set the specification correctly
306 iResult=PushBack(pTree, kAliHLTDataTypeESDTree|kAliHLTDataOriginTPC, 0);
307 }
308 delete pTree;
309 }
310 delete pESD;
311 }
312 return iResult;
313}
314