3 //**************************************************************************
4 //* This file is property of and copyright by the ALICE HLT Project *
5 //* ALICE Experiment at CERN, All rights reserved. *
7 //* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 //* for The ALICE HLT Project. *
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 //**************************************************************************
19 /** @file AliHLTTPCEsdWriterComponent.cxx
20 @author Matthias Richter
22 @brief Writer component to store tracks of the HLT TPC conformal
23 mapping tracker in the AliESD format
26 // see header file for class documentation
28 // refer to README to build package
30 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
33 #include "AliHLTTPCEsdWriterComponent.h"
34 #include "AliESDEvent.h"
35 #include "AliESDtrack.h"
38 #include "AliHLTTPCTrack.h"
39 #include "AliHLTTPCTrackArray.h"
40 #include "AliHLTTPCTrackletDataFormat.h"
41 #include "AliHLTTPCDefinitions.h"
42 #include "AliHLTTPCTransform.h"
44 /** ROOT macro for the implementation of ROOT specific class methods */
45 ClassImp(AliHLTTPCEsdWriterComponent)
47 AliHLTTPCEsdWriterComponent::AliHLTTPCEsdWriterComponent()
49 // see header file for class documentation
51 // refer to README to build package
53 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
56 AliHLTTPCEsdWriterComponent::~AliHLTTPCEsdWriterComponent()
58 // see header file for class documentation
61 AliHLTTPCEsdWriterComponent::AliWriter::AliWriter()
65 fBase(new AliHLTTPCEsdWriterComponent)
67 // see header file for class documentation
69 // refer to README to build package
71 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
74 AliHLTTPCEsdWriterComponent::AliWriter::~AliWriter()
76 // see header file for class documentation
77 if (fBase) delete fBase;
81 void AliHLTTPCEsdWriterComponent::AliWriter::GetInputDataTypes(AliHLTComponentDataTypeList& list)
83 // see header file for class documentation
84 list.push_back(AliHLTTPCDefinitions::fgkTrackSegmentsDataType);
85 list.push_back(AliHLTTPCDefinitions::fgkTracksDataType);
88 int AliHLTTPCEsdWriterComponent::AliWriter::InitWriter()
90 // see header file for class documentation
92 fESD = new AliESDEvent;
94 fESD->CreateStdContent();
95 fTree = new TTree("esdTree", "Tree with HLT ESD objects");
97 fTree->SetDirectory(0);
98 fESD->WriteToTree(fTree);
107 int AliHLTTPCEsdWriterComponent::AliWriter::CloseWriter()
109 // see header file for class documentation
112 // the esd structure is written to the user info and is
113 // needed in te ReadFromTree method to read all objects correctly
114 if (fESD) fTree->GetUserInfo()->Add(fESD);
115 WriteObject(kAliHLTVoidEventID, fTree);
116 fTree->GetUserInfo()->Clear();
121 HLTWarning("not initialized");
127 iResult=AliHLTRootFileWriterComponent::CloseWriter();
131 int AliHLTTPCEsdWriterComponent::AliWriter::DumpEvent( const AliHLTComponentEventData& evtData,
132 const AliHLTComponentBlockData* blocks,
133 AliHLTComponentTriggerData& /*trigData*/ )
135 // see header file for class documentation
139 if (pTree && fBase) {
141 AliESDEvent* pESD=fESD;
143 iResult=fBase->ProcessBlocks(pTree, pESD, blocks, (int)evtData.fBlockCnt);
152 int AliHLTTPCEsdWriterComponent::AliWriter::ScanArgument(int argc, const char** argv)
154 // see header file for class documentation
155 int iResult=AliHLTRootFileWriterComponent::ScanArgument(argc, argv);
159 int AliHLTTPCEsdWriterComponent::ProcessBlocks(TTree* pTree, AliESDEvent* pESD,
160 const AliHLTComponentBlockData* blocks,
161 int nBlocks, int* pMinSlice,
164 // see header file for class documentation
166 if (pESD && blocks) {
167 const AliHLTComponentBlockData* iter = NULL;
168 AliHLTTPCTrackletData* inPtr=NULL;
171 for (int ndx=0; ndx<nBlocks && iResult>=0; ndx++) {
173 if ( (bIsTrackSegs=(iter->fDataType == AliHLTTPCDefinitions::fgkTrackSegmentsDataType))==1 ||
174 iter->fDataType == AliHLTTPCDefinitions::fgkTracksDataType ) {
175 Int_t minslice=AliHLTTPCDefinitions::GetMinSliceNr(iter->fSpecification);
176 Int_t maxslice=AliHLTTPCDefinitions::GetMaxSliceNr(iter->fSpecification);
177 if (bIsTrackSegs==0) {
178 // slice parameter and data specification ignored, tracks already in global coordinates
181 if (pMinSlice) *pMinSlice=0;
182 if (pMaxSlice) *pMaxSlice=AliHLTTPCTransform::GetNSlice()-1;
184 if (pMinSlice && (*pMinSlice==-1 || *pMinSlice>minslice)) *pMinSlice=minslice;
185 if (pMaxSlice && (*pMaxSlice==-1 || *pMaxSlice<maxslice)) *pMaxSlice=maxslice;
187 //HLTDebug("dataspec %#x minslice %d", iter->fSpecification, minslice);
188 if (minslice >=-1 && minslice<AliHLTTPCTransform::GetNSlice()) {
189 if (minslice!=maxslice) {
190 HLTWarning("data from multiple sectors in one block: "
191 "possible mismatch in treatment of local coordinate system");
193 AliHLTTPCTrackArray tracks;
194 inPtr=(AliHLTTPCTrackletData*)iter->fPtr;
195 HLTDebug("reading block %d (slice %d): %d tracklets", ndx, minslice, inPtr->fTrackletCnt);
196 tracks.FillTracks(inPtr->fTrackletCnt, inPtr->fTracklets, minslice, 0/*don't rotate*/);
197 if ((iResult=Tracks2ESD(&tracks, pESD))>=0) {
200 HLTError("invalid sector number");
205 if (iResult>=0 && pTree) {
217 int AliHLTTPCEsdWriterComponent::Tracks2ESD(AliHLTTPCTrackArray* pTracks, AliESDEvent* pESD)
219 // see header file for class documentation
221 if (pTracks && pESD) {
222 HLTDebug("converting %d tracks from track array", pTracks->GetNTracks());
223 for (int i=0; i<pTracks->GetNTracks() && iResult>=0; i++) {
224 AliHLTTPCTrack* pTrack=(*pTracks)[i];
226 //HLTDebug("convert track %d", i);
228 int iLocal=pTrack->Convert2AliKalmanTrack();
231 iotrack.UpdateTrackParams(pTrack,AliESDtrack::kTPCin);
232 iotrack.SetTPCPoints(pTrack->GetPoints());
233 pESD->AddTrack(&iotrack);
235 HLTError("conversion to AliKalmanTrack failed for track %d of %d", i, pTracks->GetNTracks());
238 HLTError("internal mismatch in array");
249 AliHLTTPCEsdWriterComponent::AliConverter::AliConverter()
251 fBase(new AliHLTTPCEsdWriterComponent),
254 // see header file for class documentation
256 // refer to README to build package
258 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
261 AliHLTTPCEsdWriterComponent::AliConverter::~AliConverter()
263 // see header file for class documentation
264 if (fBase) delete fBase;
268 void AliHLTTPCEsdWriterComponent::AliConverter::GetInputDataTypes(AliHLTComponentDataTypeList& list)
270 // see header file for class documentation
271 list.push_back(AliHLTTPCDefinitions::fgkTrackSegmentsDataType);
272 list.push_back(AliHLTTPCDefinitions::fgkTracksDataType);
275 AliHLTComponentDataType AliHLTTPCEsdWriterComponent::AliConverter::GetOutputDataType()
277 // see header file for class documentation
278 return kAliHLTDataTypeESDTree;
281 void AliHLTTPCEsdWriterComponent::AliConverter::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
283 // see header file for class documentation
285 inputMultiplier=10.0;
288 int AliHLTTPCEsdWriterComponent::AliConverter::DoInit(int argc, const char** argv)
290 // see header file for class documentation
294 for (int i=0; i<argc && iResult>=0; i++) {
296 if (argument.IsNull()) continue;
299 if (argument.CompareTo("-notree")==0) {
303 } else if (argument.CompareTo("-tree")==0) {
307 HLTError("unknown argument %s", argument.Data());
312 HLTError("missing parameter for argument %s", argument.Data());
319 int AliHLTTPCEsdWriterComponent::AliConverter::DoDeinit()
321 // see header file for class documentation
325 int AliHLTTPCEsdWriterComponent::AliConverter::DoEvent(const AliHLTComponentEventData& evtData,
326 const AliHLTComponentBlockData* blocks,
327 AliHLTComponentTriggerData& /*trigData*/,
328 AliHLTUInt8_t* /*outputPtr*/,
329 AliHLTUInt32_t& /*size*/,
330 AliHLTComponentBlockDataList& /*outputBlocks*/ )
332 // see header file for class documentation
335 AliESDEvent* pESD = new AliESDEvent;
337 pESD->CreateStdContent();
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.
343 pTree = new TTree("esdTree", "Tree with HLT ESD objects");
345 pTree->SetDirectory(0);
346 pESD->WriteToTree(pTree);
349 if ((iResult=fBase->ProcessBlocks(pTree, pESD, blocks, (int)evtData.fBlockCnt))>=0) {
350 // TODO: set the specification correctly
352 // the esd structure is written to the user info and is
353 // needed in te ReadFromTree method to read all objects correctly
354 pTree->GetUserInfo()->Add(pESD);
355 iResult=PushBack(pTree, kAliHLTDataTypeESDTree|kAliHLTDataOriginTPC, 0);
357 iResult=PushBack(pESD, kAliHLTDataTypeESDObject|kAliHLTDataOriginTPC, 0);
361 // clear user info list to prevent objects from being deleted
362 pTree->GetUserInfo()->Clear();