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"
37 #include "AliHLTTPCTrack.h"
38 #include "AliHLTTPCTrackArray.h"
39 #include "AliHLTTPCTrackletDataFormat.h"
40 #include "AliHLTTPCDefinitions.h"
41 #include "AliHLTTPCTransform.h"
43 /** ROOT macro for the implementation of ROOT specific class methods */
44 ClassImp(AliHLTTPCEsdWriterComponent)
46 AliHLTTPCEsdWriterComponent::AliHLTTPCEsdWriterComponent()
48 // see header file for class documentation
50 // refer to README to build package
52 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
55 AliHLTTPCEsdWriterComponent::~AliHLTTPCEsdWriterComponent()
57 // see header file for class documentation
60 AliHLTTPCEsdWriterComponent::AliWriter::AliWriter()
64 fBase(new AliHLTTPCEsdWriterComponent)
66 // see header file for class documentation
68 // refer to README to build package
70 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
73 AliHLTTPCEsdWriterComponent::AliWriter::~AliWriter()
75 // see header file for class documentation
76 if (fBase) delete fBase;
80 void AliHLTTPCEsdWriterComponent::AliWriter::GetInputDataTypes(AliHLTComponentDataTypeList& list)
82 // see header file for class documentation
83 list.push_back(AliHLTTPCDefinitions::fgkTrackSegmentsDataType);
86 int AliHLTTPCEsdWriterComponent::AliWriter::InitWriter()
88 // see header file for class documentation
90 fESD = new AliESDEvent;
92 fESD->CreateStdContent();
93 fTree = new TTree("esdTree", "Tree with HLT ESD objects");
95 fTree->SetDirectory(0);
96 fESD->WriteToTree(fTree);
105 int AliHLTTPCEsdWriterComponent::AliWriter::CloseWriter()
107 // see header file for class documentation
110 WriteObject(kAliHLTVoidEventID, fTree);
115 HLTWarning("not initialized");
117 iResult=AliHLTRootFileWriterComponent::CloseWriter();
121 int AliHLTTPCEsdWriterComponent::AliWriter::DumpEvent( const AliHLTComponentEventData& evtData,
122 const AliHLTComponentBlockData* blocks,
123 AliHLTComponentTriggerData& /*trigData*/ )
125 // see header file for class documentation
129 if (pTree && fBase) {
131 AliESDEvent* pESD=fESD;
133 iResult=fBase->ProcessBlocks(pTree, pESD, blocks, (int)evtData.fBlockCnt);
142 int AliHLTTPCEsdWriterComponent::AliWriter::ScanArgument(int argc, const char** argv)
144 // see header file for class documentation
145 int iResult=AliHLTRootFileWriterComponent::ScanArgument(argc, argv);
149 int AliHLTTPCEsdWriterComponent::ProcessBlocks(TTree* pTree, AliESDEvent* pESD,
150 const AliHLTComponentBlockData* blocks,
151 int nBlocks, int* pMinSlice,
154 // see header file for class documentation
156 if (pESD && blocks) {
157 const AliHLTComponentBlockData* iter = NULL;
158 AliHLTTPCTrackletData* inPtr=NULL;
161 for (int ndx=0; ndx<nBlocks && iResult>=0; ndx++) {
163 if ( (bIsTrackSegs=(iter->fDataType == AliHLTTPCDefinitions::fgkTrackSegmentsDataType))==1 ||
164 iter->fDataType == AliHLTTPCDefinitions::fgkTracksDataType ) {
165 Int_t minslice=AliHLTTPCDefinitions::GetMinSliceNr(iter->fSpecification);
166 Int_t maxslice=AliHLTTPCDefinitions::GetMaxSliceNr(iter->fSpecification);
167 if (bIsTrackSegs==0) {
168 // slice parameter and data specification ignored, tracks already in global coordinates
171 if (pMinSlice) *pMinSlice=0;
172 if (pMaxSlice) *pMaxSlice=AliHLTTPCTransform::GetNSlice()-1;
174 if (pMinSlice && (*pMinSlice==-1 || *pMinSlice>minslice)) *pMinSlice=minslice;
175 if (pMaxSlice && (*pMaxSlice==-1 || *pMaxSlice<maxslice)) *pMaxSlice=maxslice;
177 //HLTDebug("dataspec %#x minslice %d", iter->fSpecification, minslice);
178 if (minslice >=-1 && minslice<AliHLTTPCTransform::GetNSlice()) {
179 if (minslice!=maxslice) {
180 HLTWarning("data from multiple sectors in one block: "
181 "possible missmatch in treatment of local coordinate system");
183 AliHLTTPCTrackArray tracks;
184 inPtr=(AliHLTTPCTrackletData*)iter->fPtr;
185 HLTDebug("reading block %d (slice %d): %d tracklets", ndx, minslice, inPtr->fTrackletCnt);
186 tracks.FillTracks(inPtr->fTrackletCnt, inPtr->fTracklets, minslice, 0/*don't rotate*/);
187 if ((iResult=Tracks2ESD(&tracks, pESD))>=0) {
190 HLTError("invalid sector number");
195 if (iResult>=0 && pTree) {
207 int AliHLTTPCEsdWriterComponent::Tracks2ESD(AliHLTTPCTrackArray* pTracks, AliESDEvent* pESD)
209 // see header file for class documentation
211 if (pTracks && pESD) {
212 HLTDebug("converting %d tracks from track array", pTracks->GetNTracks());
213 for (int i=0; i<pTracks->GetNTracks() && iResult>=0; i++) {
214 AliHLTTPCTrack* pTrack=(*pTracks)[i];
216 //HLTDebug("convert track %d", i);
218 int iLocal=pTrack->Convert2AliKalmanTrack();
221 iotrack.UpdateTrackParams(pTrack,AliESDtrack::kTPCin);
222 iotrack.SetTPCPoints(pTrack->GetPoints());
223 pESD->AddTrack(&iotrack);
225 HLTError("conversion to AliKalmanTrack failed for track %d of %d", i, pTracks->GetNTracks());
228 HLTError("internal missmatch in array");
239 AliHLTTPCEsdWriterComponent::AliConverter::AliConverter()
241 fBase(new AliHLTTPCEsdWriterComponent),
244 // see header file for class documentation
246 // refer to README to build package
248 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
251 AliHLTTPCEsdWriterComponent::AliConverter::~AliConverter()
253 // see header file for class documentation
254 if (fBase) delete fBase;
258 void AliHLTTPCEsdWriterComponent::AliConverter::GetInputDataTypes(AliHLTComponentDataTypeList& list)
260 // see header file for class documentation
261 list.push_back(AliHLTTPCDefinitions::fgkTrackSegmentsDataType);
264 AliHLTComponentDataType AliHLTTPCEsdWriterComponent::AliConverter::GetOutputDataType()
266 // see header file for class documentation
267 return kAliHLTDataTypeESDTree;
270 void AliHLTTPCEsdWriterComponent::AliConverter::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
272 // see header file for class documentation
277 int AliHLTTPCEsdWriterComponent::AliConverter::DoInit(int argc, const char** argv)
279 // see header file for class documentation
283 for (int i=0; i<argc && iResult>=0; i++) {
285 if (argument.IsNull()) continue;
288 if (argument.CompareTo("-notree")==0) {
292 } else if (argument.CompareTo("-tree")==0) {
296 HLTError("unknown argument %s", argument.Data());
301 HLTError("missing parameter for argument %s", argument.Data());
308 int AliHLTTPCEsdWriterComponent::AliConverter::DoDeinit()
310 // see header file for class documentation
314 int AliHLTTPCEsdWriterComponent::AliConverter::DoEvent(const AliHLTComponentEventData& evtData,
315 const AliHLTComponentBlockData* blocks,
316 AliHLTComponentTriggerData& /*trigData*/,
317 AliHLTUInt8_t* /*outputPtr*/,
318 AliHLTUInt32_t& /*size*/,
319 AliHLTComponentBlockDataList& /*outputBlocks*/ )
321 // see header file for class documentation
324 AliESDEvent* pESD = new AliESDEvent;
326 pESD->CreateStdContent();
328 // TODO: Matthias 06.12.2007
329 // Tried to write the ESD directly instead to a tree, but this did not work
330 // out. Information in the ESD is different, needs investigation.
332 pTree = new TTree("esdTree", "Tree with HLT ESD objects");
334 pTree->SetDirectory(0);
335 pESD->WriteToTree(pTree);
338 if ((iResult=fBase->ProcessBlocks(pTree, pESD, blocks, (int)evtData.fBlockCnt))>=0) {
339 // TODO: set the specification correctly
341 iResult=PushBack(pTree, kAliHLTDataTypeESDTree|kAliHLTDataOriginTPC, 0);
343 iResult=PushBack(pESD, kAliHLTDataTypeESDObject|kAliHLTDataOriginTPC, 0);