minor changes in code documentation
[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"
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);
8f471af0 84 list.push_back(AliHLTTPCDefinitions::fgkTracksDataType);
3cde846d 85}
86
37513ae4 87int AliHLTTPCEsdWriterComponent::AliWriter::InitWriter()
3cde846d 88{
2a083ac4 89 // see header file for class documentation
3cde846d 90 int iResult=0;
af885e0f 91 fESD = new AliESDEvent;
3cde846d 92 if (fESD) {
76e61c6e 93 fESD->CreateStdContent();
3cde846d 94 fTree = new TTree("esdTree", "Tree with HLT ESD objects");
95 if (fTree) {
68f62aaa 96 fTree->SetDirectory(0);
af885e0f 97 fESD->WriteToTree(fTree);
3cde846d 98 }
3cde846d 99 }
100 if (fTree==NULL) {
101 iResult=-ENOMEM;
102 }
103 return iResult;
104}
105
37513ae4 106int AliHLTTPCEsdWriterComponent::AliWriter::CloseWriter()
3cde846d 107{
2a083ac4 108 // see header file for class documentation
3cde846d 109 int iResult=0;
110 if (fTree) {
111 WriteObject(kAliHLTVoidEventID, fTree);
112 TTree* pTree=fTree;
113 fTree=NULL;
114 delete pTree;
115 } else {
116 HLTWarning("not initialized");
117 }
2a083ac4 118 iResult=AliHLTRootFileWriterComponent::CloseWriter();
119 return iResult;
3cde846d 120}
121
37513ae4 122int AliHLTTPCEsdWriterComponent::AliWriter::DumpEvent( const AliHLTComponentEventData& evtData,
3cde846d 123 const AliHLTComponentBlockData* blocks,
5d2abf3b 124 AliHLTComponentTriggerData& /*trigData*/ )
3cde846d 125{
2a083ac4 126 // see header file for class documentation
3cde846d 127 int iResult=0;
128 TTree* pTree=fTree;
37513ae4 129 assert(fBase);
130 if (pTree && fBase) {
3cde846d 131 if (fESD) {
af885e0f 132 AliESDEvent* pESD=fESD;
3cde846d 133
37513ae4 134 iResult=fBase->ProcessBlocks(pTree, pESD, blocks, (int)evtData.fBlockCnt);
135
136 } else {
137 iResult=-ENOMEM;
138 }
139 }
140 return iResult;
141}
142
143int AliHLTTPCEsdWriterComponent::AliWriter::ScanArgument(int argc, const char** argv)
144{
145 // see header file for class documentation
146 int iResult=AliHLTRootFileWriterComponent::ScanArgument(argc, argv);
147 return iResult;
148}
149
150int AliHLTTPCEsdWriterComponent::ProcessBlocks(TTree* pTree, AliESDEvent* pESD,
151 const AliHLTComponentBlockData* blocks,
152 int nBlocks, int* pMinSlice,
153 int* pMaxSlice)
154{
155 // see header file for class documentation
156 int iResult=0;
a978c0d5 157 if (pESD && blocks) {
3cde846d 158 const AliHLTComponentBlockData* iter = NULL;
3cde846d 159 AliHLTTPCTrackletData* inPtr=NULL;
de554e07 160 int bIsTrackSegs=0;
3cde846d 161
37513ae4 162 for (int ndx=0; ndx<nBlocks && iResult>=0; ndx++) {
3cde846d 163 iter = blocks+ndx;
96bda103 164 if ( (bIsTrackSegs=(iter->fDataType == AliHLTTPCDefinitions::fgkTrackSegmentsDataType))==1 ||
165 iter->fDataType == AliHLTTPCDefinitions::fgkTracksDataType ) {
4fdaad1e 166 Int_t minslice=AliHLTTPCDefinitions::GetMinSliceNr(iter->fSpecification);
167 Int_t maxslice=AliHLTTPCDefinitions::GetMaxSliceNr(iter->fSpecification);
de554e07 168 if (bIsTrackSegs==0) {
169 // slice parameter and data specification ignored, tracks already in global coordinates
b09663cd 170 minslice=-1;
171 maxslice=-1;
37513ae4 172 if (pMinSlice) *pMinSlice=0;
173 if (pMaxSlice) *pMaxSlice=AliHLTTPCTransform::GetNSlice()-1;
174 } else {
175 if (pMinSlice && (*pMinSlice==-1 || *pMinSlice>minslice)) *pMinSlice=minslice;
176 if (pMaxSlice && (*pMaxSlice==-1 || *pMaxSlice<maxslice)) *pMaxSlice=maxslice;
de554e07 177 }
4fdaad1e 178 //HLTDebug("dataspec %#x minslice %d", iter->fSpecification, minslice);
37513ae4 179 if (minslice >=-1 && minslice<AliHLTTPCTransform::GetNSlice()) {
4fdaad1e 180 if (minslice!=maxslice) {
181 HLTWarning("data from multiple sectors in one block: "
c5123824 182 "possible mismatch in treatment of local coordinate system");
4fdaad1e 183 }
184 AliHLTTPCTrackArray tracks;
185 inPtr=(AliHLTTPCTrackletData*)iter->fPtr;
186 HLTDebug("reading block %d (slice %d): %d tracklets", ndx, minslice, inPtr->fTrackletCnt);
187 tracks.FillTracks(inPtr->fTrackletCnt, inPtr->fTracklets, minslice, 0/*don't rotate*/);
188 if ((iResult=Tracks2ESD(&tracks, pESD))>=0) {
3cde846d 189 }
190 } else {
4fdaad1e 191 HLTError("invalid sector number");
192 iResult=-EBADF;
3cde846d 193 }
194 }
195 }
a978c0d5 196 if (iResult>=0 && pTree) {
4fdaad1e 197 pTree->Fill();
198 }
3cde846d 199
37513ae4 200 pESD->Reset();
201
202 } else {
203 iResult=-EINVAL;
3cde846d 204 }
205 return iResult;
206}
207
af885e0f 208int AliHLTTPCEsdWriterComponent::Tracks2ESD(AliHLTTPCTrackArray* pTracks, AliESDEvent* pESD)
3cde846d 209{
2a083ac4 210 // see header file for class documentation
3cde846d 211 int iResult=0;
212 if (pTracks && pESD) {
213 HLTDebug("converting %d tracks from track array", pTracks->GetNTracks());
214 for (int i=0; i<pTracks->GetNTracks() && iResult>=0; i++) {
215 AliHLTTPCTrack* pTrack=(*pTracks)[i];
216 if (pTrack) {
04dbc9e4 217 //HLTDebug("convert track %d", i);
218 //pTrack->Print();
3cde846d 219 int iLocal=pTrack->Convert2AliKalmanTrack();
220 if (iLocal>=0) {
221 AliESDtrack iotrack;
222 iotrack.UpdateTrackParams(pTrack,AliESDtrack::kTPCin);
223 iotrack.SetTPCPoints(pTrack->GetPoints());
224 pESD->AddTrack(&iotrack);
225 } else {
226 HLTError("conversion to AliKalmanTrack failed for track %d of %d", i, pTracks->GetNTracks());
227 }
228 } else {
c5123824 229 HLTError("internal mismatch in array");
3cde846d 230 iResult=-EFAULT;
231 }
232 }
233
234 } else {
235 iResult=-EINVAL;
236 }
237 return iResult;
238}
37513ae4 239
240AliHLTTPCEsdWriterComponent::AliConverter::AliConverter()
241 :
a978c0d5 242 fBase(new AliHLTTPCEsdWriterComponent),
243 fWriteTree(1)
37513ae4 244{
245 // see header file for class documentation
246 // or
247 // refer to README to build package
248 // or
249 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
250}
251
252AliHLTTPCEsdWriterComponent::AliConverter::~AliConverter()
253{
254 // see header file for class documentation
255 if (fBase) delete fBase;
256 fBase=NULL;
257}
258
259void AliHLTTPCEsdWriterComponent::AliConverter::GetInputDataTypes(AliHLTComponentDataTypeList& list)
260{
261 // see header file for class documentation
262 list.push_back(AliHLTTPCDefinitions::fgkTrackSegmentsDataType);
8f471af0 263 list.push_back(AliHLTTPCDefinitions::fgkTracksDataType);
37513ae4 264}
265
266AliHLTComponentDataType AliHLTTPCEsdWriterComponent::AliConverter::GetOutputDataType()
267{
268 // see header file for class documentation
269 return kAliHLTDataTypeESDTree;
270}
271
272void AliHLTTPCEsdWriterComponent::AliConverter::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
273{
274 // see header file for class documentation
275 constBase=1000000;
c5123824 276 inputMultiplier=5.0;
37513ae4 277}
278
279int AliHLTTPCEsdWriterComponent::AliConverter::DoInit(int argc, const char** argv)
280{
281 // see header file for class documentation
a978c0d5 282 int iResult=0;
283 TString argument="";
284 int bMissingParam=0;
285 for (int i=0; i<argc && iResult>=0; i++) {
286 argument=argv[i];
287 if (argument.IsNull()) continue;
288
289 // -notree
290 if (argument.CompareTo("-notree")==0) {
291 fWriteTree=0;
292
293 // -tree
294 } else if (argument.CompareTo("-tree")==0) {
295 fWriteTree=1;
296
297 } else {
298 HLTError("unknown argument %s", argument.Data());
299 break;
300 }
301 }
302 if (bMissingParam) {
303 HLTError("missing parameter for argument %s", argument.Data());
304 iResult=-EINVAL;
305 }
306
307 return iResult;
37513ae4 308}
309
310int AliHLTTPCEsdWriterComponent::AliConverter::DoDeinit()
311{
312 // see header file for class documentation
313 return 0;
314}
315
316int AliHLTTPCEsdWriterComponent::AliConverter::DoEvent(const AliHLTComponentEventData& evtData,
317 const AliHLTComponentBlockData* blocks,
318 AliHLTComponentTriggerData& /*trigData*/,
319 AliHLTUInt8_t* /*outputPtr*/,
320 AliHLTUInt32_t& /*size*/,
321 AliHLTComponentBlockDataList& /*outputBlocks*/ )
322{
323 // see header file for class documentation
324 int iResult=0;
325 assert(fBase);
326 AliESDEvent* pESD = new AliESDEvent;
327 if (pESD && fBase) {
328 pESD->CreateStdContent();
a978c0d5 329 TTree* pTree = NULL;
330 // TODO: Matthias 06.12.2007
331 // Tried to write the ESD directly instead to a tree, but this did not work
332 // out. Information in the ESD is different, needs investigation.
333 if (fWriteTree)
334 pTree = new TTree("esdTree", "Tree with HLT ESD objects");
37513ae4 335 if (pTree) {
68f62aaa 336 pTree->SetDirectory(0);
37513ae4 337 pESD->WriteToTree(pTree);
a978c0d5 338 }
37513ae4 339
a978c0d5 340 if ((iResult=fBase->ProcessBlocks(pTree, pESD, blocks, (int)evtData.fBlockCnt))>=0) {
37513ae4 341 // TODO: set the specification correctly
a978c0d5 342 if (pTree)
37513ae4 343 iResult=PushBack(pTree, kAliHLTDataTypeESDTree|kAliHLTDataOriginTPC, 0);
a978c0d5 344 else
345 iResult=PushBack(pESD, kAliHLTDataTypeESDObject|kAliHLTDataOriginTPC, 0);
37513ae4 346 }
a978c0d5 347 if (pTree)
348 delete pTree;
349
37513ae4 350 delete pESD;
351 }
352 return iResult;
353}
354