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